mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Fix bars order in chart bars order when multiseries is on.
Summary:
- Grouping series may result in series with inconsistent number of values. This can result in inconsistent ordering of the bars displayed by plotly.
- This diff fixes it by consolidating grouped series by adding unll values for each missing xvalues in the series.
Here a is a minimal example of that bug:
{F36639}
Test Plan: Includes new nbrowser test.
Reviewers: paulfitz
Reviewed By: paulfitz
Differential Revision: https://phab.getgrist.com/D3085
This commit is contained in:
@@ -60,3 +60,28 @@ export function splitValuesByIndex<T extends {values: Datum[]}>(series: Array<T>
|
||||
return {...s, values};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure series[0].values includes all of the values in xvalues and that they appears in the
|
||||
* same order. 0 is used to fill missing values in series[i].values for i > 1 (making function
|
||||
* suited only for numeric series AND only to use with for bar charts). Function does mutate series.
|
||||
*
|
||||
* Note it would make more sense to pad missing values with `null`, but plotly handles null the same
|
||||
* as missing values. Hence we're padding with 0.
|
||||
*/
|
||||
export function consolidateValues(series: Array<{values: Datum[]}>, xvalues: Datum[]) {
|
||||
let i = 0;
|
||||
for (const xval of xvalues) {
|
||||
if (i < series[0].values.length && xval !== series[0].values[i]
|
||||
|| i > series[0].values.length - 1) {
|
||||
series[0].values.splice(i, 0, xval);
|
||||
for (let j = 1; j < series.length; ++j) {
|
||||
series[j].values.splice(i, 0, 0);
|
||||
}
|
||||
}
|
||||
while (xval === series[0].values[i] && i < series[0].values.length) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return series;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user