From 5eabc451e9e8e5bd16058812f6d3a515d74b2b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Benitte?= Date: Fri, 8 Sep 2017 23:51:06 +0900 Subject: [PATCH] feat(stream): add border suppport --- src/components/charts/bar/Bar.js | 8 +++---- src/components/charts/stream/Stream.js | 6 ++++- src/components/charts/stream/StreamLayers.js | 25 ++++++++++++++++---- src/components/charts/stream/enhance.js | 6 ++++- src/components/charts/stream/props.js | 10 +++++++- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/components/charts/bar/Bar.js b/src/components/charts/bar/Bar.js index 7ba9de760..2840c4dce 100644 --- a/src/components/charts/bar/Bar.js +++ b/src/components/charts/bar/Bar.js @@ -164,10 +164,10 @@ const Bar = ({ key: bar.key, data: bar, style: { - x: spring(bar.x, motionProps), - y: spring(bar.y, motionProps), - width: spring(bar.width, motionProps), - height: spring(bar.height, motionProps), + x: spring(bar.x, springConfig), + y: spring(bar.y, springConfig), + width: spring(bar.width, springConfig), + height: spring(bar.height, springConfig), }, }))} > diff --git a/src/components/charts/stream/Stream.js b/src/components/charts/stream/Stream.js index 84dbbc3ae..37fd6e291 100644 --- a/src/components/charts/stream/Stream.js +++ b/src/components/charts/stream/Stream.js @@ -40,10 +40,12 @@ const Stream = ({ enableGridX, enableGridY, - // theming + // styling theme, getColor, fillOpacity, + borderWidth, + getBorderColor, // motion animate, @@ -107,6 +109,8 @@ const Stream = ({ - {layers.map(({ id, path, color }, i) => { + {layers.map((layer, i) => { + const { id, path, color } = layer + const handleTooltip = e => showTooltip( , e ) + return ( ) })} @@ -58,12 +67,15 @@ const StreamLayers = ({ return ( - {layers.map(({ id, path, color }, i) => { + {layers.map((layer, i) => { + const { id, path, color } = layer + const handleTooltip = e => showTooltip( , e ) + return ( )} @@ -90,7 +104,8 @@ const StreamLayers = ({ StreamLayers.propTypes = { fillOpacity: PropTypes.number.isRequired, - + borderWidth: PropTypes.number.isRequired, + getBorderColor: PropTypes.func.isRequired, theme: PropTypes.object.isRequired, // motion diff --git a/src/components/charts/stream/enhance.js b/src/components/charts/stream/enhance.js index 267e4b0f8..08953d5cd 100644 --- a/src/components/charts/stream/enhance.js +++ b/src/components/charts/stream/enhance.js @@ -16,7 +16,7 @@ import pure from 'recompose/pure' import withPropsOnChange from 'recompose/withPropsOnChange' import { stackOrderFromProp, stackOffsetFromProp } from '../../../props' import { withTheme, withCurve, withDimensions, withMotion } from '../../../hocs' -import { getColorRange } from '../../../lib/colors' +import { getColorRange, getInheritedColorGenerator } from '../../../lib/colors' import { StreamDefaultProps } from './props' const stackMin = layers => min(layers.reduce((acc, layer) => [...acc, ...layer.map(d => d[0])], [])) @@ -39,6 +39,9 @@ export default Component => withPropsOnChange(['colors'], ({ colors }) => ({ getColor: getColorRange(colors), })), + withPropsOnChange(['borderColor'], ({ borderColor }) => ({ + getBorderColor: getInheritedColorGenerator(borderColor), + })), withPropsOnChange(['keys', 'offsetType', 'order'], ({ keys, offsetType, order }) => ({ stack: d3Stack() .keys(keys) @@ -48,6 +51,7 @@ export default Component => withPropsOnChange( ['stack', 'data', 'width', 'height'], ({ stack, data, width, height }) => { + console.log('compute') const layers = stack(data) layers.forEach(layer => { layer.forEach(point => { diff --git a/src/components/charts/stream/props.js b/src/components/charts/stream/props.js index 56d90fe1a..4e8c79927 100644 --- a/src/components/charts/stream/props.js +++ b/src/components/charts/stream/props.js @@ -31,10 +31,15 @@ export const StreamPropTypes = { enableGridX: PropTypes.bool.isRequired, enableGridY: PropTypes.bool.isRequired, + // border + borderWidth: PropTypes.number.isRequired, + borderColor: PropTypes.any.isRequired, + getBorderColor: PropTypes.func.isRequired, // computed + // theming colors: PropTypes.any.isRequired, fillOpacity: PropTypes.number.isRequired, - getColor: PropTypes.func.isRequired, + getColor: PropTypes.func.isRequired, // computed // interactivity isInteractive: PropTypes.bool, @@ -53,6 +58,9 @@ export const StreamDefaultProps = { enableGridX: true, enableGridY: false, + borderWidth: 3, + borderColor: 'inherit:darker(1)', + // theming colors: 'nivo', fillOpacity: 1,