Skip to content

Commit c5404ff

Browse files
issue comments
#307 (comment)
1 parent 21c2cc3 commit c5404ff

File tree

9 files changed

+133
-147
lines changed

9 files changed

+133
-147
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,12 @@ public function enqueueMediaScripts() {
213213
global $typenow;
214214
if ( post_type_supports( $typenow, 'editor' ) ) {
215215
wp_enqueue_style( 'visualizer-media', VISUALIZER_ABSURL . 'css/media.css', array( 'media-views' ), Visualizer_Plugin::VERSION );
216-
wp_enqueue_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array( 'media-editor' ), null, true );
217-
wp_enqueue_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true );
218-
wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', array( 'visualizer-google-jsapi-old' ), Visualizer_Plugin::VERSION, true );
216+
217+
// Load all the assets for the different libraries we support.
218+
$deps = Visualizer_Render_Sidebar_Google::enqueue_assets( array( 'media-editor' ) );
219+
$deps += Visualizer_Render_Sidebar_Type_DataTable::enqueue_assets( array( 'media-editor' ) );
220+
221+
wp_enqueue_script( 'visualizer-media-model', VISUALIZER_ABSURL . 'js/media/model.js', $deps, Visualizer_Plugin::VERSION, true );
219222
wp_enqueue_script( 'visualizer-media-collection', VISUALIZER_ABSURL . 'js/media/collection.js', array( 'visualizer-media-model' ), Visualizer_Plugin::VERSION, true );
220223
wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true );
221224
wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true );
@@ -392,6 +395,16 @@ private static function handleDeprecatedCharts( $types, $enabledOnly, $get2Darra
392395
$types['dataTable']['name'] = esc_html__( 'Table', 'visualizer' );
393396
}
394397
}
398+
399+
// if a user has a Gauge/Candlestick chart, then let them keep using it.
400+
if ( ! VISUALIZER_PRO ) {
401+
if ( ! self::hasChartType( 'gauge' ) ) {
402+
$deprecated[] = 'gauge';
403+
}
404+
if ( ! self::hasChartType( 'candlestick' ) ) {
405+
$deprecated[] = 'candlestick';
406+
}
407+
}
395408
break;
396409
default:
397410
// remove the option to create a Google Table chart.
@@ -405,6 +418,16 @@ private static function handleDeprecatedCharts( $types, $enabledOnly, $get2Darra
405418
$types['dataTable']['name'] = esc_html__( 'Table', 'visualizer' );
406419
}
407420
}
421+
422+
// if a user has a Gauge/Candlestick chart, then let them keep using it.
423+
if ( ! VISUALIZER_PRO ) {
424+
if ( ! self::hasChartType( 'gauge' ) ) {
425+
$deprecated[] = 'gauge';
426+
}
427+
if ( ! self::hasChartType( 'candlestick' ) ) {
428+
$deprecated[] = 'candlestick';
429+
}
430+
}
408431
}
409432

410433
if ( $deprecated ) {

classes/Visualizer/Module/Chart.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public function __construct( Visualizer_Plugin $plugin ) {
6363
/**
6464
* Fetches charts from database.
6565
*
66+
* This method is also called from the media pop-up (classic editor: create a post and add chart from insert content).
67+
*
6668
* @since 1.0.0
6769
*
6870
* @access public
@@ -104,6 +106,16 @@ public function getCharts() {
104106
$chart = $query->next_post();
105107
$chart_data = $this->_getChartArray( $chart );
106108
$chart_data['id'] = $chart->ID;
109+
$chart_data['library'] = $this->load_chart_type( $chart->ID );
110+
$css = '';
111+
$settings = $chart_data['settings'];
112+
$arguments = $this->get_inline_custom_css( 'visualizer-chart-' . $chart->ID, $settings );
113+
if ( ! empty( $arguments ) ) {
114+
$css = $arguments[0];
115+
$settings = $arguments[1];
116+
}
117+
$chart_data['settings'] = $settings;
118+
$chart_data['css'] = $css;
107119
$charts[] = $chart_data;
108120
}
109121
self::_sendResponse(

classes/Visualizer/Render/Page/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ protected function _renderToolbar() {
434434
}
435435
echo '<input type="submit" id="settings-button" class="button button-primary button-large push-right" value="', $this->button, '">';
436436
if ( isset( $this->cancel_button ) ) {
437-
echo '<input type="submit" id="cancel-button" class="button button-secondary button-large push-right" value="', $this->cancel_button, '">';
437+
echo '<input type="submit" id="cancel-button" class="button button-secondary button-large push-left" value="', $this->cancel_button, '">';
438438
}
439439
}
440440

classes/Visualizer/Render/Sidebar/Google.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,15 @@ function load_google_assets( $deps, $is_frontend ) {
7373

7474
}
7575

76+
/**
77+
* Enqueue assets.
78+
*/
79+
public static function enqueue_assets( $deps = array() ) {
80+
wp_enqueue_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
81+
wp_enqueue_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true );
82+
wp_enqueue_script( 'visualizer-render-google-lib', VISUALIZER_ABSURL . 'js/render-google.js', array_merge( $deps, array( 'visualizer-google-jsapi-old' ) ), Visualizer_Plugin::VERSION, true );
83+
return 'visualizer-render-google-lib';
84+
}
85+
7686

7787
}

classes/Visualizer/Render/Sidebar/Type/DataTable.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@
2626
*/
2727
class Visualizer_Render_Sidebar_Type_DataTable extends Visualizer_Render_Sidebar {
2828

29+
30+
/**
31+
* The URL for the JavaScript file.
32+
*
33+
* @access private
34+
* @var string
35+
*/
36+
private static $_js = '//cdn.datatables.net/v/dt/dt-1.10.18/fc-3.2.5/fh-3.1.4/r-2.2.2/sc-1.5.0/sl-1.2.6/datatables.min.js';
37+
38+
/**
39+
* The URL for the CSS file.
40+
*
41+
* @access private
42+
* @var string
43+
*/
44+
private static $_css = '//cdn.datatables.net/v/dt/dt-1.10.18/fc-3.2.5/fh-3.1.4/r-2.2.2/sc-1.5.0/sl-1.2.6/datatables.min.css';
45+
2946
/**
3047
* Constructor.
3148
*
@@ -58,8 +75,8 @@ protected function hooks() {
5875
* @access public
5976
*/
6077
function load_assets( $deps, $is_frontend ) {
61-
wp_register_script( 'visualizer-datatables', '//cdn.datatables.net/v/dt/dt-1.10.18/fc-3.2.5/fh-3.1.4/r-2.2.2/sc-1.5.0/sl-1.2.6/datatables.min.js', array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION );
62-
wp_enqueue_style( 'visualizer-datatables', '//cdn.datatables.net/v/dt/dt-1.10.18/fc-3.2.5/fh-3.1.4/r-2.2.2/sc-1.5.0/sl-1.2.6/datatables.min.css', array(), Visualizer_Plugin::VERSION );
78+
wp_register_script( 'visualizer-datatables', self::$_js, array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION );
79+
wp_enqueue_style( 'visualizer-datatables', self::$_css, array(), Visualizer_Plugin::VERSION );
6380

6481
wp_register_script(
6582
'visualizer-render-datatables-lib',
@@ -77,6 +94,16 @@ function load_assets( $deps, $is_frontend ) {
7794
);
7895
}
7996

97+
/**
98+
* Enqueue assets.
99+
*/
100+
public static function enqueue_assets( $deps = array() ) {
101+
wp_enqueue_style( 'visualizer-datatables', self::$_css, array(), Visualizer_Plugin::VERSION );
102+
wp_enqueue_script( 'visualizer-datatables', self::$_js, array( 'jquery-ui-core' ), Visualizer_Plugin::VERSION );
103+
wp_enqueue_script( 'visualizer-render-datatables-lib', VISUALIZER_ABSURL . 'js/render-datatables.js', array_merge( $deps, array( 'jquery-ui-core', 'visualizer-datatables' ) ), Visualizer_Plugin::VERSION, true );
104+
return 'visualizer-render-datatables-lib';
105+
}
106+
80107
/**
81108
* Renders template.
82109
*
@@ -89,6 +116,22 @@ protected function _toHTML() {
89116
$this->_renderGeneralSettings();
90117
$this->_renderTableSettings();
91118
$this->_renderSeriesSettings();
119+
$this->_renderAdvancedSettings();
120+
}
121+
122+
/**
123+
* Renders chart advanced settings group.
124+
*
125+
* @access protected
126+
*/
127+
protected function _renderAdvancedSettings() {
128+
self::_renderGroupStart( esc_html__( 'Frontend Actions', 'visualizer' ) );
129+
self::_renderSectionStart();
130+
self::_renderSectionDescription( esc_html__( 'Configure frontend actions here.', 'visualizer' ) );
131+
self::_renderSectionEnd();
132+
133+
$this->_renderActionSettings();
134+
self::_renderGroupEnd();
92135
}
93136

94137
/**

css/frame.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ div.viz-group-content .viz-group-description {
366366
float: right;
367367
}
368368

369+
#toolbar .push-left {
370+
float: left;
371+
}
372+
369373
.toolbar-div a {
370374
float: left;
371375
}

js/media/view.js

Lines changed: 12 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -39,148 +39,27 @@
3939
},
4040

4141
render: function() {
42-
var self, model, chart, gv, type, series, data, table, settings, i, j, row, date, format, formatter, axis, property;
42+
var self, model, chart;
4343

4444
self = this;
45-
gv = google.visualization;
4645
model = self.model;
4746

4847
self.$el
4948
.width(self.options.width)
5049
.height(self.options.height)
5150
.css('background-image', 'none');
5251

53-
type = model.get('type');
54-
series = model.get('series');
55-
data = model.get('data');
56-
settings = model.get('settings');
57-
58-
settings.width = self.options.width;
59-
settings.height = self.options.height;
60-
61-
table = new gv.DataTable({cols: series});
62-
63-
switch (type) {
64-
case "gauge":
65-
case "table":
66-
case "timeline":
67-
chart = type.charAt(0).toUpperCase() + type.slice(1);
68-
break;
69-
default:
70-
chart = type.charAt(0).toUpperCase() + type.slice(1) + 'Chart';
71-
break;
72-
}
73-
74-
chart = new gv[chart](self.el);
75-
76-
switch (type) {
77-
case 'pie':
78-
if (settings.slices) {
79-
for (i in settings.slices) {
80-
if (settings.slices[i]['color'] === '') {
81-
delete settings.slices[i]['color'];
82-
}
83-
}
84-
}
85-
break;
86-
case 'line':
87-
case 'bar':
88-
case 'column':
89-
case 'area':
90-
case 'scatter':
91-
case 'candlestick':
92-
if (settings.series) {
93-
for (i in settings.series) {
94-
if (settings.series[i]['color'] === '') {
95-
delete settings.series[i]['color'];
96-
}
97-
}
98-
}
99-
break;
100-
case 'geo':
101-
if (settings.region !== undefined && settings.region.replace(/^\s+|\s+$/g, '') === '') {
102-
settings['region'] = 'world';
103-
}
104-
break;
105-
case 'gauge':
106-
break;
107-
default:
108-
return;
109-
}
110-
111-
if (series[0] && (series[0].type === 'date' || series[0].type === 'datetime')) {
112-
axis = false;
113-
switch (type) {
114-
case 'line':
115-
case 'area':
116-
case 'scatter':
117-
case 'candlestick':
118-
case 'column':
119-
axis = settings.hAxis;
120-
break;
121-
case 'bar':
122-
axis = settings.vAxis;
123-
break;
124-
}
125-
126-
if (axis) {
127-
for (property in axis.viewWindow) {
128-
date = new Date(axis.viewWindow[property]);
129-
if (Object.prototype.toString.call(date) === "[object Date]") {
130-
if (!isNaN(date.getTime())) {
131-
axis.viewWindow[property] = date;
132-
continue;
133-
}
134-
}
135-
136-
delete axis.viewWindow[property];
137-
}
138-
}
139-
}
140-
141-
for (i = 0; i < data.length; i++) {
142-
row = [];
143-
for (j = 0; j < series.length; j++) {
144-
if (series[j].type === 'date' || series[j].type === 'datetime') {
145-
date = new Date(data[i][j]);
146-
data[i][j] = null;
147-
if (Object.prototype.toString.call(date) === "[object Date]") {
148-
if (!isNaN(date.getTime())) {
149-
data[i][j] = date;
150-
}
151-
}
152-
}
153-
row.push(data[i][j]);
154-
}
155-
table.addRow(row);
156-
}
157-
158-
if (settings.series) {
159-
for (i = 0; i < settings.series.length; i++) {
160-
format = settings.series[i].format;
161-
if (!format || format === '') {
162-
continue;
163-
}
164-
165-
formatter = null;
166-
switch (series[i + 1].type) {
167-
case 'number':
168-
formatter = new gv.NumberFormat({pattern: format});
169-
break;
170-
case 'date':
171-
case 'datetime':
172-
case 'timeofday':
173-
formatter = new gv.DateFormat({pattern: format});
174-
break;
175-
}
176-
177-
if (formatter) {
178-
formatter.format(table, i + 1);
179-
}
180-
}
181-
}
182-
183-
chart.draw(table, settings);
52+
chart = {};
53+
chart.type = model.get('type');
54+
chart.series = model.get('series');
55+
chart.data = model.get('data');
56+
chart.library = model.get('library');
57+
chart.settings = model.get('settings');
58+
chart.settings.width = self.options.width;
59+
chart.settings.height = self.options.height;
60+
$('#' + self.id).append(model.get('css'));
61+
62+
$('body').trigger('visualizer:render:specificchart:start', {id: self.id, chart: chart, v: {page_type: 'post'}} );
18463
}
18564
});
18665

js/render-datatables.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
var all_charts;
66

77
function renderChart(id, v) {
8-
var chart, render, container, series, data, table, settings, i, j, row, date, axis, property, format, formatter;
8+
renderSpecificChart(id, all_charts[id], v);
9+
}
910

10-
chart = all_charts[id];
11+
function renderSpecificChart(id, chart, v) {
12+
var render, container, series, data, table, settings, i, j, row, date, axis, property, format, formatter;
1113

1214
if(chart.library !== 'datatables'){
1315
return;
@@ -54,6 +56,7 @@
5456

5557
if(typeof v.page_type !== 'undefined'){
5658
switch(v.page_type){
59+
case 'post':
5760
case 'library':
5861
$.extend( settings, {
5962
scrollX: 150,
@@ -148,6 +151,10 @@
148151
render(v);
149152
});
150153

154+
$('body').on('visualizer:render:specificchart:start', function(event, v){
155+
renderSpecificChart(v.id, v.chart, v.v);
156+
});
157+
151158

152159
})(jQuery);
153160

0 commit comments

Comments
 (0)