PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.14
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.14
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 / Graph.php

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

530 lines 17.3 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 sidebar settigns of graph based charts.
24 *
25 * @category Visualizer
26 * @package Render
27 * @subpackage Sidebar
28 *
29 * @since 1.0.0
30 * @abstract
31 */
32 abstract class Visualizer_Render_Sidebar_Graph extends Visualizer_Render_Sidebar_Google {
33
34 /**
35 * Determines whether we need to render vertical gridlines options or not.
36 *
37 * @since 1.0.0
38 *
39 * @access protected
40 * @var boolean
41 */
42 protected $_verticalGridLines;
43
44 /**
45 * Determines whether we need to render horizontal gridlines options or not.
46 *
47 * @since 1.0.0
48 *
49 * @access protected
50 * @var boolean
51 */
52 protected $_horizontalGridLines;
53
54 /**
55 * The array of available axis positions.
56 *
57 * @since 1.0.0
58 *
59 * @access protected
60 * @var array
61 */
62 protected $_positions;
63
64 /**
65 * Constructor.
66 *
67 * @since 1.0.0
68 *
69 * @access public
70 * @param array $data The data what has to be associated with this render.
71 */
72 public function __construct( $data = array() ) {
73 parent::__construct( $data );
74
75 $this->_verticalGridLines = true;
76 $this->_horizontalGridLines = true;
77
78 $this->_positions = array(
79 '' => '',
80 'in' => esc_html__( 'Inside the chart', 'visualizer' ),
81 'out' => esc_html__( 'Outside the chart', 'visualizer' ),
82 'none' => esc_html__( 'None', 'visualizer' ),
83 );
84 }
85
86 /**
87 * Renders chart title settings.
88 *
89 * @since 1.0.0
90 *
91 * @access protected
92 */
93 protected function _renderChartTitleSettings() {
94 self::_renderTextItem(
95 esc_html__( 'Chart Title', 'visualizer' ),
96 'title',
97 $this->title,
98 esc_html__( 'Text to display above the chart.', 'visualizer' )
99 );
100
101 self::_renderSelectItem(
102 esc_html__( 'Chart Title Position', 'visualizer' ),
103 'titlePosition',
104 $this->titlePosition,
105 $this->_positions,
106 esc_html__( 'Where to place the chart title, compared to the chart area.', 'visualizer' )
107 );
108
109 self::_renderColorPickerItem(
110 esc_html__( 'Chart Title Color', 'visualizer' ),
111 'titleTextStyle[color]',
112 isset( $this->titleTextStyle['color'] ) ? $this->titleTextStyle['color'] : null,
113 '#000'
114 );
115
116 echo '<div class="viz-section-delimiter"></div>';
117
118 self::_renderSelectItem(
119 esc_html__( 'Axes Titles Position', 'visualizer' ),
120 'axisTitlesPosition',
121 $this->axisTitlesPosition,
122 $this->_positions,
123 esc_html__( 'Determines where to place the axis titles, compared to the chart area.', 'visualizer' )
124 );
125
126 echo '<div class="viz-section-delimiter"></div>';
127
128 self::_renderTextAreaItem(
129 esc_html__( 'Chart Description', 'visualizer' ),
130 'description',
131 $this->description,
132 sprintf(
133 // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
134 esc_html__( 'Description to display in the structured data schema as explained %1$shere%2$s', 'visualizer' ),
135 '<a href="https://developers.google.com/search/docs/data-types/dataset#dataset" target="_blank">',
136 '</a>'
137 )
138 );
139
140 }
141
142 /**
143 * Renders general settings block for horizontal axis settings.
144 *
145 * @since 1.4.0
146 *
147 * @access protected
148 */
149 protected function _renderHorizontalAxisGeneralSettings() {
150 self::_renderTextItem(
151 esc_html__( 'Axis Title', 'visualizer' ),
152 'hAxis[title]',
153 isset( $this->hAxis['title'] ) ? $this->hAxis['title'] : '',
154 esc_html__( 'The title of the horizontal axis.', 'visualizer' )
155 );
156
157 self::_renderSelectItem(
158 esc_html__( 'Slanted Text', 'visualizer' ),
159 'hAxis[slantedText]',
160 isset( $this->hAxis['slantedText'] ) ? $this->hAxis['slantedText'] : false,
161 array(
162 false => 'False',
163 true => 'True',
164 ),
165 '',
166 false
167 );
168
169 self::_renderTextItem(
170 esc_html__( 'Slanted Text Angle', 'visualizer' ),
171 'hAxis[slantedTextAngle]',
172 isset( $this->hAxis['slantedTextAngle'] ) ? $this->hAxis['slantedTextAngle'] : 45,
173 '',
174 45,
175 'number',
176 array(
177 'min' => 1,
178 'step' => 15,
179 )
180 );
181
182 self::_renderSelectItem(
183 esc_html__( 'Text Position', 'visualizer' ),
184 'hAxis[textPosition]',
185 isset( $this->hAxis['textPosition'] ) ? $this->hAxis['textPosition'] : '',
186 $this->_positions,
187 esc_html__( 'Position of the horizontal axis text, relative to the chart area.', 'visualizer' )
188 );
189
190 self::_renderSelectItem(
191 esc_html__( 'Direction', 'visualizer' ),
192 'hAxis[direction]',
193 isset( $this->hAxis['direction'] ) ? $this->hAxis['direction'] : '',
194 array(
195 '' => '',
196 '1' => esc_html__( 'Identical Direction', 'visualizer' ),
197 '-1' => esc_html__( 'Reverse Direction', 'visualizer' ),
198 ),
199 esc_html__( 'The direction in which the values along the horizontal axis grow.', 'visualizer' )
200 );
201
202 self::_renderColorPickerItem(
203 esc_html__( 'Base Line Color', 'visualizer' ),
204 'vAxis[baselineColor]',
205 isset( $this->vAxis['baselineColor'] ) ? $this->vAxis['baselineColor'] : null,
206 '#000'
207 );
208 }
209
210 /**
211 * Renders horizontal axis settings.
212 *
213 * @since 1.2.0
214 *
215 * @access protected
216 */
217 protected function _renderHorizontalAxisSettings() {
218 self::_renderGroupStart( esc_html__( 'Horizontal Axis Settings', 'visualizer' ) );
219 self::_renderSectionStart( esc_html__( 'General Settings', 'visualizer' ), false );
220 $this->_renderHorizontalAxisGeneralSettings();
221 self::_renderSectionEnd();
222 if ( $this->_horizontalGridLines ) {
223 self::_renderSectionStart( esc_html__( 'Grid Lines', 'visualizer' ), false );
224 self::_renderTextItem(
225 esc_html__( 'Count', 'visualizer' ),
226 'hAxis[gridlines][count]',
227 isset( $this->hAxis['gridlines']['count'] ) ? $this->hAxis['gridlines']['count'] : '',
228 esc_html__( 'The approximate number of horizontal gridlines inside the chart area. You can specify a value of -1 to automatically compute the number of gridlines, 0 or 1 to draw no gridlines, or 2 or more to only draw gridline. Any number greater than 2 will be used to compute the minSpacing between gridlines.', 'visualizer' ),
229 5,
230 'number',
231 array( 'min' => -1, 'max' => 1000, 'step' => 1 )
232 );
233
234 self::_renderColorPickerItem(
235 esc_html__( 'Color', 'visualizer' ),
236 'hAxis[gridlines][color]',
237 isset( $this->hAxis['gridlines']['color'] ) ? $this->hAxis['gridlines']['color'] : null,
238 '#ccc'
239 );
240 self::_renderSectionEnd();
241
242 self::_renderSectionStart( esc_html__( 'Minor Grid Lines', 'visualizer' ), false );
243 self::_renderTextItem(
244 esc_html__( 'Count', 'visualizer' ),
245 'hAxis[minorGridlines][count]',
246 isset( $this->hAxis['minorGridlines']['count'] ) ? $this->hAxis['minorGridlines']['count'] : '',
247 esc_html__( 'Specify 0 to disable the minor gridlines.', 'visualizer' ),
248 0,
249 'number',
250 array( 'min' => 0, 'step' => 1 )
251 );
252
253 self::_renderColorPickerItem(
254 esc_html__( 'Color', 'visualizer' ),
255 'hAxis[minorGridlines][color]',
256 isset( $this->hAxis['minorGridlines']['color'] ) ? $this->hAxis['minorGridlines']['color'] : null,
257 null
258 );
259 self::_renderSectionEnd();
260 }
261
262 if ( $this->_horizontalGridLines ) {
263 self::_renderSectionStart( esc_html__( 'View Window', 'visualizer' ), false );
264 self::_renderTextItem(
265 esc_html__( 'Maximum Value', 'visualizer' ),
266 'hAxis[viewWindow][max]',
267 isset( $this->hAxis['viewWindow']['max'] ) ? $this->hAxis['viewWindow']['max'] : '',
268 'The maximum vertical data value to render.'
269 );
270
271 self::_renderTextItem(
272 esc_html__( 'Minimum Value', 'visualizer' ),
273 'hAxis[viewWindow][min]',
274 isset( $this->hAxis['viewWindow']['min'] ) ? $this->hAxis['viewWindow']['min'] : '',
275 'The minimum vertical data value to render.'
276 );
277 self::_renderSectionEnd();
278 }
279 self::_renderGroupEnd();
280 }
281
282 /**
283 * Renders general settings block for vertical axis settings.
284 *
285 * @since 1.4.0
286 *
287 * @access protected
288 */
289 protected function _renderVerticalAxisGeneralSettings() {
290 self::_renderTextItem(
291 esc_html__( 'Axis Title', 'visualizer' ),
292 'vAxis[title]',
293 isset( $this->vAxis['title'] ) ? $this->vAxis['title'] : '',
294 esc_html__( 'The title of the vertical axis.', 'visualizer' )
295 );
296
297 self::_renderSelectItem(
298 esc_html__( 'Text Position', 'visualizer' ),
299 'vAxis[textPosition]',
300 isset( $this->vAxis['textPosition'] ) ? $this->vAxis['textPosition'] : '',
301 $this->_positions,
302 esc_html__( 'Position of the vertical axis text, relative to the chart area.', 'visualizer' )
303 );
304
305 self::_renderSelectItem(
306 esc_html__( 'Direction', 'visualizer' ),
307 'vAxis[direction]',
308 isset( $this->vAxis['direction'] ) ? $this->vAxis['direction'] : '',
309 array(
310 '' => '',
311 '1' => esc_html__( 'Identical Direction', 'visualizer' ),
312 '-1' => esc_html__( 'Reverse Direction', 'visualizer' ),
313 ),
314 esc_html__( 'The direction in which the values along the vertical axis grow.', 'visualizer' )
315 );
316
317 self::_renderColorPickerItem(
318 esc_html__( 'Base Line Color', 'visualizer' ),
319 'hAxis[baselineColor]',
320 isset( $this->hAxis['baselineColor'] ) ? $this->hAxis['baselineColor'] : null,
321 '#000'
322 );
323 }
324
325 /**
326 * Renders vertical axis settings.
327 *
328 * @since 1.2.0
329 *
330 * @access protected
331 */
332 protected function _renderVerticalAxisSettings() {
333 self::_renderGroupStart( esc_html__( 'Vertical Axis Settings', 'visualizer' ) );
334 self::_renderSectionStart( esc_html__( 'General Settings', 'visualizer' ), false );
335 $this->_renderVerticalAxisGeneralSettings();
336 self::_renderSectionEnd();
337
338 if ( $this->_verticalGridLines ) {
339 self::_renderSectionStart( esc_html__( 'Grid Lines', 'visualizer' ), false );
340 self::_renderTextItem(
341 esc_html__( 'Count', 'visualizer' ),
342 'vAxis[gridlines][count]',
343 isset( $this->vAxis['gridlines']['count'] ) ? $this->vAxis['gridlines']['count'] : '',
344 esc_html__( 'The approximate number of vertical gridlines inside the chart area. You can specify a value of -1 to automatically compute the number of gridlines, 0 or 1 to draw no gridlines, or 2 or more to only draw gridline. Any number greater than 2 will be used to compute the minSpacing between gridlines.', 'visualizer' ),
345 5,
346 'number',
347 array( 'min' => -1, 'max' => 1000, 'step' => 1 )
348 );
349
350 self::_renderColorPickerItem(
351 esc_html__( 'Color', 'visualizer' ),
352 'vAxis[gridlines][color]',
353 isset( $this->vAxis['gridlines']['color'] ) ? $this->vAxis['gridlines']['color'] : null,
354 '#ccc'
355 );
356 self::_renderSectionEnd();
357
358 self::_renderSectionStart( esc_html__( 'Minor Grid Lines', 'visualizer' ), false );
359 self::_renderTextItem(
360 esc_html__( 'Count', 'visualizer' ),
361 'vAxis[minorGridlines][count]',
362 isset( $this->vAxis['minorGridlines']['count'] ) ? $this->vAxis['minorGridlines']['count'] : '',
363 esc_html__( 'Specify 0 to disable the minor gridlines.', 'visualizer' ),
364 0,
365 'number',
366 array( 'min' => 0, 'step' => 1 )
367 );
368
369 self::_renderColorPickerItem(
370 esc_html__( 'Color', 'visualizer' ),
371 'vAxis[minorGridlines][color]',
372 isset( $this->vAxis['minorGridlines']['color'] ) ? $this->vAxis['minorGridlines']['color'] : null,
373 null
374 );
375 self::_renderSectionEnd();
376 }
377
378 if ( $this->_verticalGridLines ) {
379 self::_renderSectionStart( esc_html__( 'View Window', 'visualizer' ), false );
380 self::_renderTextItem(
381 esc_html__( 'Maximum Value', 'visualizer' ),
382 'vAxis[viewWindow][max]',
383 isset( $this->vAxis['viewWindow']['max'] ) ? $this->vAxis['viewWindow']['max'] : '',
384 'The maximum vertical data value to render.'
385 );
386
387 self::_renderTextItem(
388 esc_html__( 'Minimum Value', 'visualizer' ),
389 'vAxis[viewWindow][min]',
390 isset( $this->vAxis['viewWindow']['min'] ) ? $this->vAxis['viewWindow']['min'] : '',
391 'The minimum vertical data value to render.'
392 );
393 self::_renderSectionEnd();
394 }
395 self::_renderGroupEnd();
396 }
397
398 /**
399 * Renders chart axes settings.
400 *
401 * @since 1.0.0
402 *
403 * @access protected
404 */
405 protected function _renderAxesSettings() {
406 $this->_renderHorizontalAxisSettings();
407 $this->_renderVerticalAxisSettings();
408 }
409
410 /**
411 * Renders series settings group.
412 *
413 * @since 1.0.0
414 *
415 * @access protected
416 */
417 protected function _renderSeriesSettings() {
418 self::_renderGroupStart( esc_html__( 'Series Settings', 'visualizer' ) );
419 self::_renderSectionStart();
420 self::_renderSectionDescription( esc_html__( 'If you have just updated/modified the chart data, you may need to save it before the new data reflects in the settings.', 'visualizer' ), 'viz-info-msg' );
421 self::_renderSectionEnd();
422
423 for ( $i = 1, $cnt = count( $this->__series ); $i < $cnt; $i++ ) {
424 if ( ! empty( $this->__series[ $i ]['label'] ) ) {
425 self::_renderSectionStart( esc_html( $this->__series[ $i ]['label'] ), false );
426 $this->_renderSeries( $i - 1 );
427 self::_renderSectionEnd();
428 }
429 }
430 self::_renderGroupEnd();
431 }
432
433 /**
434 * Renders concreate series settings.
435 *
436 * @since 1.0.0
437 *
438 * @access protected
439 * @param int $index The series index.
440 */
441 protected function _renderSeries( $index ) {
442 self::_renderSelectItem(
443 esc_html__( 'Visible In Legend', 'visualizer' ),
444 'series[' . $index . '][visibleInLegend]',
445 isset( $this->series[ $index ]['visibleInLegend'] ) ? $this->series[ $index ]['visibleInLegend'] : '',
446 array(
447 '' => '',
448 '0' => esc_html__( 'No', 'visualizer' ),
449 '1' => esc_html__( 'Yes', 'visualizer' ),
450 ),
451 esc_html__( 'Determines whether the series has to be presented in the legend or not.', 'visualizer' )
452 );
453
454 $this->_renderFormatField( $index );
455
456 self::_renderColorPickerItem(
457 esc_html__( 'Color', 'visualizer' ),
458 'series[' . $index . '][color]',
459 isset( $this->series[ $index ]['color'] ) ? $this->series[ $index ]['color'] : null,
460 null
461 );
462
463 $this->_renderRoleField( $index );
464
465 }
466
467 /**
468 * Renders format field for horizontal axis.
469 *
470 * @since 1.4.3
471 *
472 * @access protected
473 */
474 protected function _renderHorizontalAxisFormatField() {
475 self::_renderTextItem(
476 esc_html__( 'Number Format', 'visualizer' ),
477 'hAxis[format]',
478 isset( $this->hAxis['format'] ) ? $this->hAxis['format'] : '',
479 sprintf(
480 '%s<br><br>%s<br><br>%s',
481 esc_html__( 'Enter custom format pattern to apply to horizontal axis labels.', 'visualizer' ),
482 sprintf(
483 // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
484 esc_html__( 'For number axis labels, this is a subset of the decimal formatting %1$sICU pattern set%2$s. For instance, $#,###.## will display values $1,234.56 for value 1234.56. Pay attention that if you use #&#37;&#37; percentage format then your values will be multiplied by 100.', 'visualizer' ),
485 '<a href="http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details" target="_blank">',
486 '</a>'
487 ),
488 sprintf(
489 // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
490 esc_html__( 'For date axis labels, this is a subset of the date formatting %1$sICU date and time format%2$s.', 'visualizer' ),
491 '<a href="https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax" target="_blank">',
492 '</a>'
493 )
494 )
495 );
496 }
497
498 /**
499 * Renders format field for vertical axis settings.
500 *
501 * @since 1.4.3
502 *
503 * @access protected
504 */
505 protected function _renderVerticalAxisFormatField() {
506 self::_renderTextItem(
507 esc_html__( 'Number Format', 'visualizer' ),
508 'vAxis[format]',
509 isset( $this->vAxis['format'] ) ? $this->vAxis['format'] : '',
510 sprintf(
511 '%s<br><br>%s<br><br>%s',
512 esc_html__( 'Enter custom format pattern to apply to vertical axis labels.', 'visualizer' ),
513 sprintf(
514 // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
515 esc_html__( 'For number axis labels, this is a subset of the decimal formatting %1$sICU pattern set%2$s. For instance, $#,###.## will display values $1,234.56 for value 1234.56. Pay attention that if you use #&#37;&#37; percentage format then your values will be multiplied by 100.', 'visualizer' ),
516 '<a href="http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details" target="_blank">',
517 '</a>'
518 ),
519 sprintf(
520 // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
521 esc_html__( 'For date axis labels, this is a subset of the date formatting %1$sICU date and time format%2$s.', 'visualizer' ),
522 '<a href="https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax" target="_blank">',
523 '</a>'
524 )
525 )
526 );
527 }
528
529 }
530