From 1b4580d92efb53af4995787263d23b58027c761c Mon Sep 17 00:00:00 2001 From: Cyprien P Date: Wed, 19 Jan 2022 12:13:18 +0100 Subject: [PATCH] (core) Fix error when creating chart with a single column Summary: The routine that makes sure that new charts are created with at least one non-numeric series did not handle correctly when the table has one single column. This diff fixes it. Test Plan: Adds test case to ChartView3.ts Reviewers: alexmojaki Reviewed By: alexmojaki Subscribers: alexmojaki, jarek Differential Revision: https://phab.getgrist.com/D3224 --- app/client/components/GristDoc.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/client/components/GristDoc.ts b/app/client/components/GristDoc.ts index 33e8018d..c56b8768 100644 --- a/app/client/components/GristDoc.ts +++ b/app/client/components/GristDoc.ts @@ -925,12 +925,17 @@ export class GristDoc extends DisposableWithEvents { } /** - * Makes sure sure that the first y-series (ie: the view fields at index 1) is a numeric - * series. Does not handle chart with the group by option on: it is only intended to be used to - * make sure that newly created chart do have a visible y series. + * Makes sure that the first y-series (ie: the view fields at index 1) is a numeric series. Does + * not handle chart with the group by option on: it is only intended to be used to make sure that + * newly created chart do have a visible y series. */ private async _ensureOneNumericSeries(id: number) { const viewSection = this.docModel.viewSections.getRowModel(id); + const viewFields = viewSection.viewFields.peek().peek(); + + // If no y-series, then simply return. + if (viewFields.length === 1) { return; } + const field = viewSection.viewFields.peek().peek()[1]; if (isNumericOnly(viewSection.chartTypeDef.peek()) && !isNumericLike(field.column.peek())) {