VictoryCanvas
The victory-canvas
package currently provides a set of experimental primitive components that will allow Victory to render data in a Canvas container rather than as an SVG.
This API should not be used in production and only serves as an experiment.
Container Components
CanvasGroup
This component is designed to be used as the groupComponent
for any chart type to enable Canvas rendering. This component will create a <canvas />
HTML component, and allow other child components to access the Canvas context via React context.
const MyLine = (props) => (
<VictoryLine groupComponent={<CanvasGroup />} {...props} />
);
Primitive Components
Each of these primitive components depends on the Canvas context that it gets through the useCanvasContext
React hook. Rather than returning a React component, they render elements to the screen through the Canvas context.
CanvasPoint
Designed to be used with VictoryScatter
, this component mimics the behavior of Point
.
const MyScatter = (props) => (
<VictoryScatter
groupComponent={<CanvasGroup />}
dataComponent={<CanvasPoint />}
{...props}
/>
);
Props
active
boolean a flag signifying whether the component is activedata
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
.index
number the index of this point within the datasetorigin
object the svg coordinates of the center point of a polar chartpolar
boolean a flag specifying whether the component is part of a polar chartscale
object the x and y scale of the parent chart withdomain
andrange
appliedsize
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
.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
CanvasCurve
Designed to be used with [VictoryLine][], this component mimics the behavior of Curve
.
const MyLine = (props) => (
<VictoryLine
groupComponent={<CanvasGroup />}
dataComponent={<CanvasLine />}
{...props}
/>
);
Props
active
boolean a flag signifying whether the component is activedata
array the entire dataset used to define the curveevents
object events to attach to the rendered elementinterpolation
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 chartrole
string the aria role to assign to the elementscale
object the x and y scale of the parent chart withdomain
andrange
appliedstyle
object the styles to apply to the rendered elementtransform
string a transform that will be supplied to elements this component renders
CanvasBar
Designed to be used with VictoryBar
, this component mimics the behavior of Bar
.
const Bar = (props) => (
<VictoryBar
groupComponent={<CanvasGroup />}
dataComponent={<CanvasBar />}
{...props}
/>
);
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 pointbarRatio
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
.cornerRadius
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 elementindex
number the index of this bar within the datasetorigin
object the svg coordinates of the center point of a polar chartpolar
boolean a flag specifying whether the component is part of a polar chartscale
object the x and y scale of the parent chart withdomain
andrange
appliedstyle
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 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