Skip to content

Commit ed38a42

Browse files
Merge branch '3.4.0' of https://github.com/codeinwp/visualizer into issue-595
2 parents 830b99d + 6f70987 commit ed38a42

File tree

17 files changed

+2893
-94
lines changed

17 files changed

+2893
-94
lines changed

classes/Visualizer/Gutenberg/Block.php

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ public function get_visualizer_data( $post ) {
300300

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

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

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

@@ -318,6 +319,52 @@ public function get_visualizer_data( $post ) {
318319
// handle data filter hooks
319320
$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'] );
320321

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

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

classes/Visualizer/Gutenberg/build/block.css

Lines changed: 239 additions & 1 deletion
Large diffs are not rendered by default.

classes/Visualizer/Gutenberg/build/block.js

Lines changed: 2479 additions & 69 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
@@ -99,7 +99,7 @@ class Charts extends Component {
9999
{ ( Object.keys( charts ) ).map( i => {
100100
const data = formatDate( charts[i]['chart_data']);
101101

102-
let title, chart;
102+
let title, chart, footer;
103103

104104
if ( data['visualizer-settings'].title ) {
105105
title = data['visualizer-settings'].title;
@@ -123,6 +123,10 @@ class Charts extends Component {
123123
}
124124
}
125125

126+
if ( data['visualizer-data-exploded']) {
127+
footer = __( 'Annotations in this chart may not display here but they will display in the front end.' );
128+
}
129+
126130
return (
127131
<div className="visualizer-settings__charts-single" key={ `chart-${ charts[i].id }` }>
128132

@@ -138,14 +142,25 @@ class Charts extends Component {
138142
chartsScreen={ true }
139143
options={ filterCharts( data['visualizer-settings']) }
140144
/>
145+
) : ( '' !== data['visualizer-data-exploded'] ? (
146+
<Chart
147+
chartType={ chart }
148+
rows={ data['visualizer-data'] }
149+
columns={ data['visualizer-series'] }
150+
options={ filterCharts( data['visualizer-settings']) }
151+
/>
141152
) : (
142153
<Chart
143154
chartType={ chart }
144155
rows={ data['visualizer-data'] }
145156
columns={ data['visualizer-series'] }
146157
options={ filterCharts( data['visualizer-settings']) }
147158
/>
148-
) }
159+
) ) }
160+
161+
<div className="visualizer-settings__charts-footer"><sub>
162+
{ footer }
163+
</sub></div>
149164

150165
<div
151166
className="visualizer-settings__charts-controls"

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ class DataTables extends Component {
7373
const row = {};
7474

7575
columns.forEach( ( j, n ) => {
76-
row[j.data] = i[n];
76+
var datum = i[n];
77+
78+
// datum could be undefined for dynamic data (e.g. through json).
79+
if ( 'undefined' === typeof datum ) {
80+
datum = i[j.data];
81+
}
82+
row[j.data] = datum;
7783
});
7884

7985
return row;

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%;

classes/Visualizer/Module/Admin.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ public function addSplChartSchedules( $feature, $chart_id, $plan ) {
111111
}
112112

113113
$license = __( 'PRO', 'visualizer' );
114-
switch ( $plan ) {
115-
case 2:
116-
$license = __( 'Developer', 'visualizer' );
117-
break;
114+
if ( Visualizer_Module::is_pro() ) {
115+
switch ( $plan ) {
116+
case 1:
117+
$license = __( 'Developer', 'visualizer' );
118+
break;
119+
}
118120
}
119121

120122
$hours = array(
@@ -136,7 +138,10 @@ public function addSplChartSchedules( $feature, $chart_id, $plan ) {
136138
// fall-through.
137139
case 'db':
138140
// fall-through.
141+
break;
139142
case 'csv':
143+
// no support for live.
144+
unset( $hours['0'] );
140145
break;
141146
default:
142147
return;

classes/Visualizer/Render/Library.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,13 @@ private function _renderLibrary() {
118118
echo ' | </li>';
119119
}
120120
echo '</ul>';
121+
121122
echo '<form action="" method="get"><p id="visualizer-search" class="search-box">
122123
<input type="search" placeholder="' . __( 'Enter title', 'visualizer' ) . '" name="s" value="' . $filterBy . '">
123124
<input type="hidden" name="page" value="visualizer">
124125
<button type="submit" id="search-submit" title="' . __( 'Search', 'visualizer' ) . '"><i class="dashicons dashicons-search"></i></button>
125-
<button type="button" class="add-new-chart" title="' . __( 'Add New', 'visualizer' ) . '"><i class="dashicons dashicons-plus-alt"></i></button>
126126
</p> </form>';
127+
127128
echo '</div>';
128129
echo '<div id="visualizer-content-wrapper">';
129130
if ( ! empty( $this->charts ) ) {

0 commit comments

Comments
 (0)