(core) Fix chart mixing up axis

Summary:
Diff fixes couple edge cases:
 - When changing chart's groupby columns, the data-engine changes the view fields, which is not okay with charts, hence makes sure view fields stay the same as much as possible using `this.setSectionViewFieldsFromArray()`
 - Also there's a logic in `this.setSectionViewFieldsFromArray()` that handle what to do when some columns goes missing during updates. Diff fixes this logic two. This is really corner case.

Test Plan: Both cases are not added to ChartAggregate.ts

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3405
This commit is contained in:
Cyprien P 2022-05-10 17:35:42 +02:00
parent 4408315f2e
commit 87cc7d755d

View File

@ -595,6 +595,7 @@ export class GristDoc extends DisposableWithEvents {
const docData = this.docModel.docData;
const oldVal: IPageWidget = toPageWidget(section);
const viewModel = section.view();
const colIds = section.viewFields().all().map((f) => f.column().colId());
if (isEqual(oldVal, newVal)) {
// nothing to be done
@ -621,6 +622,10 @@ export class GristDoc extends DisposableWithEvents {
await docData.sendAction(
['UpdateSummaryViewSection', section.getRowId(), newVal.columns]
);
// Charts needs to keep view fields consistent across update.
if (newVal.type === 'chart' && oldVal.type === 'chart') {
await this.setSectionViewFieldsFromArray(section, colIds);
}
}
// update link
@ -650,13 +655,15 @@ export class GristDoc extends DisposableWithEvents {
// If split series and/or x-axis do not exist any more in new table, update options to make them
// undefined
if (!mapColIdToColumn.has(colIds[0])) {
if (colIds.length) {
if (section.optionsObj.prop('multiseries')()) {
await section.optionsObj.prop('multiseries').saveOnly(false);
if (!mapColIdToColumn.has(colIds[0])) {
await section.optionsObj.prop('multiseries').saveOnly(false);
}
if (colIds.length > 1 && !mapColIdToColumn.has(colIds[1])) {
await section.optionsObj.prop('isXAxisUndefined').saveOnly(true);
}
} else {
} else if (!mapColIdToColumn.has(colIds[0])) {
await section.optionsObj.prop('isXAxisUndefined').saveOnly(true);
}
}