Skip to content
Merged
Changes from all commits
Commits
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
Expand Up @@ -48,6 +48,9 @@
const [startDate, setStartDate] = useState(null);
const [endDate, setEndDate] = useState(null);

// ✅ NEW: key to force Recharts remount when needed (fixes "renders only on hover")
const [chartKey, setChartKey] = useState(0);

useEffect(() => {
dispatch(fetchSeverities());
dispatch(fetchInjuryTypes());
Expand Down Expand Up @@ -141,6 +144,30 @@
'#38BDF8', // cyan
];

// Force a resize/reflow after data/filter changes so chart draws immediately (no hover needed)
useEffect(() => {
// Only do this once the chart is supposed to be visible
if (loading || error) return;

const raf = requestAnimationFrame(() => {
window.dispatchEvent(new Event('resize')); // triggers ResponsiveContainer measure

Check warning on line 153 in src/components/BMDashboard/WeeklyProjectSummary/GroupedBarGraphInjurySeverity/InjuryCategoryBarChart.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ2sQEwkBJ5yin3Y8zzn&open=AZ2sQEwkBJ5yin3Y8zzn&pullRequest=4697
setChartKey(k => k + 1); // extra-safe: forces a clean remount
});

return () => cancelAnimationFrame(raf);
}, [
loading,
error,
darkMode,
chartData.length,
seriesProjectIds.length,
projectNameFilter,
severityFilter,
injuryTypeFilter,
startDate,
endDate,
]);

const selectStyles = darkMode && {
control: base => ({
...base,
Expand Down Expand Up @@ -265,7 +292,7 @@
{!loading && error && <p className="error">Error: {String(error)}</p>}

{!loading && !error && chartData.length > 0 && (
<ResponsiveContainer width="100%" height={420}>
<ResponsiveContainer key={chartKey} width="100%" height={420}>
<BarChart
data={chartData}
margin={{ top: 16, right: 24, bottom: 8, left: 8 }}
Expand All @@ -292,6 +319,8 @@
tickLine={{ stroke: darkMode ? '#888' : '#000' }}
/>
<Tooltip
//tooltip only; no shaded hover overlay across the chart
cursor={false}
contentStyle={{
backgroundColor: darkMode ? '#2b3e59' : '#fff',
border: `1px solid ${darkMode ? '#4a5568' : '#cccccc'}`,
Expand Down
Loading