Skip to content

Declare dimensions on typed-array line series - #187

Merged
YektaY merged 3 commits into
mainfrom
yektay/echarts-typed-dimensions
Nov 13, 2026
Merged

YektaY merged 3 commits into
mainfrom
yektay/echarts-typed-dimensions

Conversation

@YektaY

@YektaY YektaY commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Moved from slaclab/react-trace-archive#187. Its review history and CI runs stay in the archive.

Description

  • PlotArea.tsx: the main line series and the extension-line series now declare dimensions: ['x', 'y'] (one shared XY_DIMENSIONS constant, so the memoized series objects stay stable). The dimensions map to the axes in order, time then value, so no encode is needed. The main line declares them in both of its forms, the flat Float64Array and the [t, v] pairs used once an INVALID sample breaks it. The series merges by id when it switches between the two.

  • New PlotArea.typedData.test.tsx: mounts SinglePlot with canopy-charts' CanopyChart stubbed out (test/chartStub), loads the captured option into a real server-side ECharts instance (Vitest runs with NODE_ENV=test, so the development asserts are live), and reads the values back out of ECharts' store. It covers:

    • an empty, just-added trace;
    • a line with its frozen (2048-anchor) extension and its following (2-point) extension;
    • a line switching between typed and point data on one chart;
    • an INVALID-broken step line with its min/max band;
    • LTTB sampling of a dense typed line, which keeps a one-sample spike, so sampling reads the value dimension.

    Every test also checks that each series with typed-array data declares dimensions. All 6 tests fail without the fix with ECharts' assertion and pass with this change.

Motivation

In pnpm dev, clicking Add Trace crashed the plot with Uncaught Error: dimensions must be given if data is TypedArray., thrown from determineSourceDimensions in ECharts' data/Source.js. On main the page went blank.

fc8d439 switched line series data to flat Float64Arrays, which kept updates cheap while a plot scrolls. The extension lines use them too. ECharts needs dimensions to know how many values make a point in typed data. Its development build asserts on this, but the assert sits under process.env.NODE_ENV !== 'production', so production builds were unaffected and only dev broke. The typed-array data is unchanged; there is no switch back to [t, v] pairs.

Screenshots

Checked in pnpm dev against a local Canopy test backend with a simulated sine PV:

  • Before the fix, Add Trace threw the assertion and blanked the page.
  • After the fix, Add Trace and choosing the PV plot the data.
  • The tooltip value and crosshair time are correct.
  • The ECharts store shows the line with x = time and y = value, LTTB-sampled (3636 → 906 points).
  • Both extension forms load: 2 points while following, and 2048 anchors once frozen. The dashed extension survives a wheel zoom into it.
  • No new ECharts console errors appeared.

Pre-merge checklist

  • Code works interactively in the browser
  • New/changed components are covered in the test suite where possible
  • Test suite passes locally (pnpm test, 514 tests after merging main)
  • Linting passes (pnpm lint; pnpm format:check and pnpm exec tsc -b also pass)
  • Test suite passes on GitHub Actions

Line and extension series carry their points as a flat Float64Array
(25fb6c9). ECharts' development build asserts that typed-array data
declares its dimensions ("dimensions must be given if data is
TypedArray."), so in `pnpm dev` adding a trace crashed the plot. The
production build strips the assert, which is why only dev broke.

Both series now declare dimensions ['x', 'y']. They map to the axes in
order, time then value, so no encode is needed, and [t, v] pairs read
the same way: the main line keeps them when it switches to point data
at an INVALID sample.

PlotArea.option.test.tsx loads the option SinglePlot builds into a real
server-side ECharts instance and reads the values back out of its store:
an empty just-added trace, a line with its frozen (2048-anchor) and
following (2-point) extension, a line switching between typed and point
data on one chart, an INVALID-broken step line with its band, and LTTB
sampling of a dense line keeping a one-sample spike.
main added its own PlotArea.option.test.tsx (chart theme and number
formatting) with the CanopyChart migration. Keep it as is and move this
branch's typed-array test to PlotArea.typedData.test.tsx, mocking
CanopyChart through test/chartStub like the other PlotArea tests.
@YektaY
YektaY requested a review from a team as a code owner November 12, 2026 06:36

@jbellister-slac jbellister-slac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Both Tiffany and I ran into this and fixed this separately in #158 and #172. It's fine for this to go first though since it includes more tests and the others can merge or rebase.

@YektaY
YektaY merged commit d4c1fb0 into main Nov 13, 2026
6 checks passed
@YektaY
YektaY deleted the yektay/echarts-typed-dimensions branch November 13, 2026 05:07
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.

2 participants