Skip to content

Old series spec configuration remains when spec id is changed #158

@emmacunningham

Description

@emmacunningham

Describe the bug
When a SeriesSpec id is changed, the chart updates with the new spec configurations but the older spec configurations also exist as a separate copy. This is most noticeable when switching data sources; if you switch data sources and also update the spec id, you will see both data sets in the chart.

This is because on componentDidUpdate, we update the series specs by adding the updated spec to chartStore.seriesSpecs with the specId; if no specId changes are involved, the chart will update correctly. But when the specId changes too (see the code example below), then the original spec does not get updated. A first pass basic fix would be to check on update if the specId has changed; if it has, remove the previous spec from map before adding the updated spec with the new specId.

To Reproduce
Steps to reproduce the behavior:

  1. Add a SeriesSpec w/ a specId (e.g. 'foo')
  2. Toggle data source & also on toggle, change the specId (e.g. 'bar')
  3. See that the old data source is still in the chart along with the new one.

Example spec:

const MyChart = () => {
  const [isUpdated, update] = useState(false);
  return (
    <>
      <Chart renderer="canvas" className={'story-chart'}>
        <LineSeries
          id={getSpecId(isUpdated ? 'lines2' : 'lines')}
          xScaleType={ScaleType.Time}
          yScaleType={ScaleType.Linear}
          xAccessor={0}
          yAccessors={[1]}
          data={
            isUpdated
              ? KIBANA_METRICS.metrics.kibana_os_load[0].data.map(([ts, val]) => [ts, val / 4])
              : KIBANA_METRICS.metrics.kibana_os_load[0].data
          }
          yScaleToDataExtent={false}
        />
      </Chart>
      <button onClick={() => update(true)}>Update</button>
    </>
  );
};

Expected behavior
Updated spec should replace previous spec; in this screenshot below, there should only be one line.

Screenshots

series_switch

Version (please complete the following information):

  • OS: Mac 10.14.1 (will affect all OS)
  • Browser: Firefox 65.0.1 (will affect all browsers)
  • Elastic Charts: v3.8.0

Additional context

Errors in browser console
N/A

Kibana Cross Issues
N/A

Checklist

  • every related Kibana issue is listed under Kibana Cross Issues list
  • kibana cross issue tag is associated to the issue if any kibana cross issue is present

Metadata

Metadata

Labels

bugSomething isn't workingreleasedIssue released publicly

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions