Skip to content

Commit e10a9ff

Browse files
Merge pull request #776 from Codeinwp/development
[Fix] Pie chart slices offset problem in the Gutenberg editor [Fix] Warning is thrown when remote file is used as source [Fix] Bubble chart legend position not working in the Gutenberg editor
2 parents fe6700d + 169cefa commit e10a9ff

File tree

13 files changed

+99
-30
lines changed

13 files changed

+99
-30
lines changed

classes/Visualizer/Gutenberg/Block.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -588,14 +588,19 @@ public function update_chart_data( $data ) {
588588
apply_filters( 'visualizer_pro_remove_schedule', $data['id'] );
589589
}
590590

591-
if ( $source_type === 'Visualizer_Source_Query' ) {
592-
$db_schedule = intval( $data['visualizer-db-schedule'] );
593-
$db_query = $data['visualizer-db-query'];
594-
update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE, $db_schedule );
595-
update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY, stripslashes( $db_query ) );
596-
} else {
597-
delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE );
598-
delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY );
591+
// let's check if this is not an external db chart
592+
// as there is no support for that in the block editor interface
593+
$external_params = get_post_meta( $data['id'], Visualizer_Plugin::CF_REMOTE_DB_PARAMS, true );
594+
if ( empty( $external_params ) ) {
595+
if ( $source_type === 'Visualizer_Source_Query' ) {
596+
$db_schedule = intval( $data['visualizer-db-schedule'] );
597+
$db_query = $data['visualizer-db-query'];
598+
update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE, $db_schedule );
599+
update_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY, stripslashes( $db_query ) );
600+
} else {
601+
delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_SCHEDULE );
602+
delete_post_meta( $data['id'], Visualizer_Plugin::CF_DB_QUERY );
603+
}
599604
}
600605

