Skip to content

Commit 43889d4

Browse files
Merge pull request #560 from contactashish13/issue-214
add support for annotation and other roles
2 parents 2b97024 + 118fb1c commit 43889d4

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

classes/Visualizer/Render/Sidebar/Google.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,29 @@ public static function enqueue_assets( $deps = array() ) {
8383
return 'visualizer-render-google-lib';
8484
}
8585

86-
86+
/**
87+
* Renders the role field.
88+
*
89+
* @since 3.4.0
90+
*
91+
* @access protected
92+
*/
93+
protected function _renderRoleField( $index ) {
94+
self::_renderSelectItem(
95+
esc_html__( 'Special Role', 'visualizer' ),
96+
'series[' . $index . '][role]',
97+
isset( $this->series[ $index ]['role'] ) ? $this->series[ $index ]['role'] : '',
98+
array(
99+
'' => esc_html__( 'Default (Data)', 'visualizer' ),
100+
'annotation' => esc_html__( 'Annotation', 'visualizer' ),
101+
'annotationText' => esc_html__( 'Annotation Text', 'visualizer' ),
102+
'certainty' => esc_html__( 'Certainty', 'visualizer' ),
103+
'emphasis' => esc_html__( 'Emphasis', 'visualizer' ),
104+
'scope' => esc_html__( 'Scope', 'visualizer' ),
105+
'style' => esc_html__( 'Style', 'visualizer' ),
106+
'tooltip' => esc_html__( 'Tooltip', 'visualizer' ),
107+
),
108+
sprintf( esc_html__( 'Determines whether the series has to be used for a special role as mentioned in %1$shere%2$s. You can view a few examples %3$shere%4$s.', 'visualizer' ), '<a href="https://developers.google.com/chart/interactive/docs/roles#what-roles-are-available" target="_blank">', '</a>', '<a href="https://docs.themeisle.com/article/1160-roles-for-series-visualizer" target="_blank">', '</a>' )
109+
);
110+
}
87111
}

classes/Visualizer/Render/Sidebar/Graph.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ protected function _renderSeries( $index ) {
422422
isset( $this->series[ $index ]['color'] ) ? $this->series[ $index ]['color'] : null,
423423
null
424424
);
425+
426+
$this->_renderRoleField( $index );
427+
425428
}
426429

427430
/**

classes/Visualizer/Render/Sidebar/Linear.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ protected function _renderSeries( $index ) {
289289
isset( $this->series[ $index ]['color'] ) ? $this->series[ $index ]['color'] : null,
290290
null
291291
);
292+
293+
$this->_renderRoleField( $index );
294+
292295
}
293296

294297
}

js/render-facade.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@
8181
}
8282

8383
$(document).ready(function(){
84+
// facade loads twice in the library, so all charts are also loaded twice
85+
// this will ensure that even if it loaded twice, it initializes all charts only once.
86+
// fixed as part of the issue to add annotations.
87+
if(visualizer.page_type === 'library'){
88+
if(localStorage.getItem( 'viz-facade-loaded' ) === '1'){
89+
localStorage.removeItem( 'viz-facade-loaded' );
90+
return;
91+
}
92+
localStorage.setItem( 'viz-facade-loaded', '1');
93+
}
8494
$('body').trigger('visualizer:render:chart:start', visualizer);
8595
initActionsButtons(visualizer);
8696
registerDefaultActions();

js/render-google.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ var __visualizer_chart_images = [];
5555
settings['animation']['duration'] = parseInt(settings['animation']['duration']);
5656
}
5757

58+
// mark roles for series that have specified a role
59+
// and then remove them from future processing
60+
// and also adjust the indices of the series array so that
61+
// the ones with a role are ignored
62+
// e.g. if there are 6 columns (0-5) out of which 1, 3 and 5 are annotations
63+
// the final series will only include 0, 2, 4 (reindexed as 0, 1, 2)
64+
if (settings.series) {
65+
var adjusted_series = [];
66+
for (i = 0; i < settings.series.length; i++) {
67+
if (!series[i + 1] || typeof settings.series[i] === 'undefined') {
68+
continue;
69+
}
70+
if(typeof settings.series[i].role !== 'undefined'){
71+
table.setColumnProperty(i + 1, 'role', settings.series[i].role);
72+
if(settings.series[i].role === '') {
73+
adjusted_series.push(settings.series[i]);
74+
}
75+
}
76+
}
77+
settings.series = adjusted_series;
78+
}
5879
if ( settings['explorer_enabled'] && settings['explorer_enabled'] == 'true' ) { // jshint ignore:line
5980
var $explorer = {};
6081
$explorer['keepInBounds'] = true;
@@ -217,7 +238,7 @@ var __visualizer_chart_images = [];
217238
break;
218239
default:
219240
for (i = 0; i < settings.series.length; i++) {
220-
if (!series[i + 1]) {
241+
if (!series[i + 1] || typeof settings.series[i] === 'undefined') {
221242
continue;
222243
}
223244
format_data(id, table, series[i + 1].type, settings.series[i].format, i + 1);
@@ -228,7 +249,6 @@ var __visualizer_chart_images = [];
228249
format_data(id, table, 'number', settings.format, 1);
229250
}
230251

231-
232252
if(settings.hAxis) {
233253
format_data(id, table, series[0].type, settings.hAxis.format, 0);
234254
}

0 commit comments

Comments
 (0)