Skip to content

Commit fbc9731

Browse files
Merge branch 'development' of https://github.com/codeinwp/visualizer into issue-688
2 parents 38bc843 + b1c1447 commit fbc9731

File tree

5 files changed

+128
-97
lines changed

5 files changed

+128
-97
lines changed

classes/Visualizer/Gutenberg/build/block.js

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/src/Editor.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
ButtonGroup,
3030
Dashicon,
3131
Placeholder,
32+
Notice,
3233
Spinner
3334
} = wp.components;
3435

@@ -78,11 +79,20 @@ class Editor extends Component {
7879

7980
// Fetch review again if block loaded after saving.
8081
if ( this.props.attributes.id ) {
81-
let result = await apiFetch({ path: `wp/v2/visualizer/${this.props.attributes.id}` });
82-
83-
this.setState({
84-
chart: result['chart_data']
85-
});
82+
let result = await apiFetch({ path: `wp/v2/visualizer/${this.props.attributes.id}` }).catch( function( error ) {
83+
});
84+
85+
if ( result ) {
86+
this.setState({
87+
chart: result['chart_data']
88+
});
89+
} else {
90+
91+
// if the chart is not found.
92+
this.setState({
93+
route: 'error'
94+
});
95+
}
8696
}
8797
}
8898

@@ -311,10 +321,11 @@ class Editor extends Component {
311321
});
312322
}
313323

314-
editChartData( chartData, type ) {
324+
editChartData( chartData, source ) {
315325
let chart = { ...this.state.chart };
316326
let series = [];
317327
let settings = { ...chart['visualizer-settings'] };
328+
let type = chart['visualizer-chart-type'];
318329
chartData[0].map( ( i, index ) => {
319330
series[index] = {
320331
label: i,
@@ -327,17 +338,17 @@ class Editor extends Component {
327338
let map = series;
328339
let fieldName = 'series';
329340

330-
if ( 'pie' === chart['visualizer-chart-type']) {
341+
if ( 'pie' === type ) {
331342
map = chartData;
332343
fieldName = 'slices';
333344
}
334345

335346
map.map( ( i, index ) => {
336-
if ( 'pie' !== chart['visualizer-chart-type'] && 0 === index ) {
347+
if ( 'pie' !== type && 0 === index ) {
337348
return;
338349
}
339350

340-
const seriesIndex = 'pie' !== chart['visualizer-chart-type'] ? index - 1 : index;
351+
const seriesIndex = 'pie' !== type ? index - 1 : index;
341352

342353
if ( settings[fieldName][seriesIndex] === undefined ) {
343354
settings[fieldName][seriesIndex] = {};
@@ -346,11 +357,11 @@ class Editor extends Component {
346357
});
347358

348359
settings[fieldName] = settings[fieldName].filter( ( i, index ) => {
349-
const length = 'pie' !== chart['visualizer-chart-type'] ? map.length - 1 : map.length;
360+
const length = -1 >= [ 'pie', 'tabular', 'dataTable' ].indexOf( type ) ? map.length - 1 : map.length;
350361
return index < length;
351362
});
352363

353-
chart['visualizer-source'] = type;
364+
chart['visualizer-source'] = source;
354365
chart['visualizer-default-data'] = 0;
355366
chart['visualizer-data'] = chartData;
356367
chart['visualizer-series'] = series;
@@ -409,6 +420,18 @@ class Editor extends Component {
409420
}
410421

411422
render() {
423+
if ( 'error' === this.state.route ) {
424+
return (
425+
<Notice
426+
status="error"
427+
isDismissible={ false }
428+
>
429+
<Dashicon icon="chart-pie" />
430+
{ __( 'This chart is not available; it might have been deleted. Please delete this block and resubmit your chart.' ) }
431+
</Notice>
432+
);
433+
}
434+
412435
if ( 'renderChart' === this.state.route && null !== this.state.chart ) {
413436
return (
414437
<ChartRender

classes/Visualizer/Module/Frontend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public function renderChart( $atts ) {
375375
'map_api_key' => get_option( 'visualizer-map-api-key' ),
376376
'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
377377
'i10n' => array(
378-
'copied' => __( 'Copied!', 'visualizer' ),
378+
'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ),
379379
),
380380
'page_type' => 'frontend',
381381
'is_front' => true,

js/render-facade.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
function initActionsButtons(v) {
88
if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) {
9+
$('a.visualizer-action[data-visualizer-type=copy]').on('click', function(e) {
10+
e.preventDefault();
11+
});
912
var clipboard = new Clipboard('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
1013
clipboard.on('success', function(e) {
1114
window.alert(v.i10n['copied']);
@@ -88,24 +91,23 @@
8891
document.body.dispatchEvent(event);
8992
};
9093

91-
// facade loads N times in the library (where N = the number of different chart libraries supported)
94+
// facade loads N times in the library and front end (where N = the number of different chart libraries supported)
9295
// so all charts are also loaded N times
9396
// this will ensure that no matter how many times facade is loaded, it initializes all charts only once.
9497
// fixed as part of the issue to add annotations.
95-
if(visualizer.page_type === 'library'){
96-
if(localStorage.getItem( 'viz-facade-loaded' ) === '1'){
97-
// prevent library from hanging.
98-
setTimeout( function(){
99-
localStorage.removeItem( 'viz-facade-loaded' );
100-
}, 2000);
101-
return;
102-
}
103-
localStorage.setItem( 'viz-facade-loaded', '1');
104-
// remove the flag so that repeated loading of the library does not cause problems.
98+
if(localStorage.getItem( 'viz-facade-loaded' ) === '1'){
99+
// prevent library from hanging.
105100
setTimeout( function(){
106101
localStorage.removeItem( 'viz-facade-loaded' );
107102
}, 2000);
103+
return;
108104
}
105+
localStorage.setItem( 'viz-facade-loaded', '1');
106+
// remove the flag so that repeated loading of the library does not cause problems.
107+
setTimeout( function(){
108+
localStorage.removeItem( 'viz-facade-loaded' );
109+
}, 2000);
110+
109111
$('body').trigger('visualizer:render:chart:start', visualizer);
110112
initActionsButtons(visualizer);
111113
registerDefaultActions();

0 commit comments

Comments
 (0)