| @@ -83,8 +83,24 @@ | ||
| 83 | 83 | */ |
| 84 | 84 | protected $_alignments; |
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | + * Whether this chart supports animation or not. | |
| 88 | + * | |
| 89 | + * @access protected | |
| 90 | + * @var bool | |
| 91 | + */ | |
| 92 | + protected $_supportsAnimation = true; | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Which library does this this chart implement? | |
| 96 | + * | |
| 97 | + * @access protected | |
| 98 | + * @var string | |
| 99 | + */ | |
| 100 | + protected $_library = null; | |
| 101 | + | |
| 102 | + /** | |
| 87 | 103 | * Constructor. |
| 88 | 104 | * |
| 89 | 105 | * @since 1.0.0 |
| 90 | 106 | * |
| @@ -115,8 +131,10 @@ | ||
| 115 | 131 | '' => '', |
| 116 | 132 | '1' => esc_html__( 'Yes', 'visualizer' ), |
| 117 | 133 | '0' => esc_html__( 'No', 'visualizer' ), |
| 118 | 134 | ); |
| 135 | + | |
| 136 | + $this->hooks(); | |
| 119 | 137 | } |
| 120 | 138 | |
| 121 | 139 | /** |
| 122 | 140 | * Renders chart title settings. |
| @@ -156,9 +174,9 @@ | ||
| 156 | 174 | self::_renderGroupEnd(); |
| 157 | 175 | |
| 158 | 176 | self::_renderGroupStart( esc_html__( 'Manual Configuration', 'visualizer' ) ); |
| 159 | 177 | self::_renderSectionStart(); |
| 160 | - self::_renderSectionDescription( __( 'Configure the graph by providing configuration variables right from the', 'visualizer' ) . ' <a href="https://developers.google.com/chart/interactive/docs/reference" target="_blank">Google Visualization</a> API.' ); | |
| 178 | + self::_renderSectionDescription( '<span class="viz-gvlink">' . sprintf( __( 'Configure the graph by providing configuration variables right from the %1$sGoogle Visualization API%2$s. You can refer to to some examples %3$shere%4$s.', 'visualizer' ), '<a href="https://developers.google.com/chart/interactive/docs/gallery/?#configuration-options" target="_blank">', '</a>', '<a href="https://docs.themeisle.com/article/728-manual-configuration" target="_blank">', '</a>' ) . '</span>' ); | |
| 161 | 179 | |
| 162 | 180 | $example = ' |
| 163 | 181 | { |
| 164 | 182 | "vAxis": { |
| @@ -174,9 +192,10 @@ | ||
| 174 | 192 | esc_html__( 'Configuration', 'visualizer' ), |
| 175 | 193 | 'manual', |
| 176 | 194 | $this->manual, |
| 177 | 195 | sprintf( |
| 178 | - esc_html__( 'One per line in valid JSON (key:value) format e.g. %s', 'visualizer' ), '<br><code>' . $example . '</code>' | |
| 196 | + esc_html__( 'One per line in valid JSON (key:value) format e.g. %s', 'visualizer' ), | |
| 197 | + '<br><code>' . $example . '</code>' | |
| 179 | 198 | ), |
| 180 | 199 | '', |
| 181 | 200 | array( 'rows' => 5 ) |
| 182 | 201 | ); |
| @@ -197,27 +216,27 @@ | ||
| 197 | 216 | self::_renderSectionStart( esc_html__( 'Actions', 'visualizer' ), false ); |
| 198 | 217 | self::_renderCheckboxItem( |
| 199 | 218 | esc_html__( 'Print', 'visualizer' ), |
| 200 | 219 | 'actions[]', |
| 201 | - isset( $this->actions ) && in_array( 'print', $this->actions ) ? true : false, | |
| 220 | + isset( $this->actions ) && in_array( 'print', $this->actions, true ) ? true : false, | |
| 202 | 221 | 'print', |
| 203 | - $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 printing the data.', 'visualizer' ), | |
| 222 | + $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 printing the chart/data.', 'visualizer' ), | |
| 204 | 223 | $disable_actions |
| 205 | 224 | ); |
| 206 | 225 | self::_renderCheckboxItem( |
| 207 | 226 | esc_html__( 'CSV', 'visualizer' ), |
| 208 | 227 | 'actions[]', |
| 209 | - isset( $this->actions ) && in_array( 'csv;application/csv', $this->actions ) ? true : false, | |
| 228 | + isset( $this->actions ) && in_array( 'csv;application/csv', $this->actions, true ) ? true : false, | |
| 210 | 229 | 'csv;application/csv', |
| 211 | 230 | $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 downloading the data as a CSV.', 'visualizer' ), |
| 212 | 231 | $disable_actions |
| 213 | 232 | ); |
| 214 | 233 | |
| 215 | - $disabled = ! ( class_exists( 'PHPExcel' ) && extension_loaded( 'zip' ) && extension_loaded( 'xml' ) && version_compare( PHP_VERSION, '5.2.0', '>' ) ); | |
| 234 | + $disabled = ! self::is_excel_enabled(); | |
| 216 | 235 | self::_renderCheckboxItem( |
| 217 | 236 | esc_html__( 'Excel', 'visualizer' ), |
| 218 | 237 | 'actions[]', |
| 219 | - isset( $this->actions ) && in_array( 'xls;application/vnd.ms-excel', $this->actions ) ? true : false, | |
| 238 | + isset( $this->actions ) && in_array( 'xls;application/vnd.ms-excel', $this->actions, true ) ? true : false, | |
| 220 | 239 | 'xls;application/vnd.ms-excel', |
| 221 | 240 | $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__( 'Enable the ZIP and XML extensions to use this setting.', 'visualizer' ) . '</span>' : esc_html__( 'To enable downloading the data as an Excel spreadsheet.', 'visualizer' ) ), |
| 222 | 241 | $disable_actions || $disabled |
| 223 | 242 | ); |
| @@ -223,9 +242,9 @@ | ||
| 223 | 242 | ); |
| 224 | 243 | self::_renderCheckboxItem( |
| 225 | 244 | esc_html__( 'Copy', 'visualizer' ), |
| 226 | 245 | 'actions[]', |
| 227 | - isset( $this->actions ) && in_array( 'copy', $this->actions ) ? true : false, | |
| 246 | + isset( $this->actions ) && in_array( 'copy', $this->actions, true ) ? true : false, | |
| 228 | 247 | 'copy', |
| 229 | 248 | $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' ), |
| 230 | 249 | $disable_actions |
| 231 | 250 | ); |
| @@ -232,8 +251,20 @@ | ||
| 232 | 251 | self::_renderSectionEnd(); |
| 233 | 252 | } |
| 234 | 253 | |
| 235 | 254 | /** |
| 255 | + * Checks if the Excel module can be enabled. | |
| 256 | + */ | |
| 257 | + private static function is_excel_enabled() { | |
| 258 | + $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php'; | |
| 259 | + if ( is_readable( $vendor_file ) ) { | |
| 260 | + include_once( $vendor_file ); | |
| 261 | + } | |
| 262 | + | |
| 263 | + return class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) && extension_loaded( 'zip' ) && extension_loaded( 'xml' ) && extension_loaded( 'fileinfo' ) && version_compare( PHP_VERSION, '5.6.0', '>' ); | |
| 264 | + } | |
| 265 | + | |
| 266 | + /** | |
| 236 | 267 | * Renders chart general settings group. |
| 237 | 268 | * |
| 238 | 269 | * @since 1.0.0 |
| 239 | 270 | * |
| @@ -310,12 +341,61 @@ | ||
| 310 | 341 | |
| 311 | 342 | self::_renderSectionStart( esc_html__( 'Tooltip', 'visualizer' ), false ); |
| 312 | 343 | $this->_renderTooltipSettigns(); |
| 313 | 344 | self::_renderSectionEnd(); |
| 345 | + | |
| 346 | + $this->_renderAnimationSettings(); | |
| 347 | + | |
| 314 | 348 | self::_renderGroupEnd(); |
| 315 | 349 | } |
| 316 | 350 | |
| 317 | 351 | /** |
| 352 | + * Renders animation settings section. | |
| 353 | + * | |
| 354 | + * @access protected | |
| 355 | + */ | |
| 356 | + protected function _renderAnimationSettings() { | |
| 357 | + if ( ! $this->_supportsAnimation ) { | |
| 358 | + return; | |
| 359 | + } | |
| 360 | + | |
| 361 | + self::_renderSectionStart( esc_html__( 'Animation', 'visualizer' ), false ); | |
| 362 | + | |
| 363 | + self::_renderCheckboxItem( | |
| 364 | + esc_html__( 'Animate on startup', 'visualizer' ), | |
| 365 | + 'animation[startup]', | |
| 366 | + isset( $this->animation['startup'] ) ? $this->animation['startup'] : 0, | |
| 367 | + true, | |
| 368 | + esc_html__( 'Determines if the chart will animate on the initial draw.', 'visualizer' ) | |
| 369 | + ); | |
| 370 | + | |
| 371 | + self::_renderTextItem( | |
| 372 | + esc_html__( 'Duration', 'visualizer' ), | |
| 373 | + 'animation[duration]', | |
| 374 | + isset( $this->animation['duration'] ) ? $this->animation['duration'] : 0, | |
| 375 | + esc_html__( 'The duration of the animation, in milliseconds', 'visualizer' ), | |
| 376 | + 0, | |
| 377 | + 'number' | |
| 378 | + ); | |
| 379 | + | |
| 380 | + self::_renderSelectItem( | |
| 381 | + esc_html__( 'Easing', 'visualizer' ), | |
| 382 | + 'animation[easing]', | |
| 383 | + isset( $this->animation['easing'] ) ? $this->animation['easing'] : null, | |
| 384 | + array( | |
| 385 | + 'linear' => esc_html__( 'Constant speed', 'visualizer' ), | |
| 386 | + 'in' => esc_html__( 'Start slow and speed up', 'visualizer' ), | |
| 387 | + 'out' => esc_html__( 'Start fast and slow down', 'visualizer' ), | |
| 388 | + 'inAndOut' => esc_html__( 'Start slow, speed up, then slow down', 'visualizer' ), | |
| 389 | + ), | |
| 390 | + esc_html__( 'The easing function applied to the animation.', 'visualizer' ) | |
| 391 | + ); | |
| 392 | + | |
| 393 | + self::_renderSectionEnd(); | |
| 394 | + | |
| 395 | + } | |
| 396 | + | |
| 397 | + /** | |
| 318 | 398 | * Renders tooltip settings section. |
| 319 | 399 | * |
| 320 | 400 | * @since 1.4.0 |
| 321 | 401 | * |
| @@ -484,9 +564,9 @@ | ||
| 484 | 564 | echo '<a class="more-info" href="javascript:;">[?]</a>'; |
| 485 | 565 | echo '<b>', $title, '</b>'; |
| 486 | 566 | echo '<select class="control-select ', implode( ' ', $classes ) , '" name="', $name, '" ', ( $multiple ? 'multiple' : '' ), ' ' , $atts, '>'; |
| 487 | 567 | foreach ( $options as $key => $label ) { |
| 488 | - $extra = $multiple && is_array( $value ) ? ( in_array( $key, $value ) ? 'selected' : '' ) : selected( $key, $value, false ); | |
| 568 | + $extra = $multiple && is_array( $value ) ? ( in_array( $key, $value, true ) ? 'selected' : '' ) : selected( $key, $value, false ); | |
| 489 | 569 | echo '<option value="', $key, '"', $extra, '>'; |
| 490 | 570 | echo $label; |
| 491 | 571 | echo '</option>'; |
| 492 | 572 | } |
| @@ -667,9 +747,9 @@ | ||
| 667 | 747 | protected static function _renderCheckboxItem( $title, $name, $value, $default, $desc, $disabled = false ) { |
| 668 | 748 | echo '<div class="viz-section-item">'; |
| 669 | 749 | echo '<a class="more-info" href="javascript:;">[?]</a>'; |
| 670 | 750 | echo '<b>', $title, '</b>'; |
| 671 | - echo '<input type="checkbox" class="control-check" value="', $default, '" name="', $name, '" ', ( $value == $default ? 'checked' : '' ), ' ', ( $disabled ? 'disabled=disabled' : '' ), '>'; | |
| 751 | + echo '<input type="checkbox" class="control-check" value="', $default, '" name="', $name, '" ', ( $value === $default ? 'checked' : '' ), ' ', ( $disabled ? 'disabled=disabled' : '' ), '>'; | |
| 672 | 752 | echo '<p class="viz-section-description">', $desc, '</p>'; |
| 673 | 753 | echo '</div>'; |
| 674 | 754 | } |
| 675 | 755 | |
| @@ -688,7 +768,14 @@ | ||
| 688 | 768 | echo '<b>', $title, '</b>'; |
| 689 | 769 | echo '<textarea class="control-text" ', $attributes, ' name="', $name, '" placeholder="', $placeholder, '">', $value, '</textarea>'; |
| 690 | 770 | echo '<p class="viz-section-description">', $desc, '</p>'; |
| 691 | 771 | echo '</div>'; |
| 772 | + } | |
| 773 | + | |
| 774 | + /** | |
| 775 | + * Returns the library this chart implements. | |
| 776 | + */ | |
| 777 | + public function getLibrary() { | |
| 778 | + return $this->_library; | |
| 692 | 779 | } |
| 693 | 780 | |
| 694 | 781 | } |