PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.49
E2Pdf – Export Pdf Tool for WordPress v1.32.49
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 1.08.06 All 72 releases
← All changes | classes/helper/e2pdf-graph.php +62 -33 1.32.311.32.49 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',
@@ -137,8 +138,19 @@
137 138 'show_label_percent' => $this->get_boolean('g_show_label_percent', $field),
138 139 'show_label_amount' => $this->get_boolean('g_show_label_amount', $field),
139 140 'inner_radius' => $this->get_number('g_inner_radius', '0.5', $field),
140 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,
141 153 ];
142 154
143 155 if ($this->is_exists('g_legend_entry_height', $field)) {
144 156 $settings['legend_entry_height'] = $this->get_value('g_legend_entry_height', '0', $field);
@@ -237,9 +249,9 @@
237 249 'ParetoChart',
238 250 'PopulationPyramid'
239 251 );
240 252 if (in_array($this->get_value('g_type', 'BarGraph', $field), $single_array_conversion) && $this->get_value('g_multiline', '0', $field) == '2') {
241 - $new_data = array();
253 + $new_data = [];
242 254 foreach ($data as $key => $tmp) {
243 255 if (is_array($tmp)) {
244 256 foreach ($tmp as $sub_key => $sub_tmp) {
245 257 $new_data[$sub_key][$key] = $sub_tmp;
@@ -255,9 +267,9 @@
255 267 * Structured Data
256 268 */
257 269 if ($this->get_value('g_structured_data', '0', $field)) {
258 270 $settings['structured_data'] = true;
259 - $structure = array();
271 + $structure = [];
260 272 if (!$this->is_empty('g_structure_key', $field)) {
261 273 $structure['key'] = $this->get_value('g_structure_key', '0', $field);
262 274 }
263 275 if (!$this->is_empty('g_structure_value', $field)) {
@@ -303,9 +315,9 @@
303 315 $settings['structure'] = $structure;
304 316 }
305 317
306 318 if (!$this->get_boolean('g_structured_data', $field) && $this->get_boolean('g_show_legend', $field)) {
307 - $legends = array();
319 + $legends = [];
308 320 if ($this->get_value('g_multiline', '0', $field) == '1') {
309 321 if (isset($data[0]) && is_array($data[0])) {
310 322 $legends = $data[0];
311 323 }
@@ -315,16 +327,33 @@
315 327 $settings['legend_entries'] = array_keys($legends);
316 328 }
317 329
318 330 if (!$this->is_empty('g_legends', $field)) {
319 - $tmp_legends = explode("\r\n", $this->get_value('g_legends', '', $field));
320 - $legends = array();
321 - foreach ($tmp_legends as $legend) {
331 + $legends = [];
332 + foreach (explode("\r\n", $this->get_value('g_legends', '', $field)) as $legend) {
322 333 $legends[] = implode("\n", explode('\n', $legend));
323 334 }
324 335 $settings['legend_entries'] = $legends;
325 336 }
326 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 +
327 356 $count = max(count($data), 1);
328 357 foreach ($data as $sub_data) {
329 358 if (is_array($sub_data)) {
330 359 $count = max($count, count($sub_data));
@@ -329,12 +358,11 @@
329 358 if (is_array($sub_data)) {
330 359 $count = max($count, count($sub_data));
331 360 }
332 361 }
333 - $colors = array();
362 + $colors = [];
334 363 if (!$this->is_empty('g_colors', $field)) {
335 - $tmp_colors = explode("\r\n", $this->get_value('g_colors', '', $field));
336 - foreach ($tmp_colors as $color) {
364 + foreach (explode("\r\n", $this->get_value('g_colors', '', $field)) as $color) {
337 365 $colors[] = $this->get_array_value($color, '');
338 366 }
339 367 } else {
340 368 $hue = 0;
@@ -366,14 +394,14 @@
366 394 return '';
367 395 }
368 396 }
369 397
370 - public function get_graph_data($value, $separators = array(), $multiline = false) {
371 - $data = array();
398 + public function get_graph_data($value, $separators = [], $multiline = false) {
399 + $data = [];
372 400 if ($multiline != '0') {
373 401 $lines = preg_split('/\r\n|\n/', $value);
374 402 foreach ($lines as $key => $line) {
375 - $line_data = $this->get_line_data(trim($line), $separators);
403 + $line_data = $this->get_line_data($line, $separators);
376 404 if ($multiline == '1') {
377 405 $data[] = $line_data;
378 406 } elseif ($multiline == '2') {
379 407 $data = array_merge($data, $line_data);
@@ -384,35 +412,36 @@
384 412 }
385 413 return $data;
386 414 }
387 415
388 - public function get_line_data($line, $separators = array()) {
389 - $value = array();
416 + public function get_line_data($line, $separators = []) {
417 + $value = [];
390 418 $data = explode($separators['array'], $line);
391 419 foreach ($data as $line_data) {
392 420 $key = null;
393 421 if (strpos($line_data, $separators['key']) !== false) {
394 422 list($key, $line_data) = explode($separators['key'], $line_data, 2);
423 + $key = trim($key);
395 424 }
425 +
396 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 + );
397 433 if ($key !== null) {
398 - $value[$key] = explode($separators['sub_array'], $line_data);
434 + $value[$key] = $sub_array;
399 435 } else {
400 - $value[] = explode($separators['sub_array'], $line_data);
436 + $value[] = $sub_array;
401 437 }
402 438 } else {
439 + $line_data = trim($line_data);
403 440 if ($key !== null) {
404 - if ($line_data === '') {
405 - $value[$key] = null;
406 - } else {
407 - $value[$key] = $line_data;
408 - }
441 + $value[$key] = $line_data === '' ? null : $line_data;
409 442 } else {
410 - if ($line_data === '') {
411 - $value[] = null;
412 - } else {
413 - $value[] = $line_data;
414 - }
443 + $value[] = $line_data === '' ? null : $line_data;
415 444 }
416 445 }
417 446 }
418 447 return $value;
@@ -417,25 +446,25 @@
417 446 }
418 447 return $value;
419 448 }
420 449
421 - public function is_empty($key = '', $field = array()) {
450 + public function is_empty($key = '', $field = []) {
422 451 return isset($field['properties'][$key]) && $field['properties'][$key] !== '' ? false : true;
423 452 }
424 453
425 - public function is_exists($key = '', $field = array()) {
454 + public function is_exists($key = '', $field = []) {
426 455 return isset($field['properties'][$key]) ? true : false;
427 456 }
428 457
429 - public function get_value($key = '', $default = '', $field = array()) {
458 + public function get_value($key = '', $default = '', $field = []) {
430 459 return isset($field['properties'][$key]) && $field['properties'][$key] ? $field['properties'][$key] : $default;
431 460 }
432 461
433 - public function get_number($key = '', $default = '', $field = array()) {
462 + public function get_number($key = '', $default = '', $field = []) {
434 463 return isset($field['properties'][$key]) ? (float) $field['properties'][$key] : (float) $default;
435 464 }
436 465
437 - public function get_array($key = '', $default = '', $field = array()) {
466 + public function get_array($key = '', $default = '', $field = []) {
438 467 $value = isset($field['properties'][$key]) && $field['properties'][$key] ? $field['properties'][$key] : '';
439 468 if ($value && (strpos($value, ',') !== false)) {
440 469 return $value = array_map('trim', explode(',', $value));
441 470 } else {
@@ -450,8 +479,8 @@
450 479 return $value ? $value : $default;
451 480 }
452 481 }
453 482
454 - public function get_boolean($key = '', $field = array()) {
483 + public function get_boolean($key = '', $field = []) {
455 484 return isset($field['properties'][$key]) && $field['properties'][$key] ? true : false;
456 485 }
457 486 }