vx responsive svg
npm install @vx/responsiveThe @vx/responsive package is here to help you make responsive graphs.
With Enhancers
withScreenSize
withParentSize
With Components
ParentSize
ScaleSVG
withScreenSizeIf you would like your graph to adapt to the screen size, you can use withScreenSize(). The
resulting component will pass screenWidth and screenHeight props to the wrapped component
containing the respective screen dimensions.
``js
import { withScreenSize } from '@vx/responsive';
// or
// import * as Responsive from '@vx/responsive';
// Responsive.withScreenSize(...);
let chartToRender = withScreenSize(MySuperCoolVxChart);
// ... Render the chartToRender somewhere
`
If you would like your graph to adapt to it's parent component's size, you can use
withParentSize(). The resulting component will pass parentWidth and parentHeight props to the
wrapped component containing the respective parent's dimensions.
`js
import { withParentSize } from '@vx/responsive';
// or
// import * as Responsive from '@vx/responsive';
// Responsive.withParentSize(...);
let chartToRender = withParentSize(MySuperCoolVxChart);
// ... Render the chartToRender somewhere
`
You might do the same thing using the ParentSize component.
`js
import { ParentSize } from '@vx/responsive';
// or
// import * as Responsive from '@vx/responsive';
//
let chartToRender = (
{parent => (
parentHeight={parent.height}
parentTop={parent.top}
parentLeft={parent.left}
// this is the referer to the wrapper component
parentRef={parent.ref}
// this function can be called inside MySuperCoolVxChart to cause a resize of the wrapper component
resizeParent={parent.resize}
/>
)}
);
// ... Render the chartToRender somewhere
`
You can also create a responsive chart with a specific viewBox with the ScaleSVG component.
`js
import { ScaleSVG } from '@vx/responsive';
// or
// import * as Responsive from '@vx/responsive';
//
let chartToRender = (
);
// ... Render the chartToRender somewhere
`
```
npm install --save @vx/responsive