From cda990924e9494eef49fbd7e0ec4aa988734041c Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Fri, 30 Sep 2022 11:47:11 +0200 Subject: [PATCH] fix: Correct the logic to enable chart types --- app/charts/index.ts | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/app/charts/index.ts b/app/charts/index.ts index b32b1c566..61472c514 100644 --- a/app/charts/index.ts +++ b/app/charts/index.ts @@ -941,32 +941,31 @@ export const getPossibleChartType = ({ }): ChartType[] => { const { measures, dimensions } = meta; - const hasZeroQ = measures.length === 0; - const hasMultipleQ = measures.length > 1; - const hasGeo = getGeoDimensions(dimensions).length > 0; - const hasTime = getTimeDimensions(dimensions).length > 0; - - const geoBased: ChartType[] = ["map"]; - const catBased: ChartType[] = ["bar", "column", "pie", "table"]; - const multipleQ: ChartType[] = ["scatterplot"]; - const timeBased: ChartType[] = ["line", "area"]; - - let possibles: ChartType[] = []; - if (hasZeroQ) { - possibles = ["table"]; - } else { - possibles.push(...catBased); - - if (hasMultipleQ) { - possibles.push(...multipleQ); + const categoricalDimensions = getCategoricalDimensions(dimensions); + const geoDimensions = getGeoDimensions(dimensions); + const timeDimensions = getTimeDimensions(dimensions); + + const categoricalEnabled: ChartType[] = ["column", "pie"]; + const geoEnabled: ChartType[] = ["column", "map", "pie"]; + const multipleMeasuresEnabled: ChartType[] = ["scatterplot"]; + const timeEnabled: ChartType[] = ["area", "column", "line"]; + + let possibles: ChartType[] = ["table"]; + if (measures.length > 0) { + if (categoricalDimensions.length > 0) { + possibles.push(...categoricalEnabled); } - if (hasTime) { - possibles.push(...timeBased); + if (geoDimensions.length > 0) { + possibles.push(...geoEnabled); } - if (hasGeo) { - possibles.push(...geoBased); + if (measures.length > 1) { + possibles.push(...multipleMeasuresEnabled); + } + + if (timeDimensions.length > 0) { + possibles.push(...timeEnabled); } }