Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat: update logic to generate x series for line series charts (#3993)

Yunus M4083970289d8
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<ToggleGraphProps | undefined, UplotProps>(
}, [data, resetScales, create]);
return (
- <div className="uplot-graph-container" ref={targetRef}>
- {data && data[0] && data[0]?.length === 0 ? (
- <div className="not-found">
- <Typography>No Data</Typography>
- </div>
- ) : null}
- </div>
+ <ErrorBoundary FallbackComponent={ErrorBoundaryFallback}>
+ <div className="uplot-graph-container" ref={targetRef}>
+ {data && data[0] && data[0]?.length === 0 ? (
+ <div className="not-found">
+ <Typography>No Data</Typography>
+ </div>
+ ) : null}
+ </div>
+ </ErrorBoundary>
);
},
);
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;