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

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