Skip to content

Commit 4abd867

Browse files
Gutenberg: annotations don't appear - WIP
1 parent efffe37 commit 4abd867

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

classes/Visualizer/Gutenberg/Block.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,55 @@ 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+
$annotations[] = $index;
338+
}
339+
}
340+
}
341+
if ( ! empty( $annotations ) ) {
342+
$exploded_data = array();
343+
error_log(print_r($settings['series'],true));
344+
error_log(print_r($series,true));
345+
error_log(print_r($data['visualizer-data'],true));
346+
$series_names = array();
347+
foreach ( $series as $index => $serie ) {
348+
// skip X axis data.
349+
if( $index === 0) {
350+
continue;
351+
}
352+
if ( in_array( $index, $annotations, true ) ) {
353+
$series_names[] = (object) array( 'role' => $serie['type'] );
354+
} else {
355+
$series_names[] = $serie['label'];
356+
}
357+
}
358+
$exploded_data[] = $series_names;
359+
360+
foreach( $data['visualizer-data'] as $datum ) {
361+
// skip X axis data.
362+
unset( $datum[0] );
363+
$exploded_data[] = $datum;
364+
}
365+
error_log("finally " . print_r($exploded_data,true));
366+
$data['visualizer-data-exploded'] = $exploded_data;
367+
}
368+
}
369+
320370
$import = get_post_meta( $post_id, Visualizer_Plugin::CF_CHART_URL, true );
321371

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

0 commit comments

Comments
 (0)