Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [HTML][PHP]Open Flash Charts 2 i Drupal - konfiguracja, Problem z wykresem kołowym.
marcowy
post 7.07.2012, 18:39:32
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 2.11.2011

Ostrzeżenie: (0%)
-----


Witam,

Mam problem z którym męczę się od dłuższego czasu i pomyślałem, że może ktoś z tego forum mógłby mi pomóc. smile.gif

Otóż - robię stronę w Drupalu na której mają pojawiać się wykresy. Moduł który je obsługuje nazywa się Charts and Graphs i wykorzystuje w tym celu Open Flash Chart 2. Generalnie wszystko działa z wyjątkiem rzeczy dla mnie najważniejszej... czyli wykresów kołowych. Problem jest w wyświetlaniu, które wygląda o tak. Przyczyna tego leży w zbyt długich nazwach, które w połączeniu z autoskalowaniem i niewialką ilością miejsca na wykres dają efekt jak wyżej. Zależy mi, aby nazwy były wyświetlane tylko i wyłącznie w tooltip, tak jak tutaj. Tyle tytułem wstępu...

Jak udało mi się wyczytać pod tym adresem tym adresem, rozwiązaniem problemu jest wprowadzenie do kodu modułu dwóch linijek (!):

  1. $pie->set_tooltip( '#label#<br>$#val# (#percent#)' );
  2. $pie->set_no_labels();


Niestety nie znam się na PHP i chociaż próbowałem to zrobić metodą "wklej na czuja - może zadziała" - odniosłem porażkę. A właściwie - kilkadziesiąt porażek. Poniżej wklejam kod pliku charts_graphs_open_flash.class.inc, który, jak wierzę, używany jest przez moduł Charts and Graphs do komunikacji z Open Flash Chart 2. Pomożecie?

  1. <?php
  2.  
  3. /**
  4.  * @file
  5.  * Implementation of abstract class ChartsGraphsFlashCanvas for Open Charts
  6.  * Flash 2 library.
  7.  *
  8.  */
  9.  
  10. require_once dirname(__FILE__) . '/../../charts_graphs_flash_canvas.class.inc';
  11.  
  12. /**
  13.  * Implementation of abstract class ChartsGraphsFlashCanvas for Open Charts
  14.  * Flash 2 library.
  15.  */
  16. class ChartsGraphsOpenFlash extends ChartsGraphsFlashCanvas {
  17.  
  18. /**
  19.   * Holds the type definition translated to Open Charts Flash 2 types.
  20.   *
  21.   * @var <string>
  22.   */
  23. var $translated_type;
  24.  
  25. /**
  26.   * @param $cid
  27.   * cache_id from which cache to retrieve the data
  28.   */
  29. function get_data_from_cache($cid = NULL) {
  30. $cache = cache_get($cid);
  31. if (!$cache) {
  32. drupal_not_found();
  33. exit();
  34. }
  35. $canvas = $cache->data;
  36.  
  37. if (empty($canvas) || !is_object($canvas) ||
  38. !is_array($canvas->series) || empty($canvas->type)) {
  39. drupal_not_found();
  40. exit();
  41. }
  42.  
  43. $this->title = new stdClass();
  44. $this->title->text = $canvas->title;
  45. $this->title->style = 'font-size: 20px; color:#0000ff; font-family: Verdana; text-align: center;';
  46.  
  47. $this->type = $canvas->translated_type;
  48.  
  49. $is_pie = ($this->type === 'pie');
  50.  
  51. $this->y_legend = new stdClass();
  52. $this->y_legend->text = $canvas->y_legend;
  53. $this->y_legend->style = '{color: #736AFF; font-size: 12px;}';
  54.  
  55. /**
  56.   * Applying background colour setting if available.
  57.   */
  58. if (isset($canvas->colour) && !empty($canvas->colour)) {
  59. $this->bg_colour = $canvas->colour;
  60. }
  61.  
  62. $y = new stdClass();
  63. $y->grid_colour = '#00ff00';
  64. $y->offset = 50;
  65. $this->y_axis = $y;
  66.  
  67. $x = new stdClass();
  68. $x->colour = '#909090';
  69. $x->grid_colour = '#00ff00';
  70.  
  71. /**
  72.   * Some kind of bug: if labels are not PHP "strings" they do not render.
  73.   * Sigh.
  74.   *
  75.   * Seizing the oportunity and also fixing x_labels arrays whoose keys aren't
  76.   * numeric: 0, 1, 2 etc.
  77.   */
  78. $x_labels = array();
  79. foreach ($canvas->x_labels as $key => $label) {
  80. $x_labels[] = (string) $label;
  81. }
  82.  
  83. $x->labels->labels = $x_labels;
  84. $this->x_axis = $x;
  85.  
  86. $series_colours = array_values($canvas->series_colours);
  87.  
  88. /**
  89.   * Initializing $min and $max.
  90.   */
  91. $val = reset($canvas->series);
  92. $max_value = reset($val);
  93. $min_value = $max_value;
  94.  
  95. $i = 0; // for colours
  96. foreach ($canvas->series as $key => $val) {
  97. if ($is_pie && ($i > 0)) {
  98. break;
  99. }
  100. $obj = new stdClass();
  101. $val = $this->_preprocess_values($val);
  102. $obj->values = $val;
  103. if ($is_pie) {
  104. $obj->tip = '#label# #val# zl (#percent#)';
  105. $obj->{'label - colour'} = '#432BAF';
  106. }
  107. else {
  108. $max_value_arr = max($val);
  109. if ($max_value < $max_value_arr) {
  110. $max_value = $max_value_arr;
  111. }
  112. $min_value_arr = min($val);
  113. if ($min_value > $min_value_arr) {
  114. $min_value = $min_value_arr;
  115. }
  116. }
  117. $obj->text = $key;
  118. $obj->alpha = .5;
  119. $obj->type = $canvas->type;
  120. $obj->colour = $series_colours[$i];
  121. $this->elements[] = $obj;
  122. $i++;
  123. }
  124.  
  125. if (!$is_pie) {
  126. $y_step = abs(($max_value - $min_value) / 10);
  127.  
  128. $this->x_axis->{'3d'} = 5;
  129. $this->y_axis->max = $max_value + $max_value / 10;
  130. if ($this->y_axis->max > 10) {
  131. $this->y_axis->max = (int) $this->y_axis->max;
  132. }
  133. $this->y_axis->min = $min_value;
  134. if ($y_step > 5) {
  135. $y_step = (int) $y_step;
  136. }
  137. $this->y_axis->steps = $y_step;
  138.  
  139. /**
  140.   * Applying user defined min, max and step for y axis values.
  141.   */
  142. if (isset($canvas->y_min)) {
  143. $this->y_axis->min = $canvas->y_min;
  144. }
  145. if (isset($canvas->y_max)) {
  146. $this->y_axis->max = $canvas->y_max;
  147. }
  148. if (isset($canvas->y_step)) {
  149. $this->y_axis->steps = $canvas->y_step;
  150. }
  151. }
  152. }
  153.  
  154. /**
  155.   * Pie-chart has different format for $values array than bar chart etc.
  156.   * This method deals with permutations across chart types. Sigh.
  157.   *
  158.   * We also remove items with no label, while we are at it, since
  159.   * those can cause problems to Flash renderer.
  160.   */
  161. function _preprocess_values($values) {
  162. $labels = $this->x_axis->labels->labels;
  163. $i = 0;
  164.  
  165. $series_colours = array_values($this->series_colours());
  166.  
  167. switch ($this->type) {
  168. case 'pie':
  169. $new_vals = array();
  170. foreach ($values as $val) {
  171. // An accidental empty label causes SWF to go nuts.
  172. if (!empty($labels[$i]) && ($labels[$i] != 'null')) {
  173. $obj = new stdClass();
  174. $obj->value = $val;
  175. $obj->label = $labels[$i];
  176. $obj->colour = $series_colours[$i];
  177. $new_vals[] = $obj;
  178. }
  179. $i++;
  180. }
  181. return $new_vals;
  182.  
  183. /**
  184.   * Default action is just filtering values with nulled labels (leftovers
  185.   * from out joins).
  186.   */
  187. default:
  188. $new_vals = array();
  189. $new_labels = array();
  190. foreach ($values as $val) {
  191. // An accidental empty label causes SWF to go nuts.
  192. if (!empty($labels[$i]) && ($labels[$i] != 'null')) {
  193. $new_vals[] = $val;
  194. $new_labels[] = $labels[$i];
  195. }
  196. $i++;
  197. }
  198. $this->x_axis->labels->labels = $new_labels;
  199. return $new_vals;
  200. }
  201. }
  202.  
  203. /**
  204.   * Translate Charts and Graphs graph type to Open Charts Flash 2 types.
  205.   *
  206.   * It currently doesn't nothing of value but will leave it here in case some
  207.   * brave soul decides to implement horizontal bar or area or some other graph
  208.   * type.
  209.   *
  210.   * @return <string>
  211.   */
  212. protected function _get_translated_chart_type() {
  213. switch ($this->type) {
  214. default:
  215. $type = $this->type;
  216. }
  217.  
  218. return $type;
  219. }
  220.  
  221. /**
  222.   * Function that renders data.
  223.   */
  224. function get_chart() {
  225. global $base_url;
  226. $unique = charts_graphs_random_hash();
  227.  
  228. // Make current object a StdClass() for easier de-serialization
  229. $this->translated_type = $this->_get_translated_chart_type();
  230. $arr = (array) $this;
  231. $generic = (object) $arr;
  232.  
  233. //Keep for at least 30 seconds;
  234. cache_set($unique, $generic, 'cache', time() + 30);
  235.  
  236. $mod_path = drupal_get_path('module', $this->getModuleName());
  237. $openflash_swf_uri = $base_url . '/' . $mod_path . '/open-flash-chart.swf';
  238.  
  239. $data_URL = url('charts_graphs_open_flash/data/' . $unique, array('absolute' => TRUE));
  240.  
  241. /** For debugging
  242.   * $ret = drupal_http_request( $data_URL );
  243.   * echo "<pre>".print_r ( $ret,true)."</pre>";
  244.   * exit();
  245.   * */
  246. $wmode = $this->get_wmode();
  247.  
  248. $flashvars = array(
  249. 'data-file' => 'SWFDATAURL',
  250. 'preloader_color' => '#999999',
  251. 'wmode' => $wmode);
  252.  
  253. $args = array(
  254. 'params' => array(
  255. 'width' => $this->width,
  256. 'height' => $this->height,
  257. 'wmode' => $wmode
  258. ),
  259. 'flashvars' => $flashvars
  260. );
  261.  
  262. $out = swf($openflash_swf_uri, $args);
  263. $out = str_replace('SWFDATAURL', $data_URL, $out);
  264.  
  265. return $out;
  266. }
  267. }


Ps: Wybaczcie mało profesjonalny język, ale starałem się nakreślić tyle ile tylko zrozumiałem.
Ps2: Będę bardzo wdzięczny za pomoc.

Nie ma nadziei, prawda?
Go to the top of the page
+Quote Post
CuteOne
post 7.07.2012, 18:57:18
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

Ostrzeżenie: (0%)
-----


Jest nadzieja smile.gif wybierz się do działu Giełda ofert i załóż tam temat z opisem czego potrzebujesz. Tutaj pomagamy rozwiązywać problemy/błędy a nie tworzyć coś za Ciebie bo ty "nie znasz się na PHP"

Pozdrawiam
Go to the top of the page
+Quote Post
marcowy
post 7.07.2012, 19:30:02
Post #3





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 2.11.2011

Ostrzeżenie: (0%)
-----


Właśnie dlatego mam problem, że nie wiem jak coś zrobić. wink.gif Ale OK - jeśli ktoś jest zainteresowany - zapraszam do działu zleceń.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 20:41