Skip to content

Commit b3c5ae7

Browse files
committed
[IMP] calendar chart: automatically detect calendar chart
If a chart is created on a dataset with dates in the first column and numbers in the second column, we should create a calendar chart by default. Task: 5357420
1 parent a95d9a4 commit b3c5ae7

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/helpers/figures/charts/smart_chart_engine.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function buildSingleColumnChart(column: ColumnInfo, getters: Getters): ChartDefi
165165
* columns left to right, and is as follows:
166166
* - any type + percentage columns: pie chart
167167
* - number + number columns: scatter chart
168-
* - date + number columns: line chart
168+
* - date + number columns: calendar chart
169169
* - text + number columns: treemap if repetition in labels
170170
* - any other combination: bar chart
171171
*/
@@ -198,14 +198,16 @@ function buildTwoColumnChart(columns: ColumnInfo[], getters: Getters): ChartDefi
198198
};
199199
}
200200

201-
// TODO: Handle date + number with calendar chart when implemented (and change the docstring)
202201
if (columns[0].type === "date" && columns[1].type === "number") {
203202
return {
204-
...DEFAULT_LINE_CHART_CONFIG,
205-
type: "line",
203+
type: "calendar",
206204
dataSets: [{ dataRange: getUnboundRange(getters, columns[1].zone) }],
207205
labelRange: getUnboundRange(getters, columns[0].zone),
208206
dataSetsHaveTitle: isDatasetTitled(getters, columns[0]),
207+
title: {},
208+
legendPosition: "none",
209+
horizontalGroupBy: "day_of_week",
210+
verticalGroupBy: "month_number",
209211
};
210212
}
211213

tests/figures/chart/menu_item_insert_chart.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ describe("Smart chart type detection", () => {
502502
[["number", "percentage"], { type: "pie" }],
503503
[["date", "percentage"], { type: "pie" }],
504504
[["number", "number"], { type: "scatter" }],
505-
[["date", "number"], { type: "line" }],
505+
[["date", "number"], { type: "calendar" }],
506506
[["text", "number"], { type: "bar" }],
507507
[["text_repeated", "number"], { type: "treemap" }],
508508
[["text", "date"], { type: "bar" }],

0 commit comments

Comments
 (0)