From 67d970c83762d3bd2e840de5a11a1ce9cdc9e09d Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Sun, 27 Jan 2019 11:48:32 -0500 Subject: [PATCH] Moving dimension calculation to layout for SVG --- src/rendering/SVG/index.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/rendering/SVG/index.js b/src/rendering/SVG/index.js index 551fa08..17eb69f 100644 --- a/src/rendering/SVG/index.js +++ b/src/rendering/SVG/index.js @@ -21,10 +21,7 @@ const metadata = ` `; /* eslint-enable max-len */ -const SVG = ({ innerWidth, innerHeight, children }) => { - const width = Math.round(innerWidth + 2 * padding); - const height = Math.round(innerHeight + 2 * padding); - +const SVG = ({ width, height, children }) => { const svgProps = { width, height, @@ -43,15 +40,21 @@ const SVG = ({ innerWidth, innerHeight, children }) => { SVG.propTypes = { children: PropTypes.node, - innerWidth: PropTypes.number, - innerHeight: PropTypes.number + width: PropTypes.number, + height: PropTypes.number }; const layout = data => { - const child = data.children[0]; + const childBox = data.children[0].box; - data.props.innerWidth = child.box.width; - data.props.innerHeight = child.box.height; + data.box = { + width: Math.round(childBox.width + 2 * padding), + height: Math.round(childBox.height + 2 * padding) + }; + data.props = { + ...data.props, + ...data.box + }; return data; };