Skip to content

Feat/charts refactor#6

Open
vmantovani wants to merge 34 commits intomainfrom
feat/charts-refactor
Open

Feat/charts refactor#6
vmantovani wants to merge 34 commits intomainfrom
feat/charts-refactor

Conversation

@vmantovani
Copy link
Contributor

Refactor: Charts package – shared renderers, unified API, and composition cleanup

Summary

This PR refactors the @inglorious/charts package for clearer structure, less duplication, and a single public entry point for composition mode. It does not change behaviour for existing callers of chart.render(...) or Config Mode.

Main changes

1. Unified composition API

  • Single entry point: Composition mode is now exposed only as chart.render(entity, params, api) (no public renderLineChart, renderAreaChart, etc.).
  • Config Mode still uses api.render(entityId); the template renderer stays the same.
  • The per-type methods (chart.renderLineChart, chart.renderAreaChart, chart.renderBarChart, chart.renderPieChart) are no longer part of the public API. web-charts has been updated to use chart.render.

2. Shared cartesian core

  • Shared renderer: Line and area config-mode charts use a shared cartesian renderer and helpers (cartesian-renderer.js, cartesian-children.js).
  • Composed chart: A single composed renderer handles mixed Line/Area/Bar charts; bar and line/area delegate orchestration to it instead of duplicating logic.
  • Config + composition: Composed charts are supported in Config Mode (entity type: "composed" with series); web-charts has an example next to the composition version.

3. Centralised config and helpers

  • Constants: Default palettes, grid defaults, and Y-axis defaults live in utils/constants.js; bar/line/area and cartesian children use them instead of hardcoded values.
  • Context: getResolvedEntity(ctx, entity) in cartesian-helpers.js centralises ctx.entity || entity (and ctx.fullEntity for brush); all cartesian, tooltip, brush, legend, and pie renderers use it.
  • Data keys: resolveDataKeys and key exclusion live in data-utils.js and are used by all renderers for consistent series inference.

4. Chart core and instance API

  • Core layout: Chart core and related logic moved under core/ (e.g. chart-core.js, create-chart-instance.js, render-dispatch.js, declarative-children.js). Index was split so the facade stays thin.
  • Instance API: Instance render methods are built from a type dispatcher and a single method map; legacy (children-first) calls are handled in one adapter with a one-time deprecation warning.
  • Inline charts: Composition without a store entity is supported; inline tooltips and runtime IDs (e.g. clipPath) are stabilised.

5. Tests

  • Tests: Chart tests use the template render for Config Mode; composition zero-padding tests use the correct config: { width, height, padding } shape after rebase.

Commits (34)

The work is split into small commits for review; they group roughly as:

  • Constants, helpers, data keys – centralise defaults and context/data resolution.
  • Composed renderer – add composed chart, move orchestration from bar/line/area, support config-style composed.
  • Shared cartesian – extract cartesian children and renderer, support CartesianGrid stroke, fix band scale and series detection.
  • Core reorg – move core to core/, clarify naming, simplify method maps, legacy adapter, and instance render inputs.
  • Unified chart.render – remove per-type render from the facade, update web-charts to use chart.render.
  • Composed config example, tests – web-charts composed Config example; chart tests (template render, zero-padding shape).

Checklist

  • Composition API is only chart.render(...); no public renderLineChart/renderAreaChart/renderBarChart/renderPieChart.
  • Config Mode and existing chart.render(oneObject, api) usage unchanged.
  • Shared constants and helpers used across bar/line/area/composed/tooltip/brush/legend/pie.
  • Composed chart works in both Config and Composition; web-charts example added.
  • Tests updated (config-mode template render, zero-padding composition shape, web-charts).

@vercel
Copy link

vercel bot commented Mar 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
charts Ready Ready Preview, Comment Mar 21, 2026 2:53pm
dashboard Ready Ready Preview, Comment Mar 21, 2026 2:53pm
engine Ready Ready Preview, Comment Mar 21, 2026 2:53pm
flapper Ready Ready Preview, Comment Mar 21, 2026 2:53pm
forge Ready Ready Preview, Comment Mar 21, 2026 2:53pm
inglorious-flapper Ready Ready Preview, Comment Mar 21, 2026 2:53pm
inglorious-pong Ready Ready Preview, Comment Mar 21, 2026 2:53pm
motion Ready Ready Preview, Comment Mar 21, 2026 2:53pm
pong Ready Ready Preview, Comment Mar 21, 2026 2:53pm
store Ready Ready Preview, Comment Mar 21, 2026 2:53pm
ui Ready Ready Preview, Comment Mar 21, 2026 2:53pm
web Error Error Mar 21, 2026 2:53pm

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