Skip to content

Commit 820229a

Browse files
committed
feat: improve chart scaling and data handling in DashboardPage; add responsive styles and domain calculation for better visualization
2 parents e59fe9b + a80e4be commit 820229a

3 files changed

Lines changed: 81 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 🏥 Hospital Readmission Prediction System
1+
# 🏥 Hospital Readmission Prediction System
22

33
[![Azure](https://img.shields.io/badge/Deployed%20on-Azure-blue.svg)](https://azure.microsoft.com/) [![RMD Engineering College](https://img.shields.io/badge/Institution-RMD%20Engineering%20College-blue.svg)](https://rmd.ac.in)
44

frontend/src/App.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,29 @@
4040
.read-the-docs {
4141
color: #888;
4242
}
43+
44+
/* Chart scaling improvements */
45+
.recharts-wrapper {
46+
width: 100% !important;
47+
height: 100% !important;
48+
}
49+
50+
.recharts-responsive-container {
51+
width: 100% !important;
52+
height: 100% !important;
53+
}
54+
55+
/* Ensure charts scale properly on mobile */
56+
@media (max-width: 768px) {
57+
.recharts-wrapper {
58+
transform: scale(0.9);
59+
transform-origin: center;
60+
}
61+
}
62+
63+
@media (max-width: 480px) {
64+
.recharts-wrapper {
65+
transform: scale(0.8);
66+
transform-origin: center;
67+
}
68+
}

frontend/src/pages/DashboardPage.jsx

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,28 @@ const SPECIALTY_OPTIONS = [
6767
{ value: 'Other', label: 'Other' }
6868
];
6969

70+
// Helper function to calculate proper chart domain bounds
71+
const calculateChartDomain = (data) => {
72+
if (!data || data.length === 0) return [-0.01, 0.01];
73+
74+
const values = data.map(d => d.value).filter(v => Number.isFinite(v));
75+
if (values.length === 0) return [-0.01, 0.01];
76+
77+
const min = Math.min(...values);
78+
const max = Math.max(...values);
79+
const range = max - min;
80+
81+
// Handle very small ranges to prevent scaling issues
82+
if (Math.abs(range) < 0.001) {
83+
return [-0.005, 0.005];
84+
}
85+
86+
// Add padding to prevent bars from touching the edges
87+
const padding = Math.max(range * 0.1, 0.001);
88+
89+
return [min - padding, max + padding];
90+
};
91+
7092
const DashboardPage = () => {
7193
const [user] = useAuthState(auth);
7294

@@ -397,13 +419,21 @@ const DashboardPage = () => {
397419
const selectedResult = results[selectedIndex] || null;
398420
const chartData = useMemo(() => {
399421
if (!selectedResult || !selectedResult.top_contributions) return [];
400-
const items = selectedResult.top_contributions.map((c) => ({
401-
feature: c.feature.split('__').slice(-1)[0],
402-
value: c.shap_value,
403-
direction: c.shap_value >= 0 ? 'positive' : 'negative'
404-
}));
422+
423+
const items = selectedResult.top_contributions
424+
.filter(c => c && typeof c.shap_value === 'number' && Number.isFinite(c.shap_value))
425+
.map((c) => ({
426+
feature: c.feature ? c.feature.split('__').slice(-1)[0] : 'Unknown',
427+
value: parseFloat(c.shap_value) || 0,
428+
direction: c.shap_value >= 0 ? 'positive' : 'negative'
429+
}));
430+
405431
// Sort by absolute impact descending
406432
items.sort((a, b) => Math.abs(b.value) - Math.abs(a.value));
433+
434+
// Ensure we have valid data for chart scaling
435+
if (items.length === 0) return [];
436+
407437
return items;
408438
}, [selectedResult]);
409439

@@ -708,11 +738,26 @@ const DashboardPage = () => {
708738
<span className="inline-block w-3 h-3 rounded-sm ml-3" style={{ background: '#10b981' }}></span> decreases risk
709739
</div>
710740
</div>
711-
<div className="w-full h-96">
741+
<div className="w-full h-[500px]">
742+
{/* Debug info for chart scaling */}
743+
{chartData.length > 0 && (
744+
<div className="text-xs text-gray-500 mb-2 text-center">
745+
Chart range: {calculateChartDomain(chartData)[0].toFixed(6)} to {calculateChartDomain(chartData)[1].toFixed(6)}
746+
</div>
747+
)}
712748
<ResponsiveContainer width="100%" height="100%">
713-
<BarChart data={chartData} layout="vertical" margin={{ top: 10, right: 30, left: 10, bottom: 10 }}>
749+
<BarChart data={chartData} layout="vertical" margin={{ top: 20, right: 80, left: 20, bottom: 20 }}>
714750
<CartesianGrid strokeDasharray="3 3" />
715-
<XAxis type="number" tickFormatter={(v) => (Number.isFinite(v) ? Number(v).toFixed(2) : v)} domain={['auto', 'auto']} />
751+
<XAxis
752+
type="number"
753+
tickFormatter={(v) => (Number.isFinite(v) ? Number(v).toFixed(4) : v)}
754+
domain={calculateChartDomain(chartData)}
755+
ticks={chartData.length > 0 ? [
756+
calculateChartDomain(chartData)[0],
757+
0,
758+
calculateChartDomain(chartData)[1]
759+
] : []}
760+
/>
716761
<YAxis type="category" dataKey="feature" width={180} />
717762
<Tooltip formatter={(value, name) => [Number(value).toFixed(4), 'SHAP']} labelFormatter={(lbl) => `Feature: ${lbl}`} />
718763
<ReferenceLine x={0} stroke="#94a3b8" />
@@ -721,7 +766,7 @@ const DashboardPage = () => {
721766
{chartData.map((entry, index) => (
722767
<Cell key={`cell-${index}`} fill={colorFor(entry.value)} />
723768
))}
724-
<LabelList dataKey="value" position="right" formatter={(v) => Number(v).toFixed(3)} className="text-xs" />
769+
<LabelList dataKey="value" position="right" formatter={(v) => Number(v).toFixed(4)} className="text-xs" />
725770
</Bar>
726771
</BarChart>
727772
</ResponsiveContainer>

0 commit comments

Comments
 (0)