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

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

452 lines 13.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Base class for sidebar settigns of ChartJS based charts.
5 *
6 * @category Visualizer
7 * @package Render
8 * @subpackage Sidebar
9 *
10 * @since 3.2.0
11 * @abstract
12 */
13 abstract class Visualizer_Render_Sidebar_ChartJS extends Visualizer_Render_Sidebar {
14
15 /**
16 * The array of available legend positions.
17 *
18 * @since 1.0.0
19 *
20 * @access protected
21 * @var array
22 */
23 protected $_legendPositions;
24
25
26 /**
27 * The constructor.
28 */
29 public function __construct( $data = array() ) {
30 $this->_library = 'chartjs';
31 parent::__construct( $data );
32
33 $this->_legendPositions = array(
34 'left' => esc_html__( 'Left of the chart', 'visualizer' ),
35 'right' => esc_html__( 'Right of the chart', 'visualizer' ),
36 'top' => esc_html__( 'Above the chart', 'visualizer' ),
37 'bottom' => esc_html__( 'Below the chart', 'visualizer' ),
38 'bottom' => esc_html__( 'Below the chart', 'visualizer' ),
39 'none' => esc_html__( 'Omit the legend', 'visualizer' ),
40 );
41
42 }
43
44 /**
45 * Renders concrete series settings for the Bar chart.
46 *
47 * @since 3.3.0
48 *
49 * @access protected
50 * @param int $index The series index.
51 */
52 protected function _renderChartTypeSeries( $index ) {
53 // empty.
54 }
55
56 /**
57 * Renders settings specific to the Bar chart.
58 *
59 * @since 3.3.0
60 *
61 * @access protected
62 */
63 protected function _renderChartTypeSettings() {
64 // empty
65 }
66
67 /**
68 * Registers additional hooks.
69 *
70 * @access protected
71 */
72 protected function hooks() {
73 if ( $this->_library === 'chartjs' ) {
74 add_filter( 'visualizer_assets_render', array( $this, 'load_chartjs_assets' ), 10, 2 );
75 }
76 }
77
78 /**
79 * Loads the assets.
80 */
81 function load_chartjs_assets( $deps, $is_frontend ) {
82 $this->load_dependent_assets( array( 'moment', 'numeral' ) );
83
84 wp_register_script( 'chartjs', VISUALIZER_ABSURL . 'js/lib/chartjs.min.js', array( 'numeral', 'moment' ), null, true );
85 wp_register_script(
86 'visualizer-render-chartjs-lib',
87 VISUALIZER_ABSURL . 'js/render-chartjs.js',
88 array(
89 'chartjs',
90 ),
91 Visualizer_Plugin::VERSION,
92 true
93 );
94
95 return array_merge(
96 $deps,
97 array( 'visualizer-render-chartjs-lib' )
98 );
99
100 }
101
102 /**
103 * Renders series settings group.
104 *
105 * @since 3.3.0
106 *
107 * @access protected
108 */
109 protected function _renderSeriesSettings() {
110 self::_renderGroupStart( esc_html__( 'Series Settings', 'visualizer' ) );
111 self::_renderSectionStart();
112 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' );
113 self::_renderSectionEnd();
114
115 for ( $i = 1, $cnt = count( $this->__series ); $i < $cnt; $i++ ) {
116 if ( ! empty( $this->__series[ $i ]['label'] ) ) {
117 self::_renderSectionStart( esc_html( $this->__series[ $i ]['label'] ), false );
118 $this->_renderSeries( $i - 1 );
119 self::_renderSectionEnd();
120 }
121 }
122 self::_renderGroupEnd();
123 }
124
125 /**
126 * Renders concrete series settings.
127 *
128 * @since 3.3.0
129 *
130 * @access protected
131 * @param int $index The series index.
132 */
133 protected function _renderSeries( $index ) {
134 $this->_renderFormatField( $index );
135 $this->_renderChartTypeSeries( $index );
136
137 }
138
139 /**
140 * Renders template.
141 *
142 * @since 3.3.0
143 *
144 * @access protected
145 */
146 protected function _toHTML() {
147 $this->_renderGeneralSettings();
148 $this->_renderAxesSettings();
149 $this->_renderChartTypeSettings();
150 $this->_renderSeriesSettings();
151 $this->_renderViewSettings();
152 $this->_renderAdvancedSettings();
153 }
154
155 /**
156 * Renders chart title settings.
157 *
158 * @since 3.3.0
159 *
160 * @access protected
161 */
162 protected function _renderChartTitleSettings() {
163 self::_renderTextItem(
164 esc_html__( 'Chart Title', 'visualizer' ),
165 'title[text]',
166 isset( $this->title['text'] ) ? $this->title['text'] : '',
167 esc_html__( 'Text to display above the chart.', 'visualizer' )
168 );
169
170 self::_renderColorPickerItem(
171 esc_html__( 'Chart Title Color', 'visualizer' ),
172 'title[fontColor]',
173 isset( $this->title['fontColor'] ) ? $this->title['fontColor'] : '',
174 '#000'
175 );
176
177 echo '<div class="viz-section-delimiter"></div>';
178
179 self::_renderTextAreaItem(
180 esc_html__( 'Chart Description', 'visualizer' ),
181 'description',
182 $this->description,
183 sprintf(
184 // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
185 esc_html__( 'Description to display in the structured data schema as explained %1$shere%2$s', 'visualizer' ),
186 '<a href="https://developers.google.com/search/docs/data-types/dataset#dataset" target="_blank">',
187 '</a>'
188 )
189 );
190
191 }
192
193 /**
194 * Renders chart general settings group.
195 *
196 * @since 3.3.0
197 *
198 * @access protected
199 */
200 protected function _renderGeneralSettings() {
201 self::_renderGroupStart( esc_html__( 'General Settings', 'visualizer' ) );
202 self::_renderSectionStart();
203 self::_renderSectionDescription( esc_html__( 'Configure title, font styles, tooltip, legend and else settings for the chart.', 'visualizer' ) );
204 self::_renderSectionEnd();
205
206 self::_renderSectionStart( esc_html__( 'Title', 'visualizer' ), false );
207 $this->_renderChartTitleSettings();
208 self::_renderSectionEnd();
209
210 self::_renderSectionStart( esc_html__( 'Font Styles', 'visualizer' ), false );
211 echo '<div class="viz-section-item">';
212 echo '<a class="more-info" href="javascript:;">[?]</a>';
213 echo '<b>', esc_html__( 'Family And Size', 'visualizer' ), '</b>';
214
215 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
216 echo '<tr>';
217 echo '<td class="viz-section-table-column">';
218 echo '<select name="fontName" class="control-select">';
219 echo '<option></option>';
220 foreach ( self::$_fontFamilies as $font => $label ) {
221 echo '<option value="', $font, '"', selected( $font, $this->fontName, false ), '>';
222 echo $label;
223 echo '</option>';
224 }
225 echo '</select>';
226 echo '</td>';
227 echo '<td class="viz-section-table-column">';
228 echo '<select name="fontSize" class="control-select">';
229 echo '<option></option>';
230 for ( $i = 7; $i <= 20; $i++ ) {
231 echo '<option value="', $i, '"', selected( $i, $this->fontSize, false ), '>', $i, '</option>';
232 }
233 echo '</select>';
234 echo '</td>';
235 echo '</tr>';
236 echo '</table>';
237
238 echo '<p class="viz-section-description">';
239 esc_html_e( 'The default font family and size for all text in the chart.', 'visualizer' );
240 echo '</p>';
241 echo '</div>';
242 self::_renderSectionEnd();
243
244 self::_renderSectionStart( esc_html__( 'Legend', 'visualizer' ), false );
245 self::_renderSelectItem(
246 esc_html__( 'Position', 'visualizer' ),
247 'legend[position]',
248 // let's have a default otherwise the chart behaves weird when hovering in edit mode
249 isset( $this->legend['position'] ) ? $this->legend['position'] : 'top',
250 $this->_legendPositions,
251 esc_html__( 'Determines where to place the legend, compared to the chart area.', 'visualizer' )
252 );
253
254 self::_renderCheckboxItem(
255 esc_html__( 'Show datasets in reverse order', 'visualizer' ),
256 'legend[reverse]',
257 isset( $this->legend['reverse'] ) ? $this->legend['reverse'] : false,
258 'true',
259 esc_html__( 'Legend will show datasets in reverse order.', 'visualizer' )
260 );
261
262 echo '<div class="viz-section-item">';
263 echo '<a class="more-info" href="javascript:;">[?]</a>';
264 echo '<b>', esc_html__( 'Family And Size', 'visualizer' ), '</b>';
265
266 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
267 echo '<tr>';
268 echo '<td class="viz-section-table-column">';
269 echo '<select name="legend[labels][fontName]" class="control-select">';
270 echo '<option></option>';
271 foreach ( self::$_fontFamilies as $font => $label ) {
272 echo '<option value="', $font, '"', selected( $font, $this->legend['labels']['fontName'], false ), '>';
273 echo $label;
274 echo '</option>';
275 }
276 echo '</select>';
277 echo '</td>';
278 echo '<td class="viz-section-table-column">';
279 echo '<select name="legend[labels][fontSize]" class="control-select">';
280 echo '<option></option>';
281 for ( $i = 7; $i <= 20; $i++ ) {
282 echo '<option value="', $i, '"', selected( $i, $this->legend['labels']['fontSize'], false ), '>', $i, '</option>';
283 }
284 echo '</select>';
285 echo '</td>';
286 echo '</tr>';
287 echo '</table>';
288
289 self::_renderColorPickerItem(
290 esc_html__( 'Font Color', 'visualizer' ),
291 'legend[labels][fontColor]',
292 isset( $this->legend['labels']['fontColor'] ) ? $this->legend['labels']['fontColor'] : null,
293 '#000'
294 );
295
296 echo '</div>';
297
298 self::_renderSectionEnd();
299
300 self::_renderSectionStart( esc_html__( 'Tooltip', 'visualizer' ), false );
301 $this->_renderTooltipSettigns();
302 self::_renderSectionEnd();
303
304 $this->_renderAnimationSettings();
305
306 self::_renderSectionStart( esc_html__( 'License & Creator', 'visualizer' ), false );
307 self::_renderTextItem(
308 esc_html__( 'License', 'visualizer' ),
309 'license',
310 $this->license,
311 ''
312 );
313 self::_renderTextItem(
314 esc_html__( 'Creator', 'visualizer' ),
315 'creator',
316 $this->creator,
317 ''
318 );
319 self::_renderSectionEnd();
320
321 self::_renderChartImageSettings();
322
323 self::_renderGroupEnd();
324 }
325
326 /**
327 * Renders animation settings section.
328 *
329 * @access protected
330 */
331 protected function _renderAnimationSettings() {
332 if ( ! $this->_supportsAnimation ) {
333 return;
334 }
335
336 self::_renderSectionStart( esc_html__( 'Animation', 'visualizer' ), false );
337
338 self::_renderTextItem(
339 esc_html__( 'Duration', 'visualizer' ),
340 'animation[duration]',
341 isset( $this->animation['duration'] ) ? $this->animation['duration'] : 1000,
342 esc_html__( 'The duration of the animation, in milliseconds', 'visualizer' ),
343 1000,
344 'number',
345 array( 'min' => 1000 )
346 );
347
348 self::_renderSelectItem(
349 esc_html__( 'Easing', 'visualizer' ),
350 'animation[easing]',
351 isset( $this->animation['easing'] ) ? $this->animation['easing'] : null,
352 array(
353 'linear' => esc_html__( 'Constant speed', 'visualizer' ),
354 'easeInQuad' => esc_html__( 'easeInQuad', 'visualizer' ),
355 'easeOutQuad' => esc_html__( 'easeOutQuad', 'visualizer' ),
356 'easeInOutQuad' => esc_html__( 'easeInOutQuad', 'visualizer' ),
357 'easeInCubic' => esc_html__( 'easeInCubic', 'visualizer' ),
358 'easeOutCubic' => esc_html__( 'easeOutCubic', 'visualizer' ),
359 'easeInOutCubic' => esc_html__( 'easeInOutCubic', 'visualizer' ),
360 'easeInQuart' => esc_html__( 'easeInQuart', 'visualizer' ),
361 'easeOutQuart' => esc_html__( 'easeOutQuart', 'visualizer' ),
362 'easeInOutQuart' => esc_html__( 'easeInOutQuart', 'visualizer' ),
363 'easeInQuint' => esc_html__( 'easeInQuint', 'visualizer' ),
364 'easeOutQuint' => esc_html__( 'easeOutQuint', 'visualizer' ),
365 ),
366 esc_html__( 'The easing function applied to the animation.', 'visualizer' )
367 );
368
369 self::_renderSectionEnd();
370
371 }
372
373 /**
374 * Renders tooltip settings section.
375 *
376 * @since 1.4.0
377 *
378 * @access protected
379 */
380 protected function _renderTooltipSettigns() {
381 self::_renderCheckboxItem(
382 esc_html__( 'Trigger', 'visualizer' ),
383 'tooltip[intersect]',
384 $this->tooltip['intersect'],
385 1,
386 esc_html__( 'Determines if the tooltip should only display when the mouse intersects with an element.', 'visualizer' )
387 );
388 }
389
390 /**
391 * Add the correct description for the manual configuration box.
392 */
393 protected function _renderManualConfigDescription() {
394 self::_renderSectionStart();
395 self::_renderSectionDescription(
396 '<span class="viz-gvlink">' . sprintf(
397 // translators: %1$s - HTML link tag, %2$s - HTML closing link tag, %3$s - HTML link tag, %4$s - HTML closing link tag.
398 __( 'Configure the graph by providing configuration variables right from the %1$sChartJS API%2$s. You can refer to to some examples %3$shere%4$s.', 'visualizer' ),
399 '<a href="https://www.chartjs.org/docs/latest/configuration/" target="_blank">',
400 '</a>',
401 '<a href="https://docs.themeisle.com/article/728-manual-configuration" target="_blank">',
402 '</a>'
403 ) . '</span>'
404 );
405 }
406
407 /**
408 * Add the correct example for the manual configuration box.
409 */
410 protected function _renderManualConfigExample() {
411 return '{
412 "cutoutPercentage": 5,
413 "rotation": 60
414 }';
415 }
416
417 /**
418 * Renders chart view settings group.
419 *
420 * @since 3.3.0
421 *
422 * @access protected
423 */
424 protected function _renderViewSettings() {
425 self::_renderGroupStart( esc_html__( 'Chart Size', 'visualizer' ) );
426 self::_renderSectionStart();
427 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' ) );
428
429 echo '<div class="viz-section-item">';
430 echo '<a class="more-info" href="javascript:;">[?]</a>';
431 echo '<b>', esc_html__( 'Width And Height Of Chart', 'visualizer' ), '</b>';
432
433 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
434 echo '<tr>';
435 echo '<td class="viz-section-table-column">';
436 echo '<input type="text" name="width" class="control-text" value="', esc_attr( $this->width ), '" placeholder="100%">';
437 echo '</td>';
438 echo '<td class="viz-section-table-column">';
439 echo '<input type="text" name="height" class="control-text" value="', esc_attr( $this->height ), '" placeholder="400">';
440 echo '</td>';
441 echo '</tr>';
442 echo '</table>';
443
444 echo '<p class="viz-section-description">';
445 esc_html_e( 'Determines the total width and height of the chart. This will only show in the front-end.', 'visualizer' );
446 echo '</p>';
447 echo '</div>';
448 self::_renderSectionEnd();
449 self::_renderGroupEnd();
450 }
451 }
452