mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
fix(charts): use explicit tick positions on numeric x-axes
Recharts ignores the `interval` prop on `<XAxis type="number" />`. The pulse + mood charts switched to numeric axes in v1.4.25 to support multi-band rendering, which silently degraded the day-aware density policy to "every tick" on those charts. On a 365-row pulse view that meant ~365 overlapping labels. Add `computeTickPositions(chartData, viewportWidth)` — translates the existing `chooseTickInterval` skip count into explicit indices the numeric axis consumes via the `ticks` prop. Tick count clamps to a 3-12 visible-label range so dense series don't overcrowd and sparse series don't collapse to a single label. The category-axis charts (`compliance-line-chart`, `medication-compliance-chart`) stay on `interval` — Recharts honours it there.
This commit is contained in:
1 parent
5662fbecb1
commit
f463ca812c
4 files changed
+125
-7
No files matched your search
@@ -41,7 +41,7 @@ import type {
|
||||
import { ChartOverlayControls } from "./chart-overlay-controls";
|
||||
import { useChartOverlayPrefs } from "@/hooks/use-chart-overlay-prefs";
|
||||
import { useViewportWidth } from "@/hooks/use-viewport-width";
|
||||
import { chooseTickInterval } from "@/lib/charts/x-axis-density";
|
||||
import { computeTickPositions } from "@/lib/charts/x-axis-density";
|
||||
|
||||
const TIME_RANGES_KEYS = [
|
||||
{
|
||||
@@ -1281,8 +1281,13 @@ export function HealthChart({
|
||||
),
|
||||
)
|
||||
}
|
||||
interval={chooseTickInterval(
|
||||
chartData?.length ?? 0,
|
||||
// v1.4.29 — Recharts ignores `interval` on numeric
|
||||
// axes (`type="number"`). Hand explicit tick
|
||||
// positions through the `ticks` prop so the legacy
|
||||
// day-aware density policy stays effective on the
|
||||
// pulse chart.
|
||||
ticks={computeTickPositions(
|
||||
chartData ?? [],
|
||||
viewportWidth,
|
||||
)}
|
||||
padding={{ left: 10, right: 10 }}
|
||||
|
||||
@@ -36,7 +36,7 @@ import type {
|
||||
import { ChartOverlayControls } from "./chart-overlay-controls";
|
||||
import { useChartOverlayPrefs } from "@/hooks/use-chart-overlay-prefs";
|
||||
import { useViewportWidth } from "@/hooks/use-viewport-width";
|
||||
import { chooseTickInterval } from "@/lib/charts/x-axis-density";
|
||||
import { computeTickPositions } from "@/lib/charts/x-axis-density";
|
||||
import { CHART_HEIGHT_PX } from "@/lib/charts/constants";
|
||||
import { moodLabelKeyForScore } from "@/lib/mood/labels";
|
||||
|
||||
@@ -748,8 +748,10 @@ export function MoodChart({
|
||||
),
|
||||
)
|
||||
}
|
||||
interval={chooseTickInterval(
|
||||
chartData?.length ?? 0,
|
||||
// v1.4.29 — Recharts ignores `interval` on numeric
|
||||
// axes; pass explicit tick positions instead.
|
||||
ticks={computeTickPositions(
|
||||
chartData ?? [],
|
||||
viewportWidth,
|
||||
)}
|
||||
padding={{ left: 10, right: 10 }}
|
||||
|
||||
Reference in new issue
Block a user