| @@ -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', |
| @@ -248,9 +249,9 @@ | ||
| 248 | 249 | 'ParetoChart', |
| 249 | 250 | 'PopulationPyramid' |
| 250 | 251 | ); |
| 251 | 252 | if (in_array($this->get_value('g_type', 'BarGraph', $field), $single_array_conversion) && $this->get_value('g_multiline', '0', $field) == '2') { |
| 252 | - $new_data = array(); | |
| 253 | + $new_data = []; | |
| 253 | 254 | foreach ($data as $key => $tmp) { |
| 254 | 255 | if (is_array($tmp)) { |
| 255 | 256 | foreach ($tmp as $sub_key => $sub_tmp) { |
| 256 | 257 | $new_data[$sub_key][$key] = $sub_tmp; |
| @@ -266,9 +267,9 @@ | ||
| 266 | 267 | * Structured Data |
| 267 | 268 | */ |
| 268 | 269 | if ($this->get_value('g_structured_data', '0', $field)) { |
| 269 | 270 | $settings['structured_data'] = true; |
| 270 | - $structure = array(); | |
| 271 | + $structure = []; | |
| 271 | 272 | if (!$this->is_empty('g_structure_key', $field)) { |
| 272 | 273 | $structure['key'] = $this->get_value('g_structure_key', '0', $field); |
| 273 | 274 | } |
| 274 | 275 | if (!$this->is_empty('g_structure_value', $field)) { |
| @@ -314,9 +315,9 @@ | ||
| 314 | 315 | $settings['structure'] = $structure; |
| 315 | 316 | } |
| 316 | 317 | |
| 317 | 318 | if (!$this->get_boolean('g_structured_data', $field) && $this->get_boolean('g_show_legend', $field)) { |
| 318 | - $legends = array(); | |
| 319 | + $legends = []; | |
| 319 | 320 | if ($this->get_value('g_multiline', '0', $field) == '1') { |
| 320 | 321 | if (isset($data[0]) && is_array($data[0])) { |
| 321 | 322 | $legends = $data[0]; |
| 322 | 323 | } |
| @@ -326,16 +327,33 @@ | ||
| 326 | 327 | $settings['legend_entries'] = array_keys($legends); |
| 327 | 328 | } |
| 328 | 329 | |
| 329 | 330 | if (!$this->is_empty('g_legends', $field)) { |
| 330 | - $tmp_legends = explode("\r\n", $this->get_value('g_legends', '', $field)); | |
| 331 | - $legends = array(); | |
| 332 | - foreach ($tmp_legends as $legend) { | |
| 331 | + $legends = []; | |
| 332 | + foreach (explode("\r\n", $this->get_value('g_legends', '', $field)) as $legend) { | |
| 333 | 333 | $legends[] = implode("\n", explode('\n', $legend)); |
| 334 | 334 | } |
| 335 | 335 | $settings['legend_entries'] = $legends; |
| 336 | 336 | } |
| 337 | 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 | + | |
| 338 | 356 | $count = max(count($data), 1); |
| 339 | 357 | foreach ($data as $sub_data) { |
| 340 | 358 | if (is_array($sub_data)) { |
| 341 | 359 | $count = max($count, count($sub_data)); |
| @@ -340,12 +358,11 @@ | ||
| 340 | 358 | if (is_array($sub_data)) { |
| 341 | 359 | $count = max($count, count($sub_data)); |
| 342 | 360 | } |
| 343 | 361 | } |
| 344 | - $colors = array(); | |
| 362 | + $colors = []; | |
| 345 | 363 | if (!$this->is_empty('g_colors', $field)) { |
| 346 | - $tmp_colors = explode("\r\n", $this->get_value('g_colors', '', $field)); | |
| 347 | - foreach ($tmp_colors as $color) { | |
| 364 | + foreach (explode("\r\n", $this->get_value('g_colors', '', $field)) as $color) { | |
| 348 | 365 | $colors[] = $this->get_array_value($color, ''); |
| 349 | 366 | } |
| 350 | 367 | } else { |
| 351 | 368 | $hue = 0; |
| @@ -377,10 +394,10 @@ | ||
| 377 | 394 | return ''; |
| 378 | 395 | } |
| 379 | 396 | } |
| 380 | 397 | |
| 381 | - public function get_graph_data($value, $separators = array(), $multiline = false) { | |
| 382 | - $data = array(); | |
| 398 | + public function get_graph_data($value, $separators = [], $multiline = false) { | |
| 399 | + $data = []; | |
| 383 | 400 | if ($multiline != '0') { |
| 384 | 401 | $lines = preg_split('/\r\n|\n/', $value); |
| 385 | 402 | foreach ($lines as $key => $line) { |
| 386 | 403 | $line_data = $this->get_line_data($line, $separators); |
| @@ -395,10 +412,10 @@ | ||
| 395 | 412 | } |
| 396 | 413 | return $data; |
| 397 | 414 | } |
| 398 | 415 | |
| 399 | - public function get_line_data($line, $separators = array()) { | |
| 400 | - $value = array(); | |
| 416 | + public function get_line_data($line, $separators = []) { | |
| 417 | + $value = []; | |
| 401 | 418 | $data = explode($separators['array'], $line); |
| 402 | 419 | foreach ($data as $line_data) { |
| 403 | 420 | $key = null; |
| 404 | 421 | if (strpos($line_data, $separators['key']) !== false) { |
| @@ -429,25 +446,25 @@ | ||
| 429 | 446 | } |
| 430 | 447 | return $value; |
| 431 | 448 | } |
| 432 | 449 | |
| 433 | - public function is_empty($key = '', $field = array()) { | |
| 450 | + public function is_empty($key = '', $field = []) { | |
| 434 | 451 | return isset($field['properties'][$key]) && $field['properties'][$key] !== '' ? false : true; |
| 435 | 452 | } |
| 436 | 453 | |
| 437 | - public function is_exists($key = '', $field = array()) { | |
| 454 | + public function is_exists($key = '', $field = []) { | |
| 438 | 455 | return isset($field['properties'][$key]) ? true : false; |
| 439 | 456 | } |
| 440 | 457 | |
| 441 | - public function get_value($key = '', $default = '', $field = array()) { | |
| 458 | + public function get_value($key = '', $default = '', $field = []) { | |
| 442 | 459 | return isset($field['properties'][$key]) && $field['properties'][$key] ? $field['properties'][$key] : $default; |
| 443 | 460 | } |
| 444 | 461 | |
| 445 | - public function get_number($key = '', $default = '', $field = array()) { | |
| 462 | + public function get_number($key = '', $default = '', $field = []) { | |
| 446 | 463 | return isset($field['properties'][$key]) ? (float) $field['properties'][$key] : (float) $default; |
| 447 | 464 | } |
| 448 | 465 | |
| 449 | - public function get_array($key = '', $default = '', $field = array()) { | |
| 466 | + public function get_array($key = '', $default = '', $field = []) { | |
| 450 | 467 | $value = isset($field['properties'][$key]) && $field['properties'][$key] ? $field['properties'][$key] : ''; |
| 451 | 468 | if ($value && (strpos($value, ',') !== false)) { |
| 452 | 469 | return $value = array_map('trim', explode(',', $value)); |
| 453 | 470 | } else { |
| @@ -462,8 +479,8 @@ | ||
| 462 | 479 | return $value ? $value : $default; |
| 463 | 480 | } |
| 464 | 481 | } |
| 465 | 482 | |
| 466 | - public function get_boolean($key = '', $field = array()) { | |
| 483 | + public function get_boolean($key = '', $field = []) { | |
| 467 | 484 | return isset($field['properties'][$key]) && $field['properties'][$key] ? true : false; |
| 468 | 485 | } |
| 469 | 486 | } |