Chart primitives
Layouts & specialized
Interactions
Data utilities
Umbrella package
@vx/shape
Shapes are the core elements of vx
. Most of what you see on the screen, like lines, bars, and
areas are all made with shape primitives.
Installation
npm install --save @vx/shape
Examples
<Shape.LineRadial />
<Shape.Pie />
<Shape.Stack />
<Threshold />
<Shape.AreaStack />
<Shape.BarStackHorizontal />
<Shape.BarGroup />
<Shape.Line /> + <Shape.LineRadial />
<Shape.Link* />
Components
arc
<Arc />
area
<Area />
<AreaClosed />
<AreaStack />
<Bar />
<BarRounded />
<BarStackHorizontal />
<Circle />
degreesToRadians
getPoint
getPoints
line
<Line />
<LinePath />
<LineRadial />
<LinkHorizontalCurve />
<LinkHorizontalLine />
<LinkHorizontalStep />
<LinkRadialCurve />
<LinkRadialLine />
<LinkRadialStep />
<LinkVerticalCurve />
<LinkVerticalLine />
<LinkVerticalStep />
pathHorizontalCurve
pathHorizontalDiagonal
pathHorizontalLine
pathHorizontalStep
pathRadialCurve
pathRadialDiagonal
pathRadialLine
pathRadialStep
pathVerticalCurve
pathVerticalDiagonal
pathVerticalLine
pathVerticalStep
pie
<Pie />
<Polygon />
radialLine
<SplitLinePath />
stack
<Stack />
stackOffset
stackOrder
APIs
#arc
Number or accessor function which returns a number, which defines the arc cornerRadius.
Number or accessor function which returns a number, which defines the arc endAngle.
Number or accessor function which returns a number, which defines the arc innerRadius.
Number or accessor function which returns a number, which defines the arc outerRadius.
Number or accessor function which returns a number, which defines the arc padAngle.
Number or accessor function which returns a number, which defines the arc padRadius.
Number or accessor function which returns a number, which defines the arc startAngle.
#<Arc />
Override render function which is passed the configured arc generator as input.
className applied to path element.
Number or accessor function which returns a number, which defines the arc cornerRadius.
A Datum for which to generate an arc.
Number or accessor function which returns a number, which defines the arc endAngle.
Number or accessor function which returns a number, which defines the arc innerRadius.
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React ref to the path element.
Number or accessor function which returns a number, which defines the arc outerRadius.
Number or accessor function which returns a number, which defines the arc padAngle.
Number or accessor function which returns a number, which defines the arc padRadius.
Number or accessor function which returns a number, which defines the arc startAngle.
#area
Sets the curve factory (from @vx/curve or d3-curve) for the area generator. Defaults to curveLinear.
The defined accessor for the shape. The final area shape includes all points for which this function returns true. By default all points are defined.
Sets the x0 accessor function, and sets x1 to null.
Specifies the x0 accessor function which defaults to d => d0.
Specifies the x1 accessor function which defaults to null.
Sets the y0 accessor function, and sets y1 to null.
Specifies the y0 accessor function which defaults to d => 0.
#<Area />
Override render function which is passed the configured area generator as input.
Classname applied to path element.
Sets the curve factory (from @vx/curve or d3-curve) for the area generator. Defaults to curveLinear.
Array of data for which to generate an area shape.
Default []
The defined accessor for the shape. The final area shape includes all points for which this function returns true. By default all points are defined.
Default () => true
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React RefObject passed to the path element.
Sets the x0 accessor function, and sets x1 to null.
Specifies the x0 accessor function which defaults to d => d0.
Specifies the x1 accessor function which defaults to null.
Sets the y0 accessor function, and sets y1 to null.
Specifies the y0 accessor function which defaults to d => 0.
#<AreaClosed />
ScaleTime<number, number> | ScaleLinear<number, number> | ScaleLogarithmic<number, number> | ScalePower<number, number> | ... 6 more ... | ScaleOrdinal<...>
required Override render function which is passed the configured area generator as input.
Classname applied to path element.
Sets the curve factory (from @vx/curve or d3-curve) for the area generator. Defaults to curveLinear.
Array of data for which to generate an area shape.
Default []
The defined accessor for the shape. The final area shape includes all points for which this function returns true. By default all points are defined.
Default () => true
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React RefObject passed to the path element.
Sets the x0 accessor function, and sets x1 to null.
Specifies the x0 accessor function which defaults to d => d0.
Specifies the x1 accessor function which defaults to null.
Sets the y0 accessor function, and sets y1 to null.
Specifies the y0 accessor function which defaults to d => 0.
#<AreaStack />
Array of data for which generates a stack.
((args: { stacks: Series<Datum, Key>[]; path: Area<SeriesPoint<Datum>>; stack: Stack<any, Datum, Key>; }) => ReactNode) | undefined
optional Override render function which is passed the configured arc generator as input.
className applied to path element.
Returns a color for a given stack key and index.
Sets the curve factory (from @vx/curve or d3-curve) for the area generator. Defaults to curveLinear.
The defined accessor for the shape. The final area shape includes all points for which this function returns true. By default all points are defined.
Array of keys corresponding to stack layers.
Left offset of rendered Stack.
Sets the stack offset to the pre-defined d3 offset, see https://github.com/d3/d3-shape#stack_offset.
Sets the stack order to the pre-defined d3 function, see https://github.com/d3/d3-shape#stack_order.
Top offset of rendered Stack.
Sets the value accessor for a Datum, which defaults to dkey.
Sets the x0 accessor function, and sets x1 to null.
Specifies the x0 accessor function which defaults to d => d0.
Specifies the x1 accessor function which defaults to null.
Specifies the y0 accessor function which defaults to d => 0.
#<Bar />
className to apply to rect element.
((instance: SVGRectElement | null) => void) | RefObject<SVGRectElement> | null | undefined
optional reference to rect element.
#<BarRounded />
height of the bar starting from y
corner radius of the bar. clamped to center of the shorter side of the bar (Math.min(width,height) / 2)
width of the bar starting from x
left position of the bar
top position of the bar
apply corner radius to top left corner, top right corner, bottom right corner, and bottom left corner
Default false
apply corner radius to bottom right corner, and bottom left corner
Default false
apply corner radius to bottom left corner
Default false
apply corner radius to bottom right
Default false
className to apply to path element.
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional reference to path element.
apply corner radius to top left corner, and bottom left corner
Default false
apply corner radius to top right corner, and bottom right corner
Default false
apply corner radius to top left corner, and top right corner
Default false
apply corner radius to top left corner
Default false
apply corner radius to top right corner
Default false
#<BarStackHorizontal />
Returns the desired color for a bar with a given key and index.
Array of data for which generates a stack.
@vx /scale or d3-scale that takes an x value and maps it to an x axis position.
Returns the value mapped to the y of a bar.
@vx /scale or d3-scale that takes a y value and maps it to an y axis position.
Override render function which is passed the configured stack generator as input.
className applied to path element.
Array of keys corresponding to stack layers.
Left offset of rendered Stack.
"none" | "expand" | "diverging" | "silhouette" | "wiggle" | undefined
optional Sets the stack offset to the pre-defined d3 offset, see https://github.com/d3/d3-shape#stack_offset.
"none" | "ascending" | "descending" | "reverse" | "insideout" | undefined
optional Sets the stack order to the pre-defined d3 function, see https://github.com/d3/d3-shape#stack_order.
Top offset of rendered Stack.
Sets the value accessor for a Datum, which defaults to dkey.
Returns the value mapped to the x0 of a bar.
Returns the value mapped to the x1 of a bar.
#<Circle />
className to apply to circle element.
((instance: SVGCircleElement | null) => void) | RefObject<SVGCircleElement> | null | undefined
optional reference to circle element.
#degreesToRadians
#getPoint
Number of polygon sides.
Size of the shape.
Polygon center position.
Rotation transform to apply to polygon.
Default 0
#getPoints
Number of polygon sides.
Size of the shape.
Polygon center position.
Rotation transform to apply to polygon.
Default 0
#line
Sets the curve factory (from @vx/curve or d3-curve) for the line generator. Defaults to curveLinear.
The defined accessor for the shape. The final line shape includes all points for which this function returns true. By default all points are defined.
Sets the x0 accessor function, and sets x1 to null.
Sets the y0 accessor function, and sets y1 to null.
#<Line />
className to apply to line element.
fill color applied to line element.
Default transparent
Starting x,y point of the line.
Default { x: 0, y: 0 }
((instance: SVGLineElement | null) => void) | RefObject<SVGLineElement> | null | undefined
optional reference to line element.
Ending x,y point of the line.
Default { x: 1, y: 1 }
#<LinePath />
Override render function which is passed the configured path generator as input.
className applied to path element.
Sets the curve factory (from @vx/curve or d3-curve) for the line generator. Defaults to curveLinear.
Array of data for which to generate a line shape.
Default []
The defined accessor for the shape. The final line shape includes all points for which this function returns true. By default all points are defined.
Default () => true
Fill color of the path element.
Default transparent
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React RefObject passed to the path element.
Sets the x0 accessor function, and sets x1 to null.
Sets the y0 accessor function, and sets y1 to null.
#<LineRadial />
Returns the angle value in radians for a given Datum, with 0 at -y (12 o’clock).
Override render function which is passed the configured path generator as input.
className applied to path element.
Sets the curve factory (from @vx/curve or d3-curve) for the radialLine generator. Defaults to curveLinear.
Array of data for which to generate a line shape.
Default []
The defined accessor for the shape. The final radialLine shape includes all points for which this function returns true. By default all points are defined.
Fill color of the path element.
Default transparent
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React RefObject passed to the path element.
Returns the radius value in radians for a given Datum, with 0 at the center.
#<LinkHorizontalCurve />
Datum for which to render a link.
Render function override which is passed the configured path generator as input.
className applied to path element.
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React ref to the path element.
Path generator, given a link returns a path d attribute string
Default 0.2
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#<LinkHorizontalLine />
Datum for which to render a link.
Render function override which is passed the configured path generator as input.
className applied to path element.
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React ref to the path element.
Path generator, given a link returns a path d attribute string
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#<LinkHorizontalStep />
Datum for which to render a link.
Render function override which is passed the configured path generator as input.
className applied to path element.
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React ref to the path element.
Path generator, given a link returns a path d attribute string
Default 0.5
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#<LinkRadialCurve />
Datum for which to render a link.
Render function override which is passed the configured path generator as input.
className applied to path element.
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React ref to the path element.
Path generator, given a link returns a path d attribute string
Default 0.2
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#<LinkRadialLine />
Datum for which to render a link.
Render function override which is passed the configured path generator as input.
className applied to path element.
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React ref to the path element.
Path generator, given a link returns a path d attribute string
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#<LinkRadialStep />
Datum for which to render a link.
Render function override which is passed the configured path generator as input.
className applied to path element.
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React ref to the path element.
Path generator, given a link returns a path d attribute string
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#<LinkVerticalCurve />
Datum for which to render a link.
Render function override which is passed the configured path generator as input.
className applied to path element.
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React ref to the path element.
Path generator, given a link returns a path d attribute string
Default 0.2
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#<LinkVerticalLine />
Datum for which to render a link.
Render function override which is passed the configured path generator as input.
className applied to path element.
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React ref to the path element.
Path generator, given a link returns a path d attribute string
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#<LinkVerticalStep />
Datum for which to render a link.
Render function override which is passed the configured path generator as input.
className applied to path element.
((instance: SVGPathElement | null) => void) | RefObject<SVGPathElement> | null | undefined
optional React ref to the path element.
Path generator, given a link returns a path d attribute string
Default 0.5
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pathHorizontalCurve
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pathHorizontalDiagonal
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pathHorizontalLine
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pathHorizontalStep
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pathRadialCurve
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pathRadialDiagonal
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
Given a link, returns the source node.
Given a link, returns the target node.
#pathRadialLine
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pathRadialStep
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pathVerticalCurve
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pathVerticalDiagonal
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pathVerticalLine
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pathVerticalStep
Given a link, returns the source node.
Given a link, returns the target node.
Given a node, returns its x coordinate.
Given a node, returns its y coordinate.
#pie
Returns the end angle of the overall Pie shape (the last value ends at endAngle), with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
Padding angle of the Pie shape, which sets a fixed linear distance separating adjacent arcs.
Comparator function to sort arcs, overridden by sortValues if defined. If sort and sortValues are null, arcs match input data order.
Comparator function to sort arc values, overrides sort if defined. If sort and sortValues are null, arcs match input data order.
Returns the start angle of the overall Pie shape (the first value starts at startAngle), with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
Invoked for each datum, returns the value for a given Pie segment/arc datum.
#<Pie />
((xyCoords: [number, number], arc: PieArcDatum<Datum>) => ReactNode) | undefined
optional Optional render function invoked for each Datum to render something (e.g., a Label) at each pie centroid.
Render function override which is passed the configured arc generator as input.
className applied to path element.
Number or accessor function which returns a number, which defines the arc cornerRadius.
Array of data to generate a Pie for.
Default []
Returns the end angle of the overall Pie shape (the last value ends at endAngle), with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
Number or accessor function which returns a number, which defines the arc innerRadius.
Default 0
Left offset of rendered Pie.
Number or accessor function which returns a number, which defines the arc outerRadius.
Padding angle of the Pie shape, which sets a fixed linear distance separating adjacent arcs.
Number or accessor function which returns a number, which defines the arc padRadius.
Comparator function to sort arcs, overridden by pieSortValues if defined. If pieSort and pieSortValues are null, arcs match input data order.
Comparator function to sort arc values, overrides pieSort if defined. If pieSort and pieSortValues are null, arcs match input data order.
Invoked for each datum, returns the value for a given Pie segment/arc datum.
Returns the start angle of the overall Pie shape (the first value starts at startAngle), with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
Top offset of rendered Pie.
#<Polygon />
Number of polygon sides.
Polygon center position.
Render function override which is passed the generated polygon points.
className to apply to polygon element.
((instance: SVGPolygonElement | null) => void) | RefObject<SVGPolygonElement> | null | undefined
optional Reference to polygon element.
Rotation transform to apply to polygon.
Default 0
Size of the shape.
Default 25
#radialLine
Returns the angle value in radians for a given Datum, with 0 at -y (12 o’clock).
Sets the curve factory (from @vx/curve or d3-curve) for the radialLine generator. Defaults to curveLinear.
The defined accessor for the shape. The final radialLine shape includes all points for which this function returns true. By default all points are defined.
Returns the radius value in radians for a given Datum, with 0 at the center.
#<SplitLinePath />
Array of data segments, where each segment will be a separate path in the rendered line.
Pick<SVGProps<SVGPathElement>, "string" | "className" | "scale" | "width" | "height" | "stroke" | "strokeWidth" | "strokeDasharray" | "offset" | "min" | ... 456 more ... | "key">[]
required Styles to apply to each segment. If fewer styles are specified than the number of segments, they will be re-used.
((renderProps: { index: number; segment: { x: number; y: number; }[]; styles?: Pick<SVGProps<SVGPathElement>, "string" | "className" | "scale" | "width" | "height" | "stroke" | ... 460 more ... | "key"> | undefined; }) => ReactNode) | undefined
optional Override render function which is passed the configured path generator as input.
className applied to path element.
Sets the curve factory (from @vx/curve or d3-curve) for the line generator. Defaults to curveLinear.
The defined accessor for the shape. The final line shape includes all points for which this function returns true. By default all points are defined.
Optionally specify the sample rate for interpolating line segments.
Sets the x0 accessor function, and sets x1 to null.
Sets the y0 accessor function, and sets y1 to null.
#stack
Array of keys corresponding to stack layers.
Sets the stack offset to the pre-defined d3 offset, see https://github.com/d3/d3-shape#stack_offset.
Sets the stack order to the pre-defined d3 function, see https://github.com/d3/d3-shape#stack_order.
#<Stack />
Array of data for which generates a stack.
((args: { stacks: Series<Datum, Key>[]; path: Area<SeriesPoint<Datum>>; stack: Stack<any, Datum, Key>; }) => ReactNode) | undefined
optional Override render function which is passed the configured arc generator as input.
className applied to path element.
Returns a color for a given stack key and index.
Sets the curve factory (from @vx/curve or d3-curve) for the area generator. Defaults to curveLinear.
The defined accessor for the shape. The final area shape includes all points for which this function returns true. By default all points are defined.
Array of keys corresponding to stack layers.
Left offset of rendered Stack.
Sets the stack offset to the pre-defined d3 offset, see https://github.com/d3/d3-shape#stack_offset.
Sets the stack order to the pre-defined d3 function, see https://github.com/d3/d3-shape#stack_order.
Top offset of rendered Stack.
Sets the value accessor for a Datum, which defaults to dkey.
Sets the x0 accessor function, and sets x1 to null.
Specifies the x0 accessor function which defaults to d => d0.
Specifies the x1 accessor function which defaults to null.
Specifies the y0 accessor function which defaults to d => 0.