Skip to content

Commit dab8091

Browse files
Merge branch 'issue-440' of https://github.com/contactashish13/visualizer; branch '3.3.0' of https://github.com/codeinwp/visualizer into issue-440
2 parents cb6e733 + 4eb6c66 commit dab8091

File tree

8 files changed

+75
-19
lines changed

8 files changed

+75
-19
lines changed

classes/Visualizer/Gutenberg/Block.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ public function get_visualizer_data( $post ) {
194194

195195
$data['visualizer-chart-type'] = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_TYPE, true );
196196

197+
$data['visualizer-chart-library'] = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_LIBRARY, true );
198+
197199
$data['visualizer-source'] = get_post_meta( $post_id, Visualizer_Plugin::CF_SOURCE, true );
198200

199201
$data['visualizer-default-data'] = get_post_meta( $post_id, Visualizer_Plugin::CF_DEFAULT_DATA, true );

classes/Visualizer/Gutenberg/build/block.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/build/block.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/build/handsontable.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/build/handsontable.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/src/Components/Charts.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ class Charts extends Component {
101101
chart = `${ startCase( data['visualizer-chart-type']) }Chart`;
102102
}
103103

104+
if ( data['visualizer-chart-library']) {
105+
if ( 'ChartJS' === data['visualizer-chart-library']) {
106+
return;
107+
}
108+
}
109+
104110
if ( 'dataTable' === chart ) {
105111
return;
106112
}

classes/Visualizer/Module/Utility.php

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ private static function get_random_color() {
118118
}
119119

120120
/**
121-
* Sets some defaults (colors etc.) in the chart.
122-
* Currently only for ChartJS.
121+
* Sets some defaults in the chart.
123122
*
124123
* @since 3.3.0
125124
*
@@ -129,20 +128,69 @@ public static function set_defaults( $chart, $post_status = 'auto-draft' ) {
129128
$type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
130129
$library = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_LIBRARY, true );
131130

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 ) ) {
133133
return;
134134
}
135135

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 );
138137
if ( ! $series || ! is_array( $series ) ) {
139138
return;
140139
}
141140

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();
142191
$name = 'series';
143192
$count = count( $series );
144193
$max = $count - 1;
145-
$attributes = array();
146194
switch ( $type ) {
147195
case 'polarArea':
148196
// fall through.
@@ -170,10 +218,10 @@ public static function set_defaults( $chart, $post_status = 'auto-draft' ) {
170218
}
171219
break;
172220
}
221+
173222
if ( $attributes ) {
174223
$settings[ $name ] = $attributes;
175224
update_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, $settings );
176225
}
177226
}
178-
179227
}

samples/candlestick.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Date,GBP/USD,,,
1+
Date,GBP/USD,GBP/USD,GBP/USD,GBP/USD
22
date,number,number,number,number
33
2013-07-10,20,28,38,45
44
2013-07-11,31,38,55,66

0 commit comments

Comments
 (0)