PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.2.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.2.0
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
visualizer / classes / Visualizer / Render / Sidebar.php

Sidebar.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 2.2.0, at classes/Visualizer/Render/Sidebar.php

619 lines 21.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // +----------------------------------------------------------------------+
4 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
5 // +----------------------------------------------------------------------+
6 // | This program is free software; you can redistribute it and/or modify |
7 // | it under the terms of the GNU General Public License, version 2, as |
8 // | published by the Free Software Foundation. |
9 // | |
10 // | This program is distributed in the hope that it will be useful, |
11 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 // | GNU General Public License for more details. |
14 // | |
15 // | You should have received a copy of the GNU General Public License |
16 // | along with this program; if not, write to the Free Software |
17 // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
18 // | MA 02110-1301 USA |
19 // +----------------------------------------------------------------------+
20 // | Author: Eugene Manuilov <eugene@manuilov.org> |
21 // +----------------------------------------------------------------------+
22 /**
23 * Base class for all chart sidebar groups.
24 *
25 * @category Visualizer
26 * @package Render
27 *
28 * @since 1.0.0
29 * @abstract
30 */
31 abstract class Visualizer_Render_Sidebar extends Visualizer_Render {
32
33 /**
34 * The array of font families accepted by visualization API.
35 *
36 * @since 1.0.0
37 *
38 * @static
39 * @access protected
40 * @var array
41 */
42 protected static $_fontFamilies = array(
43 'Arial' => 'Arial',
44 'Sans Serif' => 'Sans Serif',
45 'serif' => 'Serif',
46 'Arial black' => 'Wide',
47 'Arial Narrow' => 'Narrow',
48 'Comic Sans MS' => 'Comic Sans MS',
49 'Courier New' => 'Courier New',
50 'Garamond' => 'Garamond',
51 'Georgia' => 'Georgia',
52 'Tahoma' => 'Tahoma',
53 'Verdana' => 'Verdana',
54 );
55
56 /**
57 * The Yes/No array.
58 *
59 * @since 1.0.0
60 *
61 * @access protected
62 * @var array
63 */
64 protected $_yesno;
65
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 * Constructor.
88 *
89 * @since 1.0.0
90 *
91 * @access public
92 * @param array $data The data what has to be associated with this render.
93 */
94 public function __construct( $data = array() ) {
95 parent::__construct( $data );
96
97 $this->_legendPositions = array(
98 '' => '',
99 'left' => esc_html__( 'Left of the chart', 'visualizer' ),
100 'right' => esc_html__( 'Right of the chart', 'visualizer' ),
101 'top' => esc_html__( 'Above the chart', 'visualizer' ),
102 'bottom' => esc_html__( 'Below the chart', 'visualizer' ),
103 'in' => esc_html__( 'Inside the chart', 'visualizer' ),
104 'none' => esc_html__( 'Omit the legend', 'visualizer' ),
105 );
106
107 $this->_alignments = array(
108 '' => '',
109 'start' => esc_html__( 'Aligned to the start of the allocated area', 'visualizer' ),
110 'center' => esc_html__( 'Centered in the allocated area', 'visualizer' ),
111 'end' => esc_html__( 'Aligned to the end of the allocated area', 'visualizer' ),
112 );
113
114 $this->_yesno = array(
115 '' => '',
116 '1' => esc_html__( 'Yes', 'visualizer' ),
117 '0' => esc_html__( 'No', 'visualizer' ),
118 );
119 }
120
121 /**
122 * Renders chart title settings.
123 *
124 * @since 1.0.0
125 *
126 * @access protected
127 */
128 protected function _renderChartTitleSettings() {
129 self::_renderTextItem(
130 esc_html__( 'Chart Title', 'visualizer' ),
131 'title',
132 $this->title,
133 esc_html__( 'Text to display above the chart.', 'visualizer' )
134 );
135
136 self::_renderColorPickerItem(
137 esc_html__( 'Chart Title Color', 'visualizer' ),
138 'titleTextStyle[color]',
139 isset( $this->titleTextStyle['color'] ) ? $this->titleTextStyle['color'] : null,
140 '#000'
141 );
142 }
143
144 /**
145 * Renders chart advanced settings group.
146 *
147 * @access protected
148 */
149 protected function _renderAdvancedSettings() {
150 self::_renderGroupStart( esc_html__( 'Frontend Actions', 'visualizer' ) );
151 self::_renderSectionStart();
152 self::_renderSectionDescription( esc_html__( 'Configure frontend actions here.', 'visualizer' ) );
153 self::_renderSectionEnd();
154
155 $this->_renderActionSettings();
156 self::_renderGroupEnd();
157 }
158
159 /**
160 * Renders chart action buttons group.
161 *
162 * @access protected
163 */
164 protected function _renderActionSettings() {
165 self::_renderSectionStart( esc_html__( 'Actions', 'visualizer' ), false );
166 self::_renderCheckboxItem(
167 esc_html__( 'Print', 'visualizer' ),
168 'actions[]',
169 isset( $this->actions ) && in_array( 'print', $this->actions ) ? true : false,
170 'print',
171 esc_html__( 'To enable printing the data.', 'visualizer' )
172 );
173 self::_renderCheckboxItem(
174 esc_html__( 'CSV', 'visualizer' ),
175 'actions[]',
176 isset( $this->actions ) && in_array( 'csv;application/csv', $this->actions ) ? true : false,
177 'csv;application/csv',
178 esc_html__( 'To enable downloading the data as a CSV.', 'visualizer' )
179 );
180
181 $disabled = ! ( extension_loaded( 'zip' ) && extension_loaded( 'xml' ) && version_compare( PHP_VERSION, '5.2.0', '>' ) );
182 self::_renderCheckboxItem(
183 esc_html__( 'Excel', 'visualizer' ),
184 'actions[]',
185 isset( $this->actions ) && in_array( 'xls;application/vnd.ms-excel', $this->actions ) ? true : false,
186 'xls;application/vnd.ms-excel',
187 $disabled ? '<span class="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' ),
188 $disabled
189 );
190 self::_renderCheckboxItem(
191 esc_html__( 'Copy', 'visualizer' ),
192 'actions[]',
193 isset( $this->actions ) && in_array( 'copy', $this->actions ) ? true : false,
194 'copy',
195 esc_html__( 'To enable copying the data to the clipboard.', 'visualizer' )
196 );
197 self::_renderSectionEnd();
198 }
199
200 /**
201 * Renders chart general settings group.
202 *
203 * @since 1.0.0
204 *
205 * @access protected
206 */
207 protected function _renderGeneralSettings() {
208 self::_renderGroupStart( esc_html__( 'General Settings', 'visualizer' ) );
209 self::_renderSectionStart();
210 self::_renderSectionDescription( esc_html__( 'Configure title, font styles, tooltip, legend and else settings for the chart.', 'visualizer' ) );
211 self::_renderSectionEnd();
212
213 self::_renderSectionStart( esc_html__( 'Title', 'visualizer' ), false );
214 $this->_renderChartTitleSettings();
215 self::_renderSectionEnd();
216
217 self::_renderSectionStart( esc_html__( 'Font Styles', 'visualizer' ), false );
218 echo '<div class="section-item">';
219 echo '<a class="more-info" href="javascript:;">[?]</a>';
220 echo '<b>', esc_html__( 'Family And Size', 'visualizer' ), '</b>';
221
222 echo '<table class="section-table" cellspacing="0" cellpadding="0" border="0">';
223 echo '<tr>';
224 echo '<td class="section-table-column">';
225 echo '<select name="fontName" class="control-select">';
226 echo '<option></option>';
227 foreach ( self::$_fontFamilies as $font => $label ) {
228 echo '<option value="', $font, '"', selected( $font, $this->fontName, false ), '>';
229 echo $label;
230 echo '</option>';
231 }
232 echo '</select>';
233 echo '</td>';
234 echo '<td class="section-table-column">';
235 echo '<select name="fontSize" class="control-select">';
236 echo '<option></option>';
237 for ( $i = 7; $i <= 20; $i++ ) {
238 echo '<option value="', $i, '"', selected( $i, $this->fontSize, false ), '>', $i, '</option>';
239 }
240 echo '</select>';
241 echo '</td>';
242 echo '</tr>';
243 echo '</table>';
244
245 echo '<p class="section-description">';
246 esc_html_e( 'The default font family and size for all text in the chart.', 'visualizer' );
247 echo '</p>';
248 echo '</div>';
249 self::_renderSectionEnd();
250
251 self::_renderSectionStart( esc_html__( 'Legend', 'visualizer' ), false );
252 self::_renderSelectItem(
253 esc_html__( 'Position', 'visualizer' ),
254 'legend[position]',
255 $this->legend['position'],
256 $this->_legendPositions,
257 esc_html__( 'Determines where to place the legend, compared to the chart area.', 'visualizer' )
258 );
259
260 self::_renderSelectItem(
261 esc_html__( 'Alignment', 'visualizer' ),
262 'legend[alignment]',
263 $this->legend['alignment'],
264 $this->_alignments,
265 esc_html__( 'Determines the alignment of the legend.', 'visualizer' )
266 );
267
268 self::_renderColorPickerItem(
269 esc_html__( 'Font Color', 'visualizer' ),
270 'legend[textStyle][color]',
271 isset( $this->legend['textStyle']['color'] ) ? $this->legend['textStyle']['color'] : null,
272 '#000'
273 );
274 self::_renderSectionEnd();
275
276 self::_renderSectionStart( esc_html__( 'Tooltip', 'visualizer' ), false );
277 $this->_renderTooltipSettigns();
278 self::_renderSectionEnd();
279 self::_renderGroupEnd();
280 }
281
282 /**
283 * Renders tooltip settings section.
284 *
285 * @since 1.4.0
286 *
287 * @access protected
288 */
289 protected function _renderTooltipSettigns() {
290 self::_renderSelectItem(
291 esc_html__( 'Trigger', 'visualizer' ),
292 'tooltip[trigger]',
293 isset( $this->tooltip['trigger'] ) ? $this->tooltip['trigger'] : null,
294 array(
295 '' => '',
296 'focus' => esc_html__( 'The tooltip will be displayed when the user hovers over an element', 'visualizer' ),
297 'selection' => esc_html__( 'The tooltip will be displayed when the user selects an element', 'visualizer' ),
298 'none' => esc_html__( 'The tooltip will not be displayed', 'visualizer' ),
299 ),
300 esc_html__( 'Determines the user interaction that causes the tooltip to be displayed.', 'visualizer' )
301 );
302
303 self::_renderSelectItem(
304 esc_html__( 'Show Color Code', 'visualizer' ),
305 'tooltip[showColorCode]',
306 isset( $this->tooltip['showColorCode'] ) ? $this->tooltip['showColorCode'] : null,
307 $this->_yesno,
308 esc_html__( 'If set to yes, will show colored squares next to the slice information in the tooltip.', 'visualizer' )
309 );
310 }
311
312 /**
313 * Renders chart view settings group.
314 *
315 * @since 1.0.0
316 *
317 * @access protected
318 */
319 protected function _renderViewSettings() {
320 self::_renderGroupStart( esc_html__( 'Layout & Chart Area', 'visualizer' ) );
321 self::_renderSectionStart( esc_html__( 'Layout', 'visualizer' ), false );
322 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' ) );
323
324 echo '<div class="section-item">';
325 echo '<a class="more-info" href="javascript:;">[?]</a>';
326 echo '<b>', esc_html__( 'Width And Height Of Chart', 'visualizer' ), '</b>';
327
328 echo '<table class="section-table" cellspacing="0" cellpadding="0" border="0">';
329 echo '<tr>';
330 echo '<td class="section-table-column">';
331 echo '<input type="text" name="width" class="control-text" value="', esc_attr( $this->width ), '" placeholder="100%">';
332 echo '</td>';
333 echo '<td class="section-table-column">';
334 echo '<input type="text" name="height" class="control-text" value="', esc_attr( $this->height ), '" placeholder="400">';
335 echo '</td>';
336 echo '</tr>';
337 echo '</table>';
338
339 echo '<p class="section-description">';
340 esc_html_e( 'Determines the total width and height of the chart.', 'visualizer' );
341 echo '</p>';
342 echo '</div>';
343
344 echo '<div class="section-delimiter"></div>';
345
346 self::_renderSectionDescription( esc_html__( 'Configure the background color for the main area of the chart and the chart border width and color.', 'visualizer' ) );
347
348 self::_renderTextItem(
349 esc_html__( 'Stroke Width', 'visualizer' ),
350 'backgroundColor[strokeWidth]',
351 isset( $this->backgroundColor['strokeWidth'] ) ? $this->backgroundColor['strokeWidth'] : null,
352 esc_html__( 'The chart border width in pixels.', 'visualizer' ),
353 '0'
354 );
355
356 self::_renderColorPickerItem(
357 esc_html__( 'Stroke Color', 'visualizer' ),
358 'backgroundColor[stroke]',
359 ! empty( $this->backgroundColor['stroke'] ) ? $this->backgroundColor['stroke'] : null,
360 '#666'
361 );
362
363 $background_color = ! empty( $this->backgroundColor['fill'] ) ? $this->backgroundColor['fill'] : null;
364 self::_renderColorPickerItem(
365 esc_html__( 'Background Color', 'visualizer' ),
366 'backgroundColor[fill]',
367 $background_color,
368 '#fff'
369 );
370
371 echo '<div class="section-item">';
372 echo '<label>';
373 echo '<input type="checkbox" class="control-checkbox" name="backgroundColor[fill]" value="transparent"', checked( $background_color, 'transparent', false ), '> ';
374 esc_html_e( 'Transparent background', 'visualizer' );
375 echo '</label>';
376 echo '</div>';
377 self::_renderSectionEnd();
378
379 self::_renderSectionStart( esc_html__( 'Chart Area', 'visualizer' ), false );
380 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' ) );
381
382 echo '<div class="section-item">';
383 echo '<a class="more-info" href="javascript:;">[?]</a>';
384 echo '<b>', esc_html__( 'Left And Top Margins', 'visualizer' ), '</b>';
385
386 echo '<table class="section-table" cellspacing="0" cellpadding="0" border="0">';
387 echo '<tr>';
388 echo '<td class="section-table-column">';
389 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%">';
390 echo '</td>';
391 echo '<td class="section-table-column">';
392 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%">';
393 echo '</td>';
394 echo '</tr>';
395 echo '</table>';
396
397 echo '<p class="section-description">';
398 esc_html_e( 'Determines how far to draw the chart from the left and top borders.', 'visualizer' );
399 echo '</p>';
400 echo '</div>';
401
402 echo '<div class="section-item">';
403 echo '<a class="more-info" href="javascript:;">[?]</a>';
404 echo '<b>', esc_html__( 'Width And Height Of Chart Area', 'visualizer' ), '</b>';
405
406 echo '<table class="section-table" cellspacing="0" cellpadding="0" border="0">';
407 echo '<tr>';
408 echo '<td class="section-table-column">';
409 echo '<input type="text" name="chartArea[width]" class="control-text" value="', ! empty( $this->chartArea['width'] ) ? esc_attr( $this->chartArea['width'] ) : '', '" placeholder="60%">';
410 echo '</td>';
411 echo '<td class="section-table-column">';
412 echo '<input type="text" name="chartArea[height]" class="control-text" value="', ! empty( $this->chartArea['height'] ) ? esc_attr( $this->chartArea['height'] ) : '', '" placeholder="60%">';
413 echo '</td>';
414 echo '</tr>';
415 echo '</table>';
416
417 echo '<p class="section-description">';
418 esc_html_e( 'Determines the width and hight of the chart area.', 'visualizer' );
419 echo '</p>';
420 echo '</div>';
421 self::_renderSectionEnd();
422 self::_renderGroupEnd();
423 }
424
425 /**
426 * Renders select item.
427 *
428 * @since 1.0.0
429 *
430 * @static
431 * @access protected
432 * @param string $title The title of the select item.
433 * @param string $name The name of the select item.
434 * @param string $value The actual value of the select item.
435 * @param array $options The array of select options.
436 * @param string $desc The description of the select item.
437 */
438 protected static function _renderSelectItem( $title, $name, $value, array $options, $desc ) {
439 echo '<div class="section-item">';
440 echo '<a class="more-info" href="javascript:;">[?]</a>';
441 echo '<b>', $title, '</b>';
442 echo '<select class="control-select" name="', $name, '">';
443 foreach ( $options as $key => $label ) {
444 echo '<option value="', $key, '"', selected( $key, $value, false ), '>';
445 echo $label;
446 echo '</option>';
447 }
448 echo '</select>';
449 echo '<p class="section-description">', $desc, '</p>';
450 echo '</div>';
451 }
452
453 /**
454 * Renders color picker item.
455 *
456 * @since 1.0.0
457 *
458 * @static
459 * @access protected
460 * @param string $title The title of the select item.
461 * @param string $name The name of the select item.
462 * @param string $value The actual value of the select item.
463 * @param string $default The default value of the color picker.
464 */
465 protected static function _renderColorPickerItem( $title, $name, $value, $default ) {
466 echo '<div class="section-item">';
467 echo '<b>', $title, '</b>';
468 echo '<div>';
469 echo '<input type="text" class="color-picker-hex" name="', $name, '" maxlength="7" placeholder="', esc_attr__( 'Hex Value', 'visualizer' ), '" value="', is_null( $value ) ? $default : esc_attr( $value ), '" data-default-color="', $default, '">';
470 echo '</div>';
471 echo '</div>';
472 }
473
474 /**
475 * Renders text item.
476 *
477 * @since 1.0.0
478 *
479 * @static
480 * @access protected
481 * @param string $title The title of the select item.
482 * @param string $name The name of the select item.
483 * @param string $value The actual value of the select item.
484 * @param string $desc The description of the select item.
485 * @param string $placeholder The placeholder for the input.
486 */
487 protected static function _renderTextItem( $title, $name, $value, $desc, $placeholder = '' ) {
488 echo '<div class="section-item">';
489 echo '<a class="more-info" href="javascript:;">[?]</a>';
490 echo '<b>', $title, '</b>';
491 echo '<input type="text" class="control-text" name="', $name, '" value="', esc_attr( $value ), '" placeholder="', $placeholder, '">';
492 echo '<p class="section-description">', $desc, '</p>';
493 echo '</div>';
494 }
495
496 /**
497 * Renders the beginning of a group.
498 *
499 * @since 1.0.0
500 *
501 * @static
502 * @access protected
503 * @param string $title The title of this group.
504 */
505 protected static function _renderGroupStart( $title ) {
506 echo '<li class="group">';
507 echo '<h3 class="group-title">', $title, '</h3>';
508 echo '<ul class="group-content">';
509 }
510
511 /**
512 * Renders the ending of a group.
513 *
514 * @since 1.0.0
515 *
516 * @static
517 * @access protected
518 */
519 protected static function _renderGroupEnd() {
520 echo '</ul>';
521 echo '</li>';
522 }
523
524 /**
525 * Renders the beginning of a section.
526 *
527 * @since 1.0.0
528 *
529 * @static
530 * @access protected
531 * @param string $title The title of this section. If the title is empty, no title will be displayed.
532 * @param boolean $open Determines whether the section items block has to be expanded or collapsed.
533 */
534 protected static function _renderSectionStart( $title = false, $open = true ) {
535
536 if ( ! empty( $title ) ) {
537 echo '<li class="subsection">';
538 echo '<span class="section-title">', $title, '</span>';
539 } else {
540 echo '<li class=" ">';
541 }
542 echo '<div class="section-items', $open ? ' open' : '', '">';
543 }
544
545 /**
546 * Renders the ending of a section.
547 *
548 * @since 1.0.0
549 *
550 * @static
551 * @access protected
552 */
553 protected static function _renderSectionEnd() {
554 echo '</div>';
555 echo '</li>';
556 }
557
558 /**
559 * Renders section description block.
560 *
561 * @since 1.0.0
562 *
563 * @static
564 * @access protected
565 * @param string $description The description text.
566 */
567 protected static function _renderSectionDescription( $description ) {
568 echo '<div class="section-item">';
569 echo '<div class="section-description">', $description, '</div>';
570 echo '</div>';
571 }
572
573 /**
574 * Renders format field according to series type.
575 *
576 * @since 1.3.0
577 *
578 * @access protected
579 * @param int $index The index of the series.
580 */
581 protected function _renderFormatField( $index = 0 ) {
582 switch ( $this->__series[ $index + 1 ]['type'] ) {
583 case 'number':
584 self::_renderTextItem(
585 esc_html__( 'Number Format', 'visualizer' ),
586 'series[' . $index . '][format]',
587 isset( $this->series[ $index ]['format'] ) ? $this->series[ $index ]['format'] : '',
588 sprintf( esc_html__( 'Enter custom format pattern to apply to this series value, similar to the %1$sICU pattern set%2$s. Use something like #,### to get 1,234 as output, or $# to add dollar sign before digits. Pay attention that if you use &#37; percentage format then your values will be multiplied by 100.', 'visualizer' ), '<a href="http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details" target="_blank">', '</a>' ),
589 '#,###.##'
590 );
591 break;
592 case 'date':
593 case 'datetime':
594 case 'timeofday':
595 self::_renderTextItem(
596 esc_html__( 'Date Format', 'visualizer' ),
597 'series[' . $index . '][format]',
598 isset( $this->series[ $index ]['format'] ) ? $this->series[ $index ]['format'] : '',
599 sprintf( esc_html__( 'Enter custom format pattern to apply to this series value, similar to the %1$sICU date and time format%2$s.', 'visualizer' ), '<a href="http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax" target="_blank">', '</a>' ),
600 'eeee, dd LLLL yyyy'
601 );
602 break;
603 }
604 }
605
606 /**
607 * Render a checkbox item
608 */
609 protected static function _renderCheckboxItem( $title, $name, $value, $default, $desc, $disabled = false ) {
610 echo '<div class="section-item">';
611 echo '<a class="more-info" href="javascript:;">[?]</a>';
612 echo '<b>', $title, '</b>';
613 echo '<input type="checkbox" class="control-check" value="', $default, '" name="', $name, '" ', ($value == $default ? 'checked' : ''), ' ', ($disabled ? 'disabled=disabled' : ''), '>';
614 echo '<p class="section-description">', $desc, '</p>';
615 echo '</div>';
616 }
617
618 }
619