Texture patterns that keep chart series apart without colour.
import {CHART_TEXTURE_COUNT,ChartPatterns,chartTextureId} from '@oztix/roadie-charts/chart-patterns'
Render ChartPatterns once, then fill any SVG shape with a fill-texture-* class. Each texture draws in the text colour.
Mark a shape with data-chart-texture and it keeps its chart colour on screen. Under forced colours and in print, where colour drops away, it switches to the texture for that slot. This example uses the patterns rendered above.
<svg viewBox='0 0 240 108' role='img' aria-label='Tickets sold by type: GA 1,210, VIP 790, Companion 480' className='w-full max-w-sm'> <rect y='0' width='240' height='28' rx='4' className='fill-chart-1' data-chart-texture='1' /> <rect y='40' width='157' height='28' rx='4' className='fill-chart-2' data-chart-texture='2' /> <rect y='80' width='95' height='28' rx='4' className='fill-chart-3' data-chart-texture='3' /> </svg>
When a class won't do, such as in a chart library's props, point fill at the pattern with chartTextureId.
<svg viewBox='0 0 120 48' aria-hidden className='w-40'> <rect width='120' height='48' rx='6' fill={`url(#${chartTextureId(3)})`} /> </svg>
ChartPatterns once per page, near the root, when you're wiring up textures by hand outside Chart and ChartPlot. Its ids are fixed, so a second copy repeats them.Chart and ChartPlot never use ChartPatterns directly. Each scopes its own textures with the useChartPatterns hook, so any number of charts can sit on one page without colliding. You don't need to render ChartPatterns yourself around them.useChartPatterns() once per instance, apply its style to an element that contains everything reading fill-texture-* or data-chart-texture (so the --chart-texture-* custom properties inherit down to it), and render its patterns anywhere in that same subtree.--chart-3 takes texture 3.data-chart-texture for most marks, so textures appear only when colour is gone. Reach for fill-texture-* when a mark needs a texture on screen too, such as the projected part of a bar.Meter segments, take data-chart-texture from the core stylesheet and don't need ChartPatterns.| Export | What it gives you |
|---|---|
chartTextureId(slot) | The pattern id for a slot from 1 to 8, such as roadie-texture-3 |
CHART_TEXTURE_COUNT | The number of patterns: 8, one per categorical colour |
useChartPatterns() | { patterns, style } for one scoped chart instance: patterns is the hidden SVG with ids unique to this call, and style sets --chart-texture-1 through -8 to point at them |