Skip to content

refactor: isolate chart type and canvas feature code per module - #4272

Merged
netil merged 2 commits into
naver:masterfrom
netil:type-isolation
Nov 11, 2026
Merged

netil merged 2 commits into
naver:masterfrom
netil:type-isolation

Conversation

@netil

@netil netil commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Keeps the code of a chart type or an optional feature in its own module, so a bundle carries it only when the module is imported. Behavior is unchanged.

  • Errors: one table (TYPE_METHOD_NEEDED) detects a missing type module. Importing the canvas modules for render.mode='svg' (and the reverse) now says what is missing instead of $$[type] is not a function.
  • Chart types: funnel is isolated into hooks registered per type name (registerCustomType). The canvas drawing and hit detection of treemap moved to src/canvas/treemap.ts (registerCanvasType).
  • Canvas features: the canvas drawing of grid, flow, subchart and selection moved to src/canvas/{grid,flow,subchart,selection}.ts. The canvas entry exports its own resolvers; the UMD bundle registers all of them. Shared code calls them optionally (getCanvasFeature?.(), ?.()).
  • A canvas chart now warns when a feature is imported from the svg entry only (grid is not drawn, because it is not imported from "billboard.js/canvas").

Bundle size (minified, raw / gzip)

bundle change
line-canvas -27.0KB / -7.8KB
line-svg, bar-svg -249B / -29~-78B
funnel-svg +509B / +257B (hooks registration)

Verification

  • Full test suite passes (110 files, 2881 tests); tsc and lint are clean.
  • Canvas pixels, brush domains and selections are identical to the previous commit in side by side runs (static subchart, y/y2 axes, rotated, brush and handle drag, flow, zoom, click/API/drag selection).
  • New tests cover a canvas chart without the feature modules, the warning, and a page with svg and canvas charts together.
  • Existing tests were changed only where they called removed internals directly (renderer.drawSubchart etc.); what they assert is the same.

Note: with the canvas entry, import grid, flow, subchart and selection from billboard.js/canvas. Using the svg entry's modules with canvas mode no longer draws those features (a warning is logged).

jaesung.park added 2 commits November 11, 2026 16:19
… chart type

So that a bundle has the code of the chart types it uses only.

- register the parts of a chart type of its own module by name
  (registerCustomType: hooks, canvas parts) instead of flat properties on the
  prototype, so more than one of these modules can be in a bundle
- move the funnel code out of the shared files into the funnel module: text
  positions, label data, the data transform after unload, and the notice that
  canvas mode is not supported (hooks); its classes are added to the class map
  when the module is called
- add a registry for the canvas parts of the types that can be more than one in
  a chart (registerCanvasType, getCanvasTypeParts) and move the treemap canvas
  drawing and hit detection into src/canvas/treemap.ts
- fall back to SVG with a warning when canvas mode is requested for treemap
  and only its svg part was imported, instead of drawing nothing
- merge TYPE_METHOD_NEEDED and CUSTOM_TYPE_NAMES into one table keyed by the
  type name, and tell which part of a type module is missing (getTypeMethod)
  when canvas modules are used in the svg mode, instead of "is not a function"
- keep the styled console output of logError

Existing tests that checked the old internals (the table keys, the module
import hints by stubs, the custom type of funnel, drawTreemaps and the treemap
hit block on stub contexts) are rewritten with the same meaning.
…ure module

The canvas drawing code of these features was always bundled with the canvas
entry, whether the feature module was imported or not. Move it behind the
module of each feature, so a canvas bundle carries it only when imported.

- add src/canvas/{grid,flow,subchart,selection}.ts and canvas entry resolvers
  (canvasGrid, canvasFlow, canvasSubchart, canvasSelection)
- add registerCanvasFeature()/getCanvasFeature() for the drawing parts; the
  interaction parts are mixed in with extend()
- call the moved members optionally in the shared code
- move the CANVAS_PART_NEEDED check to the canvas module
- warn when a feature is imported from the svg entry only, so it is not drawn
  in canvas mode

line-canvas bundle: -25.4KB raw / -7.2KB gzip. svg bundles do not grow.
@netil netil self-assigned this Nov 11, 2026
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 93.838% (-0.03%) from 93.865% — netil:type-isolation into naver:master

@netil
netil merged commit ec0fdb6 into naver:master Nov 11, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants