PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.11
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.11
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.4.11, at classes/Visualizer/Gutenberg/src/Components/ChartRender.js

130 lines 3.5 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 let chart, footer;
40
41 let data = formatDate( JSON.parse( JSON.stringify( this.props.chart ) ) );
42
43 if ( 0 <= [ 'gauge', 'tabular', 'timeline' ].indexOf( this.props.chart['visualizer-chart-type']) ) {
44 if ( 'DataTable' === data['visualizer-chart-library']) {
45 chart = data['visualizer-chart-type'];
46 } else {
47 chart = this.props.chart['visualizer-chart-type'];
48 if ( 'tabular' === chart ) {
49 chart = 'table';
50 }
51 chart = startCase( chart );
52 }
53 } else {
54 chart = `${ startCase( this.props.chart['visualizer-chart-type']) }Chart`;
55 }
56
57 if ( data['visualizer-data-exploded']) {
58 footer = __( 'Annotations in this chart may not display here but they will display in the front end.' );
59 }
60
61 return (
62 <div className={ this.props.className }>
63
64 { ( null !== this.props.chart ) &&
65 <Fragment>
66
67 <BlockControls key="toolbar-controls">
68 <Toolbar
69 className='components-toolbar'
70 >
71 <Tooltip text={ __( 'Edit Chart' ) }>
72 <Button
73 className="components-icon-button components-toolbar__control edit-pie-chart"
74 onClick={ this.props.editChart }
75 >
76 <Dashicon icon={ 'edit' } />
77 </Button>
78 </Tooltip>
79 </Toolbar>
80 </BlockControls>
81
82 { ( 'DataTable' === data['visualizer-chart-library']) ? (
83 <DataTable
84 id={ this.props.id }
85 rows={ data['visualizer-data'] }
86 columns={ data['visualizer-series'] }
87 options={ data['visualizer-settings'] }
88 />
89 ) : ( '' !== data['visualizer-data-exploded'] ? (
90 <Chart
91 chartType={ chart }
92 rows={ data['visualizer-data'] }
93 columns={ data['visualizer-series'] }
94 options={
95 isValidJSON( this.props.chart['visualizer-settings'].manual ) ?
96 merge( compact( this.props.chart['visualizer-settings']), JSON.parse( this.props.chart['visualizer-settings'].manual ) ) :
97 compact( this.props.chart['visualizer-settings'])
98 }
99 height="500px"
100 formatters={ formatData( data ) }
101 />
102 ) : (
103 <Chart
104 chartType={ chart }
105 rows={ data['visualizer-data'] }
106 columns={ data['visualizer-series'] }
107 options={
108 isValidJSON( this.props.chart['visualizer-settings'].manual ) ?
109 merge( compact( this.props.chart['visualizer-settings']), JSON.parse( this.props.chart['visualizer-settings'].manual ) ) :
110 compact( this.props.chart['visualizer-settings'])
111 }
112 height="500px"
113 formatters={ formatData( data ) }
114 />
115 ) ) }
116
117 <div className="visualizer-settings__charts-footer"><sub>
118 { footer }
119 </sub></div>
120
121 </Fragment>
122 }
123
124 </div>
125 );
126 }
127 }
128
129 export default ChartRender;
130