@@ -118,8 +118,7 @@ private static function get_random_color() {
118
118
}
119
119
120
120
/**
121
- * Sets some defaults (colors etc.) in the chart.
122
- * Currently only for ChartJS.
121
+ * Sets some defaults in the chart.
123
122
*
124
123
* @since 3.3.0
125
124
*
@@ -129,20 +128,69 @@ public static function set_defaults( $chart, $post_status = 'auto-draft' ) {
129
128
$ type = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_CHART_TYPE , true );
130
129
$ library = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_CHART_LIBRARY , true );
131
130
132
- if ( ( ! is_null ( $ post_status ) && $ chart ->post_status !== $ post_status ) || $ library !== 'ChartJS ' ) {
131
+ // if post_status is null, operate on the chart irrespective of the post_status
132
+ if ( ( ! is_null ( $ post_status ) && $ chart ->post_status !== $ post_status ) ) {
133
133
return ;
134
134
}
135
135
136
- $ series = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SERIES , true );
137
- $ settings = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SETTINGS , true );
136
+ $ series = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SERIES , true );
138
137
if ( ! $ series || ! is_array ( $ series ) ) {
139
138
return ;
140
139
}
141
140
141
+ switch ( $ library ) {
142
+ case 'ChartJS ' :
143
+ self ::set_defaults_chartjs ( $ chart , $ post_status );
144
+ break ;
145
+ case 'GoogleCharts ' :
146
+ self ::set_defaults_google ( $ chart , $ post_status );
147
+ break ;
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Sets some defaults in the chart for Google charts.
153
+ *
154
+ * @since 3.3.0
155
+ *
156
+ * @access private
157
+ */
158
+ private static function set_defaults_google ( $ chart , $ post_status ) {
159
+ $ type = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_CHART_TYPE , true );
160
+
161
+ $ attributes = array ();
162
+ if ( $ post_status === 'auto-draft ' ) {
163
+ switch ( $ type ) {
164
+ case 'combo ' :
165
+ // chart type 'bars' and first series 'line'.
166
+ $ attributes ['seriesType ' ] = 'bars ' ;
167
+ $ attributes ['series ' ][0 ]['type ' ] = 'line ' ;
168
+ break ;
169
+ }
170
+ }
171
+
172
+ if ( $ attributes ) {
173
+ $ settings = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SETTINGS , true );
174
+ update_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SETTINGS , array_merge ( $ settings , $ attributes ) );
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Sets some defaults in the chart for ChartJS charts.
180
+ *
181
+ * @since 3.3.0
182
+ *
183
+ * @access private
184
+ */
185
+ private static function set_defaults_chartjs ( $ chart , $ post_status ) {
186
+ $ type = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_CHART_TYPE , true );
187
+ $ series = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SERIES , true );
188
+ $ settings = get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SETTINGS , true );
189
+
190
+ $ attributes = array ();
142
191
$ name = 'series ' ;
143
192
$ count = count ( $ series );
144
193
$ max = $ count - 1 ;
145
- $ attributes = array ();
146
194
switch ( $ type ) {
147
195
case 'polarArea ' :
148
196
// fall through.
@@ -170,10 +218,10 @@ public static function set_defaults( $chart, $post_status = 'auto-draft' ) {
170
218
}
171
219
break ;
172
220
}
221
+
173
222
if ( $ attributes ) {
174
223
$ settings [ $ name ] = $ attributes ;
175
224
update_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SETTINGS , $ settings );
176
225
}
177
226
}
178
-
179
227
}
0 commit comments