Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/line-interpolation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperdx/common-utils': patch
'@hyperdx/api': patch
'@hyperdx/app': patch
---

feat: Add a line interpolation display setting (smooth, linear, step)
40 changes: 40 additions & 0 deletions packages/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,16 @@
"description": "Set the y-axis lower bound to the minimum of the displayed data instead of zero, making small fluctuations between series easier to see.\n",
"default": false
},
"lineInterpolation": {
"type": "string",
"enum": [
"smooth",
"linear",
"step"
],
"example": "step",
"description": "How points are connected. Defaults to \"smooth\" when omitted.\n"
},
"numberFormat": {
"$ref": "#/components/schemas/NumberFormat",
"description": "Number formatting options for displayed values."
Expand Down Expand Up @@ -2006,6 +2016,16 @@
"description": "Fill missing time buckets with zero instead of leaving gaps.",
"default": true
},
"lineInterpolation": {
"type": "string",
"enum": [
"smooth",
"linear",
"step"
],
"example": "step",
"description": "How points are connected. Defaults to \"linear\" when omitted.\n"
},
"numberFormat": {
"$ref": "#/components/schemas/NumberFormat",
"description": "Number formatting options for displayed values."
Expand Down Expand Up @@ -2620,6 +2640,16 @@
"type": "boolean",
"description": "Set the y-axis lower bound to the minimum of the displayed data instead of zero, making small fluctuations between series easier to see.\n",
"default": false
},
"lineInterpolation": {
"type": "string",
"enum": [
"smooth",
"linear",
"step"
],
"example": "step",
"description": "How points are connected. Defaults to \"smooth\" when omitted.\n"
}
}
}
Expand Down Expand Up @@ -2688,6 +2718,16 @@
"type": "boolean",
"description": "Expand date range boundaries to the query granularity interval.",
"default": true
},
"lineInterpolation": {
"type": "string",
"enum": [
"smooth",
"linear",
"step"
],
"example": "step",
"description": "How points are connected. Defaults to \"linear\" when omitted.\n"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ describe('MCP Dashboard Tools - clickstack_save_dashboard', () => {
},
compareToPreviousPeriod: true,
fitYAxisToData: true,
lineInterpolation: 'step' as const,
};
const sqlNumberConfig = {
configType: 'sql' as const,
Expand Down Expand Up @@ -996,6 +997,7 @@ describe('MCP Dashboard Tools - clickstack_save_dashboard', () => {
numberFormat,
compareToPreviousPeriod: true,
fitYAxisToData: true,
lineInterpolation: 'linear' as const,
seriesLimit: 5,
};
const barConfig = {
Expand All @@ -1009,6 +1011,7 @@ describe('MCP Dashboard Tools - clickstack_save_dashboard', () => {
const stackedLineConfig = {
...barConfig,
displayType: 'stacked_line' as const,
lineInterpolation: 'step' as const,
};
const tableConfig = {
displayType: 'table' as const,
Expand Down
12 changes: 12 additions & 0 deletions packages/api/src/mcp/tools/dashboards/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
DASHBOARD_VARIABLE_NAME_PATTERN_ANCHORED,
DashboardContainerSchema,
DashboardFilterType,
LineInterpolationSchema,
MetricsDataType,
NumberTileColorConditionSchema,
SearchConditionTrimmedLanguageSchema,
Expand Down Expand Up @@ -749,6 +750,9 @@ export const mcpLineTileSchema = mcpTileLayoutSchema.extend({
seriesLimit: seriesLimitSchema.describe(timeChartSeriesLimitDescription),
formulas: mcpTileFormulasSchema,
showOperandSeries: mcpShowOperandSeriesSchema,
lineInterpolation: LineInterpolationSchema.optional().describe(
'How points are connected: "smooth" (default), "linear", or "step".',
),
})
.describe('Line chart query and display settings.'),
});
Expand Down Expand Up @@ -794,6 +798,9 @@ export const mcpStackedLineTileSchema = mcpTileLayoutSchema.extend({
.literal('stacked_line')
.describe('Stacked line (area) chart over time'),
...mcpStackedTimeChartConfigFields,
lineInterpolation: LineInterpolationSchema.optional().describe(
'How points are connected: "linear" (default), "smooth", or "step".',
),
})
.describe('Stacked line chart query and display settings.'),
});
Expand Down Expand Up @@ -1256,6 +1263,11 @@ GROUP BY ServiceName, ts
.optional()
.describe(rawSqlNumberTileColorRulesDescription),
onClick: mcpOnClickSchema.optional(),
lineInterpolation: LineInterpolationSchema.optional().describe(
'How points are connected: "smooth", "linear", or "step". Defaults to ' +
'"smooth" for "line" and "linear" for "stacked_line". ' +
'Valid only when displayType is "line" or "stacked_line", ignored otherwise.',
),
})
.describe('Raw SQL tile query and display settings.'),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3645,6 +3645,78 @@ describe('External API v2 Dashboards - new format', () => {
expect(tiles[2].config).not.toHaveProperty('fitYAxisToData');
});

it('persists lineInterpolation on line and stacked line tiles only', async () => {
const sourceId = traceSource._id.toString();
const connectionId = connection._id.toString();
const sqlTemplate = 'SELECT count() FROM otel_logs WHERE {timeFilter}';
const select = [
{ aggFn: 'count' as const, where: '', whereLanguage: 'sql' as const },
];
const configs = [
{ displayType: 'line', sourceId, select, lineInterpolation: 'step' },
{
displayType: 'stacked_line',
sourceId,
select,
lineInterpolation: 'smooth',
},
{
configType: 'sql',
displayType: 'line',
connectionId,
sqlTemplate,
lineInterpolation: 'linear',
},
{
configType: 'sql',
displayType: 'stacked_line',
connectionId,
sqlTemplate,
lineInterpolation: 'step',
},
{
displayType: 'stacked_bar',
sourceId,
select,
lineInterpolation: 'step',
},
{ displayType: 'line', sourceId, select },
];

const createResponse = await authRequest('post', BASE_URL)
.send({
name: 'lineInterpolation dashboard',
tiles: configs.map((config, i) => ({
name: `Tile ${i}`,
x: 0,
y: i * 3,
w: 6,
h: 3,
config,
})),
tags: [],
})
.expect(200);

const getResponse = await authRequest(
'get',
`${BASE_URL}/${createResponse.body.data.id}`,
).expect(200);
const tiles: { config: Record<string, unknown> }[] =
getResponse.body.data.tiles;

expect(tiles.map(t => t.config.lineInterpolation)).toEqual([
'step',
'smooth',
'linear',
'step',
undefined,
undefined,
]);
expect(tiles[4].config).not.toHaveProperty('lineInterpolation');
expect(tiles[5].config).not.toHaveProperty('lineInterpolation');
});

it('should return 400 when source IDs do not exist', async () => {
const nonExistentSourceId = new ObjectId().toString();
const mockDashboard = createMockDashboard(nonExistentSourceId);
Expand Down
24 changes: 24 additions & 0 deletions packages/api/src/routers/external-api/v2/dashboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,12 @@ const EXTERNAL_DASHBOARD_PROJECTION = {
* instead of zero, making small fluctuations between series easier
* to see.
* default: false
* lineInterpolation:
* type: string
* enum: [smooth, linear, step]
* example: "step"
* description: >
* How points are connected. Defaults to "smooth" when omitted.
* numberFormat:
* $ref: '#/components/schemas/NumberFormat'
* description: Number formatting options for displayed values.
Expand Down Expand Up @@ -834,6 +840,12 @@ const EXTERNAL_DASHBOARD_PROJECTION = {
* type: boolean
* description: Fill missing time buckets with zero instead of leaving gaps.
* default: true
* lineInterpolation:
* type: string
* enum: [smooth, linear, step]
* example: "step"
* description: >
* How points are connected. Defaults to "linear" when omitted.
* numberFormat:
* $ref: '#/components/schemas/NumberFormat'
* description: Number formatting options for displayed values.
Expand Down Expand Up @@ -1374,6 +1386,12 @@ const EXTERNAL_DASHBOARD_PROJECTION = {
* data instead of zero, making small fluctuations between
* series easier to see.
* default: false
* lineInterpolation:
* type: string
* enum: [smooth, linear, step]
* example: "step"
* description: >
* How points are connected. Defaults to "smooth" when omitted.
*
* BarRawSqlChartConfig:
* description: Raw SQL configuration for a stacked-bar time-series chart.
Expand Down Expand Up @@ -1418,6 +1436,12 @@ const EXTERNAL_DASHBOARD_PROJECTION = {
* type: boolean
* description: Expand date range boundaries to the query granularity interval.
* default: true
* lineInterpolation:
* type: string
* enum: [smooth, linear, step]
* example: "step"
* description: >
* How points are connected. Defaults to "linear" when omitted.
*
* TableRawSqlChartConfig:
* description: Raw SQL configuration for a table chart.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const EVALUATION_INERT_CONFIG_KEYS: ReadonlySet<string> = new Set([
'backgroundChart',
'compareToPreviousPeriod',
'fitYAxisToData',
'lineInterpolation',
'onClick',
'alternateRowBackground',
// Heatmap tiles carry no alerts; alert display types ignore it.
Expand Down
16 changes: 14 additions & 2 deletions packages/api/src/routers/external-api/v2/utils/dashboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const convertToExternalTileChartConfig = (
alignDateRangeToGranularity: config.alignDateRangeToGranularity,
fillNulls: config.fillNulls !== false,
fitYAxisToData: config.fitYAxisToData,
lineInterpolation: config.lineInterpolation,
numberFormat: config.numberFormat,
compareToPreviousPeriod: config.compareToPreviousPeriod,
// Three-state passthrough: 0 (unlimited) and positive N round-trip;
Expand All @@ -262,7 +263,11 @@ export const convertToExternalTileChartConfig = (
};
// A union-typed displayType doesn't narrow to one union member.
return config.displayType === DisplayType.StackedLine
? { displayType: DisplayType.StackedLine, ...stacked }
? {
displayType: DisplayType.StackedLine,
lineInterpolation: config.lineInterpolation,
...stacked,
}
: { displayType: DisplayType.StackedBar, ...stacked };
}
case DisplayType.Table:
Expand Down Expand Up @@ -357,6 +362,7 @@ export const convertToExternalTileChartConfig = (
alignDateRangeToGranularity: config.alignDateRangeToGranularity,
fillNulls: config.fillNulls !== false,
fitYAxisToData: config.fitYAxisToData,
lineInterpolation: config.lineInterpolation,
groupBy: stringValueOrDefault(config.groupBy, undefined),
select: Array.isArray(config.select)
? config.select.map(convertToExternalSelectItem)
Expand Down Expand Up @@ -391,7 +397,11 @@ export const convertToExternalTileChartConfig = (
...externalShowOperandSeriesField,
};
return config.displayType === DisplayType.StackedLine
? { displayType: DisplayType.StackedLine, ...stacked }
? {
displayType: DisplayType.StackedLine,
lineInterpolation: config.lineInterpolation,
...stacked,
}
: { displayType: DisplayType.StackedBar, ...stacked };
}
case DisplayType.Number:
Expand Down Expand Up @@ -751,6 +761,7 @@ export function convertToInternalTileConfig(
'alignDateRangeToGranularity',
'compareToPreviousPeriod',
'fitYAxisToData',
'lineInterpolation',
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
// Round-trip the render cap so a GET→PUT does not silently wipe it.
'seriesLimit',
]),
Expand Down Expand Up @@ -818,6 +829,7 @@ export function convertToInternalTileConfig(
'alignDateRangeToGranularity',
'compareToPreviousPeriod',
'fitYAxisToData',
'lineInterpolation',
// Formulas round-trip as-is; the input schema has already
// validated the expressions against `select`.
'formulas',
Expand Down
5 changes: 5 additions & 0 deletions packages/api/src/utils/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ChartPaletteTokenSchema,
DASHBOARD_CONTAINER_ID_MAX,
DASHBOARD_MAX_TILES,
LineInterpolationSchema,
MetricFormulaSchema,
MetricsDataType,
NumberFormatSchema,
Expand Down Expand Up @@ -354,6 +355,7 @@ const externalDashboardLineChartConfigSchema =
displayType: z.literal('line'),
compareToPreviousPeriod: z.boolean().optional(),
fitYAxisToData: z.boolean().optional(),
lineInterpolation: LineInterpolationSchema.optional(),
// Three-state, matching the internal SharedChartSettingsSchema.seriesLimit:
// omitted = default render cap, 0 = unlimited, positive N = top-N by peak.
seriesLimit: z.number().int().nonnegative().optional(),
Expand All @@ -366,6 +368,7 @@ const externalDashboardLineRawSqlChartConfigSchema =
fillNulls: z.boolean().optional(),
alignDateRangeToGranularity: z.boolean().optional(),
fitYAxisToData: z.boolean().optional(),
lineInterpolation: LineInterpolationSchema.optional(),
// Three-state, matching the internal SharedChartSettingsSchema.seriesLimit:
// omitted = default render cap, 0 = unlimited, positive N = top-N by peak.
// Raw SQL Line tiles carry the client-side render cap too, so it must
Expand Down Expand Up @@ -396,11 +399,13 @@ const externalDashboardBarRawSqlChartConfigSchema =
const externalDashboardStackedLineChartConfigSchema =
externalDashboardBarChartConfigSchema.extend({
displayType: z.literal('stacked_line'),
lineInterpolation: LineInterpolationSchema.optional(),
});

const externalDashboardStackedLineRawSqlChartConfigSchema =
externalDashboardBarRawSqlChartConfigSchema.extend({
displayType: z.literal('stacked_line'),
lineInterpolation: LineInterpolationSchema.optional(),
});

const externalDashboardTableChartConfigSchema = z.object({
Expand Down
Loading
Loading