Skip to content

Commit

Permalink
fix: remove old specs with changed ids (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmacunningham authored Apr 16, 2019
1 parent c780d98 commit 6c4f705
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/specs/area_series.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export class AreaSeriesSpecComponent extends PureComponent<AreaSpecProps> {
const { chartStore, children, ...config } = this.props;
chartStore!.addSeriesSpec({ ...config });
}
componentDidUpdate() {
componentDidUpdate(prevProps: AreaSpecProps) {
const { chartStore, children, ...config } = this.props;
chartStore!.addSeriesSpec({ ...config });
if (prevProps.id !== this.props.id) {
chartStore!.removeSeriesSpec(prevProps.id);
}
}
componentWillUnmount() {
const { chartStore, id } = this.props;
Expand Down
5 changes: 4 additions & 1 deletion src/specs/bar_series.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export class BarSeriesSpecComponent extends PureComponent<BarSpecProps> {
const { chartStore, children, ...config } = this.props;
chartStore!.addSeriesSpec({ ...config });
}
componentDidUpdate() {
componentDidUpdate(prevProps: BarSpecProps) {
const { chartStore, children, ...config } = this.props;
chartStore!.addSeriesSpec({ ...config });
if (prevProps.id !== this.props.id) {
chartStore!.removeSeriesSpec(prevProps.id);
}
}
componentWillUnmount() {
const { chartStore, id } = this.props;
Expand Down
5 changes: 4 additions & 1 deletion src/specs/line_series.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export class LineSeriesSpecComponent extends PureComponent<LineSpecProps> {
const { chartStore, children, ...config } = this.props;
chartStore!.addSeriesSpec({ ...config });
}
componentDidUpdate() {
componentDidUpdate(prevProps: LineSpecProps) {
const { chartStore, children, ...config } = this.props;
chartStore!.addSeriesSpec({ ...config });
if (prevProps.id !== this.props.id) {
chartStore!.removeSeriesSpec(prevProps.id);
}
}
componentWillUnmount() {
const { chartStore, id } = this.props;
Expand Down
10 changes: 8 additions & 2 deletions stories/area_chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ const dateFormatter = timeFormatter('HH:mm');

storiesOf('Area Chart', module)
.add('basic', () => {
const toggleSpec = boolean('toggle area spec', true);
const data1 = KIBANA_METRICS.metrics.kibana_os_load[0].data;
const data2 = data1.map((datum) => [datum[0], datum[1] - 1]);
const data = toggleSpec ? data1 : data2;
const specId = toggleSpec ? 'areas1' : 'areas2';

return (
<Chart renderer="canvas" className={'story-chart'}>
<AreaSeries
id={getSpecId('areas')}
id={getSpecId(specId)}
xScaleType={ScaleType.Time}
yScaleType={ScaleType.Linear}
xAccessor={0}
yAccessors={[1]}
data={KIBANA_METRICS.metrics.kibana_os_load[0].data}
data={data}
yScaleToDataExtent={false}
/>
</Chart>
Expand Down
10 changes: 8 additions & 2 deletions stories/bar_chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ storiesOf('Bar Chart', module)
.add('basic', () => {
const darkmode = boolean('darkmode', false);
const className = darkmode ? 'story-chart-dark' : 'story-chart';
const toggleSpec = boolean('toggle bar spec', true);
const data1 = [{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }];
const data2 = data1.map((datum) => ({ ...datum, y: datum.y - 1 }));
const data = toggleSpec ? data1 : data2;
const specId = toggleSpec ? 'bars1' : 'bars2';

return (
<Chart renderer="canvas" className={className}>
<BarSeries
id={getSpecId('bars')}
id={getSpecId(specId)}
name={'Simple bar series'}
xScaleType={ScaleType.Linear}
yScaleType={ScaleType.Linear}
xAccessor="x"
yAccessors={['y']}
data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]}
data={data}
yScaleToDataExtent={false}
/>
</Chart>
Expand Down
12 changes: 10 additions & 2 deletions stories/line_chart.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { boolean } from '@storybook/addon-knobs';
import { storiesOf } from '@storybook/react';
import React from 'react';
import {
Expand All @@ -15,19 +16,26 @@ import {
} from '../src/';
import { KIBANA_METRICS } from '../src/lib/series/utils/test_dataset_kibana';
import { TSVB_DATASET } from '../src/lib/series/utils/test_dataset_tsvb';

const dateFormatter = timeFormatter(niceTimeFormatByDay(1));

storiesOf('Line Chart', module)
.add('basic', () => {
const toggleSpec = boolean('toggle line spec', true);
const data1 = KIBANA_METRICS.metrics.kibana_os_load[0].data;
const data2 = data1.map((datum) => [datum[0], datum[1] - 1]);
const data = toggleSpec ? data1 : data2;
const specId = toggleSpec ? 'lines1' : 'lines2';

return (
<Chart renderer="canvas" className={'story-chart'}>
<LineSeries
id={getSpecId('lines')}
id={getSpecId(specId)}
xScaleType={ScaleType.Time}
yScaleType={ScaleType.Linear}
xAccessor={0}
yAccessors={[1]}
data={KIBANA_METRICS.metrics.kibana_os_load[0].data}
data={data}
yScaleToDataExtent={false}
/>
</Chart>
Expand Down

0 comments on commit 6c4f705

Please sign in to comment.