PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 4.0.7
Visualizer – Tables & Charts Manager with Built-in AI Generator v4.0.7
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 4.0.7, at classes/Visualizer/Render/Sidebar/ChartJS.php

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