Commit f16a51ab authored by Jeff Avallone's avatar Jeff Avallone

Moving layout function into component module

parent 1ee3055f
import React from 'react';
import ReactDOM from 'react-dom';
import SVG from 'rendering/SVG/layout';
import Text from 'rendering/Text/layout';
import * as SVG from 'rendering/SVG';
import * as Text from 'rendering/Text';
const nodeTypes = {
SVG,
......@@ -20,7 +20,7 @@ const layout = data => {
data.children = data.children.map(layout);
}
return nodeTypes[type]({
return nodeTypes[type].layout({
props: {},
...data
});
......
......@@ -47,4 +47,14 @@ SVG.propTypes = {
innerHeight: PropTypes.number
};
const layout = data => {
const child = data.children[0];
data.props.innerWidth = child.box.width;
data.props.innerHeight = child.box.height;
return data;
};
export default SVG;
export { layout };
const layoutSVG = data => {
const child = data.children[0];
data.props.innerWidth = child.box.width;
data.props.innerHeight = child.box.height;
return data;
};
export default layoutSVG;
import React from 'react';
import PropTypes from 'prop-types';
import { getBBox } from 'layout';
import * as style from './style';
const Text = ({ transform, quoted, children }) => {
......@@ -27,4 +29,14 @@ Text.propTypes = {
]).isRequired
};
const layout = data => {
const {x, y, width, height } = getBBox(
<Text { ...data.props }>{ data.children }</Text>);
data.box = { width, height };
data.props.transform = `translate(${ -x } ${ -y })`;
return data;
};
export default Text;
export { layout };
import React from 'react';
import { getBBox } from 'layout';
import Text from 'rendering/Text';
const layoutText = data => {
const {x, y, width, height } = getBBox(
<Text { ...data.props }>{ data.children }</Text>);
data.box = { width, height };
data.props.transform = `translate(${ -x } ${ -y })`;
return data;
};
export default layoutText;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment