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: add useBarChart instead of graph (#12517)

Gaurav Tewarif69bce998a1c
diff --git a/frontend/src/container/LiveLogs/LiveLogsList/LiveLogsList.styles.scss b/frontend/src/container/LiveLogs/LiveLogsList/LiveLogsList.styles.scss
index 7b343ce050..613f5c47ad 100644
--- a/frontend/src/container/LiveLogs/LiveLogsList/LiveLogsList.styles.scss
+++ b/frontend/src/container/LiveLogs/LiveLogsList/LiveLogsList.styles.scss
@@ -4,13 +4,6 @@
padding: 0px 8px;
.logs-frequency-chart {
- .ant-card-body {
- height: 140px;
- min-height: 140px;
- padding: 0 16px 22px 16px;
- font-family: 'Geist Mono';
- }
-
margin-bottom: 0px;
}
}
diff --git a/frontend/src/container/LogsExplorerChart/LogsExplorerChart.styles.scss b/frontend/src/container/LogsExplorerChart/LogsExplorerChart.styles.scss
index e0e46e1395..10b0becfff 100644
--- a/frontend/src/container/LogsExplorerChart/LogsExplorerChart.styles.scss
+++ b/frontend/src/container/LogsExplorerChart/LogsExplorerChart.styles.scss
@@ -3,13 +3,6 @@
min-height: 200px;
border-bottom: 1px solid var(--l1-border);
- .ant-card-body {
- height: 200px;
- min-height: 200px;
- padding: 0 16px 16px 16px;
- font-family: 'Geist Mono';
- }
-
.logs-frequency-chart-loading {
height: 100%;
display: flex;
diff --git a/frontend/src/container/LogsExplorerChart/index.tsx b/frontend/src/container/LogsExplorerChart/index.tsx
index 14b4e8ed3d..756ae2be20 100644
--- a/frontend/src/container/LogsExplorerChart/index.tsx
+++ b/frontend/src/container/LogsExplorerChart/index.tsx
@@ -1,25 +1,29 @@
-import { memo, useCallback, useMemo } from 'react';
+import { memo, useCallback, useMemo, useRef } from 'react';
// eslint-disable-next-line no-restricted-imports
import { useDispatch, useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom';
-import Graph from 'components/Graph';
import Spinner from 'components/Spinner';
import { QueryParams } from 'constants/query';
-import { themeColors } from 'constants/theme';
+import BarChart from 'container/DashboardContainer/visualization/charts/BarChart/BarChart';
+import { useResizeObserver } from 'hooks/useDimensions';
import { useSafeNavigate } from 'hooks/useSafeNavigate';
import useUrlQuery from 'hooks/useUrlQuery';
-import getChartData, { GetChartDataProps } from 'lib/getChartData';
import GetMinMax from 'lib/getMinMax';
-import { colors } from 'lib/getRandomColor';
+import { LegendPosition } from 'lib/uPlotV2/components/types';
+import { StackMode } from 'lib/uPlotV2/config/types';
+import { useTimezone } from 'providers/Timezone';
import { UpdateTimeInterval } from 'store/actions';
import { AppState } from 'store/reducers';
import { GlobalReducer } from 'types/reducer/globalTime';
import { LogsExplorerChartProps } from './LogsExplorerChart.interfaces';
-import { getColorsForSeverityLabels } from './utils';
+import { useLogsExplorerChartConfig } from './useLogsExplorerChartConfig';
import './LogsExplorerChart.styles.scss';
+// Axis and tooltip format separately; both need this or only one abbreviates.
+const Y_AXIS_UNIT = 'short';
+
function LogsExplorerChart({
data,
isLoading,
@@ -37,24 +41,6 @@ function LogsExplorerChart({
const { minTime, maxTime } = useSelector<AppState, GlobalReducer>(
(state) => state.globalTime,
);
- const handleCreateDatasets: Required<GetChartDataProps>['createDataset'] =
- useCallback(
- (element, index, allLabels) => ({
- data: element,
- backgroundColor: isLogsExplorerViews
- ? getColorsForSeverityLabels(allLabels[index], index)
- : colors[index % colors.length] || themeColors.red,
- borderColor: isLogsExplorerViews
- ? getColorsForSeverityLabels(allLabels[index], index)
- : colors[index % colors.length] || themeColors.red,
- ...(isLabelEnabled
- ? {
- label: allLabels[index],
- }
- : {}),
- }),
- [isLabelEnabled, isLogsExplorerViews],
- );
const onDragSelect = useCallback(
(start: number, end: number): void => {
@@ -86,44 +72,47 @@ function LogsExplorerChart({
[dispatch, location.pathname, safeNavigate, urlQuery, isShowingLiveLogs],
);
- const graphData = useMemo(
- () =>
- getChartData({
- queryData: [
- {
- queryData: data,
- },
- ],
- createDataset: handleCreateDatasets,
- }),
- [data, handleCreateDatasets],
- );
-
- // Convert nanosecond timestamps to milliseconds for Chart.js
- const { chartMinTime, chartMaxTime } = useMemo(
+ // uPlot plots the series on a seconds-based x scale
+ const { minTimeScale, maxTimeScale } = useMemo(
() => ({
- chartMinTime: minTime ? Math.floor(minTime / 1e6) : undefined,
- chartMaxTime: maxTime ? Math.floor(maxTime / 1e6) : undefined,
+ minTimeScale: minTime ? Math.floor(minTime / 1e9) : undefined,
+ maxTimeScale: maxTime ? Math.floor(maxTime / 1e9) : undefined,
}),
[minTime, maxTime],
);
+ const { timezone } = useTimezone();
+ const graphRef = useRef<HTMLDivElement>(null);
+ const dimensions = useResizeObserver(graphRef);
+
+ const { config, chartData } = useLogsExplorerChartConfig({
+ data,
+ isLogsExplorerViews,
+ isLabelEnabled,
+ onDragSelect,
+ minTimeScale,
+ maxTimeScale,
+ yAxisUnit: Y_AXIS_UNIT,
+ });
+
return (
- <div className={`${className} logs-frequency-chart-container`}>
+ <div ref={graphRef} className={`${className} logs-frequency-chart-container`}>
{isLoading ? (
<div className="logs-frequency-chart-loading">
<Spinner size="default" height="100%" />
</div>
) : (
- <Graph
- name="logsExplorerChart"
- data={graphData.data}
- isStacked={isLogsExplorerViews}
- type="bar"
- animate
- onDragSelect={onDragSelect}
- minTime={chartMinTime}
- maxTime={chartMaxTime}
+ <BarChart
+ config={config}
+ data={chartData}
+ width={dimensions.width}
+ height={dimensions.height}
+ stack={isLogsExplorerViews ? StackMode.Normal : StackMode.None}
+ showLegend={isLabelEnabled}
+ legendConfig={{ position: LegendPosition.BOTTOM }}
+ timezone={timezone}
+ data-testid="logs-frequency-chart"
+ yAxisUnit={Y_AXIS_UNIT}
/>
)}
</div>
diff --git a/frontend/src/container/LogsExplorerChart/useLogsExplorerChartConfig.ts b/frontend/src/container/LogsExplorerChart/useLogsExplorerChartConfig.ts
new file mode 100644
index 0000000000..3ecb6b3a4d
--- /dev/null
+++ b/frontend/src/container/LogsExplorerChart/useLogsExplorerChartConfig.ts
@@ -0,0 +1,105 @@
+import { useMemo } from 'react';
+import { PANEL_TYPES } from 'constants/queryBuilder';
+import { themeColors } from 'constants/theme';
+import { buildBaseConfig } from 'container/DashboardContainer/visualization/panels/utils/baseConfigBuilder';
+import { useIsDarkMode } from 'hooks/useDarkMode';
+import getLabelName from 'lib/getLabelName';
+import { colors } from 'lib/getRandomColor';
+import { getUPlotChartData } from 'lib/uPlotLib/utils/getUplotChartData';
+import { DrawStyle } from 'lib/uPlotV2/config/types';
+import { UPlotConfigBuilder } from 'lib/uPlotV2/config/UPlotConfigBuilder';
+import { useTimezone } from 'providers/Timezone';
+import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
+import { QueryData } from 'types/api/widgets/getQuery';
+import uPlot from 'uplot';
+
+import { getColorsForSeverityLabels } from './utils';
+
+export interface UseLogsExplorerChartConfigParams {
+ data: QueryData[];
+ isLogsExplorerViews?: boolean;
+ isLabelEnabled?: boolean;
+ onDragSelect: (start: number, end: number) => void;
+ minTimeScale?: number;
+ maxTimeScale?: number;
+ yAxisUnit?: string;
+}
+
+export interface UseLogsExplorerChartConfigResult {
+ config: UPlotConfigBuilder;
+ chartData: uPlot.AlignedData;
+}
+
+export function useLogsExplorerChartConfig({
+ data,
+ isLogsExplorerViews = false,
+ isLabelEnabled = true,
+ onDragSelect,
+ minTimeScale,
+ maxTimeScale,
+ yAxisUnit,
+}: UseLogsExplorerChartConfigParams): UseLogsExplorerChartConfigResult {
+ const isDarkMode = useIsDarkMode();
+ const { timezone } = useTimezone();
+
+ // getUPlotChartData / buildBaseConfig both consume the legacy query-range payload
+ // shape, so the raw series list is wrapped instead of being plotted directly.
+ const apiResponse = useMemo(
+ () =>
+ ({
+ data: { result: data, resultType: '' },
+ }) as unknown as MetricRangePayloadProps,
+ [data],
+ );
+
+ const chartData = useMemo(() => getUPlotChartData(apiResponse), [apiResponse]);
+
+ const config = useMemo(() => {
+ const builder = buildBaseConfig({
+ id: 'logs-explorer-frequency-chart',
+ isDarkMode,
+ onDragSelect,
+ timezone,
+ minTimeScale,
+ maxTimeScale,
+ yAxisUnit,
+ panelType: PANEL_TYPES.BAR,
+ });
+
+ data.forEach((series, index) => {
+ const label = getLabelName(
+ series.metric,
+ series.queryName || '',
+ series.legend || '',
+ );
+
+ const color = isLogsExplorerViews
+ ? getColorsForSeverityLabels(label, index)
+ : colors[index % colors.length] || themeColors.red;
+
+ builder.addSeries({
+ scaleKey: 'y',
+ drawStyle: DrawStyle.Bar,
+ // No group-by yields query name "A"; use ' ' not '' so uPlot does not default the label to "Value".
+ label: isLabelEnabled && label.trim() ? label : ' ',
+ lineColor: color,
+ colorMapping: {},
+ isDarkMode,
+ });
+ });
+
+ return builder;
+ }, [
+ data,
+ isDarkMode,
+ isLabelEnabled,
+ isLogsExplorerViews,
+ maxTimeScale,
+ minTimeScale,
+ onDragSelect,
+ timezone,
+ yAxisUnit,
+ ]);
+
+ return { config, chartData };
+}
diff --git a/frontend/src/container/LogsExplorerViews/LogsExplorerViews.styles.scss b/frontend/src/container/LogsExplorerViews/LogsExplorerViews.styles.scss
index 68af75fc9e..b0a3347b6c 100644
--- a/frontend/src/container/LogsExplorerViews/LogsExplorerViews.styles.scss
+++ b/frontend/src/container/LogsExplorerViews/LogsExplorerViews.styles.scss
@@ -217,13 +217,6 @@
padding: 0px 8px;
.logs-frequency-chart {
- .ant-card-body {
- height: 140px;
- min-height: 140px;
- padding: 0 16px 22px 16px;
- font-family: 'Geist Mono';
- }
-
margin-bottom: 0px;
}
}