PEEL Shopping
Open source ecommerce : PEEL Shopping
advisto-chart.php
Go to the documentation of this file.
1 <?php
2 // This file should be in UTF8 without BOM - Accents examples: éèê
3 // +----------------------------------------------------------------------+
4 // | Copyright (c) 2004-2015 Advisto SAS, service PEEL - contact@peel.fr |
5 // +----------------------------------------------------------------------+
6 // | This file is part of PEEL Shopping 8.0.0, which is subject to an |
7 // | opensource GPL license: you are allowed to customize the code |
8 // | for your own needs, but must keep your changes under GPL |
9 // | More information: https://www.peel.fr/lire/licence-gpl-70.html |
10 // +----------------------------------------------------------------------+
11 // | Author: Advisto SAS, RCS 479 205 452, France, https://www.peel.fr/ |
12 // +----------------------------------------------------------------------+
13 // $Id: advisto-chart.php 46935 2015-09-18 08:49:48Z gboussin $
14 
15 if (!defined('IN_PEEL')) {
16  die();
17 }
18 
19 if(vb($GLOBALS['site_parameters']['chart_product']) == 'plot') {
20  require($GLOBALS['dirroot'] . '/modules/chart/plot.php');
21 } else {
22  require($GLOBALS['dirroot'] . '/modules/chart/open-flash-chart.php');
23 }
24 
37 function advistoChart(&$data, $title = null, $all_graph_type = null, $graph_type = array(), $colors = array(), $legend_font_size = 12, $width = 300, $force_chart_product = null)
38 {
39  if(empty($width)){
40  $width=300;
41  }
42  if(!empty($force_chart_product)) {
43  $chart_product = $force_chart_product;
44  } else {
45  $chart_product = vb($GLOBALS['site_parameters']['chart_product']);
46  }
47  // use the chart class to build the chart:
48  if($chart_product == 'flot') {
49  $output = '';
50  } else {
51  $graph = new graph();
52  $graph->title((str_replace(array(',', '&'), array('.', '-'), $title)), '{font-size:12px; padding:5px}');
53  if (!empty($all_graph_type) && $all_graph_type == 'pie') {
54  $graph->pie(80, '0x505050', '{font-size: ' . $legend_font_size . 'px; color: #404040;}');
55  }
56  }
57  if (!empty($data)) {
58  $max_all_data = 0;
59  $min_all_data = 0;
60  $temp = array_keys($data);
61  foreach($temp as $key) {
62  // On va remplacer le $key par sa valeur UTF8 et sans virgule
63  $value = $data[$key];
64  if (str_replace(array(',', '&'), array('.', '-'), ($key)) != $key) {
65  unset($data[$key]);
66  $key = str_replace(array(',', '&'), array('.', '-'), ($key));
67  }
68  if (!empty($value) && !is_array($value) && (!isset($data[$key]) || strpos($value, ',') !== false)) {
69  // Si on est en locale settings qui font que la décimale est séparée par une virgule et non un point
70  $data[$key] = str_replace(array(',', '&'), array('.', '-'), $value);
71  } elseif (!isset($data[$key])) {
72  $data[$key] = $value;
73  }
74  }
75  $temp = array_keys($graph_type);
76  foreach($temp as $key) {
77  // On va remplacer le $key par sa valeur UTF8 et sans virgule
78  $value = $graph_type[$key];
79  if (($key) != $key) {
80  unset($graph_type[$key]);
81  $graph_type[($key)] = $value;
82  }
83  }
84  if (!empty($all_graph_type) && $all_graph_type == 'pie') {
85  arsort($data);
86  $total = array_sum($data);
87  foreach($data as $key => $value) {
88  if ($key != 'Autre') {
89  $data[$key] = round($value / $total * 100 * 100) / 100;
90  if (empty($data[$key]) || $data[$key] < 1) {
91  if (empty($data['Autre'])) {
92  $data['Autre'] = 0;
93  }
94  $data['Autre'] += $data[$key];
95  unset($data[$key]);
96  }
97  }
98  }
99  if(!empty($graph)) {
100  $graph->set_tool_tip('#x_label#<br>#val#%');
101  }
102  } else {
103  if(!empty($graph)) {
104  $graph->set_tool_tip('#key#<br>#x_label#<br>#val#');
105  }
106  }
107  foreach($data as $data_title => $data_array) {
108  if (empty($all_graph_type) || $all_graph_type != 'pie') {
109  if (!empty($data_array)) {
110  foreach($data_array as $value) {
111  $value = floatval($value);
112  if ($value > $max_all_data) {
113  $max_all_data = $value;
114  }
115  }
116  }
117  if (!empty($data_array)) {
118  foreach($data_array as $value) {
119  $value = floatval($value);
120  if ($value < $min_all_data) {
121  $min_all_data = $value;
122  }
123  }
124  }
125  }
126  if (!empty($colors[($data_title)])) {
127  $color = $colors[($data_title)];
128  } elseif ($data_title == 'FALSE') {
129  $color = 'FF0000';
130  } elseif ($data_title == 'TRUE') {
131  $color = '009900';
132  } elseif ($data_title == 'DESACTIVATED') {
133  $color = '999977';
134  } elseif ($data_title == 'F') {
135  $color = 'FF00CC';
136  } elseif ($data_title == 'H') {
137  $color = '0000FF';
138  } else {
139  $r = base_convert(base_convert(String::substr(md5($data_title), 0, 4), 16, 10) % 15, 10, 16);
140  $g = base_convert(base_convert(String::substr(md5($data_title), 5, 4), 16, 10) % 15, 10, 16);
141  $b = base_convert(base_convert(String::substr(md5($data_title), 9, 4), 16, 10) % 15, 10, 16);
142  $color = String::strtoupper($r . '0' . $g . '0' . $b . '0');
143  }
144  if (!empty($graph_type[$data_title]) && $graph_type[$data_title] == 'bar') {
145  if($chart_product == 'flot') {
146  $i=0;
147  foreach($data_array as $x => $y) {
148  $bar_data[] = array($x, $y);
149  $i++;
150  }
151  $output .= json_encode($bar_data);
152  } else {
153  $graph->set_data($data_array);
154  $graph->bar(80, '0x' . $color, $data_title);
155  }
156  } elseif (!empty($graph_type[$data_title]) && $graph_type[$data_title] == 'dot') {
157  if($chart_product == 'flot') {
158  $output .= json_encode($points_data_array);
159  } else {
160  $i=0;
161  foreach($data_array as $x => $y) {
162  $points_data_array[] = new point($i, round($y), 6);
163  $i++;
164  }
165  $graph->scatter($points_data_array, 2, '#' . $color, $data_title, 10);
166  unset($points_data_array);
167  }
168  } elseif (!empty($all_graph_type) && $all_graph_type == 'pie') {
169  $pie_slice_colours[] = '#' . $color;
170  } elseif (!empty($graph_type[$data_title]) && $graph_type[$data_title] == 'line') {
171  if($chart_product == 'flot') {
172  $output .= json_encode($data_array);
173  } else {
174  $graph->set_data($data_array);
175  $graph->line(2, '0x' . $color, $data_title, 10);
176  }
177  } else {
178  // Par défaut line_dot
179  if($chart_product == 'flot') {
180  ksort($data_array);
181  $i=0;
182  foreach($data_array as $x => $y) {
183  $line_data[] = array($x, $y);
184  $i++;
185  }
186  $output .= json_encode($line_data);
187  } else {
188  $graph->set_data($data_array);
189  $graph->line_dot(2, 4, '0x' . $color, $data_title, 10);
190  }
191  }
192  if ((empty($graph_type[$data_title]) || $graph_type[$data_title] !== 'dot') && (empty($all_graph_type) || $all_graph_type !== 'pie')) {
193  $x_array = array_keys($data_array);
194  }
195  }
196  if (empty($all_graph_type) || $all_graph_type != 'pie') {
197  $max_y = round($max_all_data);
198  if (!empty($min_all_data)) {
199  $max_y = $max_y * 1.2;
200  }
201  if ($max_y > 0) {
202  $max_y_base = pow(10, floor(log10(abs($max_y)))-1);
203  $max_y = round($max_y / $max_y_base) * $max_y_base;
204  }
205  $min_y = round($min_all_data * 1.2);
206  if (!empty($min_y)) {
207  $min_y_base = pow(10, floor(log10(abs($min_y)))-1);
208  $min_y = round($min_y / $min_y_base) * $min_y_base;
209  }
210  // On essaie de trouver min_y qui permette d'avoir 0 qui tomnbe juste sur une des 10 numérations de y
211  if (!empty($min_y)) {
212  if (- $min_y < $max_y * 1.3 && - $min_y > $max_y * 0.7) {
213  $min_y = - $max_y;
214  } elseif (- $min_y < $max_y * 0.1) {
215  $max_y = 9 * $max_y / 10;
216  $min_y = - $max_y / 9;
217  } elseif (- $min_y < $max_y * 0.2) {
218  $max_y = 8 * $max_y / 10;
219  $min_y = -2 * $max_y / 8;
220  }
221  }
222  if($chart_product == 'flot') {
223  } else {
224  $graph->set_y_max($max_y);
225  $graph->set_y_min($min_y);
226  $graph->y_label_steps(10);
227 
228  $graph->set_x_labels($x_array);
229  $steps = round(count($x_array) * 9 * strlen(current($x_array)) / ($width-30));
230  $graph->set_x_label_style(10, '0x000000', 0, $steps);
231  }
232  } else {
233  if($chart_product == 'flot') {
234  foreach($data as $title => $value) {
235  $temp = new stdClass();
236  $temp->label = $title;
237  $temp->data = intval($value);
238  $pie_data[] = $temp;
239  unset($temp);
240  }
241  $output .= json_encode($pie_data);
242  } else {
243  $graph->pie_values($data, array_keys($data));
244  $graph->pie_slice_colours($pie_slice_colours);
245  }
246  }
247  } elseif($chart_product == 'flot') {
248  $data = array();
249  $output .= json_encode($data);
250  }
251  if($chart_product == 'flot') {
252  return $output;
253  } else {
254  // display the data
255  return $graph->render();
256  }
257 }
258 
foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) $data
Definition: chart-data.php:29
static strtoupper($string)
Returns string with all alphabetic characters converted to uppercase.
Definition: String.php:154
$colors
Definition: chart-data.php:32
$graph_type
Definition: chart-data.php:31
advistoChart(&$data, $title=null, $all_graph_type=null, $graph_type=array(), $colors=array(), $legend_font_size=12, $width=300, $force_chart_product=null)
advistoChart()
vb(&$var, $default=null)
Variable blanche if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:97
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160
$legend_font_size
Definition: chart-data.php:33
$GLOBALS['page_columns_count']
$total
$all_graph_type
Definition: chart-data.php:30
static substr($string, $start, $length=null)
Returns the portion of string specified by the start and length parameters.
Definition: String.php:112

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:27 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.