Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

UXW-46 Safari smart scalar truncation (#68248)

Denis Berezin0bba5e8742eb
diff --git a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Smart_Scalar_Dark_Theme.png b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Smart_Scalar_Dark_Theme.png
index edcda06d510..93aea9c535b 100644
Binary files a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Smart_Scalar_Dark_Theme.png and b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Smart_Scalar_Dark_Theme.png differ
diff --git a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Smart_Scalar_Light_Theme.png b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Smart_Scalar_Light_Theme.png
index 1e43f4030b5..9fa98b5fa9d 100644
Binary files a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Smart_Scalar_Light_Theme.png and b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Smart_Scalar_Light_Theme.png differ
diff --git a/.loki/reference/chrome_laptop_viz_SmartScalar_Default.png b/.loki/reference/chrome_laptop_viz_SmartScalar_Default.png
index de13986bab3..805bb992045 100644
Binary files a/.loki/reference/chrome_laptop_viz_SmartScalar_Default.png and b/.loki/reference/chrome_laptop_viz_SmartScalar_Default.png differ
diff --git a/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js b/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js
index 0218f59ef53..c7e8e2fe480 100644
--- a/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js
@@ -775,7 +775,7 @@ describe("issue 29304", () => {
// This extra 1ms is crucial, without this the test would fail.
cy.tick(WAIT_TIME + 1);
- const expectedWidth = 109;
+ const expectedWidth = 130;
cy.findByTestId("scalar-value").should(([$scalarValue]) => {
expect($scalarValue.offsetWidth).to.be.closeTo(
expectedWidth,
@@ -800,7 +800,7 @@ describe("issue 29304", () => {
// This extra 1ms is crucial, without this the test would fail.
cy.tick(WAIT_TIME + 1);
- const expectedWidth = 61;
+ const expectedWidth = 47;
cy.findByTestId("scalar-value").should(([$scalarValue]) => {
expect($scalarValue.offsetWidth).to.be.closeTo(
expectedWidth,
diff --git a/frontend/src/metabase/lib/measure-text.ts b/frontend/src/metabase/lib/measure-text.ts
index 90fbd9eb9e8..66f4c6e93f7 100644
--- a/frontend/src/metabase/lib/measure-text.ts
+++ b/frontend/src/metabase/lib/measure-text.ts
@@ -8,7 +8,15 @@ import type {
let canvas: HTMLCanvasElement | null = null;
export const measureText: TextMeasurer = (text: string, style: FontStyle) => {
- canvas ??= document.createElement("canvas");
+ if (!canvas) {
+ canvas = document.createElement("canvas");
+ document.body.appendChild(canvas);
+ canvas.style.display = "none";
+ canvas.style.fontSize = window.getComputedStyle(
+ document.documentElement,
+ ).fontSize;
+ }
+
const context = canvas.getContext("2d");
if (!context) {
diff --git a/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.tsx b/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.tsx
index 0526f7b9b79..37683fbbefe 100644
--- a/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.tsx
+++ b/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.tsx
@@ -51,7 +51,7 @@ export const ScalarValue = ({
targetWidth: width,
fontFamily: fontFamily ?? "Lato",
fontWeight: 700,
- unit: "em",
+ unit: "rem",
step: 0.2,
min: 1,
max: gridSize
diff --git a/frontend/src/metabase/visualizations/components/ScalarValue/utils.ts b/frontend/src/metabase/visualizations/components/ScalarValue/utils.ts
index 6b255a5a2c1..bf8ec39b723 100644
--- a/frontend/src/metabase/visualizations/components/ScalarValue/utils.ts
+++ b/frontend/src/metabase/visualizations/components/ScalarValue/utils.ts
@@ -5,7 +5,7 @@ interface FindSizeInput {
text: string;
targetHeight: number;
targetWidth: number;
- unit: string;
+ unit: "rem";
fontFamily: string;
fontWeight: string | number;
step: number;
diff --git a/frontend/src/metabase/visualizations/components/ScalarValue/utils.unit.spec.ts b/frontend/src/metabase/visualizations/components/ScalarValue/utils.unit.spec.ts
index c11b8dff780..ab498c010c7 100644
--- a/frontend/src/metabase/visualizations/components/ScalarValue/utils.unit.spec.ts
+++ b/frontend/src/metabase/visualizations/components/ScalarValue/utils.unit.spec.ts
@@ -13,7 +13,7 @@ const createMockMeasureText = (width: number, height: number) => {
const defaults = {
text: "test",
- unit: "rem",
+ unit: "rem" as const,
fontFamily: "Lato",
fontWeight: "900",
};