Victory Canvas
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.
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
activeboolean a flag signifying whether the component is activedataarray the entire datasetdatumobject the data point corresponding to this pointeventsobject events to attach to the rendered elementgetPathfunction a function ofx,y, andsizethat 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 thesymbols supported byPoint.indexnumber the index of this point within the datasetoriginobject the svg coordinates of the center point of a polar chartpolarboolean a flag specifying whether the component is part of a polar chartscaleobject the x and y scale of the parent chart withdomainandrangeappliedsizenumber 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.styleobject 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.transformstring a transform that will be supplied to elements this component rendersxnumber the x coordinate of the center of the pointynumber 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
activeboolean a flag signifying whether the component is activedataarray the entire dataset used to define the curveeventsobject events to attach to the rendered elementinterpolationstring or function the interpolation to use when calculating a pathoriginobject the svg coordinates of the center point of a polar chartpolarboolean a flag specifying whether the component is part of a polar chartrolestring the aria role to assign to the elementscaleobject the x and y scale of the parent chart withdomainandrangeappliedstyleobject the styles to apply to the rendered elementtransformstring 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
activeboolean 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 pointbarRationumber a number between zero and one that will be used to calculate bar width when an explicit width is not givenbarWidthnumber 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.cornerRadiusnumber, 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 valuesdataarray the entire datasetdatumobject the data point corresponding to this bareventsobject events to attach to the rendered elementindexnumber the index of this bar within the datasetoriginobject the svg coordinates of the center point of a polar chartpolarboolean a flag specifying whether the component is part of a polar chartscaleobject the x and y scale of the parent chart withdomainandrangeappliedstyleobject the styles to apply to the rendered elementtransformstring a transform that will be supplied to elements this component renderswidthnumber the width of parent chart (used to calculate default bar widthstyle.widthis not supplied)xnumber the x coordinate of the top of the bary0number the y coordinate of the baseline of the barynumber the y coordinate of the top of the bar