Moving layout function into component module
This commit is contained in:
parent
1ee3055f37
commit
f16a51abcb
@ -1,8 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
import SVG from 'rendering/SVG/layout';
|
import * as SVG from 'rendering/SVG';
|
||||||
import Text from 'rendering/Text/layout';
|
import * as Text from 'rendering/Text';
|
||||||
|
|
||||||
const nodeTypes = {
|
const nodeTypes = {
|
||||||
SVG,
|
SVG,
|
||||||
@ -20,7 +20,7 @@ const layout = data => {
|
|||||||
data.children = data.children.map(layout);
|
data.children = data.children.map(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodeTypes[type]({
|
return nodeTypes[type].layout({
|
||||||
props: {},
|
props: {},
|
||||||
...data
|
...data
|
||||||
});
|
});
|
||||||
|
@ -47,4 +47,14 @@ SVG.propTypes = {
|
|||||||
innerHeight: PropTypes.number
|
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 default SVG;
|
||||||
|
export { layout };
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
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;
|
|
@ -1,6 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
import { getBBox } from 'layout';
|
||||||
|
|
||||||
import * as style from './style';
|
import * as style from './style';
|
||||||
|
|
||||||
const Text = ({ transform, quoted, children }) => {
|
const Text = ({ transform, quoted, children }) => {
|
||||||
@ -27,4 +29,14 @@ Text.propTypes = {
|
|||||||
]).isRequired
|
]).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 default Text;
|
||||||
|
export { layout };
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
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;
|
|
Loading…
Reference in New Issue
Block a user