Skip to content

Commit 977d0bf

Browse files
Fix render chart issue when creating first time chart Codeinwp/visualizer-pro#316
1 parent eaf3aa4 commit 977d0bf

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

classes/Visualizer/Module.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -742,14 +742,16 @@ public static function get_chart_data( $chart, $type, $run_filter = true ) {
742742
// change HTML entities
743743
$data = unserialize( html_entity_decode( htmlentities( $chart->post_content ) ) );
744744
$altered = array();
745-
foreach ( $data as $index => $array ) {
746-
if ( ! is_array( $index ) && is_array( $array ) ) {
747-
foreach ( $array as &$datum ) {
748-
if ( is_string( $datum ) ) {
749-
$datum = stripslashes( $datum );
745+
if ( ! empty( $data ) ) {
746+
foreach ( $data as $index => $array ) {
747+
if ( ! is_array( $index ) && is_array( $array ) ) {
748+
foreach ( $array as &$datum ) {
749+
if ( is_string( $datum ) ) {
750+
$datum = stripslashes( $datum );
751+
}
750752
}
753+
$altered[ $index ] = $array;
751754
}
752-
$altered[ $index ] = $array;
753755
}
754756
}
755757
// if something goes wrong and the end result is empty, be safe and use the original data

classes/Visualizer/Module/Chart.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,7 @@ public function uploadData() {
11371137
$chart->post_content = $content;
11381138
}
11391139
wp_update_post( $chart->to_array() );
1140+
11401141
update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
11411142
update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
11421143
update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 );
@@ -1146,6 +1147,15 @@ public function uploadData() {
11461147
Visualizer_Module_Utility::set_defaults( $chart, null );
11471148

11481149
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
1150+
if ( isset( $settings['series'] ) && ! ( count( $settings['series'] ) - count( $source->getSeries() ) > 1 ) ) {
1151+
$diff_total_series = abs( count( $settings['series'] ) - count( $source->getSeries() ) );
1152+
if ( $diff_total_series ) {
1153+
foreach ( range( 1, $diff_total_series ) as $k => $diff_series ) {
1154+
$settings['series'][] = end( $settings['series'] );
1155+
}
1156+
update_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, $settings );
1157+
}
1158+
}
11491159

11501160
$render->id = $chart->ID;
11511161
$render->data = json_encode( $source->getRawData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );

classes/Visualizer/Source/Csv/Remote.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ private function _repopulate( $chart_id ) {
9797
* @return array The re populated array of data or old one.
9898
*/
9999
public function repopulateData( $data, $chart_id ) {
100+
if ( ! is_array( $data ) ) {
101+
$data = array();
102+
}
100103
return array_key_exists( 'data', $data ) ? $data['data'] : $data;
101104
}
102105

0 commit comments

Comments
 (0)