Skip to content

Commit af21484

Browse files
fix(charts): keep authored tooltip arrays and drop the v2 chat mode override
Chart tooltip defaults now apply to every entry of an authored `tooltip` array instead of replacing it with one object. Restore the v2 chat payload to staging: the hard-coded `mode: 'agent'` came from the removed dashboard resource work and would overwrite a resumed chat's saved mode. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S6aTRnkiu7PxYZPNPXYEMV
1 parent 3d630db commit af21484

5 files changed

Lines changed: 37 additions & 13 deletions

File tree

‎apps/sim/app/api/v2/chat/route.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,12 @@ describe('POST /api/v2/chat', () => {
414414
// CHAT pipeline now (persona + skills + CLI), not the persona-less execute surface.
415415
expect(payload).toMatchObject({
416416
message: 'hi',
417-
mode: 'agent',
418417
userId: 'user-1',
419418
workspaceId: 'workspace-1',
420419
chatId: SERVER_ISSUED_CHAT_ID,
421420
integrationCatalog: { mcpServerIds: [] },
422421
})
423-
for (const legacy of ['messages', 'isHosted', 'workspaceContext', 'userPermission']) {
422+
for (const legacy of ['messages', 'mode', 'isHosted', 'workspaceContext', 'userPermission']) {
424423
expect(payload).not.toHaveProperty(legacy)
425424
}
426425
expect(options).toMatchObject({

‎apps/sim/app/api/v2/chat/route.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ export const POST = withRouteHandler(
337337
*/
338338
const requestPayload: Record<string, unknown> = {
339339
message,
340-
mode: 'agent',
341340
userId,
342341
protocolVersion: PROTOCOL_VERSION,
343342
workspaceId,

‎apps/sim/lib/charts/option.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
buildChartRenderOption,
77
CHART_BAR_MAX_WIDTH,
88
horizontalBarChartHeight,
9+
isAboveBarLabelLayout,
910
} from '@/lib/charts/option'
1011

1112
describe('chart dataset injection', () => {
@@ -45,6 +46,19 @@ describe('horizontal bar label layout', () => {
4546
expect(authored.yAxis[0]).not.toHaveProperty('axisLabel')
4647
})
4748

49+
it('keeps every authored tooltip entry when turning off the shadow pointer', () => {
50+
const result = buildChartRenderOption({
51+
option: {
52+
tooltip: [{ show: true, confine: true }],
53+
xAxis: { type: 'value' },
54+
yAxis: { type: 'category' },
55+
series: [{ type: 'bar' }],
56+
},
57+
})
58+
expect(result.tooltip).toEqual([{ show: true, confine: true, axisPointer: { type: 'none' } }])
59+
expect(isAboveBarLabelLayout(result)).toBe(true)
60+
})
61+
4862
it('keeps the label column for grouped bars and sizes rows for every bar in the group', () => {
4963
const grouped = {
5064
xAxis: { type: 'value' },

‎apps/sim/lib/charts/option.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ export function isHorizontalBarOption(option: Record<string, unknown>): boolean
3434
)
3535
}
3636

37+
/** Applies `update` to every tooltip entry, keeping ECharts' array form when authored. */
38+
export function mapTooltipEntries(
39+
tooltip: unknown,
40+
update: (entry: Record<string, unknown>) => Record<string, unknown>
41+
): Record<string, unknown> | Record<string, unknown>[] {
42+
return Array.isArray(tooltip)
43+
? tooltip.map((entry) => update(toRecord(entry)))
44+
: update(toRecord(tooltip))
45+
}
46+
3747
const CATEGORY_LABEL_LAYOUT_KEYS = ['inside', 'width', 'margin'] as const
3848

3949
const BAR_GROUP_GAP = 4
@@ -114,8 +124,10 @@ export function buildChartRenderOption({
114124
padding: [0, 0, barWidth / 2 + 8, 0],
115125
...toRecord(axis.axisLabel),
116126
}
117-
const tooltip = toRecord(option.tooltip)
118-
option.tooltip = { ...tooltip, axisPointer: { type: 'none', ...toRecord(tooltip.axisPointer) } }
127+
option.tooltip = mapTooltipEntries(option.tooltip, (tooltip) => ({
128+
...tooltip,
129+
axisPointer: { type: 'none', ...toRecord(tooltip.axisPointer) },
130+
}))
119131
}
120132
if (rows !== null && rows !== undefined) {
121133
// The resolved rows become the FIRST dataset (id "table", datasetIndex 0).
@@ -212,7 +224,8 @@ export function isAboveBarLabelLayout(option: Record<string, unknown>): boolean
212224
if (!isHorizontalBarOption(option)) return false
213225
const axis = toRecord(Array.isArray(option.yAxis) ? option.yAxis[0] : option.yAxis)
214226
const axisLabel = toRecord(axis.axisLabel)
215-
const pointer = toRecord(toRecord(option.tooltip).axisPointer)
227+
const tooltip = Array.isArray(option.tooltip) ? option.tooltip[0] : option.tooltip
228+
const pointer = toRecord(toRecord(tooltip).axisPointer)
216229
return (
217230
axisLabel.inside === true && axisLabel.verticalAlign === 'bottom' && pointer.type === 'none'
218231
)

‎apps/sim/lib/charts/theme.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isRecordLike, toRecord } from '@sim/utils/object'
2-
import { CHART_BAR_MAX_WIDTH } from '@/lib/charts/option'
2+
import { CHART_BAR_MAX_WIDTH, mapTooltipEntries } from '@/lib/charts/option'
33
import { formatChartValue } from '@/lib/charts/summary'
44

55
function encodedTooltipValue(entry: Record<string, unknown>, dimension: 'x' | 'y' | 'value') {
@@ -58,8 +58,7 @@ export function applyChartTooltipDefaults(option: Record<string, unknown>) {
5858
const formatter = toRecord(
5959
toRecord(Array.isArray(valueAxis) ? valueAxis[0] : valueAxis).axisLabel
6060
).formatter
61-
const tooltip = toRecord(option.tooltip)
62-
option.tooltip = {
61+
option.tooltip = mapTooltipEntries(option.tooltip, (tooltip) => ({
6362
trigger: 'axis',
6463
showContent: true,
6564
formatter: (params: unknown) =>
@@ -70,20 +69,20 @@ export function applyChartTooltipDefaults(option: Record<string, unknown>) {
7069
),
7170
...tooltip,
7271
axisPointer: { type: 'shadow', ...toRecord(tooltip.axisPointer) },
73-
}
72+
}))
7473
} else if (series.length && series.every((entry) => toRecord(entry).type === 'pie')) {
7574
const valueFields = series.map((entry) => {
7675
const encoded = toRecord(toRecord(entry).encode).value
7776
return Array.isArray(encoded) ? encoded[0] : encoded
7877
})
7978
/** Native formatting handles automatic encodings; table charts supply named measures. */
8079
if (!valueFields.every((field): field is string => typeof field === 'string')) return option
81-
option.tooltip = {
80+
option.tooltip = mapTooltipEntries(option.tooltip, (tooltip) => ({
8281
trigger: 'item',
8382
formatter: (params: unknown) =>
8483
formatPieTooltip(params, valueFields[Number(toRecord(params).seriesIndex)]),
85-
...toRecord(option.tooltip),
86-
}
84+
...tooltip,
85+
}))
8786
}
8887
return option
8988
}

0 commit comments

Comments
 (0)