Mantle Chart Y Axis Domain Migration Guide
@ngrok/mantle's chart Roots (LineChart.Root, BarChart.Root, AreaChart.Root, and ScatterPlot.Root) no longer take yDomain. The YAxis part of each chart takes a domain prop in its place. A chart can now have a second y axis on the right (<LineChart.YAxis side="right" />), and each axis sets its own range, so the range moved to the axis it belongs to. This guide moves a codebase from the Root prop to the part.
TL;DR: Delete yDomain={…} from every chart Root and put the same value on that Root's YAxis as domain={…}. A Root with no YAxis gets one with the domain, which also draws the axis labels.
Codemod
From a mantle checkout:
In a project that installs @ngrok/mantle:
The rules apply steps 2 and 3. On the four chart Roots, they copy the yDomain value onto the left YAxis of the same chart as domain, then delete yDomain from the Root. A YAxis side="right" keeps its own range. The rules move the range only onto a YAxis that is a direct child of the Root. A Root whose left YAxis sits under a condition, a callback, or another element, or already has a domain, keeps yDomain. So does a Root or YAxis with a spread ({...props}), which can set the range or the side where the rules cannot read it. A file that reads YAxis outside a tag, such as const Axis = LineChart.YAxis, keeps every yDomain. The type checker names each Root that keeps yDomain, and step 4 stays manual: adding an axis changes what the chart draws, which is a design call. The rules read a part through its import from @ngrok/mantle/<chart>, under its own name or an alias. A part that reaches the file through a local re-export or a destructured namespace stays manual. A function that binds a chart's name to a parameter or a local shadows the import, so the rules leave that function alone. The codemod can run again: a migrated Root has no yDomain to match. Pass --dry-run to print the rewrites first, and run your formatter after the rewrite.
You are an agent migrating a codebase. Do this:
- Find every chart Root with the
yDomainprop:LineChart.Root,BarChart.Root,AreaChart.Root, andScatterPlot.Rootfrom@ngrok/mantle. Search foryDomain, and for a renamed import of the same part (import { LineChart as Trend }). - For each Root with a left
YAxispart of the same chart (LineChart.YAxisinsideLineChart.Root, with nosideorside="left"), adddomain={…}to thatYAxiswith the exactyDomainvalue. Leave aYAxis side="right"alone. When the leftYAxisalready has adomain, keep the one the chart needs and delete the other. Keep a dynamic value as it is:yDomain={chartDomain(stats)}becomesdomain={chartDomain(stats)}. - Delete
yDomainfrom the Root. - For each Root with
yDomainand noYAxis, add<LineChart.YAxis domain={…} />(with the chart's own namespace) as a child of the Root, and deleteyDomain. The axis then draws its tick labels in a gutter on the left. A chart with no axis, such as a sparkline, can no longer fix its range: remove the domain, or ask whether the chart needs an axis. - Leave
BarChart.RootandAreaChart.Roottypes alone: theirYAxisdomainkeeps the zero minimum ([0, number | "auto"]) that the Root'syDomainhad. - In tests:
- A test that renders a chart Root with
yDomainmoves the value to theYAxis, the same as steps 2 to 4:<LineChart.Root yDomain={[0, 100]}>becomes<LineChart.YAxis domain={[0, 100]} />. - A test that queries text in a chart with the SVG renderer and gets a new
YAxisin step 4 can find the axis's tick labels too. Scope the query to the element it reads:screen.getByText("100")becomeswithin(tooltip).getByText("100").
- A test that renders a chart Root with
- After editing, run the project's formatter, linter, type checker, and tests.
Why on the axis? A chart can draw a left and a right y axis, and each one has its own range. With the range on the Root, a second axis needed a second Root prop, and a reader had to learn which side each prop set. With the range on the
YAxispart, each axis reads one place: the part that draws it.
Before → after
A line chart with a fixed range
A dynamic range on a renamed import
A Root with no axis
Edge cases & gotchas
- A
YAxisin another component than its Root (a wrapper that renders the axis) is out of the codemod's reach. The Root keepsyDomain, and the type checker names it. Pass the domain to the wrapper by hand. - A chart with two y axes takes a
domainon each one. The right axis puts its ticks on the left axis's grid lines when its owndomainallows it.
How to verify
Run the type checker: a Root that still has yDomain fails to compile. The type checker does not see a yDomain inside an object you spread onto a Root ({...chartProps}), so search those objects for yDomain too. Then run the project's formatter, linter, and tests, and fix the tests as the In tests: step says.