← All changes
|
classes/Visualizer/Gutenberg/src/Components/ChartRender.js
+28
-14
3.1.1
→
3.3.4
View file →
| @@ -2,8 +2,10 @@ | ||
| 2 | 2 | * External dependencies |
| 3 | 3 | */ |
| 4 | 4 | import { Chart } from 'react-google-charts'; |
| 5 | 5 | |
| 6 | +import DataTable from './DataTable.js'; | |
| 7 | + | |
| 6 | 8 | import merge from 'merge'; |
| 7 | 9 | |
| 8 | 10 | import { compact, formatDate, isValidJSON } from '../utils.js'; |
| 9 | 11 | |
| @@ -33,15 +35,18 @@ | ||
| 33 | 35 | super( ...arguments ); |
| 34 | 36 | } |
| 35 | 37 | |
| 36 | 38 | render() { |
| 37 | - | |
| 38 | 39 | let chart; |
| 39 | 40 | |
| 40 | 41 | let data = formatDate( JSON.parse( JSON.stringify( this.props.chart ) ) ); |
| 41 | 42 | |
| 42 | - if ( 0 <= [ 'gauge', 'table', 'timeline' ].indexOf( this.props.chart['visualizer-chart-type']) ) { | |
| 43 | - chart = startCase( this.props.chart['visualizer-chart-type']); | |
| 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 | + } | |
| 44 | 49 | } else { |
| 45 | 50 | chart = `${ startCase( this.props.chart['visualizer-chart-type']) }Chart`; |
| 46 | 51 | } |
| 47 | 52 | |
| @@ -65,19 +70,28 @@ | ||
| 65 | 70 | </Tooltip> |
| 66 | 71 | </Toolbar> |
| 67 | 72 | </BlockControls> |
| 68 | 73 | |
| 69 | - <Chart | |
| 70 | - chartType={ chart } | |
| 71 | - rows={ data['visualizer-data'] } | |
| 72 | - columns={ data['visualizer-series'] } | |
| 73 | - options={ | |
| 74 | - isValidJSON( this.props.chart['visualizer-settings'].manual ) ? | |
| 75 | - merge( compact( this.props.chart['visualizer-settings']), JSON.parse( this.props.chart['visualizer-settings'].manual ) ) : | |
| 76 | - compact( this.props.chart['visualizer-settings']) | |
| 77 | - } | |
| 78 | - height="500px" | |
| 79 | - /> | |
| 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 | + ) } | |
| 80 | 94 | |
| 81 | 95 | </Fragment> |
| 82 | 96 | } |
| 83 | 97 | |