Chart primitives
Layouts & specialized
Interactions
Data utilities
Umbrella package
@vx/pattern
Inspired by: http://riccardoscalco.github.io/textures/
Example
import { AreaClosed } from '@vx/shape';
import { PatternLines } from '@vx/pattern';
const PatternArea = () => {
return (
<svg>
<PatternLines
id="lines"
height={5}
width={5}
stroke={'black'}
strokeWidth={1}
orientation={['diagonal']}
/>
<AreaClosed fill="url('#lines')" />
</svg>
);
};
The Definition Caveat
Like gradients, patterns are "defined." When you put down a <PatternXYZ />
, it's putting a
<pattern/>
attribute in the
SVG.
It's often better to think of these as variable definitions rather than true DOM elements. When you
use fill="url('#pattern')"
you're referencing the pattern's id: pattern
.
Pre-Made Patterns
PatternsCircles
<PatternCircles id="circles" height={6} width={6} stroke={'black'} strokeWidth={1} />
PatternsHexagons
<PatternHexagons id="hexagons" height={3} size={8} stroke={'red'} strokeWidth={1} />
PatternsLines
<PatternLines
id="lines"
height={5}
width={5}
stroke={'black'}
strokeWidth={1}
orientation={['diagonal']}
/>
PatternsWaves
<PatternWaves id="waves" height={4} width={4} stroke={'blue'} strokeWidth={1} />
Installation
npm install --save @vx/pattern
Examples
<Pattern />
<Shape.Stack />
<BoxPlot /> & <ViolinPlot />
Components
APIs
#<Pattern />
Children of pattern element to render.
Height of the pattern.
Unique id of the pattern element.
Width of the pattern.
#<Circles />
Height of the pattern element.
Unique id for the pattern.
Width of the pattern element.
Background color applied behind cirlces.
className applied to circles.
Whether to fill in circles within the pattern gaps to increase pattern density.
Default false
Fill applied to circles.
Radius of the pattern circles.
Default 2
stroke applied to circles.
strokeDasharray applied to circles.
strokeWidth applied to circles.
#<Hexagons />
Height of the pattern element.
Unique id for the pattern.
Background color applied behind hexagons.
className applied to hexagon path element.
Fill applied to hexagons.
shapeRendering applied to hexagon paths.
Size of the hexagon shape.
Default 3
Stroke color applied to hexagon paths.
strokeDasharray applied to hexagon paths.
strokeLinecap applied to hexagon paths.
strokeWidth applied to hexagon paths.
#<Lines />
Height of the pattern element.
Unique id for the pattern.
Width of the pattern element.
Background color applied behind lines.
className applied to line path element.
Array of orientations to render (can mix multiple).
Default ['vertical']
shapeRendering applied to path elements.
Default auto
Stroke color applied to path elements.
strokeDasharray applied to path elements.
strokeLinecap applied to path elements.
Default square
strokeWidth applied to path elements.
#<Path />
Height of the pattern element.
Unique id for the pattern.
Width of the pattern element.
Background color applied behind path.
className applied to the path element.
fill color applied to path.
Default transparent
d attribute of the path element
shapeRendering applied to path.
Default auto
Stroke color applied to path.
strokeDasharray applied to path.
strokeLinecap applied to path.
Default square
strokeWidth applied to path.
#<Waves />
Height of the pattern element.
Unique id for the pattern.
Width of the pattern element.
Background color applied behind path.
className applied to the path element.
fill color applied to path.
shapeRendering applied to path.
Stroke color applied to path.
strokeDasharray applied to path.
strokeLinecap applied to path.
strokeWidth applied to path.