mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) Fix error bars for bar chart
Summary: The culprit was `series = uniqXValues(series);` because it creates new series objects when they are used as keys to access error bars info (`errorBars.get(line)`). Fixed by making uniqXValues mutating series instead. Test Plan: Adds a case to test error bars with bar charts. Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D3198
This commit is contained in:
parent
50821f655d
commit
89dc9334c3
@ -802,7 +802,7 @@ function basicPlot(series: Series[], options: ChartOptions, dataOptions: Data):
|
||||
// up on hover is different than the value on the y-axis. It seems that one is the sum of all
|
||||
// values with same x-axis value, while the other is the last of them. To fix this, we force
|
||||
// unique values for the x-axis.
|
||||
series = uniqXValues(series);
|
||||
uniqXValues(series);
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -23,15 +23,14 @@ export function sortByXValues(series: Array<{values: Datum[]}>): void {
|
||||
}
|
||||
}
|
||||
|
||||
// creates new version of series that has a duplicate free version of the values in the first one.
|
||||
export function uniqXValues<T extends {values: Datum[]}>(series: Array<T>): Array<T> {
|
||||
if (!series[0]) { return []; }
|
||||
// Makes series so that the values of series[0] are duplicate free.
|
||||
export function uniqXValues<T extends {values: Datum[]}>(series: Array<T>) {
|
||||
if (!series[0]) { return; }
|
||||
const n = series[0].values.length;
|
||||
const indexToKeep = new Set(uniqBy(range(n), (i) => series[0].values[i]));
|
||||
return series.map((line: T) => ({
|
||||
...line,
|
||||
values: line.values.filter((_val, i) => indexToKeep.has(i))
|
||||
}));
|
||||
series.forEach((line: T) => {
|
||||
line.values = line.values.filter((_val, i) => indexToKeep.has(i));
|
||||
});
|
||||
}
|
||||
|
||||
// Creates new version of series that split any entry whose value in the first series is a list into
|
||||
|
Loading…
Reference in New Issue
Block a user