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

104 lines 2.3 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 } 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.editor;
32
33 class ChartRender extends Component {
34 constructor() {
35 super( ...arguments );
36 }
37
38 render() {
39 let chart;
40
41 let data = formatDate( JSON.parse( JSON.stringify( this.props.chart ) ) );
42
43 if ( 0 <= [ 'gauge', 'table', 'timeline', 'dataTable' ].indexOf( this.props.chart['visualizer-chart-type']) ) {
44 if ( 'dataTable' === data['visualizer-chart-type']) {
45 chart = data['visualizer-chart-type'];
46 } else {
47 chart = startCase( this.props.chart['visualizer-chart-type']);
48 }
49 } else {
50 chart = `${ startCase( this.props.chart['visualizer-chart-type']) }Chart`;
51 }
52
53 return (
54 <div className={ this.props.className }>
55
56 { ( null !== this.props.chart ) &&
57 <Fragment>
58
59 <BlockControls key="toolbar-controls">
60 <Toolbar
61 className='components-toolbar'
62 >
63 <Tooltip text={ __( 'Edit Chart' ) }>
64 <Button
65 className="components-icon-button components-toolbar__control edit-pie-chart"
66 onClick={ this.props.editChart }
67 >
68 <Dashicon icon={ 'edit' } />
69 </Button>
70 </Tooltip>
71 </Toolbar>
72 </BlockControls>
73
74 { ( 'dataTable' === chart ) ? (
75 <DataTable
76 id={ this.props.id }
77 rows={ data['visualizer-data'] }
78 columns={ data['visualizer-series'] }
79 options={ data['visualizer-settings'] }
80 />
81 ) : (
82 <Chart
83 chartType={ chart }
84 rows={ data['visualizer-data'] }
85 columns={ data['visualizer-series'] }
86 options={
87 isValidJSON( this.props.chart['visualizer-settings'].manual ) ?
88 merge( compact( this.props.chart['visualizer-settings']), JSON.parse( this.props.chart['visualizer-settings'].manual ) ) :
89 compact( this.props.chart['visualizer-settings'])
90 }
91 height="500px"
92 />
93 ) }
94
95 </Fragment>
96 }
97
98 </div>
99 );
100 }
101 }
102
103 export default ChartRender;
104