@@ -2,6 +2,8 @@ import React, { PureComponent } from 'react';
22import PropTypes from 'prop-types' ;
33import jschart from 'jschart' ;
44
5+ import Select from '@/components/Select' ;
6+
57export default class TimeseriesGraph extends PureComponent {
68 static propTypes = {
79 dataSeriesNames : PropTypes . array . isRequired ,
@@ -21,6 +23,14 @@ export default class TimeseriesGraph extends PureComponent {
2123 yAxisTitle : null ,
2224 } ;
2325
26+ constructor ( props ) {
27+ super ( props ) ;
28+
29+ this . state = {
30+ selectedValue : 1 ,
31+ } ;
32+ }
33+
2434 componentDidMount = ( ) => {
2535 const {
2636 xAxisSeries,
@@ -32,39 +42,59 @@ export default class TimeseriesGraph extends PureComponent {
3242 yAxisTitle,
3343 graphOptions,
3444 } = this . props ;
45+ let { selectedValue } = this . state ;
46+ selectedValue -= 1 ;
3547
3648 jschart . create_jschart ( 0 , 'timeseries' , graphId , graphName , xAxisTitle , yAxisTitle , {
3749 dynamic_chart : true ,
3850 json_object : {
3951 x_axis_series : xAxisSeries ,
40- data_series_names : dataSeriesNames ,
41- data,
52+ data_series_names : data . length > 0 ? data [ selectedValue ] . timeseriesLabels : dataSeriesNames ,
53+ data : data . length > 0 ? data [ selectedValue ] . timeseriesAggregation : data ,
4254 } ,
4355 ...graphOptions ,
4456 } ) ;
4557 } ;
4658
47- componentDidUpdate = prevProps => {
59+ componentDidUpdate = ( prevProps , prevState ) => {
4860 const { data, dataSeriesNames, xAxisSeries, graphId } = this . props ;
61+ let { selectedValue } = this . state ;
62+ selectedValue -= 1 ;
4963
5064 if (
5165 JSON . stringify ( prevProps . data ) !== JSON . stringify ( data ) ||
5266 JSON . stringify ( prevProps . dataSeriesNames ) !== JSON . stringify ( dataSeriesNames ) ||
53- prevProps . xAxisSeries !== xAxisSeries
67+ prevProps . xAxisSeries !== xAxisSeries ||
68+ prevState . selectedValue !== selectedValue
5469 ) {
55- jschart . chart_reload ( graphId , {
70+ jschart . chart_reload_options ( graphId , {
5671 json_object : {
5772 x_axis_series : xAxisSeries ,
58- data_series_names : dataSeriesNames ,
59- data,
73+ data_series_names :
74+ data . length > 0 ? data [ selectedValue ] . timeseriesLabels : dataSeriesNames ,
75+ data : data . length > 0 ? data [ selectedValue ] . timeseriesAggregation : data ,
6076 } ,
6177 } ) ;
6278 }
6379 } ;
6480
81+ onSelect = ( event , selection ) => {
82+ this . setState ( {
83+ selectedValue : selection ,
84+ } ) ;
85+ } ;
86+
6587 render ( ) {
66- const { graphId } = this . props ;
88+ const { graphId, options } = this . props ;
89+ const { selectedValue } = this . state ;
6790
68- return < div id = { graphId } /> ;
91+ return (
92+ < div >
93+ { options && (
94+ < Select onSelect = { this . onSelect } options = { options } selected = { selectedValue . toString ( ) } />
95+ ) }
96+ < div id = { graphId } />
97+ </ div >
98+ ) ;
6999 }
70100}
0 commit comments