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

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

395 lines 12.0 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 for ( $i = 1, $cnt = count( $this->__series ); $i < $cnt; $i++ ) {
99 if ( ! empty( $this->__series[ $i ]['label'] ) ) {
100 self::_renderSectionStart( esc_html( $this->__series[ $i ]['label'] ), false );
101 $this->_renderSeries( $i - 1 );
102 self::_renderSectionEnd();
103 }
104 }
105 self::_renderGroupEnd();
106 }
107
108 /**
109 * Renders concrete series settings.
110 *
111 * @since 3.3.0
112 *
113 * @access protected
114 * @param int $index The series index.
115 */
116 protected function _renderSeries( $index ) {
117 $this->_renderFormatField( $index );
118 $this->_renderChartTypeSeries( $index );
119
120 }
121
122 /**
123 * Renders template.
124 *
125 * @since 3.3.0
126 *
127 * @access protected
128 */
129 protected function _toHTML() {
130 $this->_renderGeneralSettings();
131 $this->_renderAxesSettings();
132 $this->_renderChartTypeSettings();
133 $this->_renderSeriesSettings();
134 $this->_renderViewSettings();
135 $this->_renderAdvancedSettings();
136 }
137
138 /**
139 * Renders chart title settings.
140 *
141 * @since 3.3.0
142 *
143 * @access protected
144 */
145 protected function _renderChartTitleSettings() {
146 self::_renderTextItem(
147 esc_html__( 'Chart Title', 'visualizer' ),
148 'title[text]',
149 isset( $this->title['text'] ) ? $this->title['text'] : '',
150 esc_html__( 'Text to display above the chart.', 'visualizer' )
151 );
152
153 self::_renderColorPickerItem(
154 esc_html__( 'Chart Title Color', 'visualizer' ),
155 'title[fontColor]',
156 isset( $this->title['fontColor'] ) ? $this->title['fontColor'] : '',
157 '#000'
158 );
159
160 }
161
162 /**
163 * Renders chart general settings group.
164 *
165 * @since 3.3.0
166 *
167 * @access protected
168 */
169 protected function _renderGeneralSettings() {
170 self::_renderGroupStart( esc_html__( 'General Settings', 'visualizer' ) );
171 self::_renderSectionStart();
172 self::_renderSectionDescription( esc_html__( 'Configure title, font styles, tooltip, legend and else settings for the chart.', 'visualizer' ) );
173 self::_renderSectionEnd();
174
175 self::_renderSectionStart( esc_html__( 'Title', 'visualizer' ), false );
176 $this->_renderChartTitleSettings();
177 self::_renderSectionEnd();
178
179 self::_renderSectionStart( esc_html__( 'Font Styles', 'visualizer' ), false );
180 echo '<div class="viz-section-item">';
181 echo '<a class="more-info" href="javascript:;">[?]</a>';
182 echo '<b>', esc_html__( 'Family And Size', 'visualizer' ), '</b>';
183
184 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
185 echo '<tr>';
186 echo '<td class="viz-section-table-column">';
187 echo '<select name="fontName" class="control-select">';
188 echo '<option></option>';
189 foreach ( self::$_fontFamilies as $font => $label ) {
190 echo '<option value="', $font, '"', selected( $font, $this->fontName, false ), '>';
191 echo $label;
192 echo '</option>';
193 }
194 echo '</select>';
195 echo '</td>';
196 echo '<td class="viz-section-table-column">';
197 echo '<select name="fontSize" class="control-select">';
198 echo '<option></option>';
199 for ( $i = 7; $i <= 20; $i++ ) {
200 echo '<option value="', $i, '"', selected( $i, $this->fontSize, false ), '>', $i, '</option>';
201 }
202 echo '</select>';
203 echo '</td>';
204 echo '</tr>';
205 echo '</table>';
206
207 echo '<p class="viz-section-description">';
208 esc_html_e( 'The default font family and size for all text in the chart.', 'visualizer' );
209 echo '</p>';
210 echo '</div>';
211 self::_renderSectionEnd();
212
213 self::_renderSectionStart( esc_html__( 'Legend', 'visualizer' ), false );
214 self::_renderSelectItem(
215 esc_html__( 'Position', 'visualizer' ),
216 'legend[position]',
217 // let's have a default otherwise the chart behaves weird when hovering in edit mode
218 isset( $this->legend['position'] ) ? $this->legend['position'] : 'top',
219 $this->_legendPositions,
220 esc_html__( 'Determines where to place the legend, compared to the chart area.', 'visualizer' )
221 );
222
223 self::_renderCheckboxItem(
224 esc_html__( 'Show datasets in reverse order', 'visualizer' ),
225 'legend[reverse]',
226 isset( $this->legend['reverse'] ) ? $this->legend['reverse'] : false,
227 'true',
228 esc_html__( 'Legend will show datasets in reverse order.', 'visualizer' )
229 );
230
231 echo '<div class="viz-section-item">';
232 echo '<a class="more-info" href="javascript:;">[?]</a>';
233 echo '<b>', esc_html__( 'Family And Size', 'visualizer' ), '</b>';
234
235 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
236 echo '<tr>';
237 echo '<td class="viz-section-table-column">';
238 echo '<select name="legend[labels][fontName]" class="control-select">';
239 echo '<option></option>';
240 foreach ( self::$_fontFamilies as $font => $label ) {
241 echo '<option value="', $font, '"', selected( $font, $this->legend['labels']['fontName'], false ), '>';
242 echo $label;
243 echo '</option>';
244 }
245 echo '</select>';
246 echo '</td>';
247 echo '<td class="viz-section-table-column">';
248 echo '<select name="legend[labels][fontSize]" class="control-select">';
249 echo '<option></option>';
250 for ( $i = 7; $i <= 20; $i++ ) {
251 echo '<option value="', $i, '"', selected( $i, $this->legend['labels']['fontSize'], false ), '>', $i, '</option>';
252 }
253 echo '</select>';
254 echo '</td>';
255 echo '</tr>';
256 echo '</table>';
257
258 self::_renderColorPickerItem(
259 esc_html__( 'Font Color', 'visualizer' ),
260 'legend[labels][fontColor]',
261 isset( $this->legend['labels']['fontColor'] ) ? $this->legend['labels']['fontColor'] : null,
262 '#000'
263 );
264
265 echo '</div>';
266
267 self::_renderSectionEnd();
268
269 self::_renderSectionStart( esc_html__( 'Tooltip', 'visualizer' ), false );
270 $this->_renderTooltipSettigns();
271 self::_renderSectionEnd();
272
273 $this->_renderAnimationSettings();
274
275 self::_renderGroupEnd();
276 }
277
278 /**
279 * Renders animation settings section.
280 *
281 * @access protected
282 */
283 protected function _renderAnimationSettings() {
284 if ( ! $this->_supportsAnimation ) {
285 return;
286 }
287
288 self::_renderSectionStart( esc_html__( 'Animation', 'visualizer' ), false );
289
290 self::_renderTextItem(
291 esc_html__( 'Duration', 'visualizer' ),
292 'animation[duration]',
293 isset( $this->animation['duration'] ) ? $this->animation['duration'] : 1000,
294 esc_html__( 'The duration of the animation, in milliseconds', 'visualizer' ),
295 1000,
296 'number',
297 array( 'min' => 1000 )
298 );
299
300 self::_renderSelectItem(
301 esc_html__( 'Easing', 'visualizer' ),
302 'animation[easing]',
303 isset( $this->animation['easing'] ) ? $this->animation['easing'] : null,
304 array(
305 'linear' => esc_html__( 'Constant speed', 'visualizer' ),
306 'easeInQuad' => esc_html__( 'easeInQuad', 'visualizer' ),
307 'easeOutQuad' => esc_html__( 'easeOutQuad', 'visualizer' ),
308 'easeInOutQuad' => esc_html__( 'easeInOutQuad', 'visualizer' ),
309 'easeInCubic' => esc_html__( 'easeInCubic', 'visualizer' ),
310 'easeOutCubic' => esc_html__( 'easeOutCubic', 'visualizer' ),
311 'easeInOutCubic' => esc_html__( 'easeInOutCubic', 'visualizer' ),
312 'easeInQuart' => esc_html__( 'easeInQuart', 'visualizer' ),
313 'easeOutQuart' => esc_html__( 'easeOutQuart', 'visualizer' ),
314 'easeInOutQuart' => esc_html__( 'easeInOutQuart', 'visualizer' ),
315 'easeInQuint' => esc_html__( 'easeInQuint', 'visualizer' ),
316 'easeOutQuint' => esc_html__( 'easeOutQuint', 'visualizer' ),
317 ),
318 esc_html__( 'The easing function applied to the animation.', 'visualizer' )
319 );
320
321 self::_renderSectionEnd();
322
323 }
324
325 /**
326 * Renders tooltip settings section.
327 *
328 * @since 1.4.0
329 *
330 * @access protected
331 */
332 protected function _renderTooltipSettigns() {
333 self::_renderCheckboxItem(
334 esc_html__( 'Trigger', 'visualizer' ),
335 'tooltip[intersect]',
336 $this->tooltip['intersect'],
337 1,
338 esc_html__( 'Determines if the tooltip should only display when the mouse intersects with an element.', 'visualizer' )
339 );
340 }
341
342 /**
343 * Add the correct description for the manual configuration box.
344 */
345 protected function _renderManualConfigDescription() {
346 self::_renderSectionStart();
347 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>' );
348 }
349
350 /**
351 * Add the correct example for the manual configuration box.
352 */
353 protected function _renderManualConfigExample() {
354 return '{
355 "cutoutPercentage": 5,
356 "rotation": 60
357 }';
358 }
359
360 /**
361 * Renders chart view settings group.
362 *
363 * @since 3.3.0
364 *
365 * @access protected
366 */
367 protected function _renderViewSettings() {
368 self::_renderGroupStart( esc_html__( 'Chart Size', 'visualizer' ) );
369 self::_renderSectionStart();
370 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' ) );
371
372 echo '<div class="viz-section-item">';
373 echo '<a class="more-info" href="javascript:;">[?]</a>';
374 echo '<b>', esc_html__( 'Width And Height Of Chart', 'visualizer' ), '</b>';
375
376 echo '<table class="viz-section-table" cellspacing="0" cellpadding="0" border="0">';
377 echo '<tr>';
378 echo '<td class="viz-section-table-column">';
379 echo '<input type="text" name="width" class="control-text" value="', esc_attr( $this->width ), '" placeholder="100%">';
380 echo '</td>';
381 echo '<td class="viz-section-table-column">';
382 echo '<input type="text" name="height" class="control-text" value="', esc_attr( $this->height ), '" placeholder="400">';
383 echo '</td>';
384 echo '</tr>';
385 echo '</table>';
386
387 echo '<p class="viz-section-description">';
388 esc_html_e( 'Determines the total width and height of the chart. This will only show in the front-end.', 'visualizer' );
389 echo '</p>';
390 echo '</div>';
391 self::_renderSectionEnd();
392 self::_renderGroupEnd();
393 }
394 }
395