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.

fix(dashboard): V2 pie legend format/height + table empty-cell parity with V1 (#12282)

Abhi kumar27f47f3ebca4
diff --git a/frontend/src/container/DashboardContainer/visualization/charts/Pie/Pie.module.scss b/frontend/src/container/DashboardContainer/visualization/charts/Pie/Pie.module.scss
index 48f8493cbe..78bddfbe6f 100644
--- a/frontend/src/container/DashboardContainer/visualization/charts/Pie/Pie.module.scss
+++ b/frontend/src/container/DashboardContainer/visualization/charts/Pie/Pie.module.scss
@@ -56,14 +56,19 @@
margin-top: 4px;
}
-// Wraps the shared chart Legend. Its width/height are set inline from the
-// computed chart dimensions, so the VirtuosoGrid inside gets the same bounded
-// box (right column / bottom rows) the uPlot charts use.
+// width/height are set inline from the computed chart dimensions; border-box
+// keeps the padding inside that height and overflow:hidden clips the
+// virtualized grid to the rectangle.
.pieChartLegend {
flex: 0 0 auto;
+ box-sizing: border-box;
min-height: 0;
min-width: 0;
+ overflow: hidden;
padding-left: 12px;
padding-bottom: 12px;
+}
+
+.pieChartLegendRight {
padding-top: 8px;
}
diff --git a/frontend/src/container/DashboardContainer/visualization/charts/Pie/Pie.tsx b/frontend/src/container/DashboardContainer/visualization/charts/Pie/Pie.tsx
index 44f58aad5e..4d35ed3d4c 100644
--- a/frontend/src/container/DashboardContainer/visualization/charts/Pie/Pie.tsx
+++ b/frontend/src/container/DashboardContainer/visualization/charts/Pie/Pie.tsx
@@ -3,6 +3,7 @@ import { Color } from '@signozhq/design-tokens';
import { Group } from '@visx/group';
import { Pie as VisxPie } from '@visx/shape';
import { defaultStyles, useTooltip, useTooltipInPortal } from '@visx/tooltip';
+import cx from 'classnames';
import { getYAxisFormattedValue } from 'components/Graph/yAxisConfig';
import { useResizeObserver } from 'hooks/useDimensions';
import Legend from 'lib/uPlotV2/components/Legend/Legend';
@@ -210,7 +211,9 @@ export default function Pie({
)}
</div>
<div
- className={styles.pieChartLegend}
+ className={cx(styles.pieChartLegend, {
+ [styles.pieChartLegendRight]: isRightLegend,
+ })}
style={{
width: legendWidth,
height: legendHeight,
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/PieChartPanel/__tests__/prepareData.test.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/PieChartPanel/__tests__/prepareData.test.ts
index 7a4005b1ab..33b89cdd90 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/PieChartPanel/__tests__/prepareData.test.ts
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/PieChartPanel/__tests__/prepareData.test.ts
@@ -33,7 +33,7 @@ describe('preparePieData', () => {
]);
});
- it('keeps one slice per group row for a single value column', () => {
+ it('serialises a single group-by column as {key="value"} (V1 parity)', () => {
const table = tableWith(
[
{
@@ -53,8 +53,33 @@ describe('preparePieData', () => {
const slices = preparePieData(args([table]));
expect(slices.map((s) => [s.label, s.value])).toStrictEqual([
- ['adservice', 100],
- ['cartservice', 200],
+ ['{service.name="adservice"}', 100],
+ ['{service.name="cartservice"}', 200],
+ ]);
+ });
+
+ it('serialises a grouped metrics query as {direction="write"} (V1 parity)', () => {
+ const table = tableWith(
+ [
+ {
+ name: 'direction',
+ queryName: 'A',
+ isValueColumn: false,
+ id: 'direction',
+ },
+ { name: 'A', queryName: 'A', isValueColumn: true, id: 'A' },
+ ],
+ [
+ { data: { direction: 'write', A: 3170000000 } },
+ { data: { direction: 'read', A: 10000000 } },
+ ],
+ );
+
+ const slices = preparePieData(args([table]));
+
+ expect(slices.map((s) => s.label)).toStrictEqual([
+ '{direction="write"}',
+ '{direction="read"}',
]);
});
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/PieChartPanel/prepareData.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/PieChartPanel/prepareData.ts
index bfb22f5e85..a8cab19ec9 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/PieChartPanel/prepareData.ts
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/PieChartPanel/prepareData.ts
@@ -1,5 +1,6 @@
import { themeColors } from 'constants/theme';
import type { PieSlice } from 'container/DashboardContainer/visualization/charts/types';
+import getLabelName from 'lib/getLabelName';
import { generateColor } from 'lib/uPlotLib/utils/generateColor';
import type { PanelTable } from 'pages/DashboardPageV2/DashboardContainer/queryV5/types';
@@ -51,7 +52,8 @@ export function preparePieData({
if (hasMultipleValueColumns) {
label = groupLabel ? `${groupLabel} · ${column.name}` : column.name;
} else {
- label = groupLabel || table.legend || table.queryName || '';
+ // V1 parity: serialise group-by labels as `{key="value"}`.
+ label = getLabelName(labels, table.queryName || '', table.legend || '');
}
const color = customColors?.[label] ?? generateColor(label, colorMap);
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/TablePanel/__tests__/tableColumns.test.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/TablePanel/__tests__/tableColumns.test.ts
new file mode 100644
index 0000000000..42c9087bdf
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/TablePanel/__tests__/tableColumns.test.ts
@@ -0,0 +1,60 @@
+import type { PanelTableColumn } from 'pages/DashboardPageV2/DashboardContainer/queryV5/types';
+
+import { formatTableCellText } from '../tableColumns';
+
+jest.mock('../../../utils/formatPanelValue', () => ({
+ formatPanelValue: (value: number, unit?: string): string =>
+ `${value}${unit ?? ''}`,
+}));
+
+const valueColumn: PanelTableColumn = {
+ name: 'p99',
+ queryName: 'A',
+ isValueColumn: true,
+ id: 'A',
+};
+
+const groupColumn: PanelTableColumn = {
+ name: 'service',
+ queryName: 'A',
+ isValueColumn: false,
+ id: 'service',
+};
+
+describe('formatTableCellText', () => {
+ it.each([null, undefined, ''])(
+ 'renders empty value-column cells (%p) as n/a instead of 0',
+ (raw) => {
+ expect(formatTableCellText(valueColumn, raw, 'ms', undefined)).toBe('n/a');
+ },
+ );
+
+ it('keeps a real zero as a formatted 0, not n/a', () => {
+ expect(formatTableCellText(valueColumn, 0, 'ms', undefined)).toBe('0ms');
+ });
+
+ it('formats a numeric value column through unit + precision', () => {
+ expect(formatTableCellText(valueColumn, 1234, 'ms', undefined)).toBe(
+ '1234ms',
+ );
+ });
+
+ it('renders a non-numeric value cell as raw text', () => {
+ expect(formatTableCellText(valueColumn, 'n/a', 'ms', undefined)).toBe('n/a');
+ });
+
+ it.each([null, undefined, ''])(
+ 'renders empty group-column cells (%p) as n/a',
+ (raw) => {
+ expect(formatTableCellText(groupColumn, raw, undefined, undefined)).toBe(
+ 'n/a',
+ );
+ },
+ );
+
+ it('renders group-column labels as raw text', () => {
+ expect(
+ formatTableCellText(groupColumn, 'frontend', undefined, undefined),
+ ).toBe('frontend');
+ });
+});
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/TablePanel/__tests__/tableCsv.test.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/TablePanel/__tests__/tableCsv.test.ts
index 3c42a245cf..dde1937a0f 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/TablePanel/__tests__/tableCsv.test.ts
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/TablePanel/__tests__/tableCsv.test.ts
@@ -64,6 +64,19 @@ describe('buildTableCsvRows', () => {
expect(rows).toStrictEqual([{ service: 'api', p99: 'n/a' }]);
});
+
+ it('exports empty value cells as n/a rather than 0', () => {
+ const rows = buildTableCsvRows({
+ table: {
+ ...table,
+ rows: [{ data: { service: 'api', A: null } }],
+ },
+ columnUnits: { A: 'ms' },
+ decimalPrecision: undefined,
+ });
+
+ expect(rows).toStrictEqual([{ service: 'api', p99: 'n/a' }]);
+ });
});
describe('getTableCsvRows', () => {
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/TablePanel/tableColumns.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/TablePanel/tableColumns.tsx
index 8a0d182041..2ae9f34c7a 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/TablePanel/tableColumns.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/Panels/kinds/TablePanel/tableColumns.tsx
@@ -18,6 +18,17 @@ import styles from './TablePanel.module.scss';
/** A prepared scalar-table row flattened for the antd Table, with the antd key. */
export type TableRowData = Record<string, unknown> & { key: number };
+const NA_TEXT = 'n/a';
+
+// Empty cells (null/undefined/'') aren't numbers: `Number(null)` is 0, which
+// would render/colour/sort an empty cell as a real zero.
+function toCellNumber(raw: unknown): number {
+ if (raw == null || raw === '') {
+ return NaN;
+ }
+ return Number(raw);
+}
+
/**
* Groups table thresholds by the column they target, mapping each onto the
* V2-native `PanelThreshold` consumed by `resolveActiveThreshold`. A column with
@@ -43,6 +54,9 @@ export function formatTableCellText(
unit: string | undefined,
decimalPrecision?: PrecisionOption,
): string {
+ if (raw == null || raw === '') {
+ return NA_TEXT;
+ }
if (!col.isValueColumn) {
return coerceToString(raw);
}
@@ -56,15 +70,17 @@ export function formatTableCellText(
// Sort comparator: numeric when both cells parse as numbers (value columns and
// numeric group keys), otherwise a locale string compare. Nullish sorts last.
function compareCells(a: unknown, b: unknown): number {
- const aNum = Number(a);
- const bNum = Number(b);
+ const aNum = toCellNumber(a);
+ const bNum = toCellNumber(b);
if (Number.isFinite(aNum) && Number.isFinite(bNum)) {
return aNum - bNum;
}
- if (a == null) {
- return b == null ? 0 : 1;
+ const aEmpty = a == null || a === '';
+ const bEmpty = b == null || b === '';
+ if (aEmpty) {
+ return bEmpty ? 0 : 1;
}
- if (b == null) {
+ if (bEmpty) {
return -1;
}
return coerceToString(a).localeCompare(coerceToString(b));
@@ -113,7 +129,7 @@ export function buildTableColumns({
compareCells(a[key], b[key]),
render: (raw: unknown): React.ReactNode => {
const text = formatTableCellText(col, raw, unit, decimalPrecision);
- const num = Number(raw);
+ const num = toCellNumber(raw);
if (
!col.isValueColumn ||
colThresholds.length === 0 ||
@@ -131,7 +147,7 @@ export function buildTableColumns({
const cellProps: React.HTMLAttributes<HTMLElement> = {};
if (col.isValueColumn && colThresholds.length > 0) {
- const num = Number(record[key]);
+ const num = toCellNumber(record[key]);
if (Number.isFinite(num)) {
const { threshold } = resolveActiveThreshold(colThresholds, num, unit);
if (threshold?.format === 'background') {