Skip to content

Commit 5e3057c

Browse files
author
cristian-ungureanu
authored
release: new version
- [Feat] Allow charts to render in dashboard areas via 3rd party plugins like Dashboard Widgets Suite - [Fix] Changing Line Chart series style to dot on some series changes the order of tooltip information - [Fix] Problem with X-Axis of Line chart on Safari if date/datetime is used as values - [Fix] Multiple Visualizer charts causing rendering issues (blank page) - [Fix] Charts are not resizing on landscape view on mobile - [Fix] Notices/Warnings appear on the front-end if the user is not logged in for some charts - [Fix] Radar/Spider Chart Tooltip in PRO does not show the data value
2 parents 0437b39 + b5c2ee8 commit 5e3057c

File tree

14 files changed

+1904
-123
lines changed

14 files changed

+1904
-123
lines changed

.github/workflows/test-php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
with:
5252
php-version: '7.1'
5353
extensions: simplexml, mysql
54-
tools: phpunit:7.5.15
54+
tools: phpunit-polyfills
5555
- name: Checkout source code
5656
uses: actions/checkout@v2
5757
- name: Install WordPress Test Suite

classes/Visualizer/Gutenberg/build/block.js

Lines changed: 282 additions & 10 deletions
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: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class ChartRender extends Component {
6161
footer = __( 'Annotations in this chart may not display here but they will display in the front end.' );
6262
}
6363

