From fc050c9ce7fefe6fd06b98797032de81852786a1 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 8 Apr 2026 03:56:39 +0000 Subject: [PATCH 01/20] Charts: Replace hardcoded typography with WPDS design tokens Replace all hardcoded font-family, font-size, font-weight, and line-height values across chart SCSS modules and components with WPDS (WordPress Design System) CSS custom property tokens (--wpds-font-*). SCSS modules updated: - conversion-funnel-chart: Replace SF Pro font families with --wpds-font-family-body, all font sizes with --wpds-font-size-*, weights with --wpds-font-weight-*, and line heights with --wpds-font-line-height-* - line-chart: Tokenize tooltip font-weight and annotation popover font-size - base-legend: Tokenize legend item font-size and value font-weight - base-tooltip: Tokenize tooltip font-size - pie-semi-circle-chart: Tokenize label font-weight/size and note font-size - trend-indicator: Tokenize font-size and font-weight - leaderboard-chart: Tokenize empty state font-size Theme/component updates: - Default theme svgLabelSmall: Add fontFamily token for SVG text elements - pie-chart: Wire SVG label fontSize/fontFamily through theme.svgLabelSmall - Leaderboard story: Remove hardcoded SF Pro Text fontFamily override Documentation updates: - conversion-funnel-chart docs: Replace --funnel-font-family/--step-font-family with --wpds-font-family-body - leaderboard-chart docs: Replace font-family examples with WPDS tokens - pie-semi-circle-chart docs: Reference WPDS tokens for label/note typography All tokens use current values as fallbacks to preserve visual backward compatibility when WPDS tokens are not provided by the host environment. --- .../changelog/charts-typography-tokenization | 4 ++ .../conversion-funnel-chart.module.scss | 52 +++++++++---------- .../stories/index.docs.mdx | 5 +- .../leaderboard-chart.module.scss | 2 +- .../leaderboard-chart/stories/index.docs.mdx | 3 +- .../stories/index.stories.tsx | 1 - .../charts/line-chart/line-chart.module.scss | 6 +-- .../charts/src/charts/pie-chart/pie-chart.tsx | 7 ++- .../pie-semi-circle-chart.module.scss | 6 +-- .../stories/index.docs.mdx | 4 +- .../legend/private/base-legend.module.scss | 4 +- .../tooltip/base-tooltip.module.scss | 2 +- .../trend-indicator.module.scss | 4 +- .../src/providers/chart-context/themes.ts | 6 ++- 14 files changed, 57 insertions(+), 49 deletions(-) create mode 100644 projects/js-packages/charts/changelog/charts-typography-tokenization diff --git a/projects/js-packages/charts/changelog/charts-typography-tokenization b/projects/js-packages/charts/changelog/charts-typography-tokenization new file mode 100644 index 000000000000..65f025361f98 --- /dev/null +++ b/projects/js-packages/charts/changelog/charts-typography-tokenization @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Replace hardcoded typography values with WPDS design tokens for font family, size, weight, and line height. diff --git a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss index 64040be4cb44..aba4adf04dff 100644 --- a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +++ b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss @@ -1,5 +1,5 @@ .conversion-funnel-chart { - font-family: var(--funnel-font-family, "SF Pro Text"); + font-family: var(--wpds-font-family-body, "SF Pro Text", sans-serif); &--loading { opacity: 0.6; @@ -19,22 +19,22 @@ overflow: hidden; color: #1e1e1e; text-overflow: ellipsis; - font-family: var(--funnel-font-family, "SF Pro Text"); - font-size: 18px; + font-family: var(--wpds-font-family-body, "SF Pro Text", sans-serif); + font-size: var(--wpds-font-size-xl, 18px); font-style: normal; - font-weight: 500; - line-height: 20px; + font-weight: var(--wpds-font-weight-medium, 500); + line-height: var(--wpds-font-line-height-sm, 20px); margin: 0; } .change-indicator { overflow: hidden; text-overflow: ellipsis; - font-family: var(--funnel-font-family, "SF Pro Text"); - font-size: 13px; + font-family: var(--wpds-font-family-body, "SF Pro Text", sans-serif); + font-size: var(--wpds-font-size-md, 13px); font-style: normal; - font-weight: 500; - line-height: 20px; + font-weight: var(--wpds-font-weight-medium, 500); + line-height: var(--wpds-font-line-height-sm, 20px); margin: 0; } @@ -69,11 +69,11 @@ .step-label { color: #757575; - font-family: var(--step-font-family, "SF Pro"); - font-size: 12px; + font-family: var(--wpds-font-family-body, "SF Pro", sans-serif); + font-size: var(--wpds-font-size-sm, 12px); font-style: normal; - font-weight: 400; - line-height: 16px; + font-weight: var(--wpds-font-weight-regular, 400); + line-height: var(--wpds-font-line-height-xs, 16px); margin: 0 0 2px 0; display: block; overflow: hidden; @@ -82,11 +82,11 @@ .step-rate { color: #1e1e1e; - font-family: var(--step-font-family, "SF Pro"); - font-size: 13px; + font-family: var(--wpds-font-family-body, "SF Pro", sans-serif); + font-size: var(--wpds-font-size-md, 13px); font-style: normal; - font-weight: 500; - line-height: 20px; + font-weight: var(--wpds-font-weight-medium, 500); + line-height: var(--wpds-font-line-height-sm, 20px); margin: 0; display: block; } @@ -139,25 +139,25 @@ .tooltip-title { color: #1e1e1e; - font-family: "SF Pro", sans-serif; - font-size: 12px; + font-family: var(--wpds-font-family-body, "SF Pro", sans-serif); + font-size: var(--wpds-font-size-sm, 12px); font-style: normal; - font-weight: 400; - line-height: 16px; + font-weight: var(--wpds-font-weight-regular, 400); + line-height: var(--wpds-font-line-height-xs, 16px); } .tooltip-content { color: #1e1e1e; - font-family: "SF Pro", sans-serif; - font-size: 13px; + font-family: var(--wpds-font-family-body, "SF Pro", sans-serif); + font-size: var(--wpds-font-size-md, 13px); font-style: normal; - font-weight: 500; - line-height: 20px; + font-weight: var(--wpds-font-weight-medium, 500); + line-height: var(--wpds-font-line-height-sm, 20px); } .empty-state { text-align: center; padding: 48px 24px; color: #6b7280; - font-size: 16px; + font-size: var(--wpds-font-size-lg, 16px); } diff --git a/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx b/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx index 7858ebbcc5fe..c164fadb7330 100644 --- a/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx +++ b/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx @@ -249,13 +249,12 @@ Use the `style` prop or `className` prop to customize the chart container: ### CSS Custom Properties -The component exposes CSS custom properties for font customization: +Typography is controlled via WPDS (WordPress Design System) tokens. Override these CSS custom properties to customize fonts: diff --git a/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss b/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss index f768e11bdbc9..aa61ed26681c 100644 --- a/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss +++ b/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss @@ -73,6 +73,6 @@ padding: 32px 16px; text-align: center; color: #666; - font-size: 14px; + font-size: var(--wpds-font-size-md, 14px); font-style: italic; } diff --git a/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.docs.mdx b/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.docs.mdx index b57e4d15dffa..6a3a434ed369 100644 --- a/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.docs.mdx +++ b/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.docs.mdx @@ -421,7 +421,6 @@ Combine overlay labels with custom styling and transparent colors: primaryColor="rgba(56, 88, 233, 0.08)" // Semi-transparent style={{ '--a8c--charts--leaderboard--bar--border-radius': '4px', - fontFamily: '"SF Pro Text", sans-serif', }} />` } /> @@ -445,7 +444,7 @@ The component supports CSS custom properties for advanced styling: language="css" code={ `.myCustomChart { --a8c--charts--leaderboard--bar--border-radius: 8px; - font-family: "Custom Font", sans-serif; + --wpds-font-family-body: "Custom Font", sans-serif; }` } /> diff --git a/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.stories.tsx b/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.stories.tsx index 4ca1af9e4170..60e0a5e362cd 100644 --- a/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.stories.tsx +++ b/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.stories.tsx @@ -371,7 +371,6 @@ export const OverlayLabelWithImage: Story = { loading: false, style: { '--a8c--charts--leaderboard--bar--border-radius': '4px', - fontFamily: `"SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif`, }, }, render: args => , diff --git a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss index 007d7ad8bba3..4c1eb8a8c3ca 100644 --- a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss +++ b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss @@ -21,7 +21,7 @@ } &__tooltip-date { - font-weight: 700; + font-weight: var(--wpds-font-weight-medium, 700); padding-bottom: 10px; } @@ -33,7 +33,7 @@ } &__tooltip-label { - font-weight: 500; + font-weight: var(--wpds-font-weight-medium, 500); padding-right: 1rem; } @@ -65,7 +65,7 @@ background: #fff; border: none; border-radius: 4px; - font-size: 14px; + font-size: var(--wpds-font-size-md, 14px); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); position: fixed; margin: 0.5rem; diff --git a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx index 019679316862..687804c96cda 100644 --- a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx +++ b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx @@ -441,8 +441,10 @@ const PieChartInternal = ( { groupProps.onMouseLeave = onMouseLeave; } - // Estimate text width more accurately for background sizing - const fontSize = 12; + const fontSize = + typeof providerTheme.svgLabelSmall?.fontSize === 'number' + ? providerTheme.svgLabelSmall.fontSize + : 12; const estimatedTextWidth = getStringWidth( arc.data.label, { fontSize, } ); @@ -473,6 +475,7 @@ const PieChartInternal = ( { dy=".33em" fill={ providerTheme.labelTextColor || '#333' } fontSize={ fontSize } + fontFamily={ providerTheme.svgLabelSmall?.fontFamily } textAnchor="middle" pointerEvents="none" > diff --git a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss index c1d2be2f0be6..3adeaa3156ed 100644 --- a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +++ b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss @@ -11,11 +11,11 @@ } .label { - font-weight: 600; - font-size: 16px; + font-weight: var(--wpds-font-weight-medium, 600); + font-size: var(--wpds-font-size-lg, 16px); } .note { - font-size: 14px; + font-size: var(--wpds-font-size-md, 14px); } } diff --git a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx index 69553af36d8b..5ed4be42f6c6 100644 --- a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx +++ b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx @@ -222,8 +222,8 @@ Segments automatically use theme colors, but you can override individual segment The chart includes built-in styling for labels and notes with appropriate typography hierarchy: -- **Label**: 16px, font-weight 600, positioned above the chart -- **Note**: 14px, positioned below the label +- **Label**: Uses `--wpds-font-size-lg` (default 16px), `--wpds-font-weight-medium` (default 600), positioned above the chart +- **Note**: Uses `--wpds-font-size-md` (default 14px), positioned below the label Date: Wed, 8 Apr 2026 04:16:07 +0000 Subject: [PATCH 02/20] Charts: Remove CSS Custom Properties docs section from conversion funnel WPDS tokens should be set through ThemeProvider, not raw CSS overrides. Remove the entire section per review feedback. --- .../conversion-funnel-chart/stories/index.docs.mdx | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx b/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx index c164fadb7330..3ca4e0b2c498 100644 --- a/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx +++ b/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx @@ -247,17 +247,6 @@ Use the `style` prop or `className` prop to customize the chart container: />` } /> -### CSS Custom Properties - -Typography is controlled via WPDS (WordPress Design System) tokens. Override these CSS custom properties to customize fonts: - - - ## Theming Integration Conversion Funnel Charts integrate seamlessly with the chart theming system. The default theme has neutral colors and styling, and is automatically applied to all charts unless a custom theme is provided. A custom theme can be provided by wrapping your chart in `GlobalChartsProvider` and passing a custom theme object with the properties you want to override to the `theme` prop: From 6da627d259b891313ab5334ce3e6edf2a221633c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 8 Apr 2026 04:22:16 +0000 Subject: [PATCH 03/20] Charts: Simplify font-family fallback to just sans-serif Per review feedback, use only sans-serif as the fallback for --wpds-font-family-body instead of SF Pro or system font stacks. Also remove WPDS token override from leaderboard CSS docs example. --- .../conversion-funnel-chart.module.scss | 14 +++++++------- .../leaderboard-chart/stories/index.docs.mdx | 1 - .../charts/src/providers/chart-context/themes.ts | 3 +-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss index aba4adf04dff..5ab7d6ad6f4d 100644 --- a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +++ b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss @@ -1,5 +1,5 @@ .conversion-funnel-chart { - font-family: var(--wpds-font-family-body, "SF Pro Text", sans-serif); + font-family: var(--wpds-font-family-body, sans-serif); &--loading { opacity: 0.6; @@ -19,7 +19,7 @@ overflow: hidden; color: #1e1e1e; text-overflow: ellipsis; - font-family: var(--wpds-font-family-body, "SF Pro Text", sans-serif); + font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-xl, 18px); font-style: normal; font-weight: var(--wpds-font-weight-medium, 500); @@ -30,7 +30,7 @@ .change-indicator { overflow: hidden; text-overflow: ellipsis; - font-family: var(--wpds-font-family-body, "SF Pro Text", sans-serif); + font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-md, 13px); font-style: normal; font-weight: var(--wpds-font-weight-medium, 500); @@ -69,7 +69,7 @@ .step-label { color: #757575; - font-family: var(--wpds-font-family-body, "SF Pro", sans-serif); + font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-sm, 12px); font-style: normal; font-weight: var(--wpds-font-weight-regular, 400); @@ -82,7 +82,7 @@ .step-rate { color: #1e1e1e; - font-family: var(--wpds-font-family-body, "SF Pro", sans-serif); + font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-md, 13px); font-style: normal; font-weight: var(--wpds-font-weight-medium, 500); @@ -139,7 +139,7 @@ .tooltip-title { color: #1e1e1e; - font-family: var(--wpds-font-family-body, "SF Pro", sans-serif); + font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-sm, 12px); font-style: normal; font-weight: var(--wpds-font-weight-regular, 400); @@ -148,7 +148,7 @@ .tooltip-content { color: #1e1e1e; - font-family: var(--wpds-font-family-body, "SF Pro", sans-serif); + font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-md, 13px); font-style: normal; font-weight: var(--wpds-font-weight-medium, 500); diff --git a/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.docs.mdx b/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.docs.mdx index 6a3a434ed369..dbba46002ee4 100644 --- a/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.docs.mdx +++ b/projects/js-packages/charts/src/charts/leaderboard-chart/stories/index.docs.mdx @@ -444,7 +444,6 @@ The component supports CSS custom properties for advanced styling: language="css" code={ `.myCustomChart { --a8c--charts--leaderboard--bar--border-radius: 8px; - --wpds-font-family-body: "Custom Font", sans-serif; }` } /> diff --git a/projects/js-packages/charts/src/providers/chart-context/themes.ts b/projects/js-packages/charts/src/providers/chart-context/themes.ts index 0c99ed5231fd..87110f2de301 100644 --- a/projects/js-packages/charts/src/providers/chart-context/themes.ts +++ b/projects/js-packages/charts/src/providers/chart-context/themes.ts @@ -28,8 +28,7 @@ const defaultTheme: CompleteChartTheme = { glyphs: [], svgLabelSmall: { fill: 'var(--jp-gray-80, #2c3338)', - fontFamily: - 'var(--wpds-font-family-body, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif)', + fontFamily: 'var(--wpds-font-family-body, sans-serif)', }, annotationStyles: { label: { From 3be6ee8c1eec5876918a21b92ea78f5f56c1b212 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 8 Apr 2026 04:24:45 +0000 Subject: [PATCH 04/20] Charts: Remove redundant font-family from child selectors in conversion funnel font-family is an inherited CSS property, so child elements within .conversion-funnel-chart inherit it from the top-level selector. Removed the redundant declarations from .main-rate, .change-indicator, .step-label, .step-rate, .tooltip-title, and .tooltip-content. Kept font-family on .tooltip-wrapper since tooltips render in a visx portal outside the .conversion-funnel-chart DOM tree. --- .../conversion-funnel-chart.module.scss | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss index 5ab7d6ad6f4d..bcfd3b490587 100644 --- a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +++ b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss @@ -19,7 +19,6 @@ overflow: hidden; color: #1e1e1e; text-overflow: ellipsis; - font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-xl, 18px); font-style: normal; font-weight: var(--wpds-font-weight-medium, 500); @@ -30,7 +29,6 @@ .change-indicator { overflow: hidden; text-overflow: ellipsis; - font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-md, 13px); font-style: normal; font-weight: var(--wpds-font-weight-medium, 500); @@ -69,7 +67,6 @@ .step-label { color: #757575; - font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-sm, 12px); font-style: normal; font-weight: var(--wpds-font-weight-regular, 400); @@ -82,7 +79,6 @@ .step-rate { color: #1e1e1e; - font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-md, 13px); font-style: normal; font-weight: var(--wpds-font-weight-medium, 500); @@ -126,6 +122,7 @@ justify-content: center; align-items: flex-start; gap: 4px; + font-family: var(--wpds-font-family-body, sans-serif); border-bottom: 1px solid var(--Gray-Gray-5, #dcdcde); background: var(--black-white-white, #fff); @@ -139,7 +136,6 @@ .tooltip-title { color: #1e1e1e; - font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-sm, 12px); font-style: normal; font-weight: var(--wpds-font-weight-regular, 400); @@ -148,7 +144,6 @@ .tooltip-content { color: #1e1e1e; - font-family: var(--wpds-font-family-body, sans-serif); font-size: var(--wpds-font-size-md, 13px); font-style: normal; font-weight: var(--wpds-font-weight-medium, 500); From a3a5f8f31d6c5571b5f0c44a6458a1a6ba246611 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 8 Apr 2026 04:25:56 +0000 Subject: [PATCH 05/20] Charts: Revert bold/semibold weights to hardcoded values WPDS only provides --wpds-font-weight-regular (400) and --wpds-font-weight-medium (499). There are no tokens for semibold (600) or bold (700), so these should remain hardcoded rather than being incorrectly mapped to --wpds-font-weight-medium. --- .../charts/src/charts/line-chart/line-chart.module.scss | 2 +- .../pie-semi-circle-chart/pie-semi-circle-chart.module.scss | 2 +- .../src/charts/pie-semi-circle-chart/stories/index.docs.mdx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss index 4c1eb8a8c3ca..7781388d7575 100644 --- a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss +++ b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss @@ -21,7 +21,7 @@ } &__tooltip-date { - font-weight: var(--wpds-font-weight-medium, 700); + font-weight: 700; padding-bottom: 10px; } diff --git a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss index 3adeaa3156ed..62c9452ac4c3 100644 --- a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +++ b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss @@ -11,7 +11,7 @@ } .label { - font-weight: var(--wpds-font-weight-medium, 600); + font-weight: 600; font-size: var(--wpds-font-size-lg, 16px); } diff --git a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx index 5ed4be42f6c6..3678ae9849a9 100644 --- a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx +++ b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx @@ -222,7 +222,7 @@ Segments automatically use theme colors, but you can override individual segment The chart includes built-in styling for labels and notes with appropriate typography hierarchy: -- **Label**: Uses `--wpds-font-size-lg` (default 16px), `--wpds-font-weight-medium` (default 600), positioned above the chart +- **Label**: Uses `--wpds-font-size-lg` (default 16px), font-weight 600, positioned above the chart - **Note**: Uses `--wpds-font-size-md` (default 14px), positioned below the label Date: Wed, 8 Apr 2026 20:04:26 +0000 Subject: [PATCH 06/20] Charts: Align all font-weights to WPDS design system tokens Use only weights available in the design system: - --wpds-font-weight-medium with fallback 499 - --wpds-font-weight-regular with fallback 400 Previous 500, 600, and 700 values are all mapped to medium (499) to match the WPDS token definitions. --- .../conversion-funnel-chart.module.scss | 8 ++++---- .../charts/src/charts/line-chart/line-chart.module.scss | 4 ++-- .../pie-semi-circle-chart.module.scss | 2 +- .../charts/pie-semi-circle-chart/stories/index.docs.mdx | 2 +- .../src/components/legend/private/base-legend.module.scss | 2 +- .../trend-indicator/trend-indicator.module.scss | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss index bcfd3b490587..f75427010807 100644 --- a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +++ b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss @@ -21,7 +21,7 @@ text-overflow: ellipsis; font-size: var(--wpds-font-size-xl, 18px); font-style: normal; - font-weight: var(--wpds-font-weight-medium, 500); + font-weight: var(--wpds-font-weight-medium, 499); line-height: var(--wpds-font-line-height-sm, 20px); margin: 0; } @@ -31,7 +31,7 @@ text-overflow: ellipsis; font-size: var(--wpds-font-size-md, 13px); font-style: normal; - font-weight: var(--wpds-font-weight-medium, 500); + font-weight: var(--wpds-font-weight-medium, 499); line-height: var(--wpds-font-line-height-sm, 20px); margin: 0; } @@ -81,7 +81,7 @@ color: #1e1e1e; font-size: var(--wpds-font-size-md, 13px); font-style: normal; - font-weight: var(--wpds-font-weight-medium, 500); + font-weight: var(--wpds-font-weight-medium, 499); line-height: var(--wpds-font-line-height-sm, 20px); margin: 0; display: block; @@ -146,7 +146,7 @@ color: #1e1e1e; font-size: var(--wpds-font-size-md, 13px); font-style: normal; - font-weight: var(--wpds-font-weight-medium, 500); + font-weight: var(--wpds-font-weight-medium, 499); line-height: var(--wpds-font-line-height-sm, 20px); } diff --git a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss index 7781388d7575..4ebb2743e420 100644 --- a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss +++ b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss @@ -21,7 +21,7 @@ } &__tooltip-date { - font-weight: 700; + font-weight: var(--wpds-font-weight-medium, 499); padding-bottom: 10px; } @@ -33,7 +33,7 @@ } &__tooltip-label { - font-weight: var(--wpds-font-weight-medium, 500); + font-weight: var(--wpds-font-weight-medium, 499); padding-right: 1rem; } diff --git a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss index 62c9452ac4c3..6aae99c385cd 100644 --- a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +++ b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss @@ -11,7 +11,7 @@ } .label { - font-weight: 600; + font-weight: var(--wpds-font-weight-medium, 499); font-size: var(--wpds-font-size-lg, 16px); } diff --git a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx index 3678ae9849a9..79541a09393d 100644 --- a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx +++ b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx @@ -222,7 +222,7 @@ Segments automatically use theme colors, but you can override individual segment The chart includes built-in styling for labels and notes with appropriate typography hierarchy: -- **Label**: Uses `--wpds-font-size-lg` (default 16px), font-weight 600, positioned above the chart +- **Label**: Uses `--wpds-font-size-lg` (default 16px), `--wpds-font-weight-medium` (default 499), positioned above the chart - **Note**: Uses `--wpds-font-size-md` (default 14px), positioned below the label Date: Wed, 8 Apr 2026 20:10:14 +0000 Subject: [PATCH 07/20] Charts: Add font-family token to the root selector of every chart Apply font-family: var(--wpds-font-family-body, sans-serif) to the outer selector of all chart SCSS modules so every chart opts in to the WPDS font-family token. Children inherit automatically. Charts updated: bar-chart, geo-chart, leaderboard-chart, line-chart, pie-chart, pie-semi-circle-chart, sparkline. (conversion-funnel-chart already had it.) --- .../charts/src/charts/bar-chart/bar-chart.module.scss | 1 + .../charts/src/charts/geo-chart/geo-chart.module.scss | 1 + .../src/charts/leaderboard-chart/leaderboard-chart.module.scss | 1 + .../charts/src/charts/line-chart/line-chart.module.scss | 1 + .../charts/src/charts/pie-chart/pie-chart.module.scss | 1 + .../pie-semi-circle-chart/pie-semi-circle-chart.module.scss | 2 ++ .../charts/src/charts/sparkline/sparkline.module.scss | 1 + 7 files changed, 8 insertions(+) diff --git a/projects/js-packages/charts/src/charts/bar-chart/bar-chart.module.scss b/projects/js-packages/charts/src/charts/bar-chart/bar-chart.module.scss index fd2246be150d..2880fb5d37dd 100644 --- a/projects/js-packages/charts/src/charts/bar-chart/bar-chart.module.scss +++ b/projects/js-packages/charts/src/charts/bar-chart/bar-chart.module.scss @@ -1,4 +1,5 @@ .bar-chart { + font-family: var(--wpds-font-family-body, sans-serif); svg { overflow: visible; diff --git a/projects/js-packages/charts/src/charts/geo-chart/geo-chart.module.scss b/projects/js-packages/charts/src/charts/geo-chart/geo-chart.module.scss index a69330bbc55a..ce06d45b3c64 100644 --- a/projects/js-packages/charts/src/charts/geo-chart/geo-chart.module.scss +++ b/projects/js-packages/charts/src/charts/geo-chart/geo-chart.module.scss @@ -1,4 +1,5 @@ .container { + font-family: var(--wpds-font-family-body, sans-serif); position: relative; display: flex; justify-content: center; diff --git a/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss b/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss index aa61ed26681c..f583ff9e5781 100644 --- a/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss +++ b/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss @@ -1,4 +1,5 @@ .leaderboardChart { + font-family: var(--wpds-font-family-body, sans-serif); transition: opacity 0.3s ease-in-out; &--responsive { diff --git a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss index 4ebb2743e420..e58b29eb9000 100644 --- a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss +++ b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss @@ -1,4 +1,5 @@ .line-chart { + font-family: var(--wpds-font-family-body, sans-serif); position: relative; &--animated { diff --git a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.module.scss b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.module.scss index 3c6be251d449..243bda89a054 100644 --- a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.module.scss +++ b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.module.scss @@ -1,4 +1,5 @@ .pie-chart { + font-family: var(--wpds-font-family-body, sans-serif); overflow: hidden; // Fill parent when no explicit width/height provided diff --git a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss index 6aae99c385cd..5573fab3b05d 100644 --- a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +++ b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss @@ -1,4 +1,6 @@ .pie-semi-circle-chart { + font-family: var(--wpds-font-family-body, sans-serif); + // Fill parent when no explicit width/height provided &--responsive { height: 100%; diff --git a/projects/js-packages/charts/src/charts/sparkline/sparkline.module.scss b/projects/js-packages/charts/src/charts/sparkline/sparkline.module.scss index da8af86912b5..5ac9c6904ac5 100644 --- a/projects/js-packages/charts/src/charts/sparkline/sparkline.module.scss +++ b/projects/js-packages/charts/src/charts/sparkline/sparkline.module.scss @@ -1,4 +1,5 @@ .sparkline { + font-family: var(--wpds-font-family-body, sans-serif); display: inline-block; vertical-align: middle; line-height: 1; From 3d809a6830d9e45080751d256b972bb01dabea6b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 8 Apr 2026 20:29:27 +0000 Subject: [PATCH 08/20] Charts: Remove fontFamily from svgLabelSmall theme property The fontFamily on svgLabelSmall was redundant: inline SVG elements inherit font-family from their parent HTML element via CSS inheritance. Now that every chart root selector sets font-family: var(--wpds-font-family-body, sans-serif), all SVG text inside those charts inherits it automatically. Also removes the explicit fontFamily prop from the pie chart's slice label element for the same reason. --- .../js-packages/charts/src/charts/pie-chart/pie-chart.tsx | 1 - .../js-packages/charts/src/providers/chart-context/themes.ts | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx index 687804c96cda..0464a798a1d3 100644 --- a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx +++ b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx @@ -475,7 +475,6 @@ const PieChartInternal = ( { dy=".33em" fill={ providerTheme.labelTextColor || '#333' } fontSize={ fontSize } - fontFamily={ providerTheme.svgLabelSmall?.fontFamily } textAnchor="middle" pointerEvents="none" > diff --git a/projects/js-packages/charts/src/providers/chart-context/themes.ts b/projects/js-packages/charts/src/providers/chart-context/themes.ts index 87110f2de301..e768a60c847a 100644 --- a/projects/js-packages/charts/src/providers/chart-context/themes.ts +++ b/projects/js-packages/charts/src/providers/chart-context/themes.ts @@ -26,10 +26,7 @@ const defaultTheme: CompleteChartTheme = { }, seriesLineStyles: [], glyphs: [], - svgLabelSmall: { - fill: 'var(--jp-gray-80, #2c3338)', - fontFamily: 'var(--wpds-font-family-body, sans-serif)', - }, + svgLabelSmall: { fill: 'var(--jp-gray-80, #2c3338)' }, annotationStyles: { label: { anchorLineStroke: 'var(--jp-gray-80, #2c3338)', From e4de571c6a0cbf42cdd5b545d3b164a6bd2c7a5c Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Apr 2026 11:00:57 +1200 Subject: [PATCH 09/20] Charts: Fix PieChart label background sizing to use full theme typography The label background width previously called getStringWidth with only the numeric fontSize, silently falling back to 12 when svgLabelSmall.fontSize was a string like '12px', and never passed fontFamily or fontWeight. Export resolveFontSize from use-chart-margin so it can be reused, then use it in PieChart and pass fontFamily/fontWeight through to getStringWidth so the measured background matches the rendered label. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../charts/changelog/charts-pie-label-sizing-fix | 4 ++++ .../charts/src/charts/pie-chart/pie-chart.tsx | 9 +++++---- projects/js-packages/charts/src/hooks/index.ts | 2 +- .../js-packages/charts/src/hooks/use-chart-margin.tsx | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 projects/js-packages/charts/changelog/charts-pie-label-sizing-fix diff --git a/projects/js-packages/charts/changelog/charts-pie-label-sizing-fix b/projects/js-packages/charts/changelog/charts-pie-label-sizing-fix new file mode 100644 index 000000000000..8ae44801f2fe --- /dev/null +++ b/projects/js-packages/charts/changelog/charts-pie-label-sizing-fix @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Charts: PieChart label background width now accounts for themed fontFamily, fontWeight, and string fontSize values. diff --git a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx index 0464a798a1d3..c38d01969934 100644 --- a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx +++ b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx @@ -8,6 +8,7 @@ import { useCallback, useContext, useMemo } from 'react'; import { Legend, useChartLegendItems } from '../../components/legend'; import { BaseTooltip } from '../../components/tooltip'; import { + resolveFontSize, useDataWithPercentages, useInteractiveLegendData, usePrefersReducedMotion, @@ -441,12 +442,12 @@ const PieChartInternal = ( { groupProps.onMouseLeave = onMouseLeave; } - const fontSize = - typeof providerTheme.svgLabelSmall?.fontSize === 'number' - ? providerTheme.svgLabelSmall.fontSize - : 12; + const svgLabelSmall = providerTheme.svgLabelSmall; + const fontSize = resolveFontSize( svgLabelSmall?.fontSize ) ?? 12; const estimatedTextWidth = getStringWidth( arc.data.label, { fontSize, + fontFamily: svgLabelSmall?.fontFamily, + fontWeight: svgLabelSmall?.fontWeight, } ); const labelPadding = 6; const backgroundWidth = estimatedTextWidth + labelPadding * 2; diff --git a/projects/js-packages/charts/src/hooks/index.ts b/projects/js-packages/charts/src/hooks/index.ts index 706d58ec76ac..99aa45593961 100644 --- a/projects/js-packages/charts/src/hooks/index.ts +++ b/projects/js-packages/charts/src/hooks/index.ts @@ -2,7 +2,7 @@ export { useDeepMemo } from './use-deep-memo'; export { useChartMouseHandler } from './use-chart-mouse-handler'; export { useXYChartTheme } from './use-xychart-theme'; export { useChartDataTransform } from './use-chart-data-transform'; -export { useChartMargin } from './use-chart-margin'; +export { useChartMargin, resolveFontSize } from './use-chart-margin'; export { useElementSize } from './use-element-size'; export { useTextTruncation } from './use-text-truncation'; export { useZeroValueDisplay } from './use-zero-value-display'; diff --git a/projects/js-packages/charts/src/hooks/use-chart-margin.tsx b/projects/js-packages/charts/src/hooks/use-chart-margin.tsx index e6c5ebdaee93..c8e7262342dc 100644 --- a/projects/js-packages/charts/src/hooks/use-chart-margin.tsx +++ b/projects/js-packages/charts/src/hooks/use-chart-margin.tsx @@ -50,7 +50,7 @@ const DEFAULT_TICK_LENGTH = 8; */ const DEFAULT_Y_TICK_WIDTH = 40; -const resolveFontSize = ( val?: number | string ): number | undefined => { +export const resolveFontSize = ( val?: number | string ): number | undefined => { if ( typeof val === 'number' && ! isNaN( val ) ) { return val; } From b2a09412d89f6873d6d0d6ecb69294602cb2bdd7 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Apr 2026 11:01:13 +1200 Subject: [PATCH 10/20] Charts: Restore backward compat for deprecated funnel font-family vars Re-add --funnel-font-family and --step-font-family as fallbacks in the ConversionFunnelChart cascade so consumers already setting either variable continue to get their custom font. --wpds-font-family-body takes precedence when set. Both variables are now documented as deprecated in the Storybook docs and will be removed in a future release. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../changelog/charts-conversion-funnel-deprecated-vars | 4 ++++ .../conversion-funnel-chart.module.scss | 10 +++++++++- .../conversion-funnel-chart/stories/index.docs.mdx | 9 +++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 projects/js-packages/charts/changelog/charts-conversion-funnel-deprecated-vars diff --git a/projects/js-packages/charts/changelog/charts-conversion-funnel-deprecated-vars b/projects/js-packages/charts/changelog/charts-conversion-funnel-deprecated-vars new file mode 100644 index 000000000000..162db01b1b61 --- /dev/null +++ b/projects/js-packages/charts/changelog/charts-conversion-funnel-deprecated-vars @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Charts: Restore backward compatibility for deprecated --funnel-font-family and --step-font-family CSS variables in ConversionFunnelChart. diff --git a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss index f75427010807..7aa4c7cff962 100644 --- a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +++ b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss @@ -1,5 +1,7 @@ .conversion-funnel-chart { - font-family: var(--wpds-font-family-body, sans-serif); + // `--funnel-font-family` is deprecated: prefer `--wpds-font-family-body`. + // Kept here as a fallback for backward compatibility. + font-family: var(--wpds-font-family-body, var(--funnel-font-family, sans-serif)); &--loading { opacity: 0.6; @@ -67,6 +69,9 @@ .step-label { color: #757575; + // `--step-font-family` is deprecated: prefer `--wpds-font-family-body`. + // Kept here as a fallback for backward compatibility. + font-family: var(--wpds-font-family-body, var(--step-font-family, sans-serif)); font-size: var(--wpds-font-size-sm, 12px); font-style: normal; font-weight: var(--wpds-font-weight-regular, 400); @@ -79,6 +84,9 @@ .step-rate { color: #1e1e1e; + // `--step-font-family` is deprecated: prefer `--wpds-font-family-body`. + // Kept here as a fallback for backward compatibility. + font-family: var(--wpds-font-family-body, var(--step-font-family, sans-serif)); font-size: var(--wpds-font-size-md, 13px); font-style: normal; font-weight: var(--wpds-font-weight-medium, 499); diff --git a/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx b/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx index 3ca4e0b2c498..33b121f7d989 100644 --- a/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx +++ b/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx @@ -247,6 +247,15 @@ Use the `style` prop or `className` prop to customize the chart container: />` } /> +### Deprecated CSS Custom Properties + +The following CSS custom properties are **deprecated** and will be removed in a future release. They are still honored as fallbacks for backward compatibility, but new code should set `--wpds-font-family-body` instead (typically via the host app's theme/admin configuration, not raw CSS overrides): + +- `--funnel-font-family` — previously applied to the chart root, main rate, and change indicator. Replaced by `--wpds-font-family-body`. +- `--step-font-family` — previously applied to step labels and step rates. Replaced by `--wpds-font-family-body`. + +If `--wpds-font-family-body` is set, it takes precedence and the deprecated variables are ignored. + ## Theming Integration Conversion Funnel Charts integrate seamlessly with the chart theming system. The default theme has neutral colors and styling, and is automatically applied to all charts unless a custom theme is provided. A custom theme can be provided by wrapping your chart in `GlobalChartsProvider` and passing a custom theme object with the properties you want to override to the `theme` prop: From 5111668b14bcce7ce23f49b3f31fa9c2778fc628 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Apr 2026 11:03:13 +1200 Subject: [PATCH 11/20] Charts: Consolidate changelog into single entry for this PR Remove the separate pie-chart and conversion-funnel changelog entries added alongside the recent fixes. Their contents are covered by the existing charts-typography-tokenization entry, which is the single changelog entry for this PR. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../charts/changelog/charts-conversion-funnel-deprecated-vars | 4 ---- .../js-packages/charts/changelog/charts-pie-label-sizing-fix | 4 ---- 2 files changed, 8 deletions(-) delete mode 100644 projects/js-packages/charts/changelog/charts-conversion-funnel-deprecated-vars delete mode 100644 projects/js-packages/charts/changelog/charts-pie-label-sizing-fix diff --git a/projects/js-packages/charts/changelog/charts-conversion-funnel-deprecated-vars b/projects/js-packages/charts/changelog/charts-conversion-funnel-deprecated-vars deleted file mode 100644 index 162db01b1b61..000000000000 --- a/projects/js-packages/charts/changelog/charts-conversion-funnel-deprecated-vars +++ /dev/null @@ -1,4 +0,0 @@ -Significance: patch -Type: changed - -Charts: Restore backward compatibility for deprecated --funnel-font-family and --step-font-family CSS variables in ConversionFunnelChart. diff --git a/projects/js-packages/charts/changelog/charts-pie-label-sizing-fix b/projects/js-packages/charts/changelog/charts-pie-label-sizing-fix deleted file mode 100644 index 8ae44801f2fe..000000000000 --- a/projects/js-packages/charts/changelog/charts-pie-label-sizing-fix +++ /dev/null @@ -1,4 +0,0 @@ -Significance: patch -Type: fixed - -Charts: PieChart label background width now accounts for themed fontFamily, fontWeight, and string fontSize values. From 2442d34039d6e850c28f1282c04f5d4150bb2705 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Apr 2026 11:12:53 +1200 Subject: [PATCH 12/20] Charts: Inherit font-family from host app instead of declaring it on chart roots MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Chart components should not dictate their own font-family — that is the host application's responsibility. Previously each chart module declared font-family: var(--wpds-font-family-body, sans-serif) at its root, which silently overrode the host's typography cascade whenever --wpds-font-family-body was not defined. Remove the declaration from every chart root (bar, line, pie, pie-semi-circle, sparkline, geo, leaderboard, conversion-funnel) and from the conversion-funnel tooltip-wrapper. Charts now inherit the font-family set by the host page or component, which is the standard UI component convention. Also drop the short-lived backward-compatibility layer for the deprecated --funnel-font-family and --step-font-family custom properties and its docs section, since with no font-family at the chart root there is no longer a natural home for the fallback chain. Consumers relying on the implicit sans-serif fallback will now inherit from their host page. Consumers relying on the deprecated funnel custom properties should set font-family on an ancestor element (typically body) via their own theme layer. Storybook now sets body font-family to --wpds-font-family-body, acting as a WPDS-themed host so stories render with the design system font without the chart components themselves declaring it. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../charts/src/charts/bar-chart/bar-chart.module.scss | 1 - .../conversion-funnel-chart.module.scss | 10 ---------- .../conversion-funnel-chart/stories/index.docs.mdx | 9 --------- .../charts/src/charts/geo-chart/geo-chart.module.scss | 1 - .../leaderboard-chart/leaderboard-chart.module.scss | 1 - .../src/charts/line-chart/line-chart.module.scss | 1 - .../charts/src/charts/pie-chart/pie-chart.module.scss | 1 - .../pie-semi-circle-chart.module.scss | 2 -- .../charts/src/charts/sparkline/sparkline.module.scss | 1 - projects/js-packages/storybook/storybook/style.scss | 7 +++++++ 10 files changed, 7 insertions(+), 27 deletions(-) diff --git a/projects/js-packages/charts/src/charts/bar-chart/bar-chart.module.scss b/projects/js-packages/charts/src/charts/bar-chart/bar-chart.module.scss index 2880fb5d37dd..fd2246be150d 100644 --- a/projects/js-packages/charts/src/charts/bar-chart/bar-chart.module.scss +++ b/projects/js-packages/charts/src/charts/bar-chart/bar-chart.module.scss @@ -1,5 +1,4 @@ .bar-chart { - font-family: var(--wpds-font-family-body, sans-serif); svg { overflow: visible; diff --git a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss index 7aa4c7cff962..16da365f498b 100644 --- a/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +++ b/projects/js-packages/charts/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss @@ -1,7 +1,4 @@ .conversion-funnel-chart { - // `--funnel-font-family` is deprecated: prefer `--wpds-font-family-body`. - // Kept here as a fallback for backward compatibility. - font-family: var(--wpds-font-family-body, var(--funnel-font-family, sans-serif)); &--loading { opacity: 0.6; @@ -69,9 +66,6 @@ .step-label { color: #757575; - // `--step-font-family` is deprecated: prefer `--wpds-font-family-body`. - // Kept here as a fallback for backward compatibility. - font-family: var(--wpds-font-family-body, var(--step-font-family, sans-serif)); font-size: var(--wpds-font-size-sm, 12px); font-style: normal; font-weight: var(--wpds-font-weight-regular, 400); @@ -84,9 +78,6 @@ .step-rate { color: #1e1e1e; - // `--step-font-family` is deprecated: prefer `--wpds-font-family-body`. - // Kept here as a fallback for backward compatibility. - font-family: var(--wpds-font-family-body, var(--step-font-family, sans-serif)); font-size: var(--wpds-font-size-md, 13px); font-style: normal; font-weight: var(--wpds-font-weight-medium, 499); @@ -130,7 +121,6 @@ justify-content: center; align-items: flex-start; gap: 4px; - font-family: var(--wpds-font-family-body, sans-serif); border-bottom: 1px solid var(--Gray-Gray-5, #dcdcde); background: var(--black-white-white, #fff); diff --git a/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx b/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx index 33b121f7d989..3ca4e0b2c498 100644 --- a/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx +++ b/projects/js-packages/charts/src/charts/conversion-funnel-chart/stories/index.docs.mdx @@ -247,15 +247,6 @@ Use the `style` prop or `className` prop to customize the chart container: />` } /> -### Deprecated CSS Custom Properties - -The following CSS custom properties are **deprecated** and will be removed in a future release. They are still honored as fallbacks for backward compatibility, but new code should set `--wpds-font-family-body` instead (typically via the host app's theme/admin configuration, not raw CSS overrides): - -- `--funnel-font-family` — previously applied to the chart root, main rate, and change indicator. Replaced by `--wpds-font-family-body`. -- `--step-font-family` — previously applied to step labels and step rates. Replaced by `--wpds-font-family-body`. - -If `--wpds-font-family-body` is set, it takes precedence and the deprecated variables are ignored. - ## Theming Integration Conversion Funnel Charts integrate seamlessly with the chart theming system. The default theme has neutral colors and styling, and is automatically applied to all charts unless a custom theme is provided. A custom theme can be provided by wrapping your chart in `GlobalChartsProvider` and passing a custom theme object with the properties you want to override to the `theme` prop: diff --git a/projects/js-packages/charts/src/charts/geo-chart/geo-chart.module.scss b/projects/js-packages/charts/src/charts/geo-chart/geo-chart.module.scss index ce06d45b3c64..a69330bbc55a 100644 --- a/projects/js-packages/charts/src/charts/geo-chart/geo-chart.module.scss +++ b/projects/js-packages/charts/src/charts/geo-chart/geo-chart.module.scss @@ -1,5 +1,4 @@ .container { - font-family: var(--wpds-font-family-body, sans-serif); position: relative; display: flex; justify-content: center; diff --git a/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss b/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss index f583ff9e5781..aa61ed26681c 100644 --- a/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss +++ b/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss @@ -1,5 +1,4 @@ .leaderboardChart { - font-family: var(--wpds-font-family-body, sans-serif); transition: opacity 0.3s ease-in-out; &--responsive { diff --git a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss index e58b29eb9000..4ebb2743e420 100644 --- a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss +++ b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss @@ -1,5 +1,4 @@ .line-chart { - font-family: var(--wpds-font-family-body, sans-serif); position: relative; &--animated { diff --git a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.module.scss b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.module.scss index 243bda89a054..3c6be251d449 100644 --- a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.module.scss +++ b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.module.scss @@ -1,5 +1,4 @@ .pie-chart { - font-family: var(--wpds-font-family-body, sans-serif); overflow: hidden; // Fill parent when no explicit width/height provided diff --git a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss index 5573fab3b05d..6aae99c385cd 100644 --- a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +++ b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss @@ -1,6 +1,4 @@ .pie-semi-circle-chart { - font-family: var(--wpds-font-family-body, sans-serif); - // Fill parent when no explicit width/height provided &--responsive { height: 100%; diff --git a/projects/js-packages/charts/src/charts/sparkline/sparkline.module.scss b/projects/js-packages/charts/src/charts/sparkline/sparkline.module.scss index 5ac9c6904ac5..da8af86912b5 100644 --- a/projects/js-packages/charts/src/charts/sparkline/sparkline.module.scss +++ b/projects/js-packages/charts/src/charts/sparkline/sparkline.module.scss @@ -1,5 +1,4 @@ .sparkline { - font-family: var(--wpds-font-family-body, sans-serif); display: inline-block; vertical-align: middle; line-height: 1; diff --git a/projects/js-packages/storybook/storybook/style.scss b/projects/js-packages/storybook/storybook/style.scss index 90e3457d1db8..d7a23f7a22aa 100644 --- a/projects/js-packages/storybook/storybook/style.scss +++ b/projects/js-packages/storybook/storybook/style.scss @@ -7,3 +7,10 @@ @import "@wordpress/block-library/build-style/style.css"; @import "@wordpress/block-library/build-style/theme.css"; @import "@wordpress/block-library/build-style/editor.css"; + +// Treat Storybook as a WPDS-themed host application so components +// inherit the design system body font through the normal cascade, +// rather than each component declaring font-family at its root. +body { + font-family: var(--wpds-font-family-body, system-ui, sans-serif); +} From 5e99b6e2a995d5671eb1824111a3a9052bc1d6f4 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Apr 2026 11:16:15 +1200 Subject: [PATCH 13/20] Charts: Scope Storybook WPDS body font to charts stories only The previous commit set body font-family in the shared Storybook SCSS, which would have affected every package's stories. Move the rule to a .charts-storybook-host wrapper applied by a decorator that only fires for stories titled under "JS Packages/Charts Library", so charts still render with the design system font without leaking typography changes into other packages' stories. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../storybook/storybook/preview.jsx | 18 +++++++++++++----- .../js-packages/storybook/storybook/style.scss | 10 ++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/projects/js-packages/storybook/storybook/preview.jsx b/projects/js-packages/storybook/storybook/preview.jsx index 7a3802084e80..7000061a14ca 100644 --- a/projects/js-packages/storybook/storybook/preview.jsx +++ b/projects/js-packages/storybook/storybook/preview.jsx @@ -56,11 +56,19 @@ const preview = { backgrounds: { value: 'jetpack-dashboard' }, }, decorators: [ - Story => ( - - - - ), + ( Story, context ) => { + // Charts stories render inside a WPDS-themed wrapper so they + // inherit the design system body font through normal CSS cascade. + // Chart components intentionally do not declare font-family at + // their root — they rely on the host application to provide it. + const isChartsStory = context.title?.startsWith( 'JS Packages/Charts Library' ); + const content = ; + return ( + + { isChartsStory ?
{ content }
: content } +
+ ); + }, ], tags: [ 'autodocs' ], }; diff --git a/projects/js-packages/storybook/storybook/style.scss b/projects/js-packages/storybook/storybook/style.scss index d7a23f7a22aa..227dc3c3aeb6 100644 --- a/projects/js-packages/storybook/storybook/style.scss +++ b/projects/js-packages/storybook/storybook/style.scss @@ -8,9 +8,11 @@ @import "@wordpress/block-library/build-style/theme.css"; @import "@wordpress/block-library/build-style/editor.css"; -// Treat Storybook as a WPDS-themed host application so components -// inherit the design system body font through the normal cascade, -// rather than each component declaring font-family at its root. -body { +// Charts stories are wrapped by a decorator in preview.jsx that applies +// this class, so the Charts Library renders as if it were inside a +// WPDS-themed host application (inheriting the design system body font +// through normal CSS cascade, rather than each chart declaring +// font-family at its root). +.charts-storybook-host { font-family: var(--wpds-font-family-body, system-ui, sans-serif); } From f8be36431f99bec5f4556a90f5b05cb824811eef Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Apr 2026 11:36:53 +1200 Subject: [PATCH 14/20] Charts: Move WPDS font-family host wrapper into the charts story decorator The previous commit applied the WPDS body font via a decorator and CSS class in the shared Storybook preview. That worked but put charts-specific concerns into code shared with every other package's stories. Move the host-app font-family wrapper into the charts package's own shared decorator (StoryChartProvider, which backs both chartDecorator and simpleChartDecorator). Charts stories now render inside a div with font-family: var(--wpds-font-family-body, system-ui, sans-serif) without touching the shared storybook preview.jsx or style.scss. Revert the shared Storybook changes from the previous commit so the host-app simulation lives entirely in the charts package. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../charts/src/stories/chart-decorator.tsx | 18 +++++++++++++++--- .../storybook/storybook/preview.jsx | 18 +++++------------- .../js-packages/storybook/storybook/style.scss | 9 --------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/projects/js-packages/charts/src/stories/chart-decorator.tsx b/projects/js-packages/charts/src/stories/chart-decorator.tsx index 71e537017db2..b7c763855121 100644 --- a/projects/js-packages/charts/src/stories/chart-decorator.tsx +++ b/projects/js-packages/charts/src/stories/chart-decorator.tsx @@ -161,9 +161,21 @@ const StoryChartProvider = ( { return ( - - { children } - +
+ + { children } + +
); }; diff --git a/projects/js-packages/storybook/storybook/preview.jsx b/projects/js-packages/storybook/storybook/preview.jsx index 7000061a14ca..7a3802084e80 100644 --- a/projects/js-packages/storybook/storybook/preview.jsx +++ b/projects/js-packages/storybook/storybook/preview.jsx @@ -56,19 +56,11 @@ const preview = { backgrounds: { value: 'jetpack-dashboard' }, }, decorators: [ - ( Story, context ) => { - // Charts stories render inside a WPDS-themed wrapper so they - // inherit the design system body font through normal CSS cascade. - // Chart components intentionally do not declare font-family at - // their root — they rely on the host application to provide it. - const isChartsStory = context.title?.startsWith( 'JS Packages/Charts Library' ); - const content = ; - return ( - - { isChartsStory ?
{ content }
: content } -
- ); - }, + Story => ( + + + + ), ], tags: [ 'autodocs' ], }; diff --git a/projects/js-packages/storybook/storybook/style.scss b/projects/js-packages/storybook/storybook/style.scss index 227dc3c3aeb6..90e3457d1db8 100644 --- a/projects/js-packages/storybook/storybook/style.scss +++ b/projects/js-packages/storybook/storybook/style.scss @@ -7,12 +7,3 @@ @import "@wordpress/block-library/build-style/style.css"; @import "@wordpress/block-library/build-style/theme.css"; @import "@wordpress/block-library/build-style/editor.css"; - -// Charts stories are wrapped by a decorator in preview.jsx that applies -// this class, so the Charts Library renders as if it were inside a -// WPDS-themed host application (inheriting the design system body font -// through normal CSS cascade, rather than each chart declaring -// font-family at its root). -.charts-storybook-host { - font-family: var(--wpds-font-family-body, system-ui, sans-serif); -} From 034edd42628a17f2ec679c2155134d4e3538152e Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Apr 2026 11:51:04 +1200 Subject: [PATCH 15/20] Charts: Extract resolveFontSize into a shared utility resolveFontSize was defined locally inside use-chart-margin and then re-exported through the hooks barrel so pie-chart could reuse it for label sizing. Now that there are multiple call sites, move it into its own file under src/utils alongside the other chart helpers and export it from the utils barrel. Drop the re-export from the hooks barrel and update pie-chart to import directly from utils. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../charts/src/charts/pie-chart/pie-chart.tsx | 3 +-- .../js-packages/charts/src/hooks/index.ts | 2 +- .../charts/src/hooks/use-chart-margin.tsx | 15 +------------ .../js-packages/charts/src/utils/index.ts | 3 +++ .../charts/src/utils/resolve-font-size.ts | 22 +++++++++++++++++++ 5 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 projects/js-packages/charts/src/utils/resolve-font-size.ts diff --git a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx index c38d01969934..bcf65f9c495c 100644 --- a/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx +++ b/projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx @@ -8,7 +8,6 @@ import { useCallback, useContext, useMemo } from 'react'; import { Legend, useChartLegendItems } from '../../components/legend'; import { BaseTooltip } from '../../components/tooltip'; import { - resolveFontSize, useDataWithPercentages, useInteractiveLegendData, usePrefersReducedMotion, @@ -21,7 +20,7 @@ import { useGlobalChartsTheme, GlobalChartsContext, } from '../../providers'; -import { attachSubComponents } from '../../utils'; +import { attachSubComponents, resolveFontSize } from '../../utils'; import { getStringWidth } from '../../visx/text'; import { ChartSVG, ChartHTML, useChartChildren } from '../private/chart-composition'; import { ChartLayout } from '../private/chart-layout'; diff --git a/projects/js-packages/charts/src/hooks/index.ts b/projects/js-packages/charts/src/hooks/index.ts index 99aa45593961..706d58ec76ac 100644 --- a/projects/js-packages/charts/src/hooks/index.ts +++ b/projects/js-packages/charts/src/hooks/index.ts @@ -2,7 +2,7 @@ export { useDeepMemo } from './use-deep-memo'; export { useChartMouseHandler } from './use-chart-mouse-handler'; export { useXYChartTheme } from './use-xychart-theme'; export { useChartDataTransform } from './use-chart-data-transform'; -export { useChartMargin, resolveFontSize } from './use-chart-margin'; +export { useChartMargin } from './use-chart-margin'; export { useElementSize } from './use-element-size'; export { useTextTruncation } from './use-text-truncation'; export { useZeroValueDisplay } from './use-zero-value-display'; diff --git a/projects/js-packages/charts/src/hooks/use-chart-margin.tsx b/projects/js-packages/charts/src/hooks/use-chart-margin.tsx index c8e7262342dc..9dcb30d24bb8 100644 --- a/projects/js-packages/charts/src/hooks/use-chart-margin.tsx +++ b/projects/js-packages/charts/src/hooks/use-chart-margin.tsx @@ -1,6 +1,6 @@ import { createScale, getTicks } from '@visx/scale'; import { useMemo } from 'react'; -import { getLongestTickWidth } from '../utils'; +import { getLongestTickWidth, resolveFontSize } from '../utils'; import type { BaseChartProps, DataPointDate, SeriesData } from '../types'; import type { XYChartTheme } from '@visx/xychart'; @@ -50,19 +50,6 @@ const DEFAULT_TICK_LENGTH = 8; */ const DEFAULT_Y_TICK_WIDTH = 40; -export const resolveFontSize = ( val?: number | string ): number | undefined => { - if ( typeof val === 'number' && ! isNaN( val ) ) { - return val; - } - - if ( typeof val === 'string' ) { - const parsed = parseFloat( val ); - return isNaN( parsed ) ? undefined : parsed; - } - - return undefined; -}; - const getXAxisLabelMetrics = ( theme: XYChartTheme, orientation: 'top' | 'bottom' ) => { const xAxisStyles = orientation === 'top' ? theme.axisStyles?.x?.top : theme.axisStyles?.x?.bottom; diff --git a/projects/js-packages/charts/src/utils/index.ts b/projects/js-packages/charts/src/utils/index.ts index c93a0794d15b..68039dc46559 100644 --- a/projects/js-packages/charts/src/utils/index.ts +++ b/projects/js-packages/charts/src/utils/index.ts @@ -26,3 +26,6 @@ export * from './color-utils'; // CSS utilities export { resolveCssVariable } from './resolve-css-var'; + +// Font sizing utilities +export { resolveFontSize } from './resolve-font-size'; diff --git a/projects/js-packages/charts/src/utils/resolve-font-size.ts b/projects/js-packages/charts/src/utils/resolve-font-size.ts new file mode 100644 index 000000000000..9db8ee73178c --- /dev/null +++ b/projects/js-packages/charts/src/utils/resolve-font-size.ts @@ -0,0 +1,22 @@ +/** + * Resolve a theme `fontSize` value (which can be either a number or a + * CSS length string like `"12px"`) into a plain number suitable for + * measurement calculations such as `getStringWidth`. + * + * Returns `undefined` when the value is missing or cannot be parsed, + * so callers can fall back to their own default. + * @param val - Raw font size value from a theme, axis style, or props + * @return Parsed numeric font size, or `undefined` when unresolvable + */ +export const resolveFontSize = ( val?: number | string ): number | undefined => { + if ( typeof val === 'number' && ! isNaN( val ) ) { + return val; + } + + if ( typeof val === 'string' ) { + const parsed = parseFloat( val ); + return isNaN( parsed ) ? undefined : parsed; + } + + return undefined; +}; From 079ced11629a035e38af639916c7127d47566d36 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Apr 2026 12:45:24 +1200 Subject: [PATCH 16/20] Charts: Override visx SVG label font-family with inherit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit visx's buildChartTheme injects a hardcoded font stack (-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif) into every axis tickLabel and axisLabel style, which visx's Axis components then apply as an inline style on SVG elements. Inline styles beat inherited CSS, so axis text was silently ignoring the host application's font-family cascade regardless of what the chart roots did. Set fontFamily: 'inherit' on svgLabelSmall and svgLabelBig in the default theme so the inline value emitted by visx is 'inherit', letting SVG text actually pick up the host's font-family via normal CSS inheritance — consistent with the rest of this PR's decision that chart components should not dictate typography. Expose svgLabelBig on ChartTheme so it can be overridden alongside svgLabelSmall. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../charts/src/providers/chart-context/themes.ts | 8 +++++++- projects/js-packages/charts/src/types.ts | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/projects/js-packages/charts/src/providers/chart-context/themes.ts b/projects/js-packages/charts/src/providers/chart-context/themes.ts index e768a60c847a..e8cb5882eb4a 100644 --- a/projects/js-packages/charts/src/providers/chart-context/themes.ts +++ b/projects/js-packages/charts/src/providers/chart-context/themes.ts @@ -26,7 +26,13 @@ const defaultTheme: CompleteChartTheme = { }, seriesLineStyles: [], glyphs: [], - svgLabelSmall: { fill: 'var(--jp-gray-80, #2c3338)' }, + // `fontFamily: 'inherit'` overrides visx's hardcoded default font stack + // (`-apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,sans-serif`) + // that `buildChartTheme` injects as an inline style on SVG `` + // elements for axis labels and ticks. Setting `inherit` lets SVG text + // pick up the host application's font-family via normal CSS inheritance. + svgLabelSmall: { fill: 'var(--jp-gray-80, #2c3338)', fontFamily: 'inherit' }, + svgLabelBig: { fontFamily: 'inherit' }, annotationStyles: { label: { anchorLineStroke: 'var(--jp-gray-80, #2c3338)', diff --git a/projects/js-packages/charts/src/types.ts b/projects/js-packages/charts/src/types.ts index faeb3b4beb7f..959bda24a76b 100644 --- a/projects/js-packages/charts/src/types.ts +++ b/projects/js-packages/charts/src/types.ts @@ -243,6 +243,8 @@ export type ChartTheme = { }; /** Styles for small SVG text (eg. axis tick labels), passed through to the XYChart theme. */ svgLabelSmall?: TextProps; + /** Styles for large SVG text (eg. axis titles), passed through to the XYChart theme. */ + svgLabelBig?: TextProps; annotationStyles?: AnnotationStyles; /** GeoChart specific settings */ geoChart?: { From cc4f37dabf03b97824eee6f31c17ef78f3bbf667 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Apr 2026 13:38:15 +1200 Subject: [PATCH 17/20] Charts: Drop system-ui from Storybook host font fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Earlier in this PR we standardized on a single sans-serif fallback for --wpds-font-family-body across every chart SCSS module. The Storybook decorator drifted from that policy by including system-ui in the middle of the chain. Align it with the rest of the PR so the fallback policy is consistent everywhere the variable is used. The fallback is essentially defensive — design-tokens.css is imported unconditionally by Storybook's preview, so the var should always resolve in practice. Co-Authored-By: Claude Opus 4.6 (1M context) --- projects/js-packages/charts/src/stories/chart-decorator.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/js-packages/charts/src/stories/chart-decorator.tsx b/projects/js-packages/charts/src/stories/chart-decorator.tsx index b7c763855121..3cfd5b043cab 100644 --- a/projects/js-packages/charts/src/stories/chart-decorator.tsx +++ b/projects/js-packages/charts/src/stories/chart-decorator.tsx @@ -169,7 +169,7 @@ const StoryChartProvider = ( { cascade. */ style={ { - fontFamily: 'var(--wpds-font-family-body, system-ui, sans-serif)', + fontFamily: 'var(--wpds-font-family-body, sans-serif)', } } > From eaf6d2ad68f7c2d95e8f1b33d155fb799b39f12b Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Apr 2026 14:07:22 +1200 Subject: [PATCH 18/20] Charts: Standardize --wpds-font-size-md fallback to 13px MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The same WPDS token was being used with three different fallback values across the package: 13px (conversion-funnel, svg-empty-state), 14px (line-chart, leaderboard, base-tooltip, pie-semi-circle), and 0.875rem (trend-indicator, base-legend). When WPDS tokens are present they all resolve to the same canonical value, but in no-WPDS environments the inconsistency produced visibly different sizes between adjacent components in the same chart. Standardize on 13px — the actual WPDS design system value for --wpds-font-size-md — so the fallback matches the token everywhere and matches the policy already used by the conversion funnel and empty state. Update the pie-semi-circle docs to reflect the new default. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/charts/leaderboard-chart/leaderboard-chart.module.scss | 2 +- .../charts/src/charts/line-chart/line-chart.module.scss | 2 +- .../pie-semi-circle-chart/pie-semi-circle-chart.module.scss | 2 +- .../src/charts/pie-semi-circle-chart/stories/index.docs.mdx | 2 +- .../src/components/legend/private/base-legend.module.scss | 2 +- .../charts/src/components/tooltip/base-tooltip.module.scss | 2 +- .../src/components/trend-indicator/trend-indicator.module.scss | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss b/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss index aa61ed26681c..d950bfed08cb 100644 --- a/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss +++ b/projects/js-packages/charts/src/charts/leaderboard-chart/leaderboard-chart.module.scss @@ -73,6 +73,6 @@ padding: 32px 16px; text-align: center; color: #666; - font-size: var(--wpds-font-size-md, 14px); + font-size: var(--wpds-font-size-md, 13px); font-style: italic; } diff --git a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss index 4ebb2743e420..027e9d18faac 100644 --- a/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss +++ b/projects/js-packages/charts/src/charts/line-chart/line-chart.module.scss @@ -65,7 +65,7 @@ background: #fff; border: none; border-radius: 4px; - font-size: var(--wpds-font-size-md, 14px); + font-size: var(--wpds-font-size-md, 13px); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); position: fixed; margin: 0.5rem; diff --git a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss index 6aae99c385cd..a1ac68826817 100644 --- a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss +++ b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss @@ -16,6 +16,6 @@ } .note { - font-size: var(--wpds-font-size-md, 14px); + font-size: var(--wpds-font-size-md, 13px); } } diff --git a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx index 79541a09393d..27df24a6d572 100644 --- a/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx +++ b/projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.docs.mdx @@ -223,7 +223,7 @@ Segments automatically use theme colors, but you can override individual segment The chart includes built-in styling for labels and notes with appropriate typography hierarchy: - **Label**: Uses `--wpds-font-size-lg` (default 16px), `--wpds-font-weight-medium` (default 499), positioned above the chart -- **Note**: Uses `--wpds-font-size-md` (default 14px), positioned below the label +- **Note**: Uses `--wpds-font-size-md` (default 13px), positioned below the label Date: Thu, 9 Apr 2026 14:07:39 +1200 Subject: [PATCH 19/20] Charts: Tighten resolveFontSize parsing and add unit tests The previous implementation used parseFloat() on any string input, which silently accepted relative units like 0.875rem and returned the unitless prefix (0.875). Callers in use-chart-margin and pie-chart would then treat that as a pixel value, producing nearly-zero margins or invisible label backgrounds. Tighten the parser to accept only plain numeric strings and pixel values, rejecting rem, em, %, vh, vw, and CSS keywords like inherit or medium. The function now matches its JSDoc contract: returns undefined for any value it cannot reliably resolve to absolute pixels, so callers fall back to their own defaults. Add a dedicated unit test file covering numeric input, pixel strings, whitespace trimming, NaN, undefined, empty strings, unparseable input, and the previously-accepted relative units that should now be rejected. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../charts/src/utils/resolve-font-size.ts | 33 +++++++--- .../src/utils/test/resolve-font-size.test.ts | 66 +++++++++++++++++++ 2 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 projects/js-packages/charts/src/utils/test/resolve-font-size.test.ts diff --git a/projects/js-packages/charts/src/utils/resolve-font-size.ts b/projects/js-packages/charts/src/utils/resolve-font-size.ts index 9db8ee73178c..a96109a13c74 100644 --- a/projects/js-packages/charts/src/utils/resolve-font-size.ts +++ b/projects/js-packages/charts/src/utils/resolve-font-size.ts @@ -1,20 +1,35 @@ /** - * Resolve a theme `fontSize` value (which can be either a number or a - * CSS length string like `"12px"`) into a plain number suitable for - * measurement calculations such as `getStringWidth`. + * Resolve a theme `fontSize` value into a plain number suitable for + * canvas-based measurement (e.g. `getStringWidth`). * - * Returns `undefined` when the value is missing or cannot be parsed, - * so callers can fall back to their own default. + * Accepts: + * - A number — returned as-is + * - A pixel string like `"12px"` — parsed and returned as a number + * + * Returns `undefined` for any other input (missing value, NaN, or + * relative units like `rem`/`em`/`%`/`vh`) so callers can fall back to + * their own default. Relative units are intentionally rejected because + * we cannot resolve them to absolute pixels here without a parent + * computed style, and silently returning the unitless prefix + * (`parseFloat("0.875rem") === 0.875`) would produce nearly-zero + * widths in measurement code. * @param val - Raw font size value from a theme, axis style, or props - * @return Parsed numeric font size, or `undefined` when unresolvable + * @return Parsed numeric font size in pixels, or `undefined` when unresolvable */ export const resolveFontSize = ( val?: number | string ): number | undefined => { - if ( typeof val === 'number' && ! isNaN( val ) ) { - return val; + if ( typeof val === 'number' ) { + return isNaN( val ) ? undefined : val; } if ( typeof val === 'string' ) { - const parsed = parseFloat( val ); + // Only accept plain numeric strings or pixel values. + // Reject rem, em, %, vh, vw, etc. — they cannot be resolved to + // absolute pixels without a computed style context. + const match = val.trim().match( /^(-?\d+\.?\d*|-?\.\d+)(px)?$/ ); + if ( ! match ) { + return undefined; + } + const parsed = parseFloat( match[ 1 ] ); return isNaN( parsed ) ? undefined : parsed; } diff --git a/projects/js-packages/charts/src/utils/test/resolve-font-size.test.ts b/projects/js-packages/charts/src/utils/test/resolve-font-size.test.ts new file mode 100644 index 000000000000..7c43bd1c75c6 --- /dev/null +++ b/projects/js-packages/charts/src/utils/test/resolve-font-size.test.ts @@ -0,0 +1,66 @@ +import { resolveFontSize } from '../resolve-font-size'; + +describe( 'resolveFontSize', () => { + describe( 'numeric input', () => { + it( 'returns whole numbers as-is', () => { + expect( resolveFontSize( 12 ) ).toBe( 12 ); + expect( resolveFontSize( 0 ) ).toBe( 0 ); + } ); + + it( 'returns decimal numbers as-is', () => { + expect( resolveFontSize( 13.5 ) ).toBe( 13.5 ); + } ); + + it( 'returns undefined for NaN', () => { + expect( resolveFontSize( NaN ) ).toBeUndefined(); + } ); + } ); + + describe( 'string input', () => { + it( 'parses bare numeric strings', () => { + expect( resolveFontSize( '12' ) ).toBe( 12 ); + expect( resolveFontSize( '13.5' ) ).toBe( 13.5 ); + } ); + + it( 'parses pixel strings', () => { + expect( resolveFontSize( '12px' ) ).toBe( 12 ); + expect( resolveFontSize( '13.5px' ) ).toBe( 13.5 ); + } ); + + it( 'trims whitespace before parsing', () => { + expect( resolveFontSize( ' 14px ' ) ).toBe( 14 ); + } ); + + it( 'rejects rem values rather than returning the unitless prefix', () => { + expect( resolveFontSize( '0.875rem' ) ).toBeUndefined(); + } ); + + it( 'rejects em, %, vh, vw and other relative units', () => { + expect( resolveFontSize( '1em' ) ).toBeUndefined(); + expect( resolveFontSize( '100%' ) ).toBeUndefined(); + expect( resolveFontSize( '2vh' ) ).toBeUndefined(); + expect( resolveFontSize( '2vw' ) ).toBeUndefined(); + } ); + + it( 'rejects keywords like inherit, initial, unset', () => { + expect( resolveFontSize( 'inherit' ) ).toBeUndefined(); + expect( resolveFontSize( 'initial' ) ).toBeUndefined(); + expect( resolveFontSize( 'medium' ) ).toBeUndefined(); + } ); + + it( 'returns undefined for empty string', () => { + expect( resolveFontSize( '' ) ).toBeUndefined(); + } ); + + it( 'returns undefined for unparseable strings', () => { + expect( resolveFontSize( 'abc' ) ).toBeUndefined(); + expect( resolveFontSize( 'pxpx' ) ).toBeUndefined(); + } ); + } ); + + describe( 'missing input', () => { + it( 'returns undefined for undefined', () => { + expect( resolveFontSize( undefined ) ).toBeUndefined(); + } ); + } ); +} ); From 8f9618ce68d977224d25aca901bce5eb922f7ed9 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Apr 2026 14:07:56 +1200 Subject: [PATCH 20/20] Charts: Drop id="app" from Storybook chart decorator wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The id was added as a label of intent for the host-app font wrapper div, but Storybook docs pages render multiple stories side-by-side in the same DOM, which would produce duplicate id attributes — invalid HTML and a potential selector collision. The wrapper's purpose is documented by the adjacent comment, so the id is unnecessary. Remove it. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../charts/src/stories/chart-decorator.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/projects/js-packages/charts/src/stories/chart-decorator.tsx b/projects/js-packages/charts/src/stories/chart-decorator.tsx index 3cfd5b043cab..7067b2e2941e 100644 --- a/projects/js-packages/charts/src/stories/chart-decorator.tsx +++ b/projects/js-packages/charts/src/stories/chart-decorator.tsx @@ -161,13 +161,12 @@ const StoryChartProvider = ( { return ( + { /* + Storybook acts as a WPDS-themed host application so charts + inherit the design system body font through normal CSS + cascade. + */ }