[Bug] charts: area gradient ids collide between charts on the same page
Description
area() with gradient: true gives its <linearGradient> the id area-grad-${_uid}, where [_uid = \${seriesIndex}:${s.key}`](https://github.com/meta/astryx/blob/16fe6a81adcf611953bc2918a71f1723bcfb7a9c/packages/charts/src/layout.ts#L352). That is unique within one chart, as the comment says, but not across charts: two charts on a page that each have an area series at index 0 keyed revenueboth renderid="area-grad-0-revenue"`.
url(#area-grad-0-revenue) resolves to the first matching element in the document, so the second chart is filled with the first chart's gradient. If the first chart is inside a display: none container (an inactive tab, say), the second chart's fill may not paint at all.
Suggested fix: Chart already computes a useId() and derives a colon-free clipId from it. Expose that id through the chart context and prefix the gradient id with it the same way.
Reproduction
import {Chart, area} from '@astryxdesign/charts';
const a = [{month: 'Jan', revenue: 10}, {month: 'Feb', revenue: 14}];
const b = [{month: 'Jan', revenue: 7}, {month: 'Feb', revenue: 3}];
export function Page() {
return (
<>
<Chart data={a} xKey="month" series={[area('revenue', {color: '#2563eb', gradient: true})]} />
<Chart data={b} xKey="month" series={[area('revenue', {color: '#dc2626', gradient: true})]} />
</>
);
}
- Expected: a blue area, then a red area.
- Actual: both
<linearGradient>elements haveid="area-grad-0-revenue", and the second chart has a red line over the first chart's blue fill.
Found by reading the code; I haven't rendered it.
Astryx Version
@astryxdesign/[email protected] (code checked on main at 16fe6a8)
Environment
Any browser
I'll take this one. Plan: expose the chart's useId()-derived id through the chart context and prefix the area gradient id with it (same colon-free form as clipId), so two charts on one page can no longer emit the same area-grad-* id. I'll add a regression test rendering two gradient area charts and asserting their gradient ids are distinct, and run the charts test suite + lint before opening a PR.