Skip to content

Commit ce24700

Browse files
author
cristian-ungureanu
authored
Merge pull request #852 from Codeinwp/bugfix/851
Fix multiple chart rendering issue
2 parents 870d8aa + 2f4d1af commit ce24700

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

classes/Visualizer/Module/Frontend.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ public function renderChart( $atts ) {
353353
return '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '>' . wp_get_attachment_image( $chart_image, 'full' ) . '</div>';
354354
}
355355
}
356+
// Unset chart image base64 string.
357+
if ( isset( $settings['chart-img'] ) ) {
358+
unset( $settings['chart-img'] );
359+
}
356360

357361
// add chart to the array
358362
$this->_charts[ $id ] = array(
@@ -395,22 +399,29 @@ public function renderChart( $atts ) {
395399

396400
$actions_div .= $css;
397401

402+
$_charts = array();
403+
$_charts_type = '';
398404
foreach ( $this->_charts as $id => $array ) {
405+
$_charts = $this->_charts;
399406
$library = $array['library'];
400-
wp_register_script(
401-
"visualizer-render-$library",
402-
VISUALIZER_ABSURL . 'js/render-facade.js',
403-
apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
404-
Visualizer_Plugin::VERSION,
405-
true
406-
);
407-
408-
wp_enqueue_script( "visualizer-render-$library" );
407+
$_charts_type = $library;
408+
if ( ! wp_script_is( "visualizer-render-$library", 'registered' ) ) {
409+
wp_register_script(
410+
"visualizer-render-$library",
411+
VISUALIZER_ABSURL . 'js/render-facade.js',
412+
apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
413+
Visualizer_Plugin::VERSION,
414+
true
415+
);
416+
wp_enqueue_script( "visualizer-render-$library" );
417+
}
418+
}
419+
if ( wp_script_is( "visualizer-render-$_charts_type" ) ) {
409420
wp_localize_script(
410-
"visualizer-render-$library",
421+
"visualizer-render-$_charts_type",
411422
'visualizer',
412423
array(
413-
'charts' => $this->_charts,
424+
'charts' => $_charts,
414425
'language' => $this->get_language(),
415426
'map_api_key' => get_option( 'visualizer-map-api-key' ),
416427
'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
@@ -422,8 +433,8 @@ public function renderChart( $atts ) {
422433
'is_front' => true,
423434
)
424435
);
425-
wp_enqueue_style( 'visualizer-front' );
426436
}
437+
wp_enqueue_style( 'visualizer-front' );
427438

428439
// return placeholder div
429440
return $actions_div . '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '></div>' . $this->addSchema( $chart->ID );

0 commit comments

Comments
 (0)