The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
UXW-77 fix missing bar chart labels for 12 months timeseries (#67316)
Denis Berezincf9868d50980
diff --git a/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_No_Good_Axis_Split.png b/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_No_Good_Axis_Split.pngindex 93bb45bb18e..d77d7ce1474 100644Binary files a/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_No_Good_Axis_Split.png and b/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_No_Good_Axis_Split.png differdiff --git a/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.js b/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.jsindex 135e8453e54..d4450077be6 100644--- a/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.js+++ b/e2e/test/scenarios/visualizations-charts/bar_chart.cy.spec.js@@ -1042,4 +1042,47 @@ describe("scenarios > visualizations > bar chart", () => {cy.findByText("87.5%").should("exist");});});++ it("should display all axis labels for 12 months of data (metabase#60475)", () => {+ cy.viewport(1600, 800);++ // Create a bar chart showing count of orders by month for the last 12 months+ H.visitQuestionAdhoc({+ display: "bar",+ dataset_query: {+ type: "query",+ query: {+ "source-table": ORDERS_ID,+ aggregation: [["count"]],+ breakout: [+ [+ "field",+ ORDERS.CREATED_AT,+ { "base-type": "type/DateTime", "temporal-unit": "month" },+ ],+ ],+ filter: [+ "time-interval",+ ["field", ORDERS.CREATED_AT, { "base-type": "type/DateTime" }],+ -12,+ "month",+ ],+ },+ database: SAMPLE_DB_ID,+ },+ });++ // Wait for the chart to render+ cy.wait("@dataset");+ H.echartsContainer().should("be.visible");++ // Get all x-axis labels+ H.echartsContainer().within(() => {+ // ECharts renders axis labels as text elements in SVG+ // We should see labels for all 12 months+ cy.get('svg text[text-anchor="middle"]')+ .should("have.length.at.least", 12)+ .should("be.visible");+ });+ });});diff --git a/frontend/src/metabase/visualizations/echarts/cartesian/option/ticks.ts b/frontend/src/metabase/visualizations/echarts/cartesian/option/ticks.tsindex 114cd9a40d8..3cd1923f13e 100644--- a/frontend/src/metabase/visualizations/echarts/cartesian/option/ticks.ts+++ b/frontend/src/metabase/visualizations/echarts/cartesian/option/ticks.ts@@ -90,6 +90,18 @@ export const getTicksOptions = (});}+ // HACK: For monthly ticks, we need to handle variable month lengths.+ // Setting a fixed minInterval causes ECharts to skip months because some months+ // (like February with 28 days) are shorter than others (31 days).+ // Instead, we force ECharts to generate daily ticks and filter to month starts.+ if (largestInterval.unit === "month") {+ canRender = (date: Dayjs) => isWithinRange(date) && date.date() === 1;+ maxInterval = getTimeSeriesIntervalDuration({+ count: 1,+ unit: "day",+ });+ }+// HACK: Similarly to weekly ticks, ECharts does not support quarterly ticks natively.// If we let ECharts select ticks for quarterly data it can pick January and March which// will look like a duplication because both ticks will be formatted as Q1. So we need to