Skip to content

fix: show zero baseline on deployment metrics charts when no data in range#98

Merged
acoshift merged 9 commits into
mainfrom
claude/infallible-pike-aa74a8
May 19, 2026
Merged

fix: show zero baseline on deployment metrics charts when no data in range#98
acoshift merged 9 commits into
mainfrom
claude/infallible-pike-aa74a8

Conversation

@acoshift
Copy link
Copy Markdown
Member

Summary

  • When no data exists for the selected time range, Highcharts was hiding both axes entirely, leaving a blank chart with no context
  • Now charts always show a y-axis starting at 0 and an x-axis spanning the full selected time window, so users see a flat 0 baseline instead of a disappearing chart

Changes

src/lib/components/Chart.svelte

  • yAxis.min: 0 + yAxis.showEmpty: true — y-axis always renders from 0, even with no series data
  • xAxis.showEmpty: true — x-axis renders even when empty
  • New range prop + rangeToMs() helper — parses range strings like 1h, 30dagg into milliseconds and calls xAxis.setExtremes() so the axis spans the selected window regardless of data presence

src/routes/(auth)/(project)/deployment/(detail)/metrics/+page.svelte

  • Passes range={filter.range} to all four Chart instances (CPU, Memory, Request, Egress)

Test plan

  • Select a time range with no data (e.g. a newly created deployment on a long range like 30 days) — charts should show axes with 0 baseline instead of going blank
  • Select a time range with data — charts should render normally as before
  • Switch between ranges — x-axis should update to match the selected window

🤖 Generated with Claude Code

When no data exists for the selected time window, Highcharts was hiding
both axes entirely. Now the y-axis always starts at 0 (min: 0,
showEmpty: true) and the x-axis is pinned to the selected range window
so the chart stays visible with a flat 0 baseline.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 19, 2026

Deploying deploys-app--console with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2638e3e
Status: ✅  Deploy successful!
Preview URL: https://596bc510.deploys-app--console.pages.dev
Branch Preview URL: https://claude-infallible-pike-aa74a.deploys-app--console.pages.dev

View logs

acoshift and others added 8 commits May 19, 2026 10:55
In Svelte 5, $effect only re-runs when its reactive dependencies change.
The previous code had `if (!chart) return` before reading `series` or
`range`, so on first run (before onMount sets `chart`) Svelte tracked no
dependencies — the effect was permanently dead and never fired when data
arrived.

Reading `series` and `range` first ensures they're tracked even if the
effect returns early, so the effect correctly re-runs once onMount has
created the chart instance and API data is available.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
$effect runs before onMount in Svelte 5, so `chart` was undefined on the
first execution and the early return meant Svelte never tracked series/range
as dependencies — the effect would never fire again, leaving the axes
invisible even after data arrived.

Using $state.raw() makes the chart variable a reactive signal without
deep-proxying the Highcharts instance. When onMount assigns the chart,
the effect re-runs automatically, sets xAxis extremes for the selected
range, and renders the y-axis from 0 — so empty charts still show axes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
TypeScript can't narrow a $state.raw variable across a forEach callback
boundary, so chart.series and chart.addSeries were flagged as possibly
undefined even after the early-return guard. Capturing chart in a local
const before the loop resolves the narrowing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
setExtremes() sets a user zoom and can be silently ignored or reset when
the chart has zero series. xAxis.update({ min, max }) writes directly to
the axis configuration options so Highcharts always honours the selected
time window, even when no series are present.

Also moved the axis range call to after all series add/remove operations
so that clear() + series.remove() cannot race against the extremes write.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When all series lines are empty Highcharts renders no series at all, so
even showEmpty:true axes collapse. Fix: after all series operations, if
the chart still has zero series, inject an invisible two-point placeholder
series at the time-range boundaries with value 0. This anchors the axes
to the correct window and shows a 0 baseline. The placeholder is removed
as soon as a real series is present.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@acoshift acoshift merged commit 1bb3efa into main May 19, 2026
5 checks passed
@acoshift acoshift deleted the claude/infallible-pike-aa74a8 branch May 19, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant