Skip to content

Commit e5e4792

Browse files
Merge branch '3.4.0' of https://github.com/codeinwp/visualizer into issue-611-new
2 parents 79494f5 + 42c08b2 commit e5e4792

File tree

10 files changed

+130
-14
lines changed

10 files changed

+130
-14
lines changed

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: 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/build/block.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: 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
}

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ChartSelect extends Component {
5757

5858
render() {
5959

60-
let chart;
60+
let chart, footer;
6161

6262
let data = formatDate( JSON.parse( JSON.stringify( this.props.chart ) ) );
6363

@@ -71,6 +71,10 @@ class ChartSelect extends Component {
7171
chart = `${ startCase( this.props.chart['visualizer-chart-type']) }Chart`;
7272
}
7373

74+
if ( data['visualizer-data-exploded']) {
75+
footer = __( 'Annotations in this chart may not display here but they will display in the front end.' );
76+
}
77+
7478
return (
7579
<Fragment>
7680
{ 'home' === this.state.route &&
@@ -149,7 +153,19 @@ class ChartSelect extends Component {
149153
columns={ data['visualizer-series'] }
150154
options={ data['visualizer-settings'] }
151155
/>
152-
) : (
156+
) : ( '' !== data['visualizer-data-exploded'] ? (
157+
<Chart
158+
chartType={ chart }
159+
rows={ data['visualizer-data'] }
160+
columns={ data['visualizer-series'] }
161+
options={
162+
isValidJSON( this.props.chart['visualizer-settings'].manual ) ?
163+
merge( compact( this.props.chart['visualizer-settings']), JSON.parse( this.props.chart['visualizer-settings'].manual ) ) :
164+
compact( this.props.chart['visualizer-settings'])
165+
}
166+
height="500px"
167+
/>
168+
) : (
153169
<Chart
154170
chartType={ chart }
155171
rows={ data['visualizer-data'] }
@@ -162,7 +178,11 @@ class ChartSelect extends Component {
162178
height="500px"
163179
/>
164180
)
165-
}
181+
) }
182+
183+
<div className="visualizer-settings__charts-footer"><sub>
184+
{ footer }
185+
</sub></div>
166186

167187
</div>
168188
</Fragment>

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Charts extends Component {
9696
{ ( Object.keys( charts ) ).map( i => {
9797
const data = formatDate( charts[i]['chart_data']);
9898

99-
let title, chart;
99+
let title, chart, footer;
100100

101101
if ( data['visualizer-settings'].title ) {
102102
title = data['visualizer-settings'].title;
@@ -120,6 +120,10 @@ class Charts extends Component {
120120
}
121121
}
122122

123+
if ( data['visualizer-data-exploded']) {
124+
footer = __( 'Annotations in this chart may not display here but they will display in the front end.' );
125+
}
126+
123127
return (
124128
<div className="visualizer-settings__charts-single">
125129

@@ -135,14 +139,25 @@ class Charts extends Component {
135139
chartsScreen={ true }
136140
options={ filterCharts( data['visualizer-settings']) }
137141
/>
142+
) : ( '' !== data['visualizer-data-exploded'] ? (
143+
<Chart
144+
chartType={ chart }
145+
rows={ data['visualizer-data'] }
146+
columns={ data['visualizer-series'] }
147+
options={ filterCharts( data['visualizer-settings']) }
148+
/>
138149
) : (
139150
<Chart
140151
chartType={ chart }
141152
rows={ data['visualizer-data'] }
142153
columns={ data['visualizer-series'] }
143154
options={ filterCharts( data['visualizer-settings']) }
144155
/>
145-
) }
156+
) ) }
157+
158+
<div className="visualizer-settings__charts-footer"><sub>
159+
{ footer }
160+
</sub></div>
146161

147162
<div
148163
className="visualizer-settings__charts-controls"

classes/Visualizer/Gutenberg/src/style.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
font-weight: bold;
9696
text-align: center;
9797
}
98+
99+
.visualizer-settings__charts-footer {
100+
font-size: small;
101+
}
98102

99103
.visualizer-settings__charts-controls {
100104
width: 100%;

cypress.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
}
2222
},
2323
"videoUploadOnPasses": false,
24-
"projectId": "yhx2jj"
24+
"projectId": "2375tg"
2525
}

index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function visualizer_launch() {
7070
define( 'VISUALIZER_ABSPATH', dirname( __FILE__ ) );
7171
define( 'VISUALIZER_REST_VERSION', 1 );
7272
// if the below is true, then the js/customization.js in the plugin folder will be used instead of the one in the uploads folder (if it exists).
73+
// this is also used in Block.php
7374
define( 'VISUALIZER_TEST_JS_CUSTOMIZATION', false );
7475

7576
if ( ! defined( 'VISUALIZER_CSV_DELIMITER' ) ) {

js/lib/chartjs.min.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)