Skip to content

An error is thrown when removing a series from an AreaChart #645

@Gin-Quin

Description

@Gin-Quin

After removing a series, in the AreaChart.svelte component, an error is throw here:

      const stackData = stack()
        .keys(seriesKeys) // <-- the removed series is still in seriesKeys
        .value((d, key) => {
          const s = series.find((d) => d.key === key)!;  // <-- no result here
          const value = accessor(s.value ?? y ?? s.key)(d as any);  // s.value then crashes
          return value;
        })

There seems to be an async issue between the series and the data. I.e. I update both of them at the same time in my code, but when I add logs, I can see that, for example, when I add a new series:

  1. seriesKeys does not contain the new series yet
  2. the data has the right values
  3. then, the same code is called immediately, this time with seriesKeys being correctly updated

This is harmless when adding a new series, but this crashes when removing a series.

I patched the library to transform this line of code:

- const seriesKeys = seriesState.visibleSeries.map((s) => s.key);
+ const seriesKeys = seriesState.visibleSeries.map((s) => s.key).filter(key => _chartData.some(data => key in data));

To make sure there is "extra" series keys that with no data associated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions