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

106 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 height="auto"
61 cells={ ( row, col, prop ) => {
62 let cellProperties;
63 if ( 1 === row ) {
64 cellProperties = {
65 type: 'autocomplete',
66 source: this.types,
67 strict: false
68 };
69 }
70 if ( 0 <= ( this.dates ).indexOf( col ) && 1 < row ) {
71 cellProperties = {
72 type: 'date',
73 dateFormat: 'YYYY-MM-DD',
74 correctFormat: true
75 };
76 }
77 return cellProperties;
78 } }
79 />
80
81 <ButtonGroup>
82 <Button
83 variant="secondary"
84 isLarge
85 onClick={ this.props.toggleModal }
86 >
87 { __( 'Close' ) }
88 </Button>
89 <Button
90 isPrimary
91 isLarge
92 onClick={ e => {
93 this.props.toggleModal();
94 this.props.editChartData( this.data, 'Visualizer_Source_Csv' );
95 } }
96 >
97 { __( 'Save' ) }
98 </Button>
99 </ButtonGroup>
100 </div>
101 );
102 }
103 }
104
105 export default ChartEditor;
106