PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.2.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.2.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 / ChartEditor.js

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

105 lines 2.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 { HotTable } from '@handsontable/react';
5
6 import 'handsontable/dist/handsontable.full.css';
7
8 /**
9 * WordPress dependencies
10 */
11 const { __ } = wp.i18n;
12
13 const { Component } = wp.element;
14
15 const {
16 Button,
17 ButtonGroup
18 } = wp.components;
19
20 class ChartEditor extends Component {
21 constructor() {
22 super( ...arguments );
23
24 this.data = [];
25
26 this.dates = [];
27
28 this.types = [ 'string', 'number', 'boolean', 'date', 'datetime', 'timeofday' ];
29 }
30
31 componentWillMount() {
32 this.data[this.data.length] = [];
33 this.data[this.data.length] = [];
34
35 this.props.chart['visualizer-series'].map( ( i, index ) => {
36 this.data[0][ index ] = i.label;
37 this.data[1][ index ] = i.type;
38 if ( 'date' === i.type ) {
39 this.dates.push( index );
40 }
41 });
42
43 this.props.chart['visualizer-data'].map( ( i ) => {
44 this.data[this.data.length] = i;
45 });
46 }
47
48 render() {
49
50 return (
51 <div className="visualizer-chart-editor">
52 <HotTable
53 data={ this.data }
54 allowInsertRow={ true }
55 contextMenu={ true }
56 rowHeaders={ true }
57 colHeaders={ true }
58 allowInvalid={ false }
59 className="htEditor"
60 cells={ ( row, col, prop ) => {
61 let cellProperties;
62 if ( 1 === row ) {
63 cellProperties = {
64 type: 'autocomplete',
65 source: this.types,
66 strict: false
67 };
68 }
69 if ( 0 <= ( this.dates ).indexOf( col ) && 1 < row ) {
70 cellProperties = {
71 type: 'date',
72 dateFormat: 'YYYY-MM-DD',
73 correctFormat: true
74 };
75 }
76 return cellProperties;
77 } }
78 />
79
80 <ButtonGroup>
81 <Button
82 isDefault
83 isLarge
84 onClick={ this.props.toggleModal }
85 >
86 { __( 'Close' ) }
87 </Button>
88 <Button
89 isPrimary
90 isLarge
91 onClick={ e => {
92 this.props.toggleModal();
93 this.props.editChartData( this.data, 'Visualizer_Source_Csv' );
94 } }
95 >
96 { __( 'Save' ) }
97 </Button>
98 </ButtonGroup>
99 </div>
100 );
101 }
102 }
103
104 export default ChartEditor;
105