diff --git a/src/components/ContextChart/index.js b/src/components/ContextChart/index.js index 48635063..27bfe664 100644 --- a/src/components/ContextChart/index.js +++ b/src/components/ContextChart/index.js @@ -89,6 +89,10 @@ const ContextChart = ({ xAxisPlacement, zoomable, }) => { + if (series.length === 0) { + return null; + } + const getYScale = (s, height) => { const domain = firstResolvedDomain( diff --git a/src/components/InteractionLayer/index.js b/src/components/InteractionLayer/index.js index 2496a721..befe4103 100644 --- a/src/components/InteractionLayer/index.js +++ b/src/components/InteractionLayer/index.js @@ -499,6 +499,11 @@ class InteractionLayer extends React.Component { width, zoomAxes, } = this.props; + + if (series.length === 0) { + return null; + } + const { crosshair: { x, y }, points, diff --git a/src/components/Scaler/index.tsx b/src/components/Scaler/index.tsx index c2c580fc..f1109207 100644 --- a/src/components/Scaler/index.tsx +++ b/src/components/Scaler/index.tsx @@ -193,7 +193,7 @@ class Scaler extends React.Component { return updates; }, - { domainsByItemId: {}, subDomainsByItemId: {} } + { domainsByItemId, subDomainsByItemId } ); return updated ? stateUpdates : null; } diff --git a/stories/LineChart.stories.js b/stories/LineChart.stories.js index 1c9b68c9..42e9c252 100644 --- a/stories/LineChart.stories.js +++ b/stories/LineChart.stories.js @@ -31,6 +31,54 @@ storiesOf('LineChart', module) {story()} )) + .add('Empty', () => ( + + + + )) + .add('Dynamic series', () => { + const randomColor = () => + `rgb(${Math.round(Math.random() * 255)},${Math.round( + Math.random() * 255 + )},${Math.round(Math.random() * 255)},1)`; + + class DynamicSeries extends React.Component { + state = { + series: [], + }; + + addSeries = () => + this.setState(({ series }) => ({ + series: [...series, { id: series.length + 1, color: randomColor() }], + })); + + clearSeries = () => this.setState({ series: [] }); + + render() { + const { series } = this.state; + return ( +
+ + + + {series.map(s => ( + + ))} + + +
+ ); + } + } + return ; + }) .add('Basic', () => (