Moving dimension calculation to layout for SVG

This commit is contained in:
Jeff Avallone 2019-01-27 11:48:32 -05:00
parent 35efa7cdb0
commit 67d970c837

View File

@ -21,10 +21,7 @@ const metadata = `<rdf:rdf>
</rdf:rdf>`; </rdf:rdf>`;
/* eslint-enable max-len */ /* eslint-enable max-len */
const SVG = ({ innerWidth, innerHeight, children }) => { const SVG = ({ width, height, children }) => {
const width = Math.round(innerWidth + 2 * padding);
const height = Math.round(innerHeight + 2 * padding);
const svgProps = { const svgProps = {
width, width,
height, height,
@ -43,15 +40,21 @@ const SVG = ({ innerWidth, innerHeight, children }) => {
SVG.propTypes = { SVG.propTypes = {
children: PropTypes.node, children: PropTypes.node,
innerWidth: PropTypes.number, width: PropTypes.number,
innerHeight: PropTypes.number height: PropTypes.number
}; };
const layout = data => { const layout = data => {
const child = data.children[0]; const childBox = data.children[0].box;
data.props.innerWidth = child.box.width; data.box = {
data.props.innerHeight = child.box.height; width: Math.round(childBox.width + 2 * padding),
height: Math.round(childBox.height + 2 * padding)
};
data.props = {
...data.props,
...data.box
};
return data; return data;
}; };