Skip to content

Commit b4ecc47

Browse files
set chart defaults whenver new data is loaded
1 parent ce97e12 commit b4ecc47

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ private function _handleTypesPage() {
750750
update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
751751
}
752752

753-
Visualizer_Module_Utility::set_defaults( $this->_chart, $type, $library );
753+
Visualizer_Module_Utility::set_defaults( $this->_chart );
754754

755755
// redirect to next tab
756756
// changed by Ash/Upwork
@@ -970,9 +970,15 @@ public function uploadData() {
970970
update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
971971
update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
972972
update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 );
973+
974+
Visualizer_Module_Utility::set_defaults( $chart, null );
975+
976+
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
977+
973978
$render->id = $chart->ID;
974979
$render->data = json_encode( $source->getRawData() );
975980
$render->series = json_encode( $source->getSeries() );
981+
$render->settings = json_encode( $settings );
976982
} else {
977983
$render->message = esc_html__( 'CSV file is broken or invalid. Please, try again.', 'visualizer' );
978984
}

classes/Visualizer/Module/Utility.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ private static function get_random_color() {
125125
*
126126
* @access public
127127
*/
128-
public static function set_defaults( $chart, $type, $library ) {
129-
if ( $chart->post_status !== 'auto-draft' || $library !== 'ChartJS' ) {
128+
public static function set_defaults( $chart, $post_status = 'auto-draft' ) {
129+
$type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
130+
$library = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_LIBRARY, true );
131+
132+
if ( ( ! is_null( $post_status ) && $chart->post_status !== $post_status ) || $library !== 'ChartJS' ) {
130133
return;
131134
}
132135

js/render-chartjs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@
292292
for (j = 0; j < atts.length; j++) {
293293
var values = [];
294294
for (var i = 0; i < rows.length; i++) {
295-
values.push(settings.slices[i][atts[j]]);
295+
if(typeof settings.slices[i] !== 'undefined' && typeof settings.slices[i][atts[j]] !== 'undefined'){
296+
values.push(settings.slices[i][atts[j]]);
297+
}
296298
}
297299
var object = {};
298300
object[ atts[ j ] ] = values;

0 commit comments

Comments
 (0)