@@ -69,6 +69,7 @@ import {
6969 toStartOfInterval ,
7070} from './ChartUtils' ;
7171import { useFormatTime } from './useFormatTime' ;
72+ import { useContentFontSize } from './useUserPreferences' ;
7273
7374import styles from '@styles/HDXLineChart.module.scss' ;
7475
@@ -777,7 +778,12 @@ export function collectMemoChartGradientHexes(
777778// (NumberFormat.tsx), but 2 already distinguishes values >= 0.005 from 0.
778779const MAX_AXIS_MANTISSA = 2 ;
779780
780- /** Base width ceiling for a bare signed number - see MAX_AXIS_MANTISSA's comment. */
781+ /**
782+ * Base width ceiling for a bare signed number - see MAX_AXIS_MANTISSA's
783+ * comment. A character budget rather than a pixel one, which is why
784+ * Y_AXIS_WIDTH scales with the content font size preference: the gutter has to
785+ * grow with the tick font for this to keep holding at every setting.
786+ */
781787const AXIS_CHAR_BUDGET = 5 ;
782788
783789// Flat, not suffix-length-scaled - IBM Plex Mono is monospace, so a longer
@@ -1351,6 +1357,12 @@ export const MemoChart = memo(function MemoChart({
13511357 const _id = useId ( ) ;
13521358 const id = _id . replace ( / : / g, '' ) ;
13531359
1360+ // The y-axis width budget is expressed in characters (see MAX_AXIS_MANTISSA),
1361+ // so it has to grow with the tick font or the widest labels clip.
1362+ const { compact : axisTickFontSize , scale : contentFontScale } =
1363+ useContentFontSize ( ) ;
1364+ const yAxisWidth = Math . round ( Y_AXIS_WIDTH * contentFontScale ) ;
1365+
13541366 // recharts sync group, scoped via context (see chartSync).
13551367 const syncId = useChartSyncId ( ) ;
13561368
@@ -1585,14 +1597,14 @@ export const MemoChart = memo(function MemoChart({
15851597 if ( graphResults . length !== 1 ) return undefined ;
15861598 const drawableWidth = Math . max (
15871599 0 ,
1588- containerWidth - Y_AXIS_WIDTH - SINGLE_POINT_BAR_RIGHT_PADDING ,
1600+ containerWidth - yAxisWidth - SINGLE_POINT_BAR_RIGHT_PADDING ,
15891601 ) ;
15901602 if ( drawableWidth <= 0 ) return undefined ;
15911603 return Math . max (
15921604 1 ,
15931605 Math . floor ( drawableWidth * SINGLE_POINT_BAR_WIDTH_RATIO ) ,
15941606 ) ;
1595- } , [ displayType , graphResults . length , containerWidth ] ) ;
1607+ } , [ displayType , graphResults . length , containerWidth , yAxisWidth ] ) ;
15961608
15971609 const formatTime = useFormatTime ( ) ;
15981610 const xTickFormatter = useCallback (
@@ -1932,9 +1944,9 @@ export const MemoChart = memo(function MemoChart({
19321944 }
19331945 return layoutAnnotations ( coloredAnnotations , {
19341946 domain : xAxisDomain ,
1935- plotWidth : Math . max ( 0 , containerWidth - Y_AXIS_WIDTH ) ,
1947+ plotWidth : Math . max ( 0 , containerWidth - yAxisWidth ) ,
19361948 } ) ;
1937- } , [ coloredAnnotations , xAxisDomain , containerWidth ] ) ;
1949+ } , [ coloredAnnotations , xAxisDomain , containerWidth , yAxisWidth ] ) ;
19381950
19391951 const [ hoveredAnnotation , setHoveredAnnotation ] =
19401952 useState < HoveredAnnotation | null > ( null ) ;
@@ -1948,9 +1960,9 @@ export const MemoChart = memo(function MemoChart({
19481960 // Drawable width, so markers too close together share one label. Zero on
19491961 // the first paint (before ResponsiveContainer measures), which the
19501962 // renderer treats as "label everything".
1951- plotWidth : Math . max ( 0 , containerWidth - Y_AXIS_WIDTH ) ,
1963+ plotWidth : Math . max ( 0 , containerWidth - yAxisWidth ) ,
19521964 } ) ;
1953- } , [ coloredAnnotations , xAxisDomain , containerWidth ] ) ;
1965+ } , [ coloredAnnotations , xAxisDomain , containerWidth , yAxisWidth ] ) ;
19541966
19551967 return (
19561968 < div
@@ -2063,13 +2075,19 @@ export const MemoChart = memo(function MemoChart({
20632075 type = "number"
20642076 tickFormatter = { xTickFormatter }
20652077 minTickGap = { 100 }
2066- tick = { { fontSize : 11 , fontFamily : 'IBM Plex Mono, monospace' } }
2078+ tick = { {
2079+ fontSize : axisTickFontSize ,
2080+ fontFamily : 'IBM Plex Mono, monospace' ,
2081+ } }
20672082 />
20682083 < YAxis
2069- width = { Y_AXIS_WIDTH }
2084+ width = { yAxisWidth }
20702085 minTickGap = { 25 }
20712086 tickFormatter = { yAxisTickFormatter }
2072- tick = { { fontSize : 11 , fontFamily : 'IBM Plex Mono, monospace' } }
2087+ tick = { {
2088+ fontSize : axisTickFontSize ,
2089+ fontFamily : 'IBM Plex Mono, monospace' ,
2090+ } }
20732091 domain = { yAxisDomain }
20742092 ticks = { yAxisTicks }
20752093 />
0 commit comments