From 89dc9334c3656dd098762ebff90c68951dad3453 Mon Sep 17 00:00:00 2001 From: Cyprien P Date: Mon, 3 Jan 2022 10:14:06 +0100 Subject: [PATCH] (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 --- app/client/components/ChartView.ts | 2 +- app/client/lib/chartUtil.ts | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/client/components/ChartView.ts b/app/client/components/ChartView.ts index 58d070d6..8c67fc87 100644 --- a/app/client/components/ChartView.ts +++ b/app/client/components/ChartView.ts @@ -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 { diff --git a/app/client/lib/chartUtil.ts b/app/client/lib/chartUtil.ts index cf76f177..a98ba2c5 100644 --- a/app/client/lib/chartUtil.ts +++ b/app/client/lib/chartUtil.ts @@ -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(series: Array): Array { - if (!series[0]) { return []; } +// Makes series so that the values of series[0] are duplicate free. +export function uniqXValues(series: Array) { + 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