Skip to content

Commit a2bbba7

Browse files
fix(dashboards): show inclusive range end in exact caption and cover id/x-axis threshold lookups
1 parent 8c6498e commit a2bbba7

3 files changed

Lines changed: 43 additions & 15 deletions

File tree

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,31 @@ describe('chart annotations', () => {
141141
).toThrow('Thresholds require a value axis')
142142
})
143143

144+
it('resolves a value axis selected by id, including a value x-axis on horizontal bars', () => {
145+
const byId = applyChartAnnotations(
146+
{
147+
xAxis: { type: 'time' },
148+
yAxis: [{ type: 'category' }, { id: 'latency', type: 'value' }],
149+
series: [{ type: 'line', yAxisId: 'latency' }],
150+
},
151+
{ thresholds: [{ value: 5 }] },
152+
palette
153+
)
154+
expect((byId.series as Series[])[0].markLine).toMatchObject({ data: [{ yAxis: 5 }] })
155+
const horizontal = applyChartAnnotations(
156+
{
157+
xAxis: [{ type: 'category' }, { id: 'count', type: 'value' }],
158+
yAxis: [{ type: 'value' }, { id: 'stage', type: 'category', inverse: true }],
159+
series: [{ type: 'bar', xAxisId: 'count', yAxisIndex: 1 }],
160+
},
161+
{ thresholds: [{ value: 5, label: 'Limit' }] },
162+
palette
163+
)
164+
const [first, labels] = horizontal.series as Series[]
165+
expect(first.markLine).toMatchObject({ data: [{ xAxis: 5 }] })
166+
expect(labels.markLine).toMatchObject({ data: [{ xAxis: 5, label: { position: 'start' } }] })
167+
})
168+
144169
it('rejects a first series that references an axis the chart does not define', () => {
145170
for (const reference of [{ yAxisIndex: 1 }, { yAxisIndex: -1 }, { yAxisIndex: 0.5 }])
146171
expect(() =>

‎apps/sim/lib/dashboards/time.test.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ describe('dashboard time interactions', () => {
5454
{ from: '2026-11-01T05:30:00.000Z', to: '2026-11-01T06:31:00.000Z' },
5555
'America/New_York'
5656
)
57-
expect(text).toContain('01:30:00 EDT')
58-
expect(text).toContain('01:31:00 EST')
57+
expect(text).toBe('Nov 1, 01:30:00 EDT – Nov 1, 01:30:59 EST')
5958
})
6059

6160
it('shows distinct endpoints for a sub-minute zoom range', () => {
@@ -64,6 +63,6 @@ describe('dashboard time interactions', () => {
6463
{ from: '2026-09-20T14:30:00.000Z', to: '2026-09-20T14:30:01.000Z' },
6564
'UTC'
6665
)
67-
).toBe('Sep 20, 14:30:00 UTC – Sep 20, 14:30:01 UTC')
66+
).toBe('Sep 20, 14:30:00.000 UTC – Sep 20, 14:30:00.999 UTC')
6867
})
6968
})

‎apps/sim/lib/dashboards/time.ts‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,22 @@ export function dashboardRangeText(range: DashboardTimeRange, timeZone: string):
9191
const toLocal = zonedWallClock(to, timeZone)
9292
if (fromLocal === toLocal) {
9393
// Same wall-clock minute (e.g. a DST fall-back repeat): formatRange would collapse both ends,
94-
// so show the exact exclusive end to the second.
95-
const exact = new Intl.DateTimeFormat('en-US', {
96-
timeZone,
97-
month: 'short',
98-
day: 'numeric',
99-
hour: '2-digit',
100-
minute: '2-digit',
101-
second: '2-digit',
102-
hourCycle: 'h23',
103-
timeZoneName: 'short',
104-
})
105-
return `${exact.format(from)} – ${exact.format(new Date(range.to))}`
94+
// so show each inclusive end exactly, down to milliseconds if seconds still collide.
95+
const exact = (fractionalSecondDigits?: 3) =>
96+
new Intl.DateTimeFormat('en-US', {
97+
timeZone,
98+
month: 'short',
99+
day: 'numeric',
100+
hour: '2-digit',
101+
minute: '2-digit',
102+
second: '2-digit',
103+
fractionalSecondDigits,
104+
hourCycle: 'h23',
105+
timeZoneName: 'short',
106+
})
107+
const seconds = exact()
108+
const format = seconds.format(from) === seconds.format(to) ? exact(3) : seconds
109+
return `${format.format(from)} – ${format.format(to)}`
106110
}
107111
const sameDay = fromLocal.slice(0, 10) === toLocal.slice(0, 10)
108112
return new Intl.DateTimeFormat('en-US', {

0 commit comments

Comments
 (0)