601606
if ( $source_type === 'Visualizer_Source_Json' ) {

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/Components/Sidebar/GeneralSettings.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class GeneralSettings extends Component {
4646
positions.push({ label: __( 'Inside the chart' ), value: 'in' });
4747
}
4848

49+
if ( 'bubble' === type ) {
50+
positions = positions.filter( function( obj ) {
51+
return 'left' !== obj.value;
52+
});
53+
}
54+
4955
let titleHelp = __( 'Text to display above the chart.' );
5056
if ( 0 <= [ 'tabular', 'dataTable', 'gauge', 'geo', 'timeline' ].indexOf( type ) ) {
5157
titleHelp = __( 'Text to display in the back-end admin area' );
@@ -200,9 +206,11 @@ class GeneralSettings extends Component {
200206
if ( 'pie' !== type ) {
201207
let axis = 'left' === e ? 1 : 0;
202208

203-
Object.keys( settings.series ).map( i => {
204-
settings.series[i].targetAxisIndex = axis;
205-
});
209+
if ( settings.series ) {
210+
Object.keys( settings.series ).map( i => {
211+
settings.series[i].targetAxisIndex = axis;
212+
});
213+
}
206214
}
207215

208216
settings.legend.position = e;

classes/Visualizer/Gutenberg/src/Components/Sidebar/SlicesSettings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class SlicesSettings extends Component {
6868
settings.slices[i].offset = e;
6969
this.props.edit( settings );
7070
} }
71+
type="number"
72+
min="0"
73+
step="0.1"
7174
/>
7275

7376
<BaseControl

classes/Visualizer/Module/Chart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ public function saveFilter() {
14011401
)
14021402
);
14031403

1404-
if ( ! $hours ) {
1404+
if ( 0 !== $hours && empty( $hours ) ) {
14051405
$hours = -1;
14061406
}
14071407

classes/Visualizer/Module/Setup.php

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,50 @@ public function loadTextDomain() {
190190
/**
191191
* Activate the plugin
192192
*/
193-
public function activate() {
193+
public function activate( $network_wide ) {
194+
if ( is_multisite() && $network_wide ) {
195+
foreach ( get_sites( array( 'fields' => 'ids' ) ) as $blog_id ) {
196+
switch_to_blog( $blog_id );
197+
$this->activate_on_site();
198+
restore_current_blog();
199+
}
200+
} else {
201+
$this->activate_on_site();
202+
}
203+
}
204+
205+
/**
206+
* Activates the plugin on a particular blog instance (supports multisite and single site).
207+
*/
208+
private function activate_on_site() {
194209
wp_clear_scheduled_hook( 'visualizer_schedule_refresh_db' );
195210
wp_schedule_event( strtotime( 'midnight' ) - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, 'hourly', 'visualizer_schedule_refresh_db' );
196211
add_option( 'visualizer-activated', true );
197212
}
198213

214+
/**
215+
* Deactivate the plugin
216+
*/
217+
public function deactivate( $network_wide ) {
218+
if ( is_multisite() && $network_wide ) {
219+
foreach ( get_sites( array( 'fields' => 'ids' ) ) as $blog_id ) {
220+
switch_to_blog( $blog_id );
221+
$this->deactivate_on_site();
222+
restore_current_blog();
223+
}
224+
} else {
225+
$this->deactivate_on_site();
226+
}
227+
}
228+
229+
/**
230+
* Deactivates the plugin on a particular blog instance (supports multisite and single site).
231+
*/
232+
private function deactivate_on_site() {
233+
wp_clear_scheduled_hook( 'visualizer_schedule_refresh_db' );
234+
delete_option( 'visualizer-activated', true );
235+
}
236+
199237
/**
200238
* Check if plugin has been activated and then redirect to the correct page.
201239
*/
@@ -218,14 +256,6 @@ public function adminInit() {
218256
}
219257

220258

221-
/**
222-
* Deactivate the plugin
223-
*/
224-
public function deactivate() {
225-
wp_clear_scheduled_hook( 'visualizer_schedule_refresh_db' );
226-
delete_option( 'visualizer-activated', true );
227-
}
228-
229259
/**
230260
* Refresh the specific chart from the db.
231261
*
@@ -306,13 +336,29 @@ public function refresh_db_for_chart( $chart, $chart_id, $force = false ) {
306336
update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
307337
}
308338

339+
$allow_html = false;
340+
$settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
341+
if ( isset( $settings['allowHtml'] ) && intval( $settings['allowHtml'] ) === 1 ) {
342+
$allow_html = true;
343+
}
344+
345+
$allow_html = apply_filters( 'visualizer_allow_html_content', $allow_html, $chart_id, $chart );
346+
347+
if ( $allow_html ) {
348+
kses_remove_filters();
349+
}
350+
309351
wp_update_post(
310352
array(
311353
'ID' => $chart_id,
312354
'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
313355
)
314356
);
315357

358+
if ( $allow_html ) {
359+
kses_init_filters();
360+
}
361+
316362
$chart = get_post( $chart_id );
317363
delete_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR );
318364
} else {

classes/Visualizer/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class Visualizer_Plugin {
2929

3030
const NAME = 'visualizer';
31-
const VERSION = '3.4.8';
31+
const VERSION = '3.4.9';
3232

3333
// custom post types
3434
const CPT_VISUALIZER = 'visualizer';

classes/Visualizer/Render/Sidebar/Google.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ public function __construct( $data = array() ) {
6767
'none' => esc_html__( 'Omit the legend', 'visualizer' ),
6868
);
6969

70-
if ( ! in_array( $this->get_chart_type( false ), array( 'Pie' ), true ) ) {
70+
$chart_type = $this->get_chart_type( false );
71+
if ( ! in_array( $chart_type, array( 'Pie' ), true ) ) {
7172
$this->_legendPositions['in'] = esc_html__( 'Inside the chart', 'visualizer' );
7273
}
7374

75+
if ( in_array( $chart_type, array( 'Bubble' ), true ) ) {
76+
unset( $this->_legendPositions['left'] );
77+
}
78+
7479
$this->_alignments = array(
7580
'' => '',
7681
'start' => esc_html__( 'Aligned to the start of the allocated area', 'visualizer' ),

classes/Visualizer/Render/Sidebar/Type/GoogleCharts/Pie.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,11 @@ protected function _renderSlicesSettings() {
186186
self::_renderTextItem(
187187
esc_html__( 'Slice Offset', 'visualizer' ),
188188
'slices[' . $i . '][offset]',
189-
isset( $this->slices[ $i ]['offset'] ) ? $this->slices[ $i ]['offset'] : null,
189+
isset( $this->slices[ $i ]['offset'] ) && ! empty( $this->slices[ $i ]['offset'] ) ? $this->slices[ $i ]['offset'] : 0,
190190
esc_html__( "How far to separate the slice from the rest of the pie, from 0.0 (not at all) to 1.0 (the pie's radius).", 'visualizer' ),
191-
'0.0'
191+
'0.0',
192+
'number',
193+
array( 'step' => 0.1, 'min' => 0 )
192194
);
193195

194196
self::_renderColorPickerItem(

classes/Visualizer/Source/Csv/Remote.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Visualizer_Source_Csv_Remote extends Visualizer_Source_Csv {
4747
* @access public
4848
* @return string The serialized array of data.
4949
*/
50-
public function getData() {
50+
public function getData( $dumb = false ) {
5151
return serialize(
5252
array(
5353
'source' => $this->_filename,

0 commit comments

Comments
 (0)