Victory Primitives
Victory is built around a set of simple, stateless components. Along with VictoryContainer, VictoryClipContainer, and VictoryLabel, the following list represents every simple element a Victory component might render. These simple components are responsible for supplying props to primitive components. Victory maintains a small subset of primitive components with additional logic in place to prevent unnecessary rendering. Extracting every rendered element into its own component allows Victory to support both web and React Native applications with very little additional code, as only a few components need to be modified to render react-native-svg elements rather than SVG elements. These primitives are also exposed for users to wrap, extend or reference when creating their own custom rendered components.
Primitive Components
Each of these primitive components renders SVG elements. The following components are the only Victory components that render SVG elements with the exception of VictoryContainer
and VictoryPortal
. These elements are used by other simple components such as Bar
and Area
.
Circle
Used by Background
, VictoryClipContainer
, and Voronoi
const Circle = (props) => <circle vectorEffect="non-scaling-stroke" {...props} />;
ClipPath
Used by VictoryClipContainer
and Voronoi
const ClipPath = (props) => (
<defs>
<clipPath id={props.clipId}>{props.children}</clipPath>
</defs>
);
Line
Used by Axis
, Candle
, and ErrorBar
const Line = (props) => <line vectorEffect="non-scaling-stroke" {...props} />;
Path
Used by Arc
, Area
, Bar
, Curve
, Flyout
, Point
, Slice
, and Voronoi
const Path = (props) => <path {...props} />;
Rect
Used by VictoryClipPath
, Background
, Border
, and Candle
const Rect = (props) => <rect vectorEffect="non-scaling-stroke" {...props} />;
Text
Used by VictoryLabel
const Text = (props) => {
const { children, title, desc, ...rest } = props;
return (
<text {...rest}>
{title && <title>{title}</title>}
{desc && <desc>{desc}</desc>}
{children}
</text>
);
};
TSpan
Used by VictoryLabel
const TSpan = (props) => <tspan {...props} />;
Simple Components
Arc
VictoryPolarAxis uses the Arc
primitive to draw circular axes and grid lines. Arc
renders a <Path>
element. View the source
Props
active
boolean a flag signifying whether the component is activeariaLabel
string or function a prop controlling the aria-label that will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toArc
className
string the class name that will be applied to the rendered pathclosedPath
boolean a flag signifying whether this arc is should render a closed pathcx
number the x coordinate of the center of the arc pathcy
number the y coordinate of the center of the arc pathdatum
any the data point or tick corresponding to this arcendAngle
number the end angle of the arc given in degreesevents
object events to attach to the rendered elementgroupComponent
element the element used to group rendered elements default<g/>
id
string or number an id to apply to the rendered componentpathComponent
element the rendered path element default<Path/>
r
number the radius of the arcrole
string the aria role to assign to the elementscale
object the x and y scale of the parent chart withdomain
andrange
appliedshapeRendering
string the shape rendering attribute to apply to the rendered pathstartAngle
number the start angle of the arc given in degreesstyle
object the styles to apply to the rendered elementtabIndex
number or function will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toArc
transform
string a transform that will be supplied to elements this component renders
Area
VictoryArea uses Area
to represent an entire dataset. Area
renders a <Path/>
element, or a group of paths if the stroke of the area should be rendered in a different style from the filled section of the area. View the source
Props
active
boolean a flag signifying whether the component is activeariaLabel
string or function a prop controlling the aria-label that will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toArea
className
string the class name that will be applied to the rendered pathdata
array the entire dataset used to define the areaevents
object events to attach to the rendered elementgroupComponent
element the element used to group rendered elements default<g/>
id
string or number an id to apply to the rendered componentinterpolation
string or function the interpolation to use when calculating a pathorigin
object the svg coordinates of the center point of a polar chartpolar
boolean a flag specifying whether the component is part of a polar chartpathComponent
element the rendered path element default<Path/>
role
string the aria role to assign to the elementscale
object the x and y scale of the parent chart withdomain
andrange
appliedshapeRendering
string the shape rendering attribute to apply to the rendered pathstyle
object the styles to apply to the rendered elementtabIndex
number or function that will be applied to rendered path. When this prop is given as a function it will be called with the rest of the props supplied toArea
transform
string a transform that will be supplied to elements this component renders
LineSegment
The LineSegment
component renders straight lines. This component is used to render grids, ticks, and axis lines in VictoryAxis. View the source
Props
active
boolean a flag signifying whether the component is activeariaLabel
string or function a prop controlling the aria-label that will be applied to the rendered lineComponent. When this prop is given as a function it will be called with the rest of the props supplied toLineSegment
className
string the class name that will be applied to the rendered elementdata
array the entire datasetdatum
object the data point corresponding to this lineevents
object events to attach to the rendered elementid
string or number an id to apply to the rendered componentindex
number the index of this line within the datasetlineComponent
element the rendered line element default<Line/>
role
string the aria role to assign to the elementshapeRendering
string the shape rendering attribute to apply to the rendered elementsstyle
object the styles to apply to the rendered elementtabIndex
number or funciton will be applied to the rendered lineComponent. When this prop is given as a function it will be called with the rest of the props supplied toLineSegment
transform
string a transform that will be supplied to elements this component rendersx1
number the x coordinate of the beginning of the linex2
number the x coordinate of the end of the liney1
number the y coordinate of the beginning of the liney2
number the y coordinate of the end of the line
Background
The Background
component is used to render an SVG background on VictoryChart. Background
will render a <Circle>
for charts with polar={true}
and a <Rect>
element for all other charts. View the source
Props
className
string the class name that will be applied to the rendered pathcircleComponent
element the rendered circle element default<Circle/>
events
object events to attach to the rendered elementheight
number the height of the<rect/>
elementid
string or number an id to apply to the rendered componentorigin
object the svg coordinates of the center point of a polar chartpolar
boolean a flag specifying whether the component is part of a polar chartrectComponent
element the rendered rect element default<Rect/>
role
string the aria role to assign to the elementrx
number the x radius of the rendered<rect/>
elementry
number the y radius of the rendered<rect/>
elementscale
object the x and y scale of the parent chart withdomain
andrange
appliedshapeRendering
string the shape rendering attribute to apply to the rendered pathstyle
object the styles to apply to the rendered elementwidth
number the width of the<rect/>
elementx
number the x coordinate of the upper-left corner of the background for non-polar charts and center of the background for polar chartsy
number the y coordinate of the top of the background
Bar
VictoryBar uses Bar
to represent a single data point as a bar extending horizontally or vertically from the independent axis. Bar
renders a <Path>
element. It is also used by VictoryHistogram to represent "bins" of data. View the source
Props
active
boolean a flag signifying whether the component is activealignment
*"start", "middle", or "end" specifies how a bar path should be aligned in relation to its data pointariaLabel
string or function a prop controlling the aria-label that will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toBar
barRatio
number a number between zero and one that will be used to calculate bar width when an explicit width is not givenbarWidth
number or function A prop defining the width of the bar. When this prop is given as a function, it will be called with the rest of the props supplied toBar
.className
string the class name that will be applied to the rendered pathcornerRadius
number, function or object the number of pixels of corner radius to apply when calculating a bar path. When this prop is given as a function, it will be called with the rest of the props supplied toBar
. When given as an object, this prop may include values for top, bottom, topLeft, topRight, bottomLeft and bottomRight, with more specific values overriding less specific valuesdata
array the entire datasetdatum
object the data point corresponding to this barevents
object events to attach to the rendered elementid
string or number an id to apply to the rendered componentindex
number the index of this bar within the datasetorigin
object the svg coordinates of the center point of a polar chartpathComponent
element the rendered path element default<Path/>
polar
boolean a flag specifying whether the component is part of a polar chartrole
string the aria role to assign to the elementscale
object the x and y scale of the parent chart withdomain
andrange
appliedshapeRendering
string the shape rendering attribute to apply to the rendered pathstyle
object the styles to apply to the rendered elementtabIndex
number or function number applied to rendered path. When given as a function it will be called with the rest of the props supplied toBar
transform
string a transform that will be supplied to elements this component renderswidth
number the width of parent chart (used to calculate default bar widthstyle.width
is not supplied)x
number the x coordinate of the top of the bary0
number the y coordinate of the baseline of the bary
number the y coordinate of the top of the bar
Box
VictoryLegend uses the Box
component to draw a border around a legend area. Box
renders a <Rect/>
element. View the source
note Box
also exported as Border
Props
active
boolean a flag signifying whether the component is activeariaLabel
string or function a prop that controls the a propcontrollings the aria-label that will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toBox
className
string the class name that will be applied to the rendered elementevents
object events to attach to the rendered elementheight
number the height of the<rect/>
elementid
string or number an id to apply to the rendered componentrectComponent
element the rendered path element default<Rect/>
role
string the aria role to assign to the elementshapeRendering
string the shape rendering attribute to apply to the rendered elementstyle
object the styles to apply to the rendered elementtabIndex
number or function will be applied to the rendered path. When given as a function it will be called with the rest of the props supplied toBox
transform
string a transform that will be supplied to elements this component renderswidth
number the width of the<rect/>
elementx
number the x coordinate of the upper-left corner of the<rect/>
elementy
number the y coordinate of the upper-left corner of the<rect/>
element
Candle
VictoryCandlestick uses Candle
to represent a single data point as a candle. Candle
renders a group with <Rect>
and <Line>
elements. View the source
Props
active
boolean a flag signifying whether the component is activeariaLabel
string or function a prop controlling the aria-label that will be applied to the rendered<Rect>
and<Line>
elements. When this prop is given as a function it will be called with the rest of the props supplied toCandle
candleRatio
number a number between zero and one that will be used to calculate candle width when an explicit width is not givencandleWidth
number or function A prop defining the width of the candle. When this prop is given as a function, it will be called with the rest of the props supplied toCandle
.className
string the class name that will be applied to the rendered elementclose
number the y coordinate of the closing valuedata
array the entire datasetdatum
object the data point corresponding to this candleevents
object events to attach to the rendered elementgroupComponent
element the element used to group rendered elements default<g/>
high
number the y coordinate of the high valueid
string or number an id to apply to the rendered componentindex
number the index of this candle within the datasetlineComponent
element the rendered line element default<Line/>
low
number the y coordinate of the low valueopen
number the y coordinate of the opening valuerectComponent
element the rendered path element default<Rect/>
role
string the aria role to assign to the elementscale
object the x and y scale of the parent chart withdomain
andrange
appliedshapeRendering
string the shape rendering attribute to apply to the rendered elementsstyle
object the styles to apply to the rendered elementtabIndex
number or function a prop controlling the aria-label that will be applied to the rendered<Rect>
and<Line>
elements. When given as a function it will be called with the rest of the props supplied toCandle
transform
string a transform that will be supplied to elements this component renderswidth
number the width of parent chart (used to calculate default candle widthstyle.width
is not supplied)widthStrokeWidth
number the stroke width of the candle wick. (style.strokeWidth will be used when this value is not given)x
number the x coordinate of the candle
Curve
VictoryLine uses Curve
to represent an entire dataset as a line or curve. Curve
renders a <Path>
element. View the source
Props
active
boolean a flag signifying whether the component is activeariaLabel
string or function a prop controlling the aria-label that will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toCurve
className
string the class name that will be applied to the rendered elementdata
array the entire dataset used to define the curveevents
object events to attach to the rendered elementgroupComponent
element the element used to group rendered elements default<g/>
id
string or number an id to apply to the rendered componentinterpolation
string or function the interpolation to use when calculating a pathorigin
object the svg coordinates of the center point of a polar chartpathComponent
element the rendered path element default<Path/>
polar
boolean a flag specifying whether the component is part of a polar chartrole
string the aria role to assign to the elementscale
object the x and y scale of the parent chart withdomain
andrange
appliedshapeRendering
string the shape rendering attribute to apply to the rendered pathstyle
object the styles to apply to the rendered elementtabIndex
number or function will be applied to the rendered path. When given as a function it will be called with the rest of the props supplied toCurve
transform
string a transform that will be supplied to elements this component renders
ErrorBar
VictoryErrorBar uses ErrorBar
to render x and y error bars. ErrorBar
renders a group of <Line>
elements. View the source
Props
active
boolean a flag signifying whether the component is activeariaLabel
string or function a prop controlling the aria-label that will be applied to the group,g
, containing the rendered<Line>
elements. When this prop is given as a function it will be called with the rest of the props supplied toErrorBar
borderWidth
number the width of the cross-hairs on the end of each error bar default: 10className
string the class name that will be applied to the rendered elementdata
array the entire datasetdatum
object the data point corresponding to this error barerrorX
number, array, or boolean errors in the x dimension.errorY
number, array, or boolean errors in the y dimension.events
object events to attach to the rendered elementgroupComponent
element the element used to group rendered elements default<g/>
id
string or number an id to apply to the rendered componentindex
number the index of this error bar within the datasetlineComponent
element the rendered line element default<Line/>
origin
object the svg coordinates of the center point of a polar chartpolar
boolean a flag specifying whether the component is part of a polar chartrole
string the aria role to assign to the elementscale
object the x and y scale of the parent chart withdomain
andrange
appliedshapeRendering
string the shape rendering attribute to apply to the rendered elementsstyle
object the styles to apply to the rendered elementtabIndex
number or function applies to the group,g
, containing the<Line>
elements. When this prop is given as a function it will be called with the rest of the props supplied toErrorBar
transform
string a transform that will be supplied to elements this component rendersx
number the x coordinate of the center of the error bary
number the y coordinate of the center of the error bar
Flyout
VictoryTooltip uses Flyout
to render a flyout style path around text. Flyout
renders <Path>
element. View the source
Props
active
boolean a flag signifying whether the component is activecenter
object the center coordinates of the flyoutclassName
string the class name that will be applied to the rendered elementcornerRadius
number the corner radius of the flyoutdata
array the entire dataset if applicabledatum
object the data point corresponding to this flyout if applicabledx
number offset in the x dimension.dy
number offset in the y dimension.events
object events to attach to the rendered elementheight
number the height of the flyoutid
string or number an id to apply to the rendered componentindex
number the index of this flyout within the datasetorientation
"top", "bottom", "left", "right"origin
object the svg coordinates of the center point of a polar chartpathComponent
element the rendered path element default<Path/>
pointerLength
number the length of the triangular pointerpointerWidth
number the width of the base of the triangular pointerpolar
boolean a flag specifying whether the component is part of a polar chartrole
string the aria role to assign to the elementshapeRendering
string the shape rendering attribute to apply to the rendered elementsstyle
object the styles to apply to the rendered elementtransform
string a transform that will be supplied to elements this component renderswidth
number the width of the flyoutx
number the x coordinate of data point associated with this flyouty
number the y coordinate of data point associated with this flyout
Point
VictoryScatter uses Point
to render each point in a scatter plot. Point
renders a <Path>
element. View the source
Props
active
boolean a flag signifying whether the component is activeariaLabel
string or function a prop controlling the aria-label that will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toPoint
className
string the class name that will be applied to the rendered elementdata
array the entire datasetdatum
object the data point corresponding to this pointevents
object events to attach to the rendered elementgetPath
function a function ofx
,y
, andsize
that returns a path string. When this optional function is provided, it will be used to calculate a path, rather than one of the path functions corresponding to thesymbol
s supported byPoint
.id
string or number an id to apply to the rendered componentindex
number the index of this point within the datasetorigin
object the svg coordinates of the center point of a polar chartpathComponent
element the rendered path element default<Path/>
polar
boolean a flag specifying whether the component is part of a polar chartrole
string the aria role to assign to the elementscale
object the x and y scale of the parent chart withdomain
andrange
appliedshapeRendering
string the shape rendering attribute to apply to the rendered pathsize
number or function the size of the point. When this prop is given as a function, it will be called with the rest of the props supplied toPoint
.style
object the styles to apply to the rendered elementsymbol
"circle", "cross", "diamond", "plus", "minus", "square", "star", "triangleDown", "triangleUp" which symbol the point should render. This prop may also be given as a function that returns one of the above options. When this prop is given as a function, it will be called with the rest of the props supplied toPoint
.tabIndex
number or function number will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toPoint
transform
string a transform that will be supplied to elements this component rendersx
number the x coordinate of the center of the pointy
number the y coordinate of the center of the point
Slice
VictoryPie uses Slice
to render each slice in a pie chart. Slice
renders a <Path>
element. View the source
Props
active
boolean a flag signifying whether the component is activeariaLabel
string or function a prop controlling the aria-label that will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toSlice
className
string the class name that will be applied to the rendered elementcornerRadius
number or function the corner radius to apply to this slice. When this prop is given as a function it will be called with the rest of the props supplied toSlice
.data
array the entire datasetdatum
object the data point corresponding to this sliceevents
object events to attach to the rendered elementid
string or number an id to apply to the rendered componentindex
number the index of this slice within the datasetinnerRadius
number or function the inner radius of the slice. When this prop is given as a function it will be called withdatum
andactive
.padAngle
number or function the angular padding to add to the slice. When this prop is given as a function it will be called with the rest of the props supplied toSlice
.pathComponent
element the rendered path element default<Path/>
pathFunction
function a function that calculates the path of a given slice. When given, this prop will be called with theslice
objectradius
number or function the outer radius of the slice. When this prop is given as a function it will be called with the rest of the props supplied toSlice
.role
string the aria role to assign to the elementshapeRendering
string the shape rendering attribute to apply to the rendered pathslice
object an object specifying the startAngle, endAngle, padAngle, and data of the slicesliceEndAngle
number or function the end angle the slice. When this prop is given as a function it will be called with the rest of the props supplied toSlice
.sliceStartAngle
number or function the start angle of the slice. When this prop is given as a function it will be called with the rest of the props supplied toSlice
.style
object the styles to apply to the rendered elementtabIndex
number or function number will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toSlice
.transform
string a transform that will be supplied to elements this component renders
Voronoi
VictoryVoronoi uses Voronoi
to render voronoi polygons. Voronoi
renders either a <Path>
element corresponding to a voronoi polygon, or a <Circle/>
clipped with a <ClipPath>
defined by the path of the polygon. View the source
Props
active
boolean a flag signifying whether the component is activeariaLabel
string or function a prop controlling the aria-label that will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toVoronoi
circleComponent
element the rendered circle element default<Circle/>
className
string the class name that will be applied to the rendered elementclipPathComponent
element the rendered clipPath element default<ClipPath/>
data
array the entire datasetdatum
object the data point corresponding to this voronoi polygonevents
object events to attach to the rendered elementgroupComponent
element the rendered group element default<g/>
id
string or number an id to apply to the rendered componentindex
number the index of this voronoi polygon within the datasetorigin
object the svg coordinates of the center point of a polar chartpathComponent
element the rendered path element default<Path/>
polar
boolean a flag specifying whether the component is part of a polar chartpolygon
array an array of points defining the polygonrole
string the aria role to assign to the elementshapeRendering
string the shape rendering attribute to apply to the rendered pathsize
number the maximum size of the voronoi polygonstyle
object the styles to apply to the rendered elementtabIndex
number or function will be applied to the rendered path. When this prop is given as a function it will be called with the rest of the props supplied toVoronoi
transform
string a transform that will be supplied to elements this component renders.x
number the x coordinate of the data pointy
number the y coordinate of the data point
Whisker
VictoryBoxPlot uses the Whisker
component to draw whiskers for the minimum and maximum values in a box plot. Whisker
renders a group of <Line/>
elements. View the source
Props
active
boolean a flag signifying whether the component is activeariaLabel
string or function a prop controlling the aria-label that will be applied to the rendered<Line>
elements. When this prop is given as a function it will be called with the rest of the props supplied toWhisker
className
string the class name that will be applied to the rendered elementevents
object events to attach to the rendered elementgroupComponent
element the rendered group element default<g/>
id
string or number an id to apply to the rendered componentlineComponent
element the rendered line element default<Line/>
majorWhisker
object an object with valuesx1
,x2
,y1
,y2
describing the major whisker lineminorWhisker
object an object with valuesx1
,x2
,y1
,y2
describing the minor whisker linerole
string the aria role to assign to the elementshapeRendering
string the shape rendering attribute to apply to the rendered elementstyle
object the styles to apply to the rendered elementtabIndex
number or function will be applied to the rendered<Line>
. When this prop is given as a function it will be called with the rest of the props supplied toWhisker
transform
string a transform that will be supplied to elements this component renders.