Skip to content

Fix chart y axis and other small styling tweaks#470

Merged
tudddorrr merged 1 commit intodevelopfrom
chart-styling
Feb 20, 2026
Merged

Fix chart y axis and other small styling tweaks#470
tudddorrr merged 1 commit intodevelopfrom
chart-styling

Conversation

@tudddorrr
Copy link
Collaborator

No description provided.

@tudddorrr tudddorrr added the fix This pull request contains a fix label Feb 20, 2026
@claude
Copy link

claude bot commented Feb 20, 2026

PR Review: Fix chart y axis and other small styling tweaks


🟡 Code Quality / Performance

useMemo memoization is broken due to inline transformer functions

In useYAxisWidth, the memo depends on [data, transformer]:

const yAxisWidth = useMemo(() => {
  const maxValue = Math.max(...transformer(data), 0)
  return maxValue.toLocaleString().length * pxPerChar
}, [data, transformer])

Every caller passes an inline arrow function, which creates a new reference each render:

// BarChartCard.tsx — new function reference every render
const { yAxisProps } = useYAxis({
  data,
  transformer: (d) => {
    return d.flatMap((item) => bars.map((bar) => ...))
  }
})

Since transformer always has a new identity, the useMemo recomputes on every render, making it a no-op. Callers should wrap their transformer in useCallback, or the hook can use a ref pattern to avoid the stale closure issue:

const transformerRef = useRef(transformer)
transformerRef.current = transformer

const yAxisWidth = useMemo(() => {
  const maxValue = Math.max(...transformerRef.current(data), 0)
  return maxValue.toLocaleString().length * pxPerChar
}, [data])

🔵 Minor

StatGlobalValueChart missing hasData prop — inconsistent with new pattern

BarChartCard passes hasData={data.length > 0} to ChartCard, which triggers the "No data for this date range" message. StatGlobalValueChart does not pass hasData, so ChartCard defaults to true and renders an empty chart instead of the message when dataPoints is empty:

// StatGlobalValueChart.tsx — hasData not passed
<ChartCard
  title='Global value'
  loading={loading}
  error={error}
  // hasData={dataPoints.length > 0}  <-- missing
>

@tudddorrr tudddorrr merged commit f828dff into develop Feb 20, 2026
5 checks passed
@tudddorrr tudddorrr deleted the chart-styling branch February 20, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix This pull request contains a fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant