Skip to content
Source
Sign inSign up
TanStack/charts

[Feature] Declare `<pattern>` paint resources (hatch, dot and animated fills) #128

Send to my agent
Opentoomingos(GitHub profile, opens in a new tab) opened this issue 1 comment

Version: reported on @tanstack/charts 0.16.0; still absent in 1.1.0 (57774e1).

ChartSpec.gradients lets a definition declare linear gradients that the renderer emits into <defs> and marks reference as url(#id) paint, and the export path serialises them. There is no equivalent for <pattern>: a definition cannot declare a hatch, dot or stripe fill, and F-259 in API-FRICTION.md ("Chart resources cannot declare patterns") notes that injecting an application-owned pattern into the chart svg is not an intended workaround.

Without it, pattern fills (a common request for accessibility-friendly and print-friendly series encoding in Recharts, ECharts, Highcharts and Vega) have to be rendered by the host outside the chart svg and referenced by id, which breaks renderChartImage/serializeChartSvg and ties the fill to the DOM host. Concrete uses we are migrating: a funnel stage renderPattern(id, color) prop, sankey link patterns, hatched area fills on candlestick and gauge, heatmap cell hatch, and a loading placeholder whose sweep is an animated <pattern>.

Would it be possible to add a patterns resource next to gradients (id, width/height, patternUnits, and either a small set of presets such as lines/circles with stroke/fill/strokeWidth/angle, or a list of primitive shapes), emitted by the SVG renderer and the export path alike, so marks can use fill: 'url(#id)' natively? An optional svgAnimation-aware offset on the pattern would also cover animated sweeps on loading placeholders.

Open PR #166 implements this.

The <mask> resource from the comment below moved to #216, together with the path-clip ask from #191.

  1. One more resource type from the same migration (0.16.0): an SVG <mask> with maskUnits="userSpaceOnUse" used as an edge fade on a live (rolling) line chart. It fades the line, its fill and the tip marker together, so a stroke gradient with opacity stops in spec.gradients cannot replace it. We render it beside the chart svg for now and reference it by id, the same seam as patterns.

Sign in to join this conversation.