mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
fix(charts): chart wrappers allow vertical scroll passthrough on mobile
Phase A5 mobile audit / B-mobile CRITICAL #1: Recharts wraps every chart in a `<ResponsiveContainer>` whose default `touch-action: auto` makes the browser wait for the chart's JS touchmove handler before starting page scroll. Recharts then dispatches a Redux action + tooltip re-render synchronously per touchmove. On slow devices that manifests as Marc's "Scrolling-Hänger im Dashboard auf Charts". Add the Tailwind `touch-pan-y` utility on every chart's wrapping `<div>` so the browser starts vertical scroll immediately without waiting for the JS handler. Chart-internal gestures (tap for tooltip, horizontal swipe inside the chart) still flow through to JS. Affected charts: health-chart, mood-chart, medication-compliance-chart, compliance-line-chart, scatter-correlation-chart. The latter two were rendering `<ResponsiveContainer>` without an explicit wrapper div, so both gain a `<div className="touch-pan-y">` parent. Evidence: new `touch-action-guard.test.ts` reads each chart source and asserts `touch-pan-y` (or the inline `touchAction: "pan-y"` style) is present. The test was first verified to fail on every chart before the fix, then turned green after. Findings ID: A5/CRITICAL-#1 (top of `.planning/phase-A5-mobile-findings.md`). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
bf7391b579
commit
316c3b0824
6 files changed
+165
-109
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
/**
|
||||
* Phase A5 / B-mobile finding (CRITICAL #1): Recharts wraps every
|
||||
* chart in a `<ResponsiveContainer>` whose default
|
||||
* `touch-action: auto` makes the browser wait for the chart's JS
|
||||
* touchmove handler before starting page scroll. On slow devices that
|
||||
* causes Marc's "Scrolling-Hänger im Dashboard auf Charts".
|
||||
*
|
||||
* Fix: every chart's wrapper `<div>` (the one that contains the
|
||||
* `<ResponsiveContainer>`) must carry the Tailwind `touch-pan-y`
|
||||
* utility so the browser starts vertical scroll immediately without
|
||||
* waiting for the JS handler.
|
||||
*
|
||||
* This test is a textual guard: if a future refactor accidentally
|
||||
* drops `touch-pan-y` from any chart wrapper, the unit test catches
|
||||
* it before it ships. The simpler textual check (vs. rendering each
|
||||
* chart) avoids the heavy Recharts + TanStack-Query + Auth provider
|
||||
* scaffold every individual chart needs to render.
|
||||
*/
|
||||
const CHART_FILES = [
|
||||
"health-chart.tsx",
|
||||
"mood-chart.tsx",
|
||||
"medication-compliance-chart.tsx",
|
||||
"compliance-line-chart.tsx",
|
||||
"scatter-correlation-chart.tsx",
|
||||
];
|
||||
|
||||
describe("chart wrappers — touch-action: pan-y guard", () => {
|
||||
for (const filename of CHART_FILES) {
|
||||
it(`${filename}: every ResponsiveContainer has a wrapper with touch-pan-y`, () => {
|
||||
const path = join(process.cwd(), "src/components/charts", filename);
|
||||
const src = readFileSync(path, "utf8");
|
||||
const responsiveCount = (src.match(/ResponsiveContainer\b/g) ?? [])
|
||||
.length;
|
||||
// The import line + opening tag + closing tag — but we want at least
|
||||
// one occurrence of the utility class. We also accept the explicit
|
||||
// inline style `touchAction: "pan-y"` in case a future refactor
|
||||
// moves to inline styles.
|
||||
const hasUtility = /touch-pan-y/.test(src);
|
||||
const hasInlineStyle = /touchAction\s*:\s*["']pan-y["']/.test(src);
|
||||
expect(
|
||||
hasUtility || hasInlineStyle,
|
||||
`${filename} mentions ResponsiveContainer (${responsiveCount} occurrences) but does not declare touch-pan-y on the wrapper. ` +
|
||||
`Add the Tailwind utility 'touch-pan-y' to the <div> that contains the <ResponsiveContainer> ` +
|
||||
`so the browser starts vertical scroll immediately. See .planning/phase-A5-mobile-findings.md → Scroll-lockup root-cause.`,
|
||||
).toBe(true);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -88,59 +88,61 @@ export function ComplianceLineChart({
|
||||
Keine Daten im gewählten Zeitraum
|
||||
</div>
|
||||
) : (
|
||||
<ResponsiveContainer width="100%" height={180}>
|
||||
<LineChart data={chartData}>
|
||||
<CartesianGrid
|
||||
strokeDasharray="3 3"
|
||||
stroke="var(--border)"
|
||||
opacity={0.5}
|
||||
/>
|
||||
<XAxis
|
||||
dataKey="date"
|
||||
tick={{ fontSize: 11, fill: "var(--muted-foreground)" }}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
/>
|
||||
<YAxis
|
||||
domain={[0, 100]}
|
||||
tick={{ fontSize: 11, fill: "var(--muted-foreground)" }}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
unit="%"
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={{
|
||||
backgroundColor: "var(--card)",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: "0.5rem",
|
||||
fontSize: "0.875rem",
|
||||
}}
|
||||
formatter={(value) => [`${value}%`, "Compliance"]}
|
||||
/>
|
||||
<ReferenceLine
|
||||
y={80}
|
||||
stroke="var(--dracula-green)"
|
||||
strokeDasharray="5 5"
|
||||
strokeOpacity={0.7}
|
||||
label={{
|
||||
value: "Ziel 80%",
|
||||
position: "right",
|
||||
fill: "var(--muted-foreground)",
|
||||
fontSize: 10,
|
||||
}}
|
||||
/>
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="rate"
|
||||
name="Compliance"
|
||||
stroke="var(--dracula-purple)"
|
||||
strokeWidth={2}
|
||||
dot={{ r: 2, fill: "var(--dracula-purple)" }}
|
||||
activeDot={{ r: 4 }}
|
||||
connectNulls
|
||||
/>
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
<div className="touch-pan-y">
|
||||
<ResponsiveContainer width="100%" height={180}>
|
||||
<LineChart data={chartData}>
|
||||
<CartesianGrid
|
||||
strokeDasharray="3 3"
|
||||
stroke="var(--border)"
|
||||
opacity={0.5}
|
||||
/>
|
||||
<XAxis
|
||||
dataKey="date"
|
||||
tick={{ fontSize: 11, fill: "var(--muted-foreground)" }}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
/>
|
||||
<YAxis
|
||||
domain={[0, 100]}
|
||||
tick={{ fontSize: 11, fill: "var(--muted-foreground)" }}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
unit="%"
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={{
|
||||
backgroundColor: "var(--card)",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: "0.5rem",
|
||||
fontSize: "0.875rem",
|
||||
}}
|
||||
formatter={(value) => [`${value}%`, "Compliance"]}
|
||||
/>
|
||||
<ReferenceLine
|
||||
y={80}
|
||||
stroke="var(--dracula-green)"
|
||||
strokeDasharray="5 5"
|
||||
strokeOpacity={0.7}
|
||||
label={{
|
||||
value: "Ziel 80%",
|
||||
position: "right",
|
||||
fill: "var(--muted-foreground)",
|
||||
fontSize: 10,
|
||||
}}
|
||||
/>
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="rate"
|
||||
name="Compliance"
|
||||
stroke="var(--dracula-purple)"
|
||||
strokeWidth={2}
|
||||
dot={{ r: 2, fill: "var(--dracula-purple)" }}
|
||||
activeDot={{ r: 4 }}
|
||||
connectNulls
|
||||
/>
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -712,7 +712,7 @@ export function HealthChart({
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="relative z-10 h-full">
|
||||
<div className="relative z-10 h-full touch-pan-y">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart
|
||||
data={chartData}
|
||||
|
||||
@@ -164,7 +164,7 @@ export function MedicationComplianceChart({
|
||||
{t("charts.noData")}
|
||||
</div>
|
||||
) : (
|
||||
<div className="h-[240px]">
|
||||
<div className="h-[240px] touch-pan-y">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart
|
||||
data={chartData}
|
||||
|
||||
@@ -457,7 +457,7 @@ export function MoodChart({ title }: MoodChartProps) {
|
||||
{t("charts.noData")}
|
||||
</div>
|
||||
) : (
|
||||
<div className="h-[280px]">
|
||||
<div className="h-[280px] touch-pan-y">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart
|
||||
data={chartData}
|
||||
|
||||
@@ -83,58 +83,60 @@ export function ScatterCorrelationChart<T extends Record<string, number>>({
|
||||
height = 250,
|
||||
}: ScatterCorrelationChartProps<T>) {
|
||||
return (
|
||||
<ResponsiveContainer width="100%" height={height}>
|
||||
<ScatterChart margin={{ top: 10, right: 20, bottom: 36, left: 12 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" />
|
||||
<XAxis
|
||||
dataKey={xAxis.dataKey}
|
||||
type="number"
|
||||
name={xAxis.name}
|
||||
unit={xAxis.unit}
|
||||
tick={{ fontSize: 12, fill: "var(--dracula-fg)" }}
|
||||
tickMargin={8}
|
||||
height={52}
|
||||
interval="preserveStartEnd"
|
||||
padding={{ left: 8, right: 8 }}
|
||||
stroke="var(--dracula-comment)"
|
||||
domain={xAxis.domain}
|
||||
ticks={xAxis.ticks}
|
||||
tickFormatter={xAxis.tickFormatter}
|
||||
label={
|
||||
xAxis.label
|
||||
? {
|
||||
value: xAxis.label,
|
||||
position: "bottom",
|
||||
fontSize: 12,
|
||||
fill: "var(--dracula-comment)",
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
<YAxis
|
||||
dataKey={yAxis.dataKey}
|
||||
type="number"
|
||||
name={yAxis.name}
|
||||
unit={yAxis.unit}
|
||||
tick={{ fontSize: 12, fill: "var(--dracula-fg)" }}
|
||||
stroke="var(--dracula-comment)"
|
||||
domain={yAxis.domain}
|
||||
ticks={yAxis.ticks}
|
||||
tickFormatter={yAxis.tickFormatter}
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={{
|
||||
backgroundColor: "hsl(var(--card))",
|
||||
border: "1px solid hsl(var(--border))",
|
||||
borderRadius: "0.5rem",
|
||||
fontSize: "0.75rem",
|
||||
}}
|
||||
itemStyle={{ color: "var(--dracula-fg)" }}
|
||||
labelStyle={{ color: "var(--dracula-fg)" }}
|
||||
formatter={tooltipFormatter}
|
||||
/>
|
||||
<Scatter data={data} fill={fill} opacity={0.8} />
|
||||
</ScatterChart>
|
||||
</ResponsiveContainer>
|
||||
<div className="touch-pan-y" style={{ height }}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<ScatterChart margin={{ top: 10, right: 20, bottom: 36, left: 12 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" />
|
||||
<XAxis
|
||||
dataKey={xAxis.dataKey}
|
||||
type="number"
|
||||
name={xAxis.name}
|
||||
unit={xAxis.unit}
|
||||
tick={{ fontSize: 12, fill: "var(--dracula-fg)" }}
|
||||
tickMargin={8}
|
||||
height={52}
|
||||
interval="preserveStartEnd"
|
||||
padding={{ left: 8, right: 8 }}
|
||||
stroke="var(--dracula-comment)"
|
||||
domain={xAxis.domain}
|
||||
ticks={xAxis.ticks}
|
||||
tickFormatter={xAxis.tickFormatter}
|
||||
label={
|
||||
xAxis.label
|
||||
? {
|
||||
value: xAxis.label,
|
||||
position: "bottom",
|
||||
fontSize: 12,
|
||||
fill: "var(--dracula-comment)",
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
<YAxis
|
||||
dataKey={yAxis.dataKey}
|
||||
type="number"
|
||||
name={yAxis.name}
|
||||
unit={yAxis.unit}
|
||||
tick={{ fontSize: 12, fill: "var(--dracula-fg)" }}
|
||||
stroke="var(--dracula-comment)"
|
||||
domain={yAxis.domain}
|
||||
ticks={yAxis.ticks}
|
||||
tickFormatter={yAxis.tickFormatter}
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={{
|
||||
backgroundColor: "hsl(var(--card))",
|
||||
border: "1px solid hsl(var(--border))",
|
||||
borderRadius: "0.5rem",
|
||||
fontSize: "0.75rem",
|
||||
}}
|
||||
itemStyle={{ color: "var(--dracula-fg)" }}
|
||||
labelStyle={{ color: "var(--dracula-fg)" }}
|
||||
formatter={tooltipFormatter}
|
||||
/>
|
||||
<Scatter data={data} fill={fill} opacity={0.8} />
|
||||
</ScatterChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user