PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.8.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.8.0
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
visualizer / classes / Visualizer / Gutenberg / src / Components / ChartRender.js

ChartRender.js in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.8.0, at classes/Visualizer/Gutenberg/src/Components/ChartRender.js

141 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * External dependencies
3 */
4 import { Chart } from 'react-google-charts';
5
6 import DataTable from './DataTable.js';
7
8 import merge from 'merge';
9
10 import { compact, formatDate, isValidJSON, formatData } from '../utils.js';
11
12 /**
13 * WordPress dependencies
14 */
15 const { startCase } = lodash;
16
17 const { __ } = wp.i18n;
18
19 const {
20 Component,
21 Fragment
22 } = wp.element;
23
24 const {
25 Button,
26 Dashicon,
27 Toolbar,
28 Tooltip
29 } = wp.components;
30
31 const { BlockControls } = wp.blockEditor || wp.editor;
32
33 class ChartRender extends Component {
34 constructor() {
35 super( ...arguments );
36 }
37
38 render() {
39
40 let chartVersion = 'undefined' !== typeof google ? google.visualization.Version : 'current';
41
42 let chart, footer;
43
44 let data = formatDate( JSON.parse( JSON.stringify( this.props.chart ) ) );
45
46 if ( 0 <= [ 'gauge', 'tabular', 'timeline' ].indexOf( this.props.chart['visualizer-chart-type']) ) {
47 if ( 'DataTable' === data['visualizer-chart-library']) {
48 chart = data['visualizer-chart-type'];
49 } else {
50 chart = this.props.chart['visualizer-chart-type'];
51 if ( 'tabular' === chart ) {
52 chart = 'table';
53 }
54 chart = startCase( chart );
55 }
56 } else {
57 chart = `${ startCase( this.props.chart['visualizer-chart-type']) }Chart`;
58 }
59
60 if ( data['visualizer-data-exploded']) {
61 footer = __( 'Annotations in this chart may not display here but they will display in the front end.' );
62 }
63
64 if ( this.props.chart['visualizer-series'] && 0 <= [ 'date', 'datetime', 'timeofday' ].indexOf( this.props.chart['visualizer-series'][0].type ) ) {
65 if ( this.props.chart['visualizer-settings'] && '' == this.props.chart['visualizer-settings'].hAxis.format ) {
66 this.props.chart['visualizer-settings'].hAxis.format = 'YYYY-MM-dd';
67 }
68 }
69
70 return (
71 <div className={ this.props.className }>
72
73 { ( null !== this.props.chart ) &&
74 <Fragment>
75
76 <BlockControls key="toolbar-controls">
77 <Toolbar
78 className='components-toolbar'
79 >
80 <Tooltip text={ __( 'Edit Chart' ) }>
81 <Button
82 className="components-icon-button components-toolbar__control edit-pie-chart"
83 onClick={ this.props.editChart }
84 >
85 <Dashicon icon={ 'edit' } />
86 </Button>
87 </Tooltip>
88 </Toolbar>
89 </BlockControls>
90
91 { ( 'DataTable' === data['visualizer-chart-library']) ? (
92 <DataTable
93 id={ this.props.id }
94 rows={ data['visualizer-data'] }
95 columns={ data['visualizer-series'] }
96 options={ data['visualizer-settings'] }
97 />
98 ) : ( '' !== data['visualizer-data-exploded'] ? (
99 <Chart
100 chartVersion={ chartVersion }
101 chartType={ chart }
102 rows={ data['visualizer-data'] }
103 columns={ data['visualizer-series'] }
104 options={
105 isValidJSON( this.props.chart['visualizer-settings'].manual ) ?
106 merge( compact( this.props.chart['visualizer-settings']), JSON.parse( this.props.chart['visualizer-settings'].manual ) ) :
107 compact( this.props.chart['visualizer-settings'])
108 }
109 height="500px"
110 formatters={ formatData( data ) }
111 />
112 ) : (
113 <Chart
114 chartVersion={ chartVersion }
115 chartType={ chart }
116 rows={ data['visualizer-data'] }
117 columns={ data['visualizer-series'] }
118 options={
119 isValidJSON( this.props.chart['visualizer-settings'].manual ) ?
120 merge( compact( this.props.chart['visualizer-settings']), JSON.parse( this.props.chart['visualizer-settings'].manual ) ) :
121 compact( this.props.chart['visualizer-settings'])
122 }
123 height="500px"
124 formatters={ formatData( data ) }
125 />
126 ) ) }
127
128 <div className="visualizer-settings__charts-footer"><sub>
129 { footer }
130 </sub></div>
131
132 </Fragment>
133 }
134
135 </div>
136 );
137 }
138 }
139
140 export default ChartRender;
141