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 / ChartSelect.js

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

201 lines 5.7 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 FileImport from './Import/FileImport.js';
9
10 import RemoteImport from './Import/RemoteImport.js';
11
12 import ChartImport from './Import/ChartImport.js';
13
14 import DataImport from './Import/DataImport.js';
15
16 import ManualData from './Import/ManualData.js';
17
18 import Sidebar from './Sidebar.js';
19
20 import ChartPermissions from './ChartPermissions.js';
21
22 import PanelButton from './PanelButton.js';
23
24 import merge from 'merge';
25
26 import { compact, formatDate, isValidJSON, formatData } from '../utils.js';
27
28 /**
29 * WordPress dependencies
30 */
31 const { startCase } = lodash;
32
33 const { __ } = wp.i18n;
34
35 const {
36 Component,
37 Fragment
38 } = wp.element;
39
40 const { InspectorControls } = wp.blockEditor || wp.editor;
41
42 class ChartSelect extends Component {
43 constructor() {
44 super( ...arguments );
45
46 this.state = {
47
48 /**
49 * Sidebar Route Status
50 *
51 * home - Initial screen.
52 * showAdvanced - Show Advanced Options.
53 */
54 route: 'home'
55 };
56 }
57
58 render() {
59
60 let chart, footer;
61
62 let data = formatDate( JSON.parse( JSON.stringify( this.props.chart ) ) );
63
64 if ( 0 <= [ 'gauge', 'tabular', 'timeline' ].indexOf( this.props.chart['visualizer-chart-type']) ) {
65 if ( 'DataTable' === data['visualizer-chart-library']) {
66 chart = data['visualizer-chart-type'];
67 } else {
68 chart = this.props.chart['visualizer-chart-type'];
69 if ( 'tabular' === chart ) {
70 chart = 'table';
71 }
72 chart = startCase( chart );
73 }
74 } else {
75 chart = `${ startCase( this.props.chart['visualizer-chart-type']) }Chart`;
76 }
77
78 if ( data['visualizer-data-exploded']) {
79 footer = __( 'Annotations in this chart may not display here but they will display in the front end.' );
80 }
81
82 return (
83 <Fragment>
84 { 'home' === this.state.route &&
85 <InspectorControls>
86
87 <FileImport
88 chart={ this.props.chart }
89 readUploadedFile={ this.props.readUploadedFile }
90 />
91
92 <RemoteImport
93 id={ this.props.id }
94 chart={ this.props.chart }
95 editURL={ this.props.editURL }
96 isLoading={ this.props.isLoading }
97 uploadData={ this.props.uploadData }
98 editSchedule={ this.props.editSchedule }
99 editJSONSchedule={ this.props.editJSONSchedule }
100 editJSONURL={ this.props.editJSONURL }
101 editJSONHeaders={ this.props.editJSONHeaders }
102 editJSONRoot={ this.props.editJSONRoot }
103 editJSONPaging={ this.props.editJSONPaging }
104 JSONImportData={ this.props.JSONImportData }
105 />
106
107 <ChartImport getChartData={ this.props.getChartData } isLoading={ this.props.isLoading } />
108
109 <DataImport
110 chart={ this.props.chart }
111 editSchedule={ this.props.editDatabaseSchedule }
112 databaseImportData={ this.props.databaseImportData }
113 />
114
115 <ManualData chart={ this.props.chart } editChartData={ this.props.editChartData } />
116
117 <PanelButton
118 label={ __( 'Advanced Options' ) }
119 className="visualizer-advanced-options"
120 icon="admin-tools"
121 onClick={ () => this.setState({ route: 'showAdvanced' }) }
122 />
123
124 <PanelButton
125 label={ __( 'Chart Permissions' ) }
126 icon="admin-users"
127 onClick={ () => this.setState({ route: 'showPermissions' }) }
128 />
129 </InspectorControls>
130 }
131
132 { ( 'showAdvanced' === this.state.route || 'showPermissions' === this.state.route ) &&
133 <InspectorControls>
134 <PanelButton
135 label={ __( 'Chart Settings' ) }
136 onClick={ () => this.setState({ route: 'home' }) }
137 isBack={ true }
138 />
139
140 { 'showAdvanced' === this.state.route &&
141 <Sidebar chart={ this.props.chart } attributes={ this.props.attributes } edit={ this.props.editSettings } />
142 }
143
144 { 'showPermissions' === this.state.route &&
145 <ChartPermissions chart={ this.props.chart } edit={ this.props.editPermissions } />
146 }
147 </InspectorControls>
148 }
149
150 <div className="visualizer-settings__chart" data-chart-type={ chart }>
151
152 { ( null !== this.props.chart ) &&
153
154 ( 'DataTable' === data['visualizer-chart-library']) ? (
155 <DataTable
156 id={ this.props.id }
157 rows={ data['visualizer-data'] }
158 columns={ data['visualizer-series'] }
159 options={ data['visualizer-settings'] }
160 />
161 ) : ( '' !== data['visualizer-data-exploded'] ? (
162 <Chart
163 chartType={ chart }
164 rows={ data['visualizer-data'] }
165 columns={ data['visualizer-series'] }
166 options={
167 isValidJSON( this.props.chart['visualizer-settings'].manual ) ?
168 merge( compact( this.props.chart['visualizer-settings']), JSON.parse( this.props.chart['visualizer-settings'].manual ) ) :
169 compact( this.props.chart['visualizer-settings'])
170 }
171 height="500px"
172 formatters={ formatData( data ) }
173 />
174 ) : (
175 <Chart
176 chartType={ chart }
177 rows={ data['visualizer-data'] }
178 columns={ data['visualizer-series'] }
179 options={
180 isValidJSON( this.props.chart['visualizer-settings'].manual ) ?
181 merge( compact( this.props.chart['visualizer-settings']), JSON.parse( this.props.chart['visualizer-settings'].manual ) ) :
182 compact( this.props.chart['visualizer-settings'])
183 }
184 height="500px"
185 formatters={ formatData( data ) }
186 />
187 )
188 ) }
189
190 <div className="visualizer-settings__charts-footer"><sub>
191 { footer }
192 </sub></div>
193
194 </div>
195 </Fragment>
196 );
197 }
198 }
199
200 export default ChartSelect;
201