| @@ -63,28 +63,8 @@ | ||
| 63 | 63 | */ |
| 64 | 64 | protected $_yesno; |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | - * The array of available legend positions. | |
| 68 | - * | |
| 69 | - * @since 1.0.0 | |
| 70 | - * | |
| 71 | - * @access protected | |
| 72 | - * @var array | |
| 73 | - */ | |
| 74 | - protected $_legendPositions; | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * The array of available alignments. | |
| 78 | - * | |
| 79 | - * @since 1.0.0 | |
| 80 | - * | |
| 81 | - * @access protected | |
| 82 | - * @var array | |
| 83 | - */ | |
| 84 | - protected $_alignments; | |
| 85 | - | |
| 86 | - /** | |
| 87 | 67 | * Whether this chart supports animation or not. |
| 88 | 68 | * |
| 89 | 69 | * @access protected |
| 90 | 70 | * @var bool |
| @@ -109,25 +89,8 @@ | ||
| 109 | 89 | */ |
| 110 | 90 | public function __construct( $data = array() ) { |
| 111 | 91 | parent::__construct( $data ); |
| 112 | 92 | |
| 113 | - $this->_legendPositions = array( | |
| 114 | - '' => '', | |
| 115 | - 'left' => esc_html__( 'Left of the chart', 'visualizer' ), | |
| 116 | - 'right' => esc_html__( 'Right of the chart', 'visualizer' ), | |
| 117 | - 'top' => esc_html__( 'Above the chart', 'visualizer' ), | |
| 118 | - 'bottom' => esc_html__( 'Below the chart', 'visualizer' ), | |
| 119 | - 'in' => esc_html__( 'Inside the chart', 'visualizer' ), | |
| 120 | - 'none' => esc_html__( 'Omit the legend', 'visualizer' ), | |
| 121 | - ); | |
| 122 | - | |
| 123 | - $this->_alignments = array( | |
| 124 | - '' => '', | |
| 125 | - 'start' => esc_html__( 'Aligned to the start of the allocated area', 'visualizer' ), | |
| 126 | - 'center' => esc_html__( 'Centered in the allocated area', 'visualizer' ), | |
| 127 | - 'end' => esc_html__( 'Aligned to the end of the allocated area', 'visualizer' ), | |
| 128 | - ); | |
| 129 | - | |
| 130 | 93 | $this->_yesno = array( |
| 131 | 94 | '' => '', |
| 132 | 95 | '1' => esc_html__( 'Yes', 'visualizer' ), |
| 133 | 96 | '0' => esc_html__( 'No', 'visualizer' ), |
| @@ -259,8 +222,19 @@ | ||
| 259 | 222 | 'copy', |
| 260 | 223 | $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : esc_html__( 'To enable copying the data to the clipboard.', 'visualizer' ), |
| 261 | 224 | $disable_actions |
| 262 | 225 | ); |
| 226 | + | |
| 227 | + // not all charts support downloading as an image. | |
| 228 | + $disabled = ! $this->can_chart_have_action( 'image' ); | |
| 229 | + self::_renderCheckboxItem( | |
| 230 | + esc_html__( 'Download Image', 'visualizer' ), | |
| 231 | + 'actions[]', | |
| 232 | + isset( $this->actions ) && in_array( 'image', $this->actions, true ) ? true : false, | |
| 233 | + 'image', | |
| 234 | + $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : ( $disabled ? '<span class="viz-section-error">' . esc_html__( 'Not supported for this chart type.', 'visualizer' ) . '</span>' : esc_html__( 'To download the chart as an image.', 'visualizer' ) ), | |
| 235 | + $disable_actions || $disabled | |
| 236 | + ); | |
| 263 | 237 | self::_renderSectionEnd(); |
| 264 | 238 | } |
| 265 | 239 | |
| 266 | 240 | /** |
| @@ -277,284 +251,8 @@ | ||
| 277 | 251 | return false; |
| 278 | 252 | } |
| 279 | 253 | |
| 280 | 254 | return class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) && extension_loaded( 'zip' ) && extension_loaded( 'xml' ) && extension_loaded( 'fileinfo' ); |
| 281 | - } | |
| 282 | - | |
| 283 | - /** | |
| 284 | - * Renders chart general settings group. | |
| 285 | - * | |
| 286 | - * @since 1.0.0 | |
| 287 | - * | |
| 288 | - * @access protected | |
| 289 | - */ | |
| 290 | - protected function _renderGeneralSettings() { | |
| 291 | - self::_renderGroupStart( esc_html__( 'General Settings', 'visualizer' ) ); | |
| 292 | - self::_renderSectionStart(); | |
| 293 | - self::_renderSectionDescription( esc_html__( 'Configure title, font styles, tooltip, legend and else settings for the chart.', 'visualizer' ) ); | |
| 294 | - self::_renderSectionEnd(); | |
| 295 | - | |
| 296 | - self::_renderSectionStart( esc_html__( 'Title', 'visualizer' ), false ); | |
| 297 | - $this->_renderChartTitleSettings(); | |
| 298 | - self::_renderSectionEnd(); | |
| 299 | - | |
| 300 | - self::_renderSectionStart( esc_html__( 'Font Styles', 'visualizer' ), false ); | |
| 301 | - echo '<div class="viz-section-item">'; | |
| 302 | - echo '<a class="more-info" href="javascript:;">[?]</a>'; | |
| 303 | - echo '<b>', esc_html__( 'Family And Size', 'visualizer' ), '</b>'; | |
| 304 | - | |
| 305 | - echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">'; | |
| 306 | - echo '<tr>'; | |
| 307 | - echo '<td class="viz-section-table-column">'; | |
| 308 | - echo '<select name="fontName" class="control-select">'; | |
| 309 | - echo '<option></option>'; | |
| 310 | - foreach ( self::$_fontFamilies as $font => $label ) { | |
| 311 | - echo '<option value="', $font, '"', selected( $font, $this->fontName, false ), '>'; | |
| 312 | - echo $label; | |
| 313 | - echo '</option>'; | |
| 314 | - } | |
| 315 | - echo '</select>'; | |
| 316 | - echo '</td>'; | |
| 317 | - echo '<td class="viz-section-table-column">'; | |
| 318 | - echo '<select name="fontSize" class="control-select">'; | |
| 319 | - echo '<option></option>'; | |
| 320 | - for ( $i = 7; $i <= 20; $i++ ) { | |
| 321 | - echo '<option value="', $i, '"', selected( $i, $this->fontSize, false ), '>', $i, '</option>'; | |
| 322 | - } | |
| 323 | - echo '</select>'; | |
| 324 | - echo '</td>'; | |
| 325 | - echo '</tr>'; | |
| 326 | - echo '</table>'; | |
| 327 | - | |
| 328 | - echo '<p class="viz-section-description">'; | |
| 329 | - esc_html_e( 'The default font family and size for all text in the chart.', 'visualizer' ); | |
| 330 | - echo '</p>'; | |
| 331 | - echo '</div>'; | |
| 332 | - self::_renderSectionEnd(); | |
| 333 | - | |
| 334 | - self::_renderSectionStart( esc_html__( 'Legend', 'visualizer' ), false ); | |
| 335 | - self::_renderSelectItem( | |
| 336 | - esc_html__( 'Position', 'visualizer' ), | |
| 337 | - 'legend[position]', | |
| 338 | - $this->legend['position'], | |
| 339 | - $this->_legendPositions, | |
| 340 | - esc_html__( 'Determines where to place the legend, compared to the chart area.', 'visualizer' ) | |
| 341 | - ); | |
| 342 | - | |
| 343 | - self::_renderSelectItem( | |
| 344 | - esc_html__( 'Alignment', 'visualizer' ), | |
| 345 | - 'legend[alignment]', | |
| 346 | - $this->legend['alignment'], | |
| 347 | - $this->_alignments, | |
| 348 | - esc_html__( 'Determines the alignment of the legend.', 'visualizer' ) | |
| 349 | - ); | |
| 350 | - | |
| 351 | - self::_renderColorPickerItem( | |
| 352 | - esc_html__( 'Font Color', 'visualizer' ), | |
| 353 | - 'legend[textStyle][color]', | |
| 354 | - isset( $this->legend['textStyle']['color'] ) ? $this->legend['textStyle']['color'] : null, | |
| 355 | - '#000' | |
| 356 | - ); | |
| 357 | - self::_renderSectionEnd(); | |
| 358 | - | |
| 359 | - self::_renderSectionStart( esc_html__( 'Tooltip', 'visualizer' ), false ); | |
| 360 | - $this->_renderTooltipSettigns(); | |
| 361 | - self::_renderSectionEnd(); | |
| 362 | - | |
| 363 | - $this->_renderAnimationSettings(); | |
| 364 | - | |
| 365 | - do_action( 'visualizer_chart_settings', get_class( $this ), $this->_data, 'general', array( 'generic' => true ) ); | |
| 366 | - | |
| 367 | - self::_renderGroupEnd(); | |
| 368 | - } | |
| 369 | - | |
| 370 | - /** | |
| 371 | - * Renders animation settings section. | |
| 372 | - * | |
| 373 | - * @access protected | |
| 374 | - */ | |
| 375 | - protected function _renderAnimationSettings() { | |
| 376 | - if ( ! $this->_supportsAnimation ) { | |
| 377 | - return; | |
| 378 | - } | |
| 379 | - | |
| 380 | - self::_renderSectionStart( esc_html__( 'Animation', 'visualizer' ), false ); | |
| 381 | - | |
| 382 | - self::_renderCheckboxItem( | |
| 383 | - esc_html__( 'Animate on startup', 'visualizer' ), | |
| 384 | - 'animation[startup]', | |
| 385 | - isset( $this->animation['startup'] ) ? $this->animation['startup'] : 0, | |
| 386 | - true, | |
| 387 | - esc_html__( 'Determines if the chart will animate on the initial draw.', 'visualizer' ) | |
| 388 | - ); | |
| 389 | - | |
| 390 | - self::_renderTextItem( | |
| 391 | - esc_html__( 'Duration', 'visualizer' ), | |
| 392 | - 'animation[duration]', | |
| 393 | - isset( $this->animation['duration'] ) ? $this->animation['duration'] : 0, | |
| 394 | - esc_html__( 'The duration of the animation, in milliseconds', 'visualizer' ), | |
| 395 | - 0, | |
| 396 | - 'number' | |
| 397 | - ); | |
| 398 | - | |
| 399 | - self::_renderSelectItem( | |
| 400 | - esc_html__( 'Easing', 'visualizer' ), | |
| 401 | - 'animation[easing]', | |
| 402 | - isset( $this->animation['easing'] ) ? $this->animation['easing'] : null, | |
| 403 | - array( | |
| 404 | - 'linear' => esc_html__( 'Constant speed', 'visualizer' ), | |
| 405 | - 'in' => esc_html__( 'Start slow and speed up', 'visualizer' ), | |
| 406 | - 'out' => esc_html__( 'Start fast and slow down', 'visualizer' ), | |
| 407 | - 'inAndOut' => esc_html__( 'Start slow, speed up, then slow down', 'visualizer' ), | |
| 408 | - ), | |
| 409 | - esc_html__( 'The easing function applied to the animation.', 'visualizer' ) | |
| 410 | - ); | |
| 411 | - | |
| 412 | - self::_renderSectionEnd(); | |
| 413 | - | |
| 414 | - } | |
| 415 | - | |
| 416 | - /** | |
| 417 | - * Renders tooltip settings section. | |
| 418 | - * | |
| 419 | - * @since 1.4.0 | |
| 420 | - * | |
| 421 | - * @access protected | |
| 422 | - */ | |
| 423 | - protected function _renderTooltipSettigns() { | |
| 424 | - self::_renderSelectItem( | |
| 425 | - esc_html__( 'Trigger', 'visualizer' ), | |
| 426 | - 'tooltip[trigger]', | |
| 427 | - isset( $this->tooltip['trigger'] ) ? $this->tooltip['trigger'] : null, | |
| 428 | - array( | |
| 429 | - '' => '', | |
| 430 | - 'focus' => esc_html__( 'The tooltip will be displayed when the user hovers over an element', 'visualizer' ), | |
| 431 | - 'selection' => esc_html__( 'The tooltip will be displayed when the user selects an element', 'visualizer' ), | |
| 432 | - 'none' => esc_html__( 'The tooltip will not be displayed', 'visualizer' ), | |
| 433 | - ), | |
| 434 | - esc_html__( 'Determines the user interaction that causes the tooltip to be displayed.', 'visualizer' ) | |
| 435 | - ); | |
| 436 | - | |
| 437 | - self::_renderSelectItem( | |
| 438 | - esc_html__( 'Show Color Code', 'visualizer' ), | |
| 439 | - 'tooltip[showColorCode]', | |
| 440 | - isset( $this->tooltip['showColorCode'] ) ? $this->tooltip['showColorCode'] : null, | |
| 441 | - $this->_yesno, | |
| 442 | - esc_html__( 'If set to yes, will show colored squares next to the slice information in the tooltip.', 'visualizer' ) | |
| 443 | - ); | |
| 444 | - } | |
| 445 | - | |
| 446 | - /** | |
| 447 | - * Renders chart view settings group. | |
| 448 | - * | |
| 449 | - * @since 1.0.0 | |
| 450 | - * | |
| 451 | - * @access protected | |
| 452 | - */ | |
| 453 | - protected function _renderViewSettings() { | |
| 454 | - self::_renderGroupStart( esc_html__( 'Chart Size & Placement', 'visualizer' ) ); | |
| 455 | - self::_renderSectionStart( esc_html__( 'Chart Size/Layout', 'visualizer' ), false ); | |
| 456 | - self::_renderSectionDescription( esc_html__( 'Configure the total size of the chart. Two formats are supported: a number, or a number followed by %. A simple number is a value in pixels; a number followed by % is a percentage.', 'visualizer' ) ); | |
| 457 | - | |
| 458 | - echo '<div class="viz-section-item">'; | |
| 459 | - echo '<a class="more-info" href="javascript:;">[?]</a>'; | |
| 460 | - echo '<b>', esc_html__( 'Width And Height Of Chart', 'visualizer' ), '</b>'; | |
| 461 | - | |
| 462 | - echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">'; | |
| 463 | - echo '<tr>'; | |
| 464 | - echo '<td class="viz-section-table-column">'; | |
| 465 | - echo '<input type="text" name="width" class="control-text" value="', esc_attr( $this->width ), '" placeholder="100%">'; | |
| 466 | - echo '</td>'; | |
| 467 | - echo '<td class="viz-section-table-column">'; | |
| 468 | - echo '<input type="text" name="height" class="control-text" value="', esc_attr( $this->height ), '" placeholder="400">'; | |
| 469 | - echo '</td>'; | |
| 470 | - echo '</tr>'; | |
| 471 | - echo '</table>'; | |
| 472 | - | |
| 473 | - echo '<p class="viz-section-description">'; | |
| 474 | - esc_html_e( 'Determines the total width and height of the chart. This will only show in the front-end.', 'visualizer' ); | |
| 475 | - echo '</p>'; | |
| 476 | - echo '</div>'; | |
| 477 | - | |
| 478 | - echo '<div class="viz-section-delimiter"></div>'; | |
| 479 | - | |
| 480 | - self::_renderSectionDescription( esc_html__( 'Configure the background color for the main area of the chart and the chart border width and color.', 'visualizer' ) ); | |
| 481 | - | |
| 482 | - self::_renderTextItem( | |
| 483 | - esc_html__( 'Stroke Width', 'visualizer' ), | |
| 484 | - 'backgroundColor[strokeWidth]', | |
| 485 | - isset( $this->backgroundColor['strokeWidth'] ) ? $this->backgroundColor['strokeWidth'] : null, | |
| 486 | - esc_html__( 'The chart border width in pixels.', 'visualizer' ), | |
| 487 | - '0' | |
| 488 | - ); | |
| 489 | - | |
| 490 | - self::_renderColorPickerItem( | |
| 491 | - esc_html__( 'Stroke Color', 'visualizer' ), | |
| 492 | - 'backgroundColor[stroke]', | |
| 493 | - ! empty( $this->backgroundColor['stroke'] ) ? $this->backgroundColor['stroke'] : null, | |
| 494 | - '#666' | |
| 495 | - ); | |
| 496 | - | |
| 497 | - $background_color = ! empty( $this->backgroundColor['fill'] ) ? $this->backgroundColor['fill'] : null; | |
| 498 | - self::_renderColorPickerItem( | |
| 499 | - esc_html__( 'Background Color', 'visualizer' ), | |
| 500 | - 'backgroundColor[fill]', | |
| 501 | - $background_color, | |
| 502 | - '#fff' | |
| 503 | - ); | |
| 504 | - | |
| 505 | - echo '<div class="viz-section-item">'; | |
| 506 | - echo '<label>'; | |
| 507 | - echo '<input type="checkbox" class="control-checkbox" name="backgroundColor[fill]" value="transparent"', checked( $background_color, 'transparent', false ), '> '; | |
| 508 | - esc_html_e( 'Transparent background', 'visualizer' ); | |
| 509 | - echo '</label>'; | |
| 510 | - echo '</div>'; | |
| 511 | - self::_renderSectionEnd(); | |
| 512 | - | |
| 513 | - self::_renderSectionStart( esc_html__( 'Placement', 'visualizer' ), false ); | |
| 514 | - self::_renderSectionDescription( esc_html__( 'Configure the placement and size of the chart area (where the chart itself is drawn, excluding axis and legends). Two formats are supported: a number, or a number followed by %. A simple number is a value in pixels; a number followed by % is a percentage.', 'visualizer' ) ); | |
| 515 | - | |
| 516 | - echo '<div class="viz-section-item">'; | |
| 517 | - echo '<a class="more-info" href="javascript:;">[?]</a>'; | |
| 518 | - echo '<b>', esc_html__( 'Left And Top Margins', 'visualizer' ), '</b>'; | |
| 519 | - | |
| 520 | - echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">'; | |
| 521 | - echo '<tr>'; | |
| 522 | - echo '<td class="viz-section-table-column">'; | |
| 523 | - echo '<input type="text" name="chartArea[left]" class="control-text" value="', $this->chartArea['left'] || $this->chartArea['left'] === '0' ? esc_attr( $this->chartArea['left'] ) : '', '" placeholder="20%">'; | |
| 524 | - echo '</td>'; | |
| 525 | - echo '<td class="viz-section-table-column">'; | |
| 526 | - echo '<input type="text" name="chartArea[top]" class="control-text" value="', $this->chartArea['top'] || $this->chartArea['top'] === '0' ? esc_attr( $this->chartArea['top'] ) : '', '" placeholder="20%">'; | |
| 527 | - echo '</td>'; | |
| 528 | - echo '</tr>'; | |
| 529 | - echo '</table>'; | |
| 530 | - | |
| 531 | - echo '<p class="viz-section-description">'; | |
| 532 | - esc_html_e( 'Determines how far to draw the chart from the left and top borders.', 'visualizer' ); | |
| 533 | - echo '</p>'; | |
| 534 | - echo '</div>'; | |
| 535 | - | |
| 536 | - echo '<div class="viz-section-item">'; | |
| 537 | - echo '<a class="more-info" href="javascript:;">[?]</a>'; | |
| 538 | - echo '<b>', esc_html__( 'Width And Height Of Chart Area', 'visualizer' ), '</b>'; | |
| 539 | - | |
| 540 | - echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">'; | |
| 541 | - echo '<tr>'; | |
| 542 | - echo '<td class="viz-section-table-column">'; | |
| 543 | - echo '<input type="text" name="chartArea[width]" class="control-text" value="', ! empty( $this->chartArea['width'] ) ? esc_attr( $this->chartArea['width'] ) : '', '" placeholder="60%">'; | |
| 544 | - echo '</td>'; | |
| 545 | - echo '<td class="viz-section-table-column">'; | |
| 546 | - echo '<input type="text" name="chartArea[height]" class="control-text" value="', ! empty( $this->chartArea['height'] ) ? esc_attr( $this->chartArea['height'] ) : '', '" placeholder="60%">'; | |
| 547 | - echo '</td>'; | |
| 548 | - echo '</tr>'; | |
| 549 | - echo '</table>'; | |
| 550 | - | |
| 551 | - echo '<p class="viz-section-description">'; | |
| 552 | - esc_html_e( 'Determines the width and hight of the chart area.', 'visualizer' ); | |
| 553 | - echo '</p>'; | |
| 554 | - echo '</div>'; | |
| 555 | - self::_renderSectionEnd(); | |
| 556 | - self::_renderGroupEnd(); | |
| 557 | 255 | } |
| 558 | 256 | |
| 559 | 257 | /** |
| 560 | 258 | * Renders select item. |