fix: incremental chart updates in ApexChart (updateSeries instead of full re-render) (#23) #32

Merged
pitfriedrich merged 1 commits from ai/issue-23-incremental-chart-updates into main 2026-07-28 17:33:21 +00:00
Collaborator

Closes #23

What

ApexChart had exactly one path to the client: renderChart with a full option set, which rebuilds the chart on every data change (animations restart from zero, zoom/selection state lost).

This adds a data-only update path:

  • apex-chart.ts: new updateData(patchJson) client function. It merges series (and categories/labels) into the stored options and applies them via ApexCharts' updateSeries on the existing instance. updateOptions is only called when categories/labels actually changed — a pure data refresh never touches it. The theme overlay is re-applied to the merged options and lastOptionsJson is refreshed, so a rebuild after a detach (gridstack re-append, Flow detach) starts from the patched data.
  • Java API: ApexChart.sendDataPatch(...) / hasSentOptions(), plus public AxisChart.updateData(seriesName, values, categories) and PieChart.updateData(values, labels). Before the first render there is no chart to patch, so both fall back to setData(...).

First render is unchanged — setData(...) still sends the full option set.

Tests

  • components/ApexChartUpdateTest (browserless): asserts the queued client call is updateData with a data-only payload after a render, and renderChart with the full theme options before one.
  • e2e/DashboardChartPlaywrightTest (Chromium): tags the rendered <svg> node, triggers a data update, and asserts the same node is still there (patched in place, not recreated) with the new data — plus that grid.borderColor is still a resolved theme color after the update.

./mvnw test — 16/16 green, e2e included.

Closes #23 ## What `ApexChart` had exactly one path to the client: `renderChart` with a full option set, which rebuilds the chart on every data change (animations restart from zero, zoom/selection state lost). This adds a data-only update path: - **`apex-chart.ts`**: new `updateData(patchJson)` client function. It merges `series` (and `categories`/`labels`) into the stored options and applies them via ApexCharts' `updateSeries` on the existing instance. `updateOptions` is only called when categories/labels actually changed — a pure data refresh never touches it. The theme overlay is re-applied to the merged options and `lastOptionsJson` is refreshed, so a rebuild after a detach (gridstack re-append, Flow detach) starts from the patched data. - **Java API**: `ApexChart.sendDataPatch(...)` / `hasSentOptions()`, plus public `AxisChart.updateData(seriesName, values, categories)` and `PieChart.updateData(values, labels)`. Before the first render there is no chart to patch, so both fall back to `setData(...)`. First render is unchanged — `setData(...)` still sends the full option set. ## Tests - `components/ApexChartUpdateTest` (browserless): asserts the queued client call is `updateData` with a data-only payload after a render, and `renderChart` with the full theme options before one. - `e2e/DashboardChartPlaywrightTest` (Chromium): tags the rendered `<svg>` node, triggers a data update, and asserts the same node is still there (patched in place, not recreated) with the new data — plus that `grid.borderColor` is still a resolved theme color after the update. `./mvnw test` — 16/16 green, e2e included.
claude-bot added 1 commit 2026-07-28 17:29:28 +00:00
fix: update ApexCharts data in place instead of re-rendering (#23)
CI / build-and-test (pull_request) Successful in 2m21s
640616c60a
Every data change went through renderChart, which rebuilt the chart from a
full option set: animations restarted and zoom/selection state was lost.

Add an updateData path that patches the live chart via ApexCharts'
updateSeries (and updateOptions only when categories/labels actually
change), exposed as AxisChart.updateData / PieChart.updateData. Before the
first render there is nothing to patch, so those fall back to setData.
The theme overlay is re-applied to the merged options, so a rebuild after
a detach starts from the patched data.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0124BiJikbhbiEsNfJxdWM69
pitfriedrich merged commit ed9e6f81ea into main 2026-07-28 17:33:21 +00:00
pitfriedrich deleted branch ai/issue-23-incremental-chart-updates 2026-07-28 17:33:21 +00:00
Sign in to join this conversation.