Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fc050c9
Charts: Replace hardcoded typography with WPDS design tokens
cursoragent Apr 8, 2026
7fdf5b0
Charts: Remove CSS Custom Properties docs section from conversion funnel
cursoragent Apr 8, 2026
6da627d
Charts: Simplify font-family fallback to just sans-serif
cursoragent Apr 8, 2026
3be6ee8
Charts: Remove redundant font-family from child selectors in conversi…
cursoragent Apr 8, 2026
a3a5f8f
Charts: Revert bold/semibold weights to hardcoded values
cursoragent Apr 8, 2026
92cb1fd
Charts: Align all font-weights to WPDS design system tokens
cursoragent Apr 8, 2026
25a52e5
Charts: Add font-family token to the root selector of every chart
cursoragent Apr 8, 2026
3d809a6
Charts: Remove fontFamily from svgLabelSmall theme property
cursoragent Apr 8, 2026
e4de571
Charts: Fix PieChart label background sizing to use full theme typogr…
adamwoodnz Apr 8, 2026
b2a0941
Charts: Restore backward compat for deprecated funnel font-family vars
adamwoodnz Apr 8, 2026
5111668
Charts: Consolidate changelog into single entry for this PR
adamwoodnz Apr 8, 2026
2442d34
Charts: Inherit font-family from host app instead of declaring it on …
adamwoodnz Apr 8, 2026
5e99b6e
Charts: Scope Storybook WPDS body font to charts stories only
adamwoodnz Apr 8, 2026
f8be364
Charts: Move WPDS font-family host wrapper into the charts story deco…
adamwoodnz Apr 8, 2026
034edd4
Charts: Extract resolveFontSize into a shared utility
adamwoodnz Apr 8, 2026
079ced1
Charts: Override visx SVG label font-family with inherit
adamwoodnz Apr 9, 2026
cc4f37d
Charts: Drop system-ui from Storybook host font fallback
adamwoodnz Apr 9, 2026
eaf6d2a
Charts: Standardize --wpds-font-size-md fallback to 13px
adamwoodnz Apr 9, 2026
046738f
Charts: Tighten resolveFontSize parsing and add unit tests
adamwoodnz Apr 9, 2026
8f9618c
Charts: Drop id="app" from Storybook chart decorator wrapper
adamwoodnz Apr 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Replace hardcoded typography values with WPDS design tokens for font family, size, weight, and line height.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.conversion-funnel-chart {
font-family: var(--funnel-font-family, "SF Pro Text");

&--loading {
opacity: 0.6;
Expand All @@ -19,22 +18,20 @@
overflow: hidden;
color: #1e1e1e;
text-overflow: ellipsis;
font-family: var(--funnel-font-family, "SF Pro Text");
font-size: 18px;
font-size: var(--wpds-font-size-xl, 18px);
font-style: normal;
font-weight: 500;
line-height: 20px;
font-weight: var(--wpds-font-weight-medium, 499);
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-size: var(--wpds-font-size-md, 13px);
font-style: normal;
font-weight: 500;
line-height: 20px;
font-weight: var(--wpds-font-weight-medium, 499);
line-height: var(--wpds-font-line-height-sm, 20px);
margin: 0;
}

Expand Down Expand Up @@ -69,11 +66,10 @@

.step-label {
color: #757575;
font-family: var(--step-font-family, "SF Pro");
font-size: 12px;
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;
Expand All @@ -82,11 +78,10 @@

.step-rate {
color: #1e1e1e;
font-family: var(--step-font-family, "SF Pro");
font-size: 13px;
font-size: var(--wpds-font-size-md, 13px);
font-style: normal;
font-weight: 500;
line-height: 20px;
font-weight: var(--wpds-font-weight-medium, 499);
line-height: var(--wpds-font-line-height-sm, 20px);
margin: 0;
display: block;
}
Expand Down Expand Up @@ -139,25 +134,23 @@

.tooltip-title {
color: #1e1e1e;
font-family: "SF Pro", sans-serif;
font-size: 12px;
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-size: var(--wpds-font-size-md, 13px);
font-style: normal;
font-weight: 500;
line-height: 20px;
font-weight: var(--wpds-font-weight-medium, 499);
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,6 @@ Use the `style` prop or `className` prop to customize the chart container:
/>` }
/>

### CSS Custom Properties

The component exposes CSS custom properties for font customization:

<Source
language="css"
code={ `.my-custom-funnel {
--funnel-font-family: "Inter", sans-serif;
--step-font-family: "Inter", sans-serif;
}` }
/>

## 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}}
/>` }
/>
Expand All @@ -445,7 +444,6 @@ 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;
}` }
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => <LeaderboardChartWithOverlayLabelImage { ...args } />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}

&__tooltip-date {
font-weight: 700;
font-weight: var(--wpds-font-weight-medium, 499);
padding-bottom: 10px;
}

Expand All @@ -33,7 +33,7 @@
}

&__tooltip-label {
font-weight: 500;
font-weight: var(--wpds-font-weight-medium, 499);
padding-right: 1rem;
}

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,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';
Expand Down Expand Up @@ -441,10 +441,12 @@ const PieChartInternal = ( {
groupProps.onMouseLeave = onMouseLeave;
}

// Estimate text width more accurately for background sizing
const 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
}

.label {
font-weight: 600;
font-size: 16px;
font-weight: var(--wpds-font-weight-medium, 499);
font-size: var(--wpds-font-size-lg, 16px);
}

.note {
font-size: 14px;
font-size: var(--wpds-font-size-md, 14px);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 499), positioned above the chart
- **Note**: Uses `--wpds-font-size-md` (default 14px), positioned below the label

<Source
language="jsx"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
.legend-item {
display: flex;
align-items: center;
font-size: 0.875rem;
font-size: var(--wpds-font-size-md, 0.875rem);

&--interactive {
cursor: pointer;
Expand Down Expand Up @@ -101,6 +101,6 @@
}

.legend-item-value {
font-weight: 500;
font-weight: var(--wpds-font-weight-medium, 499);
flex-shrink: 0; // Prevent value from shrinking when text is ellipsized
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
background-color: rgba(0, 0, 0, 0.85);
color: #fff;
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: absolute;
pointer-events: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
display: inline-flex;
align-items: center;
gap: 0.125em;
font-size: 0.875rem;
font-weight: 500;
font-size: var(--wpds-font-size-md, 0.875rem);
font-weight: var(--wpds-font-weight-medium, 499);
line-height: 1;

&--up {
Expand Down
15 changes: 1 addition & 14 deletions projects/js-packages/charts/src/hooks/use-chart-margin.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -50,19 +50,6 @@ const DEFAULT_TICK_LENGTH = 8;
*/
const DEFAULT_Y_TICK_WIDTH = 40;

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;
Expand Down
18 changes: 15 additions & 3 deletions projects/js-packages/charts/src/stories/chart-decorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,21 @@ const StoryChartProvider = ( {

return (
<ThemeProvider color={ themeProviderColor }>
<GlobalChartsProvider key={ providerKey } theme={ theme }>
{ children }
</GlobalChartsProvider>
<div
id="app"
/*
Storybook acts as a WPDS-themed host application so charts
inherit the design system body font through normal CSS
cascade.
*/
style={ {
fontFamily: 'var(--wpds-font-family-body, system-ui, sans-serif)',
} }
>
<GlobalChartsProvider key={ providerKey } theme={ theme }>
{ children }
</GlobalChartsProvider>
</div>
</ThemeProvider>
);
};
Expand Down
3 changes: 3 additions & 0 deletions projects/js-packages/charts/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
22 changes: 22 additions & 0 deletions projects/js-packages/charts/src/utils/resolve-font-size.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Loading