From 3fcf31bc48e836da30a9b9c16c4ab9ba31993091 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Tue, 29 Jan 2019 17:16:09 -0500 Subject: [PATCH] Adjusting font baseline to avoid needing to transform it --- src/rendering/Box/index.js | 9 +-------- src/rendering/Box/style.js | 2 +- src/rendering/Text/index.js | 13 +++---------- src/rendering/Text/style.js | 3 ++- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/rendering/Box/index.js b/src/rendering/Box/index.js index 9fc4498..b8e44d1 100644 --- a/src/rendering/Box/index.js +++ b/src/rendering/Box/index.js @@ -12,7 +12,6 @@ const Box = ({ width, height, rectTransform, - labelTransform, contentTransform, children }) => { @@ -24,14 +23,10 @@ const Box = ({ ry: radius, transform: rectTransform }; - const textProps = { - transform: labelTransform, - style: style.infoText - }; return <> - { label && { label } } + { label && { label } } { children } @@ -51,7 +46,6 @@ Box.propTypes = { width: PropTypes.number, height: PropTypes.number, rectTransform: PropTypes.string, - labelTransform: PropTypes.string, contentTransform: PropTypes.string, children: PropTypes.node }; @@ -75,7 +69,6 @@ const layout = data => { width: data.box.width, height: childBox.height + 2 * padding, rectTransform: `translate(0 ${ labelBox.height })`, - labelTransform: `translate(0 ${ labelBox.height })`, contentTransform: `translate(${ padding } ${ padding + labelBox.height })` }; return data; diff --git a/src/rendering/Box/style.js b/src/rendering/Box/style.js index ada161b..2562008 100644 --- a/src/rendering/Box/style.js +++ b/src/rendering/Box/style.js @@ -34,5 +34,5 @@ export const anchor = { export const infoText = { fontSize: fontSizeSmall, fontFamily: fontFamily, - dominantBaseline: 'text-after-edge' + dominantBaseline: 'text-before-edge' }; diff --git a/src/rendering/Text/index.js b/src/rendering/Text/index.js index a674555..dd44a41 100644 --- a/src/rendering/Text/index.js +++ b/src/rendering/Text/index.js @@ -5,13 +5,8 @@ import { getBBox } from 'layout'; import * as style from './style'; -const Text = ({ transform, quoted, theme, children }) => { - const textProps = { - style: { ...style.text, ...style[theme] }, - transform - }; - - return +const Text = ({ quoted, theme, children }) => { + return { quoted ? <> { children } @@ -23,7 +18,6 @@ const Text = ({ transform, quoted, theme, children }) => { Text.propTypes = { quoted: PropTypes.bool, theme: PropTypes.string, - transform: PropTypes.string, children: PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.node), PropTypes.node @@ -31,11 +25,10 @@ Text.propTypes = { }; const layout = data => { - const {x, y, width, height } = getBBox( + const { width, height } = getBBox( { data.children }); data.box = { width, height }; - data.props.transform = `translate(${ -x } ${ -y })`; return data; }; diff --git a/src/rendering/Text/style.js b/src/rendering/Text/style.js index 3c21a3e..4dfc18a 100644 --- a/src/rendering/Text/style.js +++ b/src/rendering/Text/style.js @@ -1,7 +1,8 @@ import { fontSize, fontFamily, white, grey } from 'rendering/style'; export const text = { - fontSize, fontFamily + fontSize, fontFamily, + dominantBaseline: 'text-before-edge' }; export const anchor = { fill: white