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
Fix: very low percentages can collide with the y-axis when there are lots of decimals (#67219)
github-actions[bot]b99d3d186dd0
diff --git a/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_Image_Cut_Off_37275.png b/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_Image_Cut_Off_37275.pngindex aa4a4ecd2da..f1bddbe7346 100644Binary files a/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_Image_Cut_Off_37275.png and b/.loki/reference/chrome_laptop_Viz_Static_Viz_ComboChart_Image_Cut_Off_37275.png differdiff --git a/e2e/test/scenarios/visualizations-charts/visualizations-charts-reproductions.cy.spec.ts b/e2e/test/scenarios/visualizations-charts/visualizations-charts-reproductions.cy.spec.tsindex fed8f5723af..c7f96e3c0df 100644--- a/e2e/test/scenarios/visualizations-charts/visualizations-charts-reproductions.cy.spec.ts+++ b/e2e/test/scenarios/visualizations-charts/visualizations-charts-reproductions.cy.spec.ts@@ -1,5 +1,5 @@const { H } = cy;-import { SAMPLE_DB_ID } from "e2e/support/cypress_data";+import { SAMPLE_DB_ID, WRITABLE_DB_ID } from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import type { StructuredQuestionDetails } from "e2e/support/helpers";@@ -531,3 +531,90 @@ union all select 'Medium length category', 30 as count`;});});});++describe("issue 55853", () => {+ const questionDetails = {+ name: "55853",+ database: WRITABLE_DB_ID,+ native: {+ query: `select 'Category A' as category, 0.0001 as value union all+ select 'Category B' as category, 0.0002 as value union all+ select 'Category C' as category, 0.00015 as value union all+ select 'Category D' as category, 0.00025 as value`,+ "template-tags": {},+ },+ display: "bar",+ visualization_settings: {+ "graph.dimensions": ["category"],+ "graph.metrics": ["value"],+ column_settings: {+ '["name","value"]': {+ number_style: "percent",+ },+ },+ },+ };++ beforeEach(() => {+ H.restore("postgres-12");+ cy.signInAsAdmin();+ });++ it("should not have y-axis labels colliding with very low percentages (metabase#55853)", () => {+ H.createNativeQuestion(questionDetails, { visitQuestion: true });++ cy.log("Verify that the chart renders successfully");+ H.echartsContainer().should("be.visible");+ H.echartsContainer().get("text").should("contain", "%");+ H.chartPathWithFillColor("#88BF4D").should("have.length", 4);++ cy.log("Check that axis labels and title don't overlap");+ H.echartsContainer()+ .get("text")+ .then(($texts) => {+ const percentTexts: Array<{ text: string; element: HTMLElement }> = [];+ const axisTitle: Array<{ text: string; element: HTMLElement }> = [];++ $texts.each((i, el) => {+ const text = (el as HTMLElement).textContent?.trim() || "";+ if (text.includes("%") && text !== "value") {+ percentTexts.push({ text, element: el as HTMLElement });+ }+ if (text === "value") {+ axisTitle.push({ text, element: el as HTMLElement });+ }+ });++ cy.log("Verify we have percentage labels");+ expect(percentTexts.length).to.be.greaterThan(0);++ cy.log("Check that axis labels and title don't overlap");+ if (axisTitle.length > 0 && percentTexts.length > 0) {+ const titleRect = axisTitle[0].element.getBoundingClientRect();++ percentTexts.forEach(({ text, element }) => {+ const labelRect = element.getBoundingClientRect();++ expect(+ labelRect.left - titleRect.right,+ `Label "${text}" should not overlap with axis title "${axisTitle[0].text}"`,+ ).to.be.greaterThan(5);+ });+ }+ });++ cy.log(+ "Verify tooltips show correct percentage values (not incorrectly rounded)",+ );+ H.chartPathWithFillColor("#88BF4D").first().realHover();+ H.assertEChartsTooltip({+ header: "Category A",+ rows: [+ {+ name: "value",+ value: "0.01%",+ },+ ],+ });+ });+});diff --git a/frontend/src/metabase/visualizations/echarts/cartesian/chart-measurements/index.ts b/frontend/src/metabase/visualizations/echarts/cartesian/chart-measurements/index.tsindex 42e09fcc2bc..40301192fe5 100644--- a/frontend/src/metabase/visualizations/echarts/cartesian/chart-measurements/index.ts+++ b/frontend/src/metabase/visualizations/echarts/cartesian/chart-measurements/index.ts@@ -57,8 +57,6 @@ const getEvenlySpacedIndices = (return Array.from(result);};-const roundToHundredth = (value: number) => Math.ceil(value * 100) / 100;-const getValuesToMeasure = (min: number, max: number): number[] => {if (min === max) {return [min];@@ -132,9 +130,8 @@ const getYAxisTicksWidth = (settings.column?.(axisModel.column).number_style === "percent";let value = rawValue;- if (isPercent) {- value = roundToHundredth(rawValue);- } else if (!areDecimalTicksExpected) {++ if (!isPercent && !areDecimalTicksExpected) {value = Math.round(rawValue);}