64+
if ( this.props.chart['visualizer-series'] && 0 <= [ 'date', 'datetime', 'timeofday' ].indexOf( this.props.chart['visualizer-series'][0].type ) ) {
65+
if ( this.props.chart['visualizer-settings'] && '' == this.props.chart['visualizer-settings'].hAxis.format ) {
66+
this.props.chart['visualizer-settings'].hAxis.format = 'YYYY-MM-dd';
67+
}
68+
}
69+
6470
return (
6571
<div className={ this.props.className }>
6672

classes/Visualizer/Gutenberg/src/Components/Sidebar/SeriesSettings.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SeriesSettings extends Component {
6363
let indexToFormat = parseInt( i );
6464
let label = series[i].label || '';
6565
let type = series[i].type || '';
66-
66+
let timer = 0;
6767
if ( 'tabular' !== type ) {
6868
indexToFormat = index;
6969
}
@@ -105,6 +105,15 @@ class SeriesSettings extends Component {
105105
settings.series[index].lineWidth = e;
106106
this.props.edit( settings );
107107
} }
108+
onKeyUp={ e => {
109+
clearTimeout( timer );
110+
timer = setTimeout( () => {
111+
if ( '' != settings.series[index].lineWidth && 0 >= settings.series[index].lineWidth ) {
112+
settings.series[index].lineWidth = '0.1';
113+
this.props.edit( settings );
114+
}
115+
}, 700 );
116+
} }
108117
/>
109118

110119
<TextControl

classes/Visualizer/Module.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -740,16 +740,28 @@ public static final function get_features_for_license( $plan ) {
740740
*/
741741
public static function get_chart_data( $chart, $type, $run_filter = true ) {
742742
// change HTML entities
743-
$data = unserialize( html_entity_decode( htmlentities( $chart->post_content ) ) );
743+
$post_content = html_entity_decode( htmlentities( $chart->post_content ) );
744+
$post_content = preg_replace_callback(
745+
'!s:(\d+):"(.*?)";!s',
746+
function ( $matches ) {
747+
if ( isset( $matches[2] ) ) {
748+
return 's:' . strlen( $matches[2] ) . ':"' . $matches[2] . '";';
749+
}
750+
},
751+
$post_content
752+
);
753+
$data = unserialize( $post_content );
744754
$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 );
755+
if ( ! empty( $data ) ) {
756+
foreach ( $data as $index => $array ) {
757+
if ( ! is_array( $index ) && is_array( $array ) ) {
758+
foreach ( $array as &$datum ) {
759+
if ( is_string( $datum ) ) {
760+
$datum = stripslashes( $datum );
761+
}
750762
}
763+
$altered[ $index ] = $array;
751764
}
752-
$altered[ $index ] = $array;
753765
}
754766
}
755767
// 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/Module/Frontend.php

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
5454
parent::__construct( $plugin );
5555

5656
$this->_addAction( 'wp_enqueue_scripts', 'enqueueScripts' );
57+
$this->_addAction( 'load-index.php', 'enqueueScripts' );
5758
$this->_addAction( 'visualizer_enqueue_scripts', 'enqueueScripts' );
5859
$this->_addFilter( 'visualizer_get_language', 'getLanguage' );
5960
$this->_addShortcode( 'visualizer', 'renderChart' );
@@ -353,6 +354,10 @@ public function renderChart( $atts ) {
353354
return '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '>' . wp_get_attachment_image( $chart_image, 'full' ) . '</div>';
354355
}
355356
}
357+
// Unset chart image base64 string.
358+
if ( isset( $settings['chart-img'] ) ) {
359+
unset( $settings['chart-img'] );
360+
}
356361

357362
// add chart to the array
358363
$this->_charts[ $id ] = array(
@@ -395,22 +400,29 @@ public function renderChart( $atts ) {
395400

396401
$actions_div .= $css;
397402

403+
$_charts = array();
404+
$_charts_type = '';
398405
foreach ( $this->_charts as $id => $array ) {
406+
$_charts = $this->_charts;
399407
$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" );
408+
$_charts_type = $library;
409+
if ( ! wp_script_is( "visualizer-render-$library", 'registered' ) ) {
410+
wp_register_script(
411+
"visualizer-render-$library",
412+
VISUALIZER_ABSURL . 'js/render-facade.js',
413+
apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
414+
Visualizer_Plugin::VERSION,
415+
true
416+
);
417+
wp_enqueue_script( "visualizer-render-$library" );
418+
}
419+
}
420+
if ( wp_script_is( "visualizer-render-$_charts_type" ) ) {
409421
wp_localize_script(
410-
"visualizer-render-$library",
422+
"visualizer-render-$_charts_type",
411423
'visualizer',
412424
array(
413-
'charts' => $this->_charts,
425+
'charts' => $_charts,
414426
'language' => $this->get_language(),
415427
'map_api_key' => get_option( 'visualizer-map-api-key' ),
416428
'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
@@ -422,8 +434,8 @@ public function renderChart( $atts ) {
422434
'is_front' => true,
423435
)
424436
);
425-
wp_enqueue_style( 'visualizer-front' );
426437
}
438+
wp_enqueue_style( 'visualizer-front' );
427439

428440
// return placeholder div
429441
return $actions_div . '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '></div>' . $this->addSchema( $chart->ID );
@@ -570,13 +582,25 @@ private function getChartData( $cache_key = '', $chart_id = 0 ) {
570582
// Get chart by ID.
571583
$chart = get_post( $chart_id );
572584
if ( $chart && Visualizer_Plugin::CPT_VISUALIZER === $chart->post_type ) {
585+
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
586+
$series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true );
587+
588+
if ( isset( $settings['series'] ) && ! ( count( $settings['series'] ) - count( $series ) > 1 ) ) {
589+
$diff_total_series = abs( count( $settings['series'] ) - count( $series ) );
590+
if ( $diff_total_series ) {
591+
foreach ( range( 1, $diff_total_series ) as $k => $diff_series ) {
592+
$settings['series'][] = end( $settings['series'] );
593+
}
594+
}
595+
}
573596
$chart_data = array(
574597
'chart' => $chart,
575598
'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ),
576-
'settings' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ),
577-
'series' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ),
599+
'settings' => $settings,
600+
'series' => $series,
578601
'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ),
579602
);
603+
580604
// Put the results in a transient. Expire after 12 hours.
581605
set_transient( $cache_key, $chart_data, apply_filters( Visualizer_Plugin::FILTER_HANDLE_CACHE_EXPIRATION_TIME, 12 * HOUR_IN_SECONDS ) );
582606
return $chart_data;

classes/Visualizer/Render/Sidebar/Linear.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ protected function _renderSeries( $index ) {
257257
echo '<tr>';
258258
echo '<td class="viz-section-table-column">';
259259
$line_width = isset( $this->series[ $index ]['lineWidth'] ) ? $this->series[ $index ]['lineWidth'] : '';
260-
echo '<input type="text" name="series[', $index, '][lineWidth]" class="control-text" value="', esc_attr( $line_width ), '" placeholder="2">';
260+
echo '<input type="text" name="series[', $index, '][lineWidth]" class="control-text series-linewidth" value="', esc_attr( $line_width ), '" placeholder="2">';
261261
echo '</td>';
262262
echo '<td class="viz-section-table-column">';
263263
$point_size = isset( $this->series[ $index ]['pointSize'] ) ? $this->series[ $index ]['pointSize'] : '';

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)