Skip to content

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

Number and Trend cards UI tweaks 4 and 5 (#84599)

Denis Berezindc1517ce24e9
diff --git a/.loki/reference/chrome_laptop_App_Embed_DashCardMenuButton_States.png b/.loki/reference/chrome_laptop_App_Embed_DashCardMenuButton_States.png
index b3dd3a8c0cc..15ba0bf4024 100644
Binary files a/.loki/reference/chrome_laptop_App_Embed_DashCardMenuButton_States.png and b/.loki/reference/chrome_laptop_App_Embed_DashCardMenuButton_States.png differ
diff --git a/.loki/reference/chrome_laptop_viz_Scalar_Long_Values.png b/.loki/reference/chrome_laptop_viz_Scalar_Long_Values.png
new file mode 100644
index 00000000000..a0717fcb02e
Binary files /dev/null and b/.loki/reference/chrome_laptop_viz_Scalar_Long_Values.png differ
diff --git a/.loki/reference/chrome_laptop_viz_SmartScalar_Dashcard_Long_Value.png b/.loki/reference/chrome_laptop_viz_SmartScalar_Dashcard_Long_Value.png
new file mode 100644
index 00000000000..f9c1cc764b2
Binary files /dev/null and b/.loki/reference/chrome_laptop_viz_SmartScalar_Dashcard_Long_Value.png differ
diff --git a/.loki/reference/chrome_laptop_viz_SmartScalar_Dashcard_Multiple_Comparisons.png b/.loki/reference/chrome_laptop_viz_SmartScalar_Dashcard_Multiple_Comparisons.png
index b8729391549..af6a9c3db9c 100644
Binary files a/.loki/reference/chrome_laptop_viz_SmartScalar_Dashcard_Multiple_Comparisons.png and b/.loki/reference/chrome_laptop_viz_SmartScalar_Dashcard_Multiple_Comparisons.png differ
diff --git a/.loki/reference/chrome_laptop_viz_SmartScalar_Default.png b/.loki/reference/chrome_laptop_viz_SmartScalar_Default.png
index 38fcbcdafe3..9b7e1a40f99 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/.loki/reference/chrome_laptop_viz_SmartScalar_Embedding_Theme.png b/.loki/reference/chrome_laptop_viz_SmartScalar_Embedding_Theme.png
index 2ee3f52530f..6b2173a37d9 100644
Binary files a/.loki/reference/chrome_laptop_viz_SmartScalar_Embedding_Theme.png and b/.loki/reference/chrome_laptop_viz_SmartScalar_Embedding_Theme.png differ
diff --git a/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.js b/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.js
index 65be744c9ba..a363343df2a 100644
--- a/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.js
+++ b/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.js
@@ -668,6 +668,7 @@ describe("issue 31628", () => {
.then((ids) => cy.get(`[data-dashcard-key="${ids[index]}"]`));
const scalarContainer = (card) => card.findByTestId("scalar-container");
+ const scalarValue = (card) => card.findByTestId("scalar-value");
const previousValue = (card) => card.findByTestId("scalar-previous-value");
const moveMouseAway = () => {
@@ -738,7 +739,7 @@ describe("issue 31628", () => {
H.getDashboardCards().should("have.length", cards.length);
cy.log("scalar 1x2: should truncate value and show value tooltip on hover");
- scalarContainer(card("scalar1x2")).then(($element) =>
+ scalarValue(card("scalar1x2")).then(($element) =>
H.assertIsEllipsified($element[0]),
);
//TODO: Need to hover on the actual text, not just the container. This is a weird one
@@ -747,7 +748,7 @@ describe("issue 31628", () => {
moveMouseAway();
cy.log("scalar 2x2: should not truncate value");
- scalarContainer(card("scalar2x2")).then(($element) =>
+ scalarValue(card("scalar2x2")).then(($element) =>
H.assertIsNotEllipsified($element[0]),
);
cy.log("scalar 2x2: should keep the title visible without hovering");
@@ -762,7 +763,7 @@ describe("issue 31628", () => {
cy.log(
"scalar 6x3: should not truncate value and should not show value tooltip on hover",
);
- scalarContainer(card("scalar6x3")).then(($element) =>
+ scalarValue(card("scalar6x3")).then(($element) =>
H.assertIsNotEllipsified($element[0]),
);
scalarContainer(card("scalar6x3")).realHover();
@@ -770,7 +771,7 @@ describe("issue 31628", () => {
moveMouseAway();
cy.log("smart scalar 2x2: should not truncate value");
- scalarContainer(card("smart2x2")).then(($element) =>
+ scalarValue(card("smart2x2")).then(($element) =>
H.assertIsNotEllipsified($element[0]),
);
cy.log("smart scalar 2x2: should keep the title visible without hovering");
@@ -829,7 +830,7 @@ describe("issue 31628", () => {
cy.log(
`${key}: should not truncate value and should not show value tooltip on hover`,
);
- scalarContainer(card(key)).then(($element) =>
+ scalarValue(card(key)).then(($element) =>
H.assertIsNotEllipsified($element[0]),
);
scalarContainer(card(key)).realHover();
diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCard.module.css b/frontend/src/metabase/dashboard/components/DashCard/DashCard.module.css
index 128dbb11af8..84665622410 100644
--- a/frontend/src/metabase/dashboard/components/DashCard/DashCard.module.css
+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCard.module.css
@@ -21,12 +21,9 @@
scroll-margin: 6px 0;
border-radius: 0.75rem;
border: 1px solid var(--mb-color-border-neutral);
- transition: border-color 0.15s ease-in-out;
&:hover {
--scalar-description-opacity: 1;
-
- border-color: var(--mb-color-border-neutral-strong);
}
&.isAction {
diff --git a/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.module.css b/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.module.css
index 44abd3069dd..ff5c93e10e8 100644
--- a/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.module.css
+++ b/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.module.css
@@ -1,5 +1,14 @@
.value {
- display: inline;
+ /* shrinks to the text so the parent can center it, and once the text is
+ wider than the card it fills the width and truncates from the end */
+ display: inline-block;
+ max-width: 100%;
+ vertical-align: top;
+ text-align: start;
+ /* clip only horizontally so deep descenders still render (metabase#72443) */
+ overflow-x: clip;
+ overflow-y: visible;
+ text-overflow: ellipsis;
color: var(--scalar-value-color, inherit);
}
diff --git a/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.tsx b/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.tsx
index e3d49676848..8c2a895e4e1 100644
--- a/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.tsx
+++ b/frontend/src/metabase/visualizations/components/ScalarValue/ScalarValue.tsx
@@ -39,31 +39,32 @@ interface ScalarValueProps {
disableHover?: boolean;
}
-export const ScalarValue = ({
- value,
- fontSize,
- color = "inherit",
- disableHover,
-}: ScalarValueProps) => {
- const {
- other: { number: numberTheme },
- } = useMantineTheme();
+export const ScalarValue = forwardRef<HTMLHeadingElement, ScalarValueProps>(
+ function ScalarValue(
+ { value, fontSize, color = "inherit", disableHover },
+ ref,
+ ) {
+ const {
+ other: { number: numberTheme },
+ } = useMantineTheme();
- return (
- <Box
- component="h1"
- className={cx(
- DashboardS.ScalarValue,
- S.value,
- !disableHover && S.hoverable,
- )}
- fz={numberTheme?.value?.fontSize ?? fontSize}
- lh={numberTheme?.value?.lineHeight ?? 1}
- data-testid="scalar-value"
- // Route color through a CSS variable so `S.hoverable:hover` can override (inline `style` would beat the class on specificity).
- style={{ "--scalar-value-color": color }}
- >
- {value ?? t`null`}
- </Box>
- );
-};
+ return (
+ <Box
+ component="h1"
+ ref={ref}
+ className={cx(
+ DashboardS.ScalarValue,
+ S.value,
+ !disableHover && S.hoverable,
+ )}
+ fz={numberTheme?.value?.fontSize ?? fontSize}
+ lh={numberTheme?.value?.lineHeight ?? 1}
+ data-testid="scalar-value"
+ // Route color through a CSS variable so `S.hoverable:hover` can override (inline `style` would beat the class on specificity).
+ style={{ "--scalar-value-color": color }}
+ >
+ {value ?? t`null`}
+ </Box>
+ );
+ },
+);
diff --git a/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.stories.tsx b/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.stories.tsx
index 3cd756dc991..f1fc45d2b3a 100644
--- a/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.stories.tsx
+++ b/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.stories.tsx
@@ -3,11 +3,15 @@ import createAsyncCallback from "@loki/create-async-callback";
import { expect, userEvent, within } from "@storybook/test";
import { VisualizationWrapper } from "__support__/storybook";
-import { NumberColumn } from "__support__/visualizations";
-import { Box, SimpleGrid } from "metabase/ui";
+import {
+ DateTimeColumn,
+ NumberColumn,
+ StringColumn,
+} from "__support__/visualizations";
+import { Box, Flex, SimpleGrid } from "metabase/ui";
import Visualization from "metabase/visualizations/components/Visualization";
import { registerVisualization } from "metabase/viz-core";
-import type { Series } from "metabase-types/api";
+import type { DatasetColumn, RowValue, Series } from "metabase-types/api";
import {
createMockCard,
createMockSegmentFormatting,
@@ -145,3 +149,52 @@ WithFormattingAndHover.play = async ({
asyncCallback();
}
};
+
+// values the card cannot compact truncate from the end instead of overflowing
+const longValueSeries = (value: RowValue, col: DatasetColumn): Series =>
+ // Unjustified type cast. FIXME
+ [
+ {
+ card: createMockCard({ name: "Metabase token", display: "scalar" }),
+ data: { cols: [col], rows: [[value]] },
+ },
+ ] as Series;
+
+const LONG_VALUE_SERIES = [
+ longValueSeries(
+ "0d79f0c276571a3c7fd2b5b6db30c1a9",
+ StringColumn({ name: "Token" }),
+ ),
+ longValueSeries(
+ "2025-04-22T22:18:00",
+ DateTimeColumn({ name: "Oldest open PR", unit: "minute" }),
+ ),
+ longValueSeries(Number.MAX_SAFE_INTEGER, NumberColumn({ name: "Count" })),
+];
+
+const LONG_VALUE_CARD_SIZES = [
+ { width: 345, height: 170 },
+ { width: 521, height: 288 },
+];
+
+export const LongValues = () => (
+ <VisualizationWrapper>
+ <Flex gap="lg" wrap="wrap" align="flex-start" p="lg">
+ {LONG_VALUE_CARD_SIZES.flatMap(({ width, height }) =>
+ LONG_VALUE_SERIES.map((rawSeries, index) => (
+ <Box
+ key={`${width}x${height}-${index}`}
+ w={width}
+ h={height}
+ style={{
+ borderRadius: 12,
+ border: "1px solid var(--mb-color-border-neutral)",
+ }}
+ >
+ <Visualization rawSeries={rawSeries} showTitle width={width} />
+ </Box>
+ )),
+ )}
+ </Flex>
+ </VisualizationWrapper>
+);
diff --git a/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.tsx b/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.tsx
index 89576013f58..04b232b3462 100644
--- a/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.tsx
+++ b/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.tsx
@@ -3,6 +3,7 @@ import _ from "underscore";
import DashboardS from "metabase/css/dashboard.module.css";
import { Box, Stack, Text, Tooltip } from "metabase/ui";
+import { useIsTruncated } from "metabase/ui/hooks/use-is-truncated";
import {
ScalarCardShell,
useScalarCardShell,
@@ -47,6 +48,8 @@ function ScalarComponent(
props: VisualizationProps & VisualizationPassThroughProps,
) {
const scalarRef = useRef<HTMLDivElement>(null);
+ const { isTruncated: isValueTruncated, ref: valueRef } =
+ useIsTruncated<HTMLHeadingElement>({ ignoreHeightTruncation: true });
const {
series: [
@@ -133,6 +136,9 @@ function ScalarComponent(
}
};
+ const showsFullValueTooltip =
+ fullScalarValue !== displayValue || isValueTruncated;
+
return (
<ScalarCardShell
tier={tier}
@@ -143,7 +149,7 @@ function ScalarComponent(
<ScalarValueContainer
className={DashboardS.fullscreenNormalText}
tooltip={fullScalarValue}
- alwaysShowTooltip={fullScalarValue !== displayValue}
+ alwaysShowTooltip={showsFullValueTooltip}
isClickable={isClickable}
>
<Tooltip
@@ -155,6 +161,7 @@ function ScalarComponent(
>
<Stack onClick={handleClick} ref={scalarRef} align="center" gap={0}>
<ScalarValue
+ ref={valueRef}
color={color}
disableHover={isMetricsViewer}
fontSize={tier.valueFontSize}
diff --git a/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.unit.spec.tsx b/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.unit.spec.tsx
index 2959df73751..727419e54a4 100644
--- a/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.unit.spec.tsx
+++ b/frontend/src/metabase/visualizations/visualizations/Scalar/Scalar.unit.spec.tsx
@@ -3,6 +3,7 @@ import type { ComponentProps } from "react";
import {
fireEvent,
+ mockTextOverflow,
render,
renderWithProviders,
screen,
@@ -272,22 +273,60 @@ describe("Scalar", () => {
expect(screen.getByText("null")).toBeInTheDocument();
});
- it("should not apply text-overflow ellipsis to the container", () => {
- render(
- <Scalar
- {...mockedProps}
- series={series(1234567)}
- rawSeries={series(1234567)}
- settings={settings}
- visualizationIsClickable={() => false}
- width={230}
- />,
- );
- const container = screen.getByTestId("scalar-container");
- const styles = window.getComputedStyle(container);
- // The container should not have text-overflow: ellipsis
- // as the ScalarValue component handles sizing to fit
- expect(styles.textOverflow).not.toBe("ellipsis");
+ describe("values wider than the card", () => {
+ const TOKEN = "0d79f0c276571a3c7fd2b5b6db30c1a9";
+ const textSeries = () =>
+ // Unjustified type cast. FIXME
+ [
+ {
+ card: createMockCard({ display: "scalar" }),
+ data: {
+ rows: [[TOKEN]],
+ cols: [createMockColumn({ name: "count", base_type: "type/Text" })],
+ },
+ },
+ ] as Series;
+
+ afterEach(() => {
+ jest.restoreAllMocks();
+ });
+
+ it("should show the full value in a tooltip when the value is truncated", async () => {
+ mockTextOverflow();
+ renderWithProviders(
+ <Scalar
+ {...mockedProps}
+ series={textSeries()}
+ rawSeries={textSeries()}
+ settings={settings}
+ visualizationIsClickable={() => false}
+ width={230}
+ />,
+ );
+
+ await userEvent.hover(screen.getByTestId("scalar-value"));
+
+ expect(
+ within(await screen.findByRole("tooltip")).getByText(TOKEN),
+ ).toBeInTheDocument();
+ });
+
+ it("should not show a tooltip for a value that fits", async () => {
+ renderWithProviders(
+ <Scalar
+ {...mockedProps}
+ series={textSeries()}
+ rawSeries={textSeries()}
+ settings={settings}
+ visualizationIsClickable={() => false}
+ width={230}
+ />,
+ );
+
+ await userEvent.hover(screen.getByTestId("scalar-value"));
+
+ expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
+ });
});
it("lets Unicode subscript descenders render past the line box (metabase#72443)", () => {
diff --git a/frontend/src/metabase/visualizations/visualizations/SmartScalar/SmartScalar.stories.tsx b/frontend/src/metabase/visualizations/visualizations/SmartScalar/SmartScalar.stories.tsx
index 0b37855a53e..4f873b593e3 100644
--- a/frontend/src/metabase/visualizations/visualizations/SmartScalar/SmartScalar.stories.tsx
+++ b/frontend/src/metabase/visualizations/visualizations/SmartScalar/SmartScalar.stories.tsx
@@ -137,6 +137,44 @@ export const DashcardMultipleComparisonsTall: StoryFn = () => (
</VisualizationWrapper>
);
+// a value the card cannot compact truncates after the trend symbol
+const MOCK_LONG_VALUE_SERIES = mockSeries({
+ rows: [
+ ["2019-10-01T00:00:00", 9007199254740000],
+ ["2019-11-01T00:00:00", Number.MAX_SAFE_INTEGER],
+ ],
+ insights: [{ unit: "month", col: "Count" }],
+ name: "Last invoice",
+ settings: { "scalar.compact_primary_number": false },
+});
+
+// the narrowest card cannot fit even the compact value
+const LONG_VALUE_CARD_SIZES = [{ width: 170, height: 126 }, ...CARD_SIZES];
+
+export const DashcardLongValue: StoryFn = () => (
+ <VisualizationWrapper>
+ <Flex gap="lg" align="flex-start" p="lg" wrap="wrap">
+ {LONG_VALUE_CARD_SIZES.map(({ width, height }) => (
+ <Box
+ key={`${width}x${height}`}
+ w={width}
+ h={height}
+ style={{
+ borderRadius: 12,
+ border: "1px solid var(--mb-color-border-neutral)",
+ }}
+ >
+ <Visualization
+ rawSeries={MOCK_LONG_VALUE_SERIES}
+ showTitle
+ width={width}
+ />
+ </Box>
+ ))}
+ </Flex>
+ </VisualizationWrapper>
+);
+
// a single comparison on a full-page question renders inline with the trend
// symbol and the full comparison value
export const QueryBuilderSingleComparison: StoryFn = () => (
diff --git a/frontend/src/metabase/visualizations/visualizations/SmartScalar/SmartScalar.tsx b/frontend/src/metabase/visualizations/visualizations/SmartScalar/SmartScalar.tsx
index 34ad528307d..2dde79128e9 100644
--- a/frontend/src/metabase/visualizations/visualizations/SmartScalar/SmartScalar.tsx
+++ b/frontend/src/metabase/visualizations/visualizations/SmartScalar/SmartScalar.tsx
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useRef } from "react";
import DashboardS from "metabase/css/dashboard.module.css";
import { Box, Stack, Text } from "metabase/ui";
+import { useIsTruncated } from "metabase/ui/hooks/use-is-truncated";
import { assignLazily } from "metabase/utils/merge-lazily";
import {
ScalarCardShell,
@@ -12,7 +13,10 @@ import {
ScalarWrapper,
} from "metabase/visualizations/components/ScalarValue/ScalarValue";
import { useBrowserRenderingContext } from "metabase/visualizations/hooks/use-browser-rendering-context";
-import { compactifyValue } from "metabase/visualizations/lib/scalar_utils";
+import {
+ compactifyValue,
+ estimateScalarValueWidth,
+} from "metabase/visualizations/lib/scalar_utils";
import type {
VisualizationPassThroughProps,
VisualizationProps,
@@ -46,6 +50,8 @@ function SmartScalarComponent(
} = props;
const scalarRef = useRef(null);
+ const { isTruncated: isValueTruncated, ref: valueRef } =
+ useIsTruncated<HTMLHeadingElement>({ ignoreHeightTruncation: true });
const { getColor } = useBrowserRenderingContext({ fontFamily });
const insights = rawSeries?.[0].data?.insights;
@@ -106,27 +112,47 @@ function SmartScalarComponent(
symbolDirection != null
? (tier.symbolSize + tier.symbolGap) * rootFontScale
: 0;
- const valueMaxWidth = Math.max(
+ const centeredValueMaxWidth = Math.max(
width - 2 * Math.max(tier.xPadding * rootFontScale, symbolAllowance),
0,
);
const { displayValue, fullScalarValue } = compactifyValue(
value,
- valueMaxWidth,
+ centeredValueMaxWidth,
tier.valueFontSize,
formatOptions,
);
+ const isValueWide =
+ typeof displayValue === "string" &&
+ estimateScalarValueWidth(displayValue, tier.valueFontSize) >
+ centeredValueMaxWidth;
+ const valueMaxWidth = isValueWide
+ ? Math.max(availableWidth - symbolAllowance, 0)
+ : centeredValueMaxWidth;
+ const valueBoxProps = {
+ pos: "relative" as const,
+ style: {
+ maxWidth: `${valueMaxWidth}px`,
+ marginLeft: isValueWide ? `${symbolAllowance}px` : undefined,
+ alignSelf: isValueWide ? ("flex-start" as const) : undefined,
+ },
+ "data-testid": "scalar-value-box",
+ };
+
+ const hasValueTooltip = fullScalarValue !== displayValue || isValueTruncated;
+
const valueElement = (
<ScalarValueContainer
className={DashboardS.fullscreenNormalText}
tooltip={fullScalarValue}
- alwaysShowTooltip={fullScalarValue !== displayValue}
+ alwaysShowTooltip={hasValueTooltip}
isClickable={isClickable}
>
<span onClick={handleClick} ref={scalarRef}>
<ScalarValue
+ ref={valueRef}
fontSize={tier.valueFontSize}
// Unjustified type cast. FIXME
value={displayValue as string}
@@ -158,7 +184,7 @@ function SmartScalarComponent(
<ScalarWrapper xPadding={tier.xPadding}>
<Stack align="center" gap="lg" maw="100%" data-testid="scalar-content">
{hasSingleComparison ? (
- <Box pos="relative" maw={`${valueMaxWidth}px`}>
+ <Box {...valueBoxProps}>
{valueElement}
{symbolElement}
</Box>
@@ -200,11 +226,7 @@ function SmartScalarComponent(
return (
<ScalarCardShell tier={tier} actionButtons={actionButtons}>
- <Box
- pos="relative"
- // measured pixels, not a design size — must not be rem-scaled
- maw={`${valueMaxWidth}px`}
- >
+ <Box {...valueBoxProps}>
{valueElement}
{symbolElement}
</Box>
diff --git a/frontend/src/metabase/visualizations/visualizations/SmartScalar/tests/SmartScalar.unit.spec.tsx b/frontend/src/metabase/visualizations/visualizations/SmartScalar/tests/SmartScalar.unit.spec.tsx
index 07d5efe7afc..8d1d0bc2d23 100644
--- a/frontend/src/metabase/visualizations/visualizations/SmartScalar/tests/SmartScalar.unit.spec.tsx
+++ b/frontend/src/metabase/visualizations/visualizations/SmartScalar/tests/SmartScalar.unit.spec.tsx
@@ -239,6 +239,61 @@ describe("SmartScalar", () => {
expect(screen.getByText("81,005")).toBeInTheDocument();
});
+ it("should show the full value in a tooltip when the value is truncated", async () => {
+ mockTextOverflow();
+ const rows = [
+ ["2019-10-01T00:00:00", 100],
+ ["2019-11-01T00:00:00", 120],
+ ];
+ const insights = createMockInsights([{ unit: "month", col: "Count" }]);
+
+ setup({ series: series({ rows, insights }), width: 400 });
+
+ await userEvent.hover(screen.getByTestId("scalar-value"));
+
+ expect(
+ within(await screen.findByRole("tooltip")).getByText("120"),
+ ).toBeInTheDocument();
+
+ jest.restoreAllMocks();
+ });
+
+ it("should start a value wider than the centered box after the trend symbol", () => {
+ const rows = [
+ ["2019-10-01T00:00:00", 9007199254740000],
+ ["2019-11-01T00:00:00", Number.MAX_SAFE_INTEGER],
+ ];
+ const insights = createMockInsights([{ unit: "month", col: "Count" }]);
+
+ // 170px is the narrowest size-200 card: 24px padding and a 24px symbol
+ // allowance leave a 122px centered box, which "9007.2T" overflows
+ setup({ series: series({ rows, insights }), width: 170 });
+
+ expect(screen.getByText("9007.2T")).toBeInTheDocument();
+ expect(screen.getByTestId("scalar-value-box")).toHaveStyle({
+ marginLeft: "24px",
+ alignSelf: "flex-start",
+ maxWidth: "98px",
+ });
+ });
+
+ it("should keep a value that fits centered without a symbol offset", () => {
+ const rows = [
+ ["2019-10-01T00:00:00", 100],
+ ["2019-11-01T00:00:00", 120],
+ ];
+ const insights = createMockInsights([{ unit: "month", col: "Count" }]);
+
+ setup({ series: series({ rows, insights }), width: 170 });
+
+ expect(screen.getByTestId("scalar-value-box")).not.toHaveStyle({
+ alignSelf: "flex-start",
+ });
+ expect(screen.getByTestId("scalar-value-box")).toHaveStyle({
+ maxWidth: "122px",
+ });
+ });
+
it("should render compact if normal formatting is >6 characters and width <250", () => {
const width = 200;
const rows = [