PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.51
E2Pdf – Export Pdf Tool for WordPress v1.32.51
1.32.51 1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 All 73 releases
← All changes | classes/helper/e2pdf-graph.php +71 -32 1.32.181.32.51 View file →
@@ -19,9 +19,9 @@
19 19 public function __construct() {
20 20 $this->helper = Helper_E2pdf_Helper::instance();
21 21 }
22 22
23 - public function graph($value = '', $field = array()) {
23 + public function graph($value = '', $field = []) {
24 24
25 25 if (!$value) {
26 26 return '';
27 27 }
@@ -34,8 +34,9 @@
34 34 $height = $field['height'];
35 35
36 36 $settings = [
37 37 'auto_fit' => false,
38 + 'keep_colour_order' => true,
38 39 'back_stroke_width' => 0,
39 40 'back_stroke_colour' => '',
40 41 'link_base' => '/',
41 42 'link_target' => '_top',
@@ -131,8 +132,25 @@
131 132 'depth_shade_gradient' => array("black:0.2", "black:0.2", "black:0.2", "h"),
132 133 'aspect_ratio' => $this->get_value('g_aspect_ratio', '1', $field),
133 134 'bar_width' => $this->get_value('g_bar_width', '0', $field),
134 135 'bar_width_min' => $this->get_value('g_bar_width_min', '1', $field),
136 + 'show_labels' => $this->is_exists('g_show_labels', $field) ? $this->get_boolean('g_show_labels', $field) : true,
137 + 'show_label_key' => $this->is_exists('g_show_label_key', $field) ? $this->get_boolean('g_show_label_key', $field) : true,
138 + 'show_label_percent' => $this->get_boolean('g_show_label_percent', $field),
139 + 'show_label_amount' => $this->get_boolean('g_show_label_amount', $field),
140 + 'inner_radius' => $this->get_number('g_inner_radius', '0.5', $field),
141 + 'start_angle' => $this->get_value('g_start_angle', '0', $field),
142 + 'grid_straight' => $this->get_boolean('g_grid_straight', $field),
143 + 'fill_opacity' => $this->get_value('g_fill_opacity', '1', $field),
144 + 'grid_dash' => $this->get_value('g_grid_dash', '', $field),
145 + 'grid_dash_h' => $this->get_value('g_grid_dash_h', '', $field),
146 + 'grid_dash_v' => $this->get_value('g_grid_dash_v', '', $field),
147 + 'axis_colour_h' => $this->get_value('g_axis_colour_h', '', $field),
148 + 'axis_font_size_h' => $this->get_value('g_axis_font_size_h', '', $field),
149 + 'axis_colour_v' => $this->get_value('g_axis_colour_v', '', $field),
150 + 'axis_font_size_v' => $this->get_value('g_axis_font_size_v', '', $field),
151 + 'axis_font_weight_h' => $this->get_boolean('g_axis_font_weight_h', $field) ? 'bold' : null,
152 + 'axis_font_weight_v' => $this->get_boolean('g_axis_font_weight_v', $field) ? 'bold' : null,
135 153 ];
136 154
137 155 if ($this->is_exists('g_legend_entry_height', $field)) {
138 156 $settings['legend_entry_height'] = $this->get_value('g_legend_entry_height', '0', $field);
@@ -231,9 +249,9 @@
231 249 'ParetoChart',
232 250 'PopulationPyramid'
233 251 );
234 252 if (in_array($this->get_value('g_type', 'BarGraph', $field), $single_array_conversion) && $this->get_value('g_multiline', '0', $field) == '2') {
235 - $new_data = array();
253 + $new_data = [];
236 254 foreach ($data as $key => $tmp) {
237 255 if (is_array($tmp)) {
238 256 foreach ($tmp as $sub_key => $sub_tmp) {
239 257 $new_data[$sub_key][$key] = $sub_tmp;
@@ -249,9 +267,9 @@
249 267 * Structured Data
250 268 */
251 269 if ($this->get_value('g_structured_data', '0', $field)) {
252 270 $settings['structured_data'] = true;
253 - $structure = array();
271 + $structure = [];
254 272 if (!$this->is_empty('g_structure_key', $field)) {
255 273 $structure['key'] = $this->get_value('g_structure_key', '0', $field);
256 274 }
257 275 if (!$this->is_empty('g_structure_value', $field)) {
@@ -297,9 +315,9 @@
297 315 $settings['structure'] = $structure;
298 316 }
299 317
300 318 if (!$this->get_boolean('g_structured_data', $field) && $this->get_boolean('g_show_legend', $field)) {
301 - $legends = array();
319 + $legends = [];
302 320 if ($this->get_value('g_multiline', '0', $field) == '1') {
303 321 if (isset($data[0]) && is_array($data[0])) {
304 322 $legends = $data[0];
305 323 }
@@ -309,16 +327,33 @@
309 327 $settings['legend_entries'] = array_keys($legends);
310 328 }
311 329
312 330 if (!$this->is_empty('g_legends', $field)) {
313 - $tmp_legends = explode("\r\n", $this->get_value('g_legends', '', $field));
314 - $legends = array();
315 - foreach ($tmp_legends as $legend) {
331 + $legends = [];
332 + foreach (explode("\r\n", $this->get_value('g_legends', '', $field)) as $legend) {
316 333 $legends[] = implode("\n", explode('\n', $legend));
317 334 }
318 335 $settings['legend_entries'] = $legends;
319 336 }
320 337
338 + if (!$this->is_empty('g_axis_text_callback_y', $field)) {
339 + $texts = explode("\r\n", $this->get_value('g_axis_text_callback_y', '', $field));
340 + if (!empty($texts)) {
341 + $settings['axis_text_callback_y'] = function ($v, $key = '') use ($texts) {
342 + return isset($texts[$v]) ? $texts[$v] : $key;
343 + };
344 + }
345 + }
346 +
347 + if (!$this->is_empty('g_axis_text_callback_x', $field)) {
348 + $texts = explode("\r\n", $this->get_value('g_axis_text_callback_x', '', $field));
349 + if (!empty($texts)) {
350 + $settings['axis_text_callback_x'] = function ($v, $key = '') use ($texts) {
351 + return isset($texts[$v]) ? $texts[$v] : $key;
352 + };
353 + }
354 + }
355 +
321 356 $count = max(count($data), 1);
322 357 foreach ($data as $sub_data) {
323 358 if (is_array($sub_data)) {
324 359 $count = max($count, count($sub_data));
@@ -323,12 +358,11 @@
323 358 if (is_array($sub_data)) {
324 359 $count = max($count, count($sub_data));
325 360 }
326 361 }
327 - $colors = array();
362 + $colors = [];
328 363 if (!$this->is_empty('g_colors', $field)) {
329 - $tmp_colors = explode("\r\n", $this->get_value('g_colors', '', $field));
330 - foreach ($tmp_colors as $color) {
364 + foreach (explode("\r\n", $this->get_value('g_colors', '', $field)) as $color) {
331 365 $colors[] = $this->get_array_value($color, '');
332 366 }
333 367 } else {
334 368 $hue = 0;
@@ -360,14 +394,14 @@
360 394 return '';
361 395 }
362 396 }
363 397
364 - public function get_graph_data($value, $separators = array(), $multiline = false) {
365 - $data = array();
398 + public function get_graph_data($value, $separators = [], $multiline = false) {
399 + $data = [];
366 400 if ($multiline != '0') {
367 401 $lines = preg_split('/\r\n|\n/', $value);
368 402 foreach ($lines as $key => $line) {
369 - $line_data = $this->get_line_data(trim($line), $separators);
403 + $line_data = $this->get_line_data($line, $separators);
370 404 if ($multiline == '1') {
371 405 $data[] = $line_data;
372 406 } elseif ($multiline == '2') {
373 407 $data = array_merge($data, $line_data);
@@ -378,35 +412,36 @@
378 412 }
379 413 return $data;
380 414 }
381 415
382 - public function get_line_data($line, $separators = array()) {
383 - $value = array();
416 + public function get_line_data($line, $separators = []) {
417 + $value = [];
384 418 $data = explode($separators['array'], $line);
385 419 foreach ($data as $line_data) {
386 420 $key = null;
387 421 if (strpos($line_data, $separators['key']) !== false) {
388 422 list($key, $line_data) = explode($separators['key'], $line_data, 2);
423 + $key = trim($key);
389 424 }
425 +
390 426 if (strpos($line_data, $separators['sub_array']) !== false) {
427 + $sub_array = array_map(
428 + function ($item) {
429 + $item = trim($item);
430 + return $item === '' ? null : $item;
431 + }, explode($separators['sub_array'], $line_data)
432 + );
391 433 if ($key !== null) {
392 - $value[$key] = explode($separators['sub_array'], $line_data);
434 + $value[$key] = $sub_array;
393 435 } else {
394 - $value[] = explode($separators['sub_array'], $line_data);
436 + $value[] = $sub_array;
395 437 }
396 438 } else {
439 + $line_data = trim($line_data);
397 440 if ($key !== null) {
398 - if ($line_data === '') {
399 - $value[$key] = null;
400 - } else {
401 - $value[$key] = $line_data;
402 - }
441 + $value[$key] = $line_data === '' ? null : $line_data;
403 442 } else {
404 - if ($line_data === '') {
405 - $value[] = null;
406 - } else {
407 - $value[] = $line_data;
408 - }
443 + $value[] = $line_data === '' ? null : $line_data;
409 444 }
410 445 }
411 446 }
412 447 return $value;
@@ -411,21 +446,25 @@
411 446 }
412 447 return $value;
413 448 }
414 449
415 - public function is_empty($key = '', $field = array()) {
450 + public function is_empty($key = '', $field = []) {
416 451 return isset($field['properties'][$key]) && $field['properties'][$key] !== '' ? false : true;
417 452 }
418 453
419 - public function is_exists($key = '', $field = array()) {
454 + public function is_exists($key = '', $field = []) {
420 455 return isset($field['properties'][$key]) ? true : false;
421 456 }
422 457
423 - public function get_value($key = '', $default = '', $field = array()) {
458 + public function get_value($key = '', $default = '', $field = []) {
424 459 return isset($field['properties'][$key]) && $field['properties'][$key] ? $field['properties'][$key] : $default;
425 460 }
426 461
427 - public function get_array($key = '', $default = '', $field = array()) {
462 + public function get_number($key = '', $default = '', $field = []) {
463 + return isset($field['properties'][$key]) ? (float) $field['properties'][$key] : (float) $default;
464 + }
465 +
466 + public function get_array($key = '', $default = '', $field = []) {
428 467 $value = isset($field['properties'][$key]) && $field['properties'][$key] ? $field['properties'][$key] : '';
429 468 if ($value && (strpos($value, ',') !== false)) {
430 469 return $value = array_map('trim', explode(',', $value));
431 470 } else {
@@ -440,8 +479,8 @@
440 479 return $value ? $value : $default;
441 480 }
442 481 }
443 482
444 - public function get_boolean($key = '', $field = array()) {
483 + public function get_boolean($key = '', $field = []) {
445 484 return isset($field['properties'][$key]) && $field['properties'][$key] ? true : false;
446 485 }
447 486 }