diff --git a/src/layout.js b/src/layout.js
index 6b05543..ac57841 100644
--- a/src/layout.js
+++ b/src/layout.js
@@ -1,3 +1,6 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
+
import SVG from 'rendering/SVG/layout';
import Text from 'rendering/Text/layout';
@@ -19,4 +22,20 @@ const layout = data => {
});
};
+const getBBox = content => {
+ const container = document.createElement('div');
+ document.body.appendChild(container);
+
+ ReactDOM.render(
+ , container);
+
+ const box = container.querySelector('svg > g').getBBox();
+ document.body.removeChild(container);
+
+ return box;
+};
+
export default layout;
+export { getBBox };
diff --git a/src/rendering/Text/layout.js b/src/rendering/Text/layout.js
index cfe82e1..da1cdff 100644
--- a/src/rendering/Text/layout.js
+++ b/src/rendering/Text/layout.js
@@ -1,26 +1,14 @@
import React from 'react';
-import ReactDOM from 'react-dom';
+import { getBBox } from 'layout';
import Text from 'rendering/Text';
const layoutText = data => {
- const container = document.createElement('div');
- document.body.appendChild(container);
+ const {x, y, width, height } = getBBox(
+ { data.children });
- ReactDOM.render(
- ,
- container);
-
- const box = container.querySelector('svg > text').getBBox();
- document.body.removeChild(container);
-
- data.box = {
- width: box.width,
- height: box.height
- };
- data.props.transform = `translate(${ -box.x } ${ -box.y })`;
+ data.box = { width, height };
+ data.props.transform = `translate(${ -x } ${ -y })`;
return data;
};