diff --git a/frontend/src/components/Uplot/Uplot.tsx b/frontend/src/components/Uplot/Uplot.tsx index c3df529752..7e80d8bda4 100644 --- a/frontend/src/components/Uplot/Uplot.tsx +++ b/frontend/src/components/Uplot/Uplot.tsx @@ -3,6 +3,7 @@ import './uplot.scss'; import { Typography } from 'antd'; import { ToggleGraphProps } from 'components/Graph/types'; +import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback'; import { forwardRef, memo, @@ -11,6 +12,7 @@ import { useImperativeHandle, useRef, } from 'react'; +import { ErrorBoundary } from 'react-error-boundary'; import UPlot from 'uplot'; import { dataMatch, optionsUpdateState } from './utils'; @@ -119,13 +121,15 @@ const Uplot = forwardRef( }, [data, resetScales, create]); return ( -
- {data && data[0] && data[0]?.length === 0 ? ( -
- No Data -
- ) : null} -
+ +
+ {data && data[0] && data[0]?.length === 0 ? ( +
+ No Data +
+ ) : null} +
+
); }, ); diff --git a/frontend/src/lib/uPlotLib/utils/getChartData.ts b/frontend/src/lib/uPlotLib/utils/getChartData.ts index b80ccec9dc..fe9cec3350 100644 --- a/frontend/src/lib/uPlotLib/utils/getChartData.ts +++ b/frontend/src/lib/uPlotLib/utils/getChartData.ts @@ -7,13 +7,24 @@ export const getUPlotChartData = ( const seriesList = apiResponse?.data?.result || []; const uPlotData: uPlot.AlignedData = []; + // this helps us identify the series with the max number of values and helps define the x axis - timestamps + const xSeries = seriesList.reduce( + (maxObj, currentObj) => + currentObj.values.length > maxObj.values.length ? currentObj : maxObj, + seriesList[0], + ); + // sort seriesList for (let index = 0; index < seriesList.length; index += 1) { seriesList[index]?.values?.sort((a, b) => a[0] - b[0]); } + const timestampArr = xSeries?.values?.map((v) => v[0]); + + const uplotDataFormatArr = new Float64Array(timestampArr); + // timestamp - uPlotData.push(new Float64Array(seriesList[0]?.values?.map((v) => v[0]))); + uPlotData.push(uplotDataFormatArr); const numberOfTimestamps = uPlotData[0].length;