Skip to content

Commit 10e2c0e

Browse files
author
cristian-ungureanu
authored
release: new version
- Fix multiple charts lazy rendering issue - Upgrade jQuery UI core library CDN - Fix console error when rendering multiple charts - Keep only Line / Pie / bar / Table charts in free version
2 parents 3f5a59e + b8fc5e5 commit 10e2c0e

File tree

18 files changed

+145
-108
lines changed

18 files changed

+145
-108
lines changed

classes/Visualizer/Gutenberg/Block.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public function enqueue_gutenberg_scripts() {
111111
'adminPage' => menu_page_url( 'visualizer', false ),
112112
'sqlTable' => $table_col_mapping,
113113
'chartsPerPage' => defined( 'TI_CYPRESS_TESTING' ) ? 20 : 6,
114+
'proFeaturesLocked' => Visualizer_Module_Admin::proFeaturesLocked(),
114115
);
115116
wp_localize_script( 'visualizer-gutenberg-block', 'visualizerLocalize', $translation_array );
116117

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
} = wp.element;
1010

1111
const {
12+
Button,
1213
CheckboxControl,
1314
PanelBody
1415
} = wp.components;
@@ -34,6 +35,7 @@ class FrontendActions extends Component {
3435
const type = this.props.chart['visualizer-chart-type'];
3536

3637
return (
38+
( '' !== visualizerLocalize.proFeaturesLocked ) ?
3739
<PanelBody
3840
title={ __( 'Frontend Actions' ) }
3941
initialOpen={ false }
@@ -135,7 +137,25 @@ class FrontendActions extends Component {
135137

136138
) }
137139

138-
</PanelBody>
140+
</PanelBody> :
141+
<PanelBody
142+
title={ __( 'Frontend Actions' ) }
143+
initialOpen={ false }
144+
icon="lock"
145+
className="visualizer-advanced-panel"
146+
>
147+
148+
<p>{ __( 'Enable this feature in PRO version!' ) }</p>
149+
150+
<Button
151+
isPrimary
152+
href={ visualizerLocalize.proTeaser }
153+
target="_blank"
154+
>
155+
{ __( 'Buy Now' ) }
156+
</Button>
157+
158+
</PanelBody>
139159
);
140160
}
141161
}

classes/Visualizer/Module/Admin.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -389,64 +389,66 @@ public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darra
389389
);
390390
}
391391

392+
$enabled = self::proFeaturesLocked();
393+
392394
$types = array_merge(
393395
$additional,
394396
array(
395397
'tabular' => array(
396398
'name' => esc_html__( 'Table', 'visualizer' ),
397399
'enabled' => true,
398-
'supports' => array( 'Google Charts', 'DataTable' ),
400+
'supports' => $enabled ? array( 'Google Charts', 'DataTable' ) : array( 'DataTable' ),
399401
),
400402
'pie' => array(
401403
'name' => esc_html__( 'Pie/Donut', 'visualizer' ),
402404
'enabled' => true,
403-
'supports' => array( 'Google Charts', 'ChartJS' ),
405+
'supports' => $enabled ? array( 'Google Charts', 'ChartJS' ) : array( 'Google Charts' ),
404406
),
405407
'line' => array(
406408
'name' => esc_html__( 'Line', 'visualizer' ),
407409
'enabled' => true,
408-
'supports' => array( 'Google Charts', 'ChartJS' ),
410+
'supports' => $enabled ? array( 'Google Charts', 'ChartJS' ) : array( 'Google Charts' ),
411+
),
412+
'bar' => array(
413+
'name' => esc_html__( 'Bar', 'visualizer' ),
414+
'enabled' => true,
415+
'supports' => $enabled ? array( 'Google Charts', 'ChartJS' ) : array( 'Google Charts' ),
409416
),
410417
'area' => array(
411418
'name' => esc_html__( 'Area', 'visualizer' ),
412-
'enabled' => true,
419+
'enabled' => $enabled,
413420
// in ChartJS, the fill option is used to make Line chart an area: https://www.chartjs.org/docs/latest/charts/area.html
414421
'supports' => array( 'Google Charts' ),
415422
),
416423
'geo' => array(
417424
'name' => esc_html__( 'Geo', 'visualizer' ),
418-
'enabled' => true,
425+
'enabled' => $enabled,
419426
'supports' => array( 'Google Charts' ),
420427
),
421-
'bar' => array(
422-
'name' => esc_html__( 'Bar', 'visualizer' ),
423-
'enabled' => true,
424-
'supports' => array( 'Google Charts', 'ChartJS' ),
425-
),
426428
'column' => array(
427429
'name' => esc_html__( 'Column', 'visualizer' ),
428-
'enabled' => true,
430+
'enabled' => $enabled,
429431
'supports' => array( 'Google Charts', 'ChartJS' ),
430432
),
431433
'bubble' => array(
432434
'name' => esc_html__( 'Bubble', 'visualizer' ),
433-
'enabled' => true,
435+
'enabled' => $enabled,
434436
// chartjs' bubble is ugly looking (and it won't work off the default bubble.csv) so it is being excluded for the time being.
435437
'supports' => array( 'Google Charts' ),
436438
),
437439
'scatter' => array(
438440
'name' => esc_html__( 'Scatter', 'visualizer' ),
439-
'enabled' => true,
441+
'enabled' => $enabled,
440442
'supports' => array( 'Google Charts' ),
441443
),
442444
'gauge' => array(
443445
'name' => esc_html__( 'Gauge', 'visualizer' ),
444-
'enabled' => true,
446+
'enabled' => $enabled,
445447
'supports' => array( 'Google Charts' ),
446448
),
447449
'candlestick' => array(
448450
'name' => esc_html__( 'Candlestick', 'visualizer' ),
449-
'enabled' => true,
451+
'enabled' => $enabled,
450452
'supports' => array( 'Google Charts' ),
451453
),
452454
// pro types
@@ -1046,4 +1048,15 @@ public function getPluginMetaLinks( $plugin_meta, $plugin_file ) {
10461048
return $plugin_meta;
10471049
}
10481050

1051+
/**
1052+
* If check is existing user.
1053+
*
1054+
* @return bool Default false
1055+
*/
1056+
public static function proFeaturesLocked() {
1057+
if ( Visualizer_Module::is_pro() ) {
1058+
return true;
1059+
}
1060+
return 'yes' === get_option( 'visualizer-new-user', 'yes' ) ? false : true;
1061+
}
10491062
}

classes/Visualizer/Module/Chart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ private function loadCodeEditorAssets( $chart_id ) {
633633
// data tables assets.
634634
wp_register_script( 'visualizer-datatables', VISUALIZER_ABSURL . 'js/lib/datatables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION );
635635
wp_register_style( 'visualizer-datatables', VISUALIZER_ABSURL . 'css/lib/datatables.min.css', array(), Visualizer_Plugin::VERSION );
636-
wp_register_style( 'visualizer-jquery-ui', sprintf( '//ajax.googleapis.com/ajax/libs/jqueryui/%s/themes/smoothness/jquery-ui.css', $wp_scripts->registered['jquery-ui-core']->ver ), array( 'visualizer-datatables' ), Visualizer_Plugin::VERSION );
636+
wp_register_style( 'visualizer-jquery-ui', sprintf( '//code.jquery.com/ui/%s/themes/smoothness/jquery-ui.css', $wp_scripts->registered['jquery-ui-core']->ver ), array( 'visualizer-datatables' ), Visualizer_Plugin::VERSION );
637637
wp_enqueue_script( 'visualizer-datatables' );
638638
wp_enqueue_style( 'visualizer-jquery-ui' );
639639

classes/Visualizer/Module/Frontend.php

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ public function renderChart( $atts ) {
436436

437437
$_charts = array();
438438
$_charts_type = '';
439+
$count = 0;
439440
foreach ( $this->_charts as $id => $array ) {
440441
$_charts = $this->_charts;
441442
$library = $array['library'];
@@ -450,24 +451,26 @@ public function renderChart( $atts ) {
450451
);
451452
wp_enqueue_script( "visualizer-render-$library" );
452453
}
453-
}
454-
if ( wp_script_is( "visualizer-render-$_charts_type" ) ) {
455-
wp_localize_script(
456-
"visualizer-render-$_charts_type",
457-
'visualizer',
458-
array(
459-
'charts' => $_charts,
460-
'language' => $this->get_language(),
461-
'map_api_key' => get_option( 'visualizer-map-api-key' ),
462-
'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
463-
'wp_nonce' => wp_create_nonce( 'wp_rest' ),
464-
'i10n' => array(
465-
'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ),
466-
),
467-
'page_type' => 'frontend',
468-
'is_front' => true,
469-
)
470-
);
454+
455+
if ( wp_script_is( "visualizer-render-$_charts_type" ) && 0 === $count ) {
456+
wp_localize_script(
457+
"visualizer-render-$_charts_type",
458+
'visualizer',
459+
array(
460+
'charts' => $this->_charts,
461+
'language' => $this->get_language(),
462+
'map_api_key' => get_option( 'visualizer-map-api-key' ),
463+
'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
464+
'wp_nonce' => wp_create_nonce( 'wp_rest' ),
465+
'i10n' => array(
466+
'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ),
467+
),
468+
'page_type' => 'frontend',
469+
'is_front' => true,
470+
)
471+
);
472+
}
473+
$count++;
471474
}
472475

473476
// return placeholder div
@@ -669,9 +672,13 @@ function visualizerTriggerScriptLoader() {
669672

670673
function visualizerLoadScripts() {
671674
document.querySelectorAll("script[data-visualizer-script]").forEach(function(elem) {
672-
jQuery.getScript( elem.getAttribute("data-visualizer-script"), function() {
675+
jQuery.getScript( elem.getAttribute("data-visualizer-script") )
676+
.done( function( script, textStatus ) {
673677
elem.setAttribute("src", elem.getAttribute("data-visualizer-script"));
674678
elem.removeAttribute("data-visualizer-script");
679+
setTimeout( function() {
680+
jQuery( '.visualizer-front:not(.visualizer-chart-loaded)' ).resize();
681+
} );
675682
} );
676683
});
677684
}

classes/Visualizer/Module/Setup.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function __construct( Visualizer_Plugin $plugin ) {
5353
$this->_addFilter( 'visualizer_logger_data', 'getLoggerData' );
5454
$this->_addFilter( 'visualizer_get_chart_counts', 'getUsage', 10, 2 );
5555

56+
$this->_addAction( 'init', 'checkIsExistingUser' );
57+
5658
// only for testing
5759
// $this->_addAction( 'admin_init', 'getUsage' );
5860
}
@@ -405,4 +407,20 @@ public function refreshDbChart() {
405407
update_option( Visualizer_Plugin::CF_DB_SCHEDULE, $new_schedules );
406408
}
407409

410+
/**
411+
* Save flag for existing users.
412+
*/
413+
public function checkIsExistingUser() {
414+
$chart_exists = get_option( 'visualizer-new-user', '' );
415+
if ( '' === $chart_exists ) {
416+
$charts = get_posts(
417+
array(
418+
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
419+
'fields' => 'ids',
420+
)
421+
);
422+
update_option( 'visualizer-new-user', ! empty( $charts ) ? 'no' : 'yes' );
423+
}
424+
}
425+
408426
}

classes/Visualizer/Render/Layout.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ class="dashicons dashicons-lock"></span></h2>
960960
</li>
961961

962962
<!-- manual -->
963-
<li class="viz-group visualizer_source_manual">
963+
<li class="viz-group visualizer_source_manual <?php echo ! Visualizer_Module_Admin::proFeaturesLocked() ? apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ) : ''; ?>">
964964
<h2 class="viz-group-title viz-sub-group visualizer-editor-tab" data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?>
965965
<span class="dashicons dashicons-lock"></span>
966966
</h2>
@@ -1002,6 +1002,11 @@ class="dashicons dashicons-lock"></span></h2>
10021002
>
10031003
<p class="viz-group-description viz-info-msg"><?php echo sprintf( __( 'Please make sure you click \'Show Chart\' before you save the chart.', 'visualizer' ) ); ?></p>
10041004
<?php } ?>
1005+
<?php
1006+
if ( ! Visualizer_Module_Admin::proFeaturesLocked() ) {
1007+
echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' );
1008+
}
1009+
?>
10051010
</form>
10061011
</div>
10071012
</li>

classes/Visualizer/Render/Library.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,15 @@ private function _renderSidebar() {
359359
echo '<li>' . __( 'Frontend editor', 'visualizer' ) . '</li>';
360360
echo '<li>' . __( 'Private charts', 'visualizer' ) . '</li>';
361361
echo '<li>' . __( 'Auto-sync with online files', 'visualizer' ) . '</li>';
362-
echo '<li>' . __( '6 more chart types', 'visualizer' ) . '</li></ul>';
362+
if ( Visualizer_Module_Admin::proFeaturesLocked() ) {
363+
echo '<li>' . __( '6 more chart types', 'visualizer' ) . '</ul>';
364+
} else {
365+
echo '<li>' . __( '11 more chart types', 'visualizer' ) . '</li>';
366+
echo '<li>' . __( 'Manual Data Editor', 'visualizer' ) . '</li>';
367+
echo '<li>' . __( 'ChartJS Charts', 'visualizer' ) . '</li>';
368+
echo '<li>' . __( 'Table Google chart', 'visualizer' ) . '</li>';
369+
echo '<li>' . __( 'Frontend Actions(Print Chart, Export to CSV, Export to Excel, Copy, Download Chart Image)', 'visualizer' ) . '</li></ul>';
370+
}
363371
echo '<p><a href="' . Visualizer_Plugin::PRO_TEASER_URL . '" target="_blank" class="button button-primary">' . __( 'View more features', 'visualizer' ) . '</a></p>';
364372
echo '<p style="background-color: #0073aac7; color: #ffffff; padding: 2px; font-weight: bold;">' . __( 'We offer a 30-day no-questions-asked money back guarantee!', 'visualizer' ) . '</p>';
365373
echo '<p><a href="' . VISUALIZER_SURVEY . '" target="_blank" class="">' . __( 'Don\'t see the features you need? Help us improve!', 'visualizer' ) . '</a></p>';

classes/Visualizer/Render/Page/Types.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function _renderToolbar() {
120120

121121
if ( ! empty( $libraries ) ) {
122122
?>
123-
<select name="chart-library" class="viz-select-library" data-type-vs-library="<?php echo esc_attr( json_encode( $type_vs_library ) ); ?>">
123+
<select name="chart-library" class="viz-select-library<?php echo ! Visualizer_Module_Admin::proFeaturesLocked() && ! defined( 'TI_CYPRESS_TESTING' ) ? ' viz-hide-libary' : ''; ?>" data-type-vs-library="<?php echo esc_attr( json_encode( $type_vs_library ) ); ?>">
124124
<option value=""><?php esc_html_e( 'Use Library', 'visualizer' ); ?></option>
125125
<?php
126126
foreach ( $libraries as $library ) {

0 commit comments

Comments
 (0)