Skip to content

Commit d8e8573

Browse files
Merge branch '3.4.0' of https://github.com/codeinwp/visualizer into issue-525
2 parents 12be3e4 + 90b36b1 commit d8e8573

File tree

12 files changed

+142
-24
lines changed

12 files changed

+142
-24
lines changed

classes/Visualizer/Gutenberg/.eslintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
],
1717
"rules": {
1818
"indent": [
19-
"error",
19+
"warn",
2020
"tab"
2121
],
2222
"linebreak-style": [
23-
"error",
23+
"warn",
2424
"unix"
2525
],
2626
"quotes": [

classes/Visualizer/Gutenberg/Block.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function enqueue_gutenberg_scripts() {
7575
$handsontableCSS = VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/handsontable.css';
7676

7777
if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) {
78-
$version = filemtime( VISUALIZER_ABSPATH . 'classes/Visualizer/Gutenberg/build/block.js' );
78+
$version = filemtime( VISUALIZER_ABSPATH . '/classes/Visualizer/Gutenberg/build/block.js' );
7979
} else {
8080
$version = $this->version;
8181
}
@@ -299,7 +299,8 @@ public function get_visualizer_data( $post ) {
299299

300300
$data['visualizer-chart-type'] = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_TYPE, true );
301301

302-
$data['visualizer-chart-library'] = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_LIBRARY, true );
302+
$library = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_LIBRARY, true );
303+
$data['visualizer-chart-library'] = $library;
303304

304305
$data['visualizer-source'] = get_post_meta( $post_id, Visualizer_Plugin::CF_SOURCE, true );
305306

@@ -317,6 +318,52 @@ public function get_visualizer_data( $post ) {
317318
// handle data filter hooks
318319
$data['visualizer-data'] = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( get_the_content( $post_id ) ) ), $post_id, $data['visualizer-chart-type'] );
319320

321+
$data['visualizer-data-exploded'] = '';
322+
// handle annotations for google charts
323+
if ( 'GoogleCharts' === $library ) {
324+
// this will contain the data of both axis.
325+
$settings = $data['visualizer-settings'];
326+
// this will contain data only of Y axis.
327+
$series = $data['visualizer-series'];
328+
$annotations = array();
329+
if ( isset( $settings['series'] ) ) {
330+
foreach ( $settings['series'] as $index => $serie ) {
331+
// skip X axis data.
332+
if ( $index === 0 ) {
333+
continue;
334+
}
335+
if ( ! empty( $serie['role'] ) ) {
336+
// this series is some kind of annotation, so let's collect its index.
337+
// the index will be +1 because the X axis value is index 0, which is being ignored.
338+
$annotations[ 'role' . ( intval( $index ) + 1 ) ] = $serie['role'];
339+
}
340+
}
341+
}
342+
if ( ! empty( $annotations ) ) {
343+
$exploded_data = array();
344+
$series_names = array();
345+
foreach ( $series as $index => $serie ) {
346+
// skip X axis data.
347+
if ( $index === 0 ) {
348+
continue;
349+
}
350+
if ( array_key_exists( 'role' . $index, $annotations ) ) {
351+
$series_names[] = (object) array( 'role' => $annotations[ 'role' . $index ], 'type' => $serie['type'] );
352+
} else {
353+
$series_names[] = $serie['label'];
354+
}
355+
}
356+
$exploded_data[] = $series_names;
357+
358+
foreach ( $data['visualizer-data'] as $datum ) {
359+
// skip X axis data.
360+
unset( $datum[0] );
361+
$exploded_data[] = $datum;
362+
}
363+
$data['visualizer-data-exploded'] = array( $exploded_data );
364+
}
365+
}
366+
320367
$import = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_URL, true );
321368

322369
$schedule = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true );

classes/Visualizer/Gutenberg/build/block.css

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/build/block.js

Lines changed: 5 additions & 5 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: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ChartRender extends Component {
3636
}
3737

3838
render() {
39-
let chart;
39+
let chart, footer;
4040

4141
let data = formatDate( JSON.parse( JSON.stringify( this.props.chart ) ) );
4242

@@ -50,6 +50,10 @@ class ChartRender extends Component {
5050
chart = `${ startCase( this.props.chart['visualizer-chart-type']) }Chart`;
5151
}
5252

53+
if ( data['visualizer-data-exploded']) {
54+
footer = __( 'Annotations in this chart may not display here but they will display in the front end.' );
55+
}
56+
5357
return (
5458
<div className={ this.props.className }>
5559

@@ -78,7 +82,7 @@ class ChartRender extends Component {
7882
columns={ data['visualizer-series'] }
7983
options={ data['visualizer-settings'] }
8084
/>
81-
) : (
85+
) : ( '' !== data['visualizer-data-exploded'] ? (
8286
<Chart
8387
chartType={ chart }
8488
rows={ data['visualizer-data'] }
@@ -90,7 +94,23 @@ class ChartRender extends Component {
9094
}
9195
height="500px"
9296
/>
93-
) }
97+
) : (
98+
<Chart
99+
chartType={ chart }
100+
rows={ data['visualizer-data'] }
101+
columns={ data['visualizer-series'] }
102+
options={
103+
isValidJSON( this.props.chart['visualizer-settings'].manual ) ?
104+
merge( compact( this.props.chart['visualizer-settings']), JSON.parse( this.props.chart['visualizer-settings'].manual ) ) :
105+
compact( this.props.chart['visualizer-settings'])
106+
}
107+
height="500px"
108+
/>
109+
) ) }
110+
111+
<div className="visualizer-settings__charts-footer"><sub>
112+
{ footer }
113+
</sub></div>
94114

95115
</Fragment>
96116
}

0 commit comments

Comments
 (0)