Skip to content

Commit 79b0917

Browse files
Merge pull request #398 from Codeinwp/3.2.0
Add support to show chart as an HTML table in AMP requests Add support to show charts from JSON/REST endpoints Fix loading of Google Visualization javascript files Add simple editors for editing chart data Tested up to WP 5.2
2 parents 6c5fdf1 + 6792036 commit 79b0917

29 files changed

+1808
-135
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11

2+
### v3.1.3 - 2019-02-24
3+
**Changes:**
4+
* Fix issue with changing column settings of the last column in table chart
5+
* Add support for query language to get subset of data from Google Spreadsheet
6+
* Fix conflict with jquery 3.3.x
7+
* Migrated PHPExcel to PhpSpreadsheet
8+
* Front end action 'print' should print the chart and fall back to printing the data
9+
* Fix issue with table chart not showing in IE
10+
* Fix issue with multiple instances of same chart not showing
11+
* Fix issue with date type column does not work with Combo charts
12+
* Tested with WP 5.1
13+
214
### v3.1.2 - 2018-12-06
315
**Changes:**
416
* Fix bug "Warning: A non-numeric value encountered"

classes/Visualizer/Module.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
6666

6767
$this->_addFilter( Visualizer_Plugin::FILTER_UNDO_REVISIONS, 'undoRevisions', 10, 2 );
6868
$this->_addFilter( Visualizer_Plugin::FILTER_HANDLE_REVISIONS, 'handleExistingRevisions', 10, 2 );
69+
$this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, 'getDataAs', 10, 3 );
6970

7071
}
7172

@@ -147,6 +148,15 @@ protected function _addShortcode( $tag, $method ) {
147148
return $this;
148149
}
149150

151+
/**
152+
* A wrapper around the actual function _getDataAs. This function is invoked as a filter.
153+
*
154+
* @since 3.2.0
155+
*/
156+
public function getDataAs( $final, $chart_id, $type ) {
157+
return $this->_getDataAs( $chart_id, $type );
158+
}
159+
150160
/**
151161
* Extracts the data for a chart and prepares it for the given type.
152162
*
@@ -223,14 +233,16 @@ public function _getDataAs( $chart_id, $type ) {
223233
private function _getCSV( $rows, $filename ) {
224234
$filename .= '.csv';
225235

236+
$bom = chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF );
226237
$fp = tmpfile();
227238
// support for MS Excel
228-
fprintf( $fp, $bom = ( chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF ) ) );
239+
fprintf( $fp, $bom );
229240
foreach ( $rows as $row ) {
230241
fputcsv( $fp, $row );
231242
}
232243
rewind( $fp );
233244
$csv = '';
245+
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
234246
while ( ( $array = fgetcsv( $fp ) ) !== false ) {
235247
if ( strlen( $csv ) > 0 ) {
236248
$csv .= PHP_EOL;
@@ -242,6 +254,7 @@ private function _getCSV( $rows, $filename ) {
242254
return array(
243255
'csv' => $csv,
244256
'name' => $filename,
257+
'string' => str_replace( $bom, '', $csv ),
245258
);
246259
}
247260

@@ -280,6 +293,7 @@ private function _getExcel( $rows, $filename ) {
280293
return array(
281294
'csv' => 'data:application/vnd.ms-excel;base64,' . base64_encode( $xlsData ),
282295
'name' => $filename,
296+
'raw' => base64_encode( $xlsData ),
283297
);
284298
}
285299

@@ -311,6 +325,12 @@ private function _getHTML( $rows ) {
311325
$table = '<table class="visualizer-print">';
312326
$index = 0;
313327
foreach ( $rows as $row ) {
328+
// skip the data type row.
329+
if ( 1 === $index ) {
330+
$index++;
331+
continue;
332+
}
333+
314334
$table .= '<tr>';
315335
foreach ( $row as $col ) {
316336
if ( $index === 0 ) {
@@ -432,6 +452,7 @@ protected function get_user_customization_js() {
432452
}
433453

434454
if ( ! $wp_filesystem->exists( $dir ) ) {
455+
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
435456
if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) {
436457
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
437458
return $default;
@@ -441,6 +462,7 @@ protected function get_user_customization_js() {
441462
// if file does not exist, copy.
442463
if ( ! $wp_filesystem->exists( $file ) ) {
443464
$src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
465+
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
444466
if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) {
445467
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ );
446468
return $default;

classes/Visualizer/Module/AMP.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
// +----------------------------------------------------------------------+
3+
// | Copyright 2013 Madpixels (email : [email protected]) |
4+
// +----------------------------------------------------------------------+
5+
// | This program is free software; you can redistribute it and/or modify |
6+
// | it under the terms of the GNU General Public License, version 2, as |
7+
// | published by the Free Software Foundation. |
8+
// | |
9+
// | This program is distributed in the hope that it will be useful, |
10+
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11+
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12+
// | GNU General Public License for more details. |
13+
// | |
14+
// | You should have received a copy of the GNU General Public License |
15+
// | along with this program; if not, write to the Free Software |
16+
// | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
17+
// | MA 02110-1301 USA |
18+
// +----------------------------------------------------------------------+
19+
// | Author: Eugene Manuilov <[email protected]> |
20+
// +----------------------------------------------------------------------+
21+
/**
22+
* The module for all AMP stuff.
23+
*
24+
* @category Visualizer
25+
* @package Module
26+
*
27+
* @since 1.0.0
28+
*/
29+
class Visualizer_Module_AMP extends Visualizer_Module {
30+
31+
const NAME = __CLASS__;
32+
33+
/**
34+
* Constructor.
35+
*
36+
* @since 1.0.0
37+
*
38+
* @access public
39+
*
40+
* @param Visualizer_Plugin $plugin The instance of the plugin.
41+
*/
42+
public function __construct( Visualizer_Plugin $plugin ) {
43+
$this->_addFilter( 'amp_post_template_data', 'addToHeader' );
44+
}
45+
46+
/**
47+
* Add the iframe component to the header.
48+
*/
49+
public function addToHeader( $data ) {
50+
$data['amp_component_scripts'] = array_merge(
51+
$data['amp_component_scripts'],
52+
array(
53+
'amp-iframe' => 'https://cdn.ampproject.org/v0/amp-iframe-latest.js',
54+
)
55+
);
56+
return $data;
57+
}
58+
59+
/**
60+
* Is this an AMP request?
61+
*/
62+
public static function is_amp() {
63+
return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint();
64+
}
65+
66+
/**
67+
* Loads the alterview view of the chart.
68+
*/
69+
public function get_chart( $chart, $data, $series, $settings ) {
70+
$view = apply_filters( 'visualizer_amp_view', null, $chart, $data, $series, $settings );
71+
if ( ! is_null( $view ) ) {
72+
return $view;
73+
}
74+
$output = $this->_getDataAs( $chart->ID, 'print' );
75+
return $output['csv'];
76+
}
77+
78+
}

classes/Visualizer/Module/Admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ public function renderLibraryPage() {
706706
),
707707
),
708708
'page_type' => 'library',
709+
'is_front' => false,
709710
)
710711
);
711712
// render library page

0 commit comments

Comments
 (0)