diff --git a/src/app/components/TimeSeriesDialog/TSDataContainer.tsx b/src/app/components/TimeSeriesDialog/TSDataContainer.tsx index 0128678..afd19ff 100644 --- a/src/app/components/TimeSeriesDialog/TSDataContainer.tsx +++ b/src/app/components/TimeSeriesDialog/TSDataContainer.tsx @@ -182,16 +182,26 @@ const TSDataContainer = (props: TSDataContainerProps) => { const { t } = useTranslation(); - let nfltr = 'MOVING_AVERAGE'; - let sfltr = 'NO_SMOOTHING'; - let mfltr = 'model_ensemble'; + const [nfltr, setNfltr] = useState('MOVING_AVERAGE'); + const [sfltr, setSfltr] = useState('NO_SMOOTHING'); + const [mfltr, setMfltr] = useState('model_ensemble'); + const [smfltr, setSMfltr] = useState('model_ensemble'); + + const toDisplay = x => { + return x.name.indexOf('_BOUND_'); + }; const getLegend = () => { //TODO names lookup const legend = timeseries ?.filter(x => x.name.indexOf('_BOUND_') < 0) .filter(x => x.name.indexOf(nfltr) >= 0) - .filter(x => x.name.indexOf(mfltr) >= 0 || x.name.length < 20) + .filter( + x => + x.name.indexOf(mfltr) >= 0 || + x.name.length < 20 || + x.name.indexOf(smfltr) >= 0, + ) .map(item => item.name); return legend; }; @@ -202,7 +212,12 @@ const TSDataContainer = (props: TSDataContainerProps) => { const legend = timeseries ?.filter(x => x.name.indexOf('_BOUND_') < 0) .filter(x => x.name.indexOf(nfltr) >= 0) - .filter(x => x.name.indexOf(mfltr) >= 0 || x.name.length < 20) + .filter( + x => + x.name.indexOf(mfltr) >= 0 || + x.name.length < 20 || + x.name.indexOf(smfltr) >= 0, + ) .map(x => (ret[x.name] = true)); //.map(x => (ret[x.name] = x.info.smoothing === 'no_smoothing')); return ret; @@ -237,8 +252,8 @@ const TSDataContainer = (props: TSDataContainerProps) => { const getChartData = (item, series) => { if ( item.name.indexOf('_BOUND_') >= 0 && - item.name.indexOf(nfltr) < 0 && - item.name.indexOf(mfltr) < 0 + item.name.indexOf(nfltr) >= 0 && + (item.name.indexOf(mfltr) >= 0 || item.name.indexOf(smfltr) >= 0) ) { if (item.name.indexOf('UPPER') >= 0) { let ret: number[] = []; @@ -250,16 +265,6 @@ const TSDataContainer = (props: TSDataContainerProps) => { ret.push(item.values[i].value - lbitem[0].values[i].value); } return ret; - } else if (item.name.indexOf('LOWER') >= 0) { - let ret: number[] = []; - let lbitem = series.filter( - x => x.name === item.name.replace('LOWER', 'UPPER'), - ); - if (lbitem) - for (let i in item.values) { - ret.push(item.values[i].value - lbitem[0].values[i].value); - } - return ret; } } return item.values.map(x => x.value); @@ -273,9 +278,7 @@ const TSDataContainer = (props: TSDataContainerProps) => { }; const getStack = dataset => { - return dataset.name.indexOf('_BOUND_') > 0 - ? dataset.info.smoothing - : dataset.name; + return dataset.name.replace('_LOWER_', '').replace('_UPPER_', ''); }; const getAreaStyle = dataset => { if (dataset.name.indexOf('_UPPER_BOUND_') > 0) { @@ -299,7 +302,8 @@ const TSDataContainer = (props: TSDataContainerProps) => { const pseriesObj = timeseries?.filter(item => { return ( //item.name.indexOf('_BOUND_') >= 0 && - item.name.indexOf(nfltr) >= 0 && item.name.indexOf(mfltr) >= 0 + item.name.indexOf(nfltr) >= 0 && + (item.name.indexOf(mfltr) >= 0 || item.name.indexOf(smfltr) >= 0) ); }); const seriesObj = pseriesObj.map(item => ({ @@ -525,19 +529,19 @@ const TSDataContainer = (props: TSDataContainerProps) => { }, [getXAxis, timeseries]); const setSensorSmoothing = v => { - if (v == 0) { - sfltr = 'NO_SMOOTHING'; - } else if (v == 1) { - sfltr = 'MOVING_AVERAGE'; + if (v === 0) { + setSfltr('NO_SMOOTHING'); + } else if (v === 1) { + setSfltr('MOVING_AVERAGE'); } }; const setModelSmoothing = v => { - if (v == 0) { - nfltr = 'NO_SMOOTHING'; - } else if (v == 1) { - nfltr = 'MOVING_AVERAGE'; - } else if (v == 2) { - nfltr = 'LOESS'; + if (v === 0) { + setNfltr('NO_SMOOTHING'); + } else if (v === 1) { + setNfltr('MOVING_AVERAGE'); + } else if (v === 2) { + setNfltr('LOESS'); } }; @@ -549,20 +553,7 @@ const TSDataContainer = (props: TSDataContainerProps) => { {t('app.map.timeSeriesDialog.selectedModel')} - + @@ -573,13 +564,16 @@ const TSDataContainer = (props: TSDataContainerProps) => {