Repository navigation
refactor: isolate chart type and canvas feature code per module - #4272
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
TYPE_METHOD_NEEDED) detects a missing type module. Importing the canvas modules forrender.mode='svg'(and the reverse) now says what is missing instead of$$[type] is not a function.registerCustomType). The canvas drawing and hit detection of treemap moved tosrc/canvas/treemap.ts(registerCanvasType).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?.(),?.()).grid is not drawn, because it is not imported from "billboard.js/canvas").Bundle size (minified, raw / gzip)
Verification
renderer.drawSubchartetc.); what they assert is the same.Note: with the canvas entry, import
grid,flow,subchartandselectionfrombillboard.js/canvas. Using the svg entry's modules with canvas mode no longer draws those features (a warning is logged).