Create a maternal morbidity public dashboard combining hospital metrics, qualitative…
- User
Create a maternal morbidity public dashboard combining hospital metrics, qualitative narratives, and equity commitments.
Assistant
Create a maternal morbidity public dashboard combining hospital metrics, qualitative narratives, and equity commitments.
The user wants a maternal morbidity public dashboard that combines:
This is a serious healthcare/public health topic, so I need to:
Design approach:
Key sections:
Dynamic elements:
I'll use Canvas for simple charts to keep it vanilla JS without heavy libraries.
Let me build this out with:
Color scheme:
I need to be careful with:
Typography & Color Palette:
Layout Structure:
Interactions:
Accessibility:
prefers-reduced-motion respectedEquity Focus:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Maternal Health Outcomes Dashboard</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=IBM+Plex+Sans:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg: #F7F5F2;
--bg-alt: #EDEAE5;
--fg: #1A1A1A;
--muted: #5C5C5C;
--accent: #0D5C63;
--accent-light: #148A8F;
--coral: #E07A5F;
--coral-dark: #C45D42;
--gold: #D4A574;
--card: #FFFFFF;
--border: #D9D5CE;
--success: #2D6A4F;
--warning: #BC6C25;
--danger: #9D4E4E;
}
* {
box-sizing: border-box;
}
body {
font-family: 'IBM Plex Sans', sans-serif;
background-color: var(--bg);
color: var(--fg);
line-height: 1.6;
}
h1, h2, h3, .display-font {
font-family: 'DM Serif Display', serif;
}
.pattern-bg {
background-color: var(--bg);
background-image:
radial-gradient(circle at 20% 80%, rgba(13, 92, 99, 0.03) 0%, transparent 50%),
radial-gradient(circle at 80% 20%, rgba(224, 122, 95, 0.03) 0%, transparent 50%),
url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23000000' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.hero-gradient {
background: linear-gradient(135deg, var(--accent) 0%, #0A4A50 50%, #083B40 100%);
}
.stat-card {
background: var(--card);
border: 1px solid var(--border);
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.stat-card:hover {
transform: translateY(-2px);
box-shadow: 0 8px 24px rgba(13, 92, 99, 0.12);
border-color: var(--accent);
}
.narrative-card {
background: var(--card);
border-left: 4px solid var(--coral);
transition: all 0.3s ease;
}
.narrative-card:hover {
border-left-color: var(--accent);
box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}
.progress-bar {
background: var(--bg-alt);
border-radius: 100px;
overflow: hidden;
}
.progress-fill {
height: 100%;
border-radius: 100px;
transition: width 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.tab-btn {
position: relative;
padding: 12px 24px;
font-weight: 500;
color: var(--muted);
transition: all 0.3s ease;
}
.tab-btn::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 3px;
background: var(--accent);
transform: scaleX(0);
transition: transform 0.3s ease;
}
.tab-btn.active {
color: var(--accent);
}
.tab-btn.active::after {
transform: scaleX(1);
}
.tab-btn:hover {
color: var(--accent);
}
.equity-meter {
position: relative;
height: 12px;
background: linear-gradient(90deg, var(--coral) 0%, var(--gold) 50%, var(--success) 100%);
border-radius: 100px;
}
.equity-marker {
position: absolute;
top: -6px;
width: 24px;
height: 24px;
background: var(--card);
border: 3px solid var(--fg);
border-radius: 50%;
transform: translateX(-50%);
transition: left 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.reveal {
opacity: 0;
transform: translateY(30px);
transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}
.reveal.visible {
opacity: 1;
transform: translateY(0);
}
.metric-value {
font-variant-numeric: tabular-nums;
}
.chart-container {
background: var(--card);
border: 1px solid var(--border);
border-radius: 12px;
}
.badge {
display: inline-flex;
align-items: center;
padding: 4px 12px;
border-radius: 100px;
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.badge-success {
background: rgba(45, 106, 79, 0.1);
color: var(--success);
}
.badge-warning {
background: rgba(188, 108, 37, 0.1);
color: var(--warning);
}
.badge-danger {
background: rgba(157, 78, 78, 0.1);
color: var(--danger);
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
@keyframes pulse-subtle {
0%, 100% { opacity: 1; }
50% { opacity: 0.7; }
}
.pulse-subtle {
animation: pulse-subtle 2s ease-in-out infinite;
}
:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
</style>
</head>
<body class="pattern-bg min-h-screen">
<!-- Header -->
<header class="hero-gradient text-white">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="py-6 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
<div>
<h1 class="text-2xl sm:text-3xl tracking-tight">Maternal Health Outcomes</h1>
<p class="text-teal-100 mt-1 text-sm">Regional Healthcare Quality Dashboard</p>
</div>
<div class="flex items-center gap-3">
<span class="badge badge-warning bg-amber-900/30 text-amber-200">Demonstration Data</span>
<span class="text-xs text-teal-200">Last updated: Jan 2025</span>
</div>
</div>
<!-- Key Stats Ticker -->
<div class="pb-8 grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="bg-white/10 backdrop-blur-sm rounded-xl p-4 border border-white/20">
<p class="text-teal-100 text-xs uppercase tracking-wide mb-1">Severe Morbidity Rate</p>
<p class="text-3xl font-semibold metric-value" data-counter="4.2">0</p>
<p class="text-teal-200 text-xs mt-1">per 1,000 deliveries</p>
</div>
<div class="bg-white/10 backdrop-blur-sm rounded-xl p-4 border border-white/20">
<p class="text-teal-100 text-xs uppercase tracking-wide mb-1">Reporting Hospitals</p>
<p class="text-3xl font-semibold metric-value" data-counter="47">0</p>
<p class="text-teal-200 text-xs mt-1">facilities</p>
</div>
<div class="bg-white/10 backdrop-blur-sm rounded-xl p-4 border border-white/20">
<p class="text-teal-100 text-xs uppercase tracking-wide mb-1">Equity Gap</p>
<p class="text-3xl font-semibold metric-value text-amber-300" data-counter="2.4">0</p>
<p class="text-teal-200 text-xs mt-1">x disparity ratio</p>
</div>
<div class="bg-white/10 backdrop-blur-sm rounded-xl p-4 border border-white/20">
<p class="text-teal-100 text-xs uppercase tracking-wide mb-1">Lives Impacted</p>
<p class="text-3xl font-semibold metric-value" data-counter="312">0</p>
<p class="text-teal-200 text-xs mt-1">cases reviewed</p>
</div>
</div>
</div>
</header>
<!-- Navigation Tabs -->
<nav class="sticky top-0 z-50 bg-white/95 backdrop-blur-sm border-b border-gray-200 shadow-sm">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex overflow-x-auto hide-scrollbar">
<button class="tab-btn active" data-tab="metrics" aria-selected="true">Hospital Metrics</button>
<button class="tab-btn" data-tab="narratives" aria-selected="false">Patient Narratives</button>
<button class="tab-btn" data-tab="equity" aria-selected="false">Equity Commitments</button>
</div>
</div>
</nav>
<main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<!-- Tab: Metrics -->
<section id="metrics-panel" class="tab-panel">
<div class="reveal">
<h2 class="text-2xl mb-6">Hospital Performance Metrics</h2>
<!-- Metrics Grid -->
<div class="grid md:grid-cols-3 gap-6 mb-8">
<div class="stat-card rounded-xl p-6">
<div class="flex items-start justify-between mb-4">
<div>
<p class="text-sm text-gray-500 uppercase tracking-wide">Hemorrhage Rate</p>
<p class="text-4xl font-bold mt-2 metric-value" style="color: var(--accent)">2.8%</p>
</div>
<span class="badge badge-success">-12% YoY</span>
</div>
<div class="progress-bar h-2 mt-4">
<div class="progress-fill" style="background: var(--accent); width: 0%;" data-width="72%"></div>
</div>
<p class="text-xs text-gray-500 mt-2">Target: 2.0% | National avg: 3.1%</p>
</div>
<div class="stat-card rounded-xl p-6">
<div class="flex items-start justify-between mb-4">
<div>
<p class="text-sm text-gray-500 uppercase tracking-wide">Preeclampsia Cases</p>
<p class="text-4xl font-bold mt-2 metric-value" style="color: var(--coral)">4.1%</p>
</div>
<span class="badge badge-warning">+3% YoY</span>
</div>
<div class="progress-bar h-2 mt-4">
<div class="progress-fill" style="background: var(--coral); width: 0%;" data-width="58%"></div>
</div>
<p class="text-xs text-gray-500 mt-2">Target: 3.5% | National avg: 4.4%</p>
</div>
<div class="stat-card rounded-xl p-6">
<div class="flex items-start justify-between mb-4">
<div>
<p class="text-sm text-gray-500 uppercase tracking-wide">ICU Transfers</p>
<p class="text-4xl font-bold mt-2 metric-value" style="color: var(--gold)">1.9%</p>
</div>
<span class="badge badge-success">-8% YoY</span>
</div>
<div class="progress-bar h-2 mt-4">
<div class="progress-fill" style="background: var(--gold); width: 0%;" data-width="81%"></div>
</div>
<p class="text-xs text-gray-500 mt-2">Target: 1.5% | National avg: 2.3%</p>
</div>
</div>
<!-- Chart Section -->
<div class="chart-container p-6 mb-8">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
<div>
<h3 class="text-xl">Morbidity by Demographics</h3>
<p class="text-sm text-gray-500">Severe maternal morbidity rates per 1,000 deliveries</p>
</div>
<div class="flex gap-2">
<button class="chart-filter active px-3 py-1.5 text-sm rounded-lg bg-teal-100 text-teal-800" data-filter="race">Race/Ethnicity</button>
<button class="chart-filter px-3 py-1.5 text-sm rounded-lg bg-gray-100 text-gray-600 hover:bg-gray-200" data-filter="age">Age Group</button>
</div>
</div>
<canvas id="demographicsChart" height="280" aria-label="Bar chart showing maternal morbidity rates by demographic group"></canvas>
</div>
<!-- Hospital List -->
<div class="chart-container overflow-hidden">
<div class="p-6 border-b border-gray-100">
<h3 class="text-xl">Facility Performance</h3>
</div>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-50 text-xs uppercase tracking-wide text-gray-500">
<tr>
<th class="px-6 py-3 text-left">Facility</th>
<th class="px-6 py-3 text-right">Deliveries</th>
<th class="px-6 py-3 text-right">SMM Rate</th>
<th class="px-6 py-3 text-center">Equity Score</th>
<th class="px-6 py-3 text-center">Status</th>
</tr>
</thead>
<tbody id="hospitalTable" class="divide-y divide-gray-100">
</tbody>
</table>
</div>
</div>
</div>
</section>
<!-- Tab: Narratives -->
<section id="narratives-panel" class="tab-panel hidden">
<div class="reveal">
<div class="mb-8">
<h2 class="text-2xl mb-2">Patient Experience Narratives</h2>
<p class="text-gray-600">Qualitative insights from maternal health experiences, anonymized and thematic.</p>
</div>
<div class="grid md:grid-cols-2 gap-6 mb-8" id="narrativesGrid">
<!-- Narratives injected via JS -->
</div>
<!-- Theme Summary -->
<div class="chart-container p-6">
<h3 class="text-xl mb-6">Emerging Themes</h3>
<div class="grid sm:grid-cols-2 lg:grid-cols-4 gap-4" id="themesGrid">
<!-- Themes injected via JS -->
</div>
</div>
</div>
</section>
<!-- Tab: Equity -->
<section id="equity-panel" class="tab-panel hidden">
<div class="reveal">
<div class="mb-8">
<h2 class="text-2xl mb-2">Equity Commitments</h2>
<p class="text-gray-600">System-wide pledges and progress toward eliminating racial disparities in maternal outcomes.</p>
</div>
<!-- Equity Meter -->
<div class="chart-container p-6 mb-8">
<div class="flex items-center justify-between mb-6">
<div>
<h3 class="text-xl">Regional Equity Index</h3>
<p class="text-sm text-gray-500">Composite score measuring disparity reduction progress</p>
</div>
<div class="text-right">
<p class="text-3xl font-bold" style="color: var(--gold)">58</p>
<p class="text-xs text-gray-500">of 100 target</p>
</div>
</div>
<div class="equity-meter mb-2">
<div class="equity-marker" style="left: 0%;" data-position="58%"></div>
</div>
<div class="flex justify-between text-xs text-gray-400 mt-2">
<span>Critical Gap</span>
<span>Progressing</span>
<span>Equity Achieved</span>
</div>
</div>
<!-- Commitments -->
<div class="grid md:grid-cols-2 gap-6 mb-8" id="commitmentsGrid">
<!-- Commitments injected via JS -->
</div>
<!-- Disparity Breakdown -->
<div class="chart-container p-6">
<h3 class="text-xl mb-6">Disparity Indicators</h3>
<div class="space-y-6" id="disparityList">
<!-- Disparities injected via JS -->
</div>
</div>
</div>
</section>
</main>
<!-- Footer -->
<footer class="bg-gray-900 text-gray-400 py-8 mt-12">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="grid md:grid-cols-3 gap-8">
<div>
<h4 class="text-white font-semibold mb-3">About This Dashboard</h4>
<p class="text-sm leading-relaxed">This demonstration dashboard illustrates how maternal health data can be presented transparently to support quality improvement and equity accountability.</p>
</div>
<div>
<h4 class="text-white font-semibold mb-3">Data Sources</h4>
<p class="text-sm leading-relaxed">All metrics shown are illustrative. Real implementation would integrate hospital discharge data, vital statistics, and patient-reported outcomes.</p>
</div>
<div>
<h4 class="text-white font-semibold mb-3">Contact</h4>
<p class="text-sm leading-relaxed">For questions about methodology or to report data concerns, contact the Regional Quality Improvement Office.</p>
</div>
</div>
<div class="border-t border-gray-800 mt-8 pt-6 text-center text-xs">
<p>Demonstration Dashboard | Not for Clinical Use</p>
</div>
</div>
</footer>
<script>
// === DATA ===
const hospitalData = [
{ name: "Regional Medical Center", deliveries: 3420, smmRate: 3.8, equityScore: 72, status: "on-track" },
{ name: "University Hospital", deliveries: 2890, smmRate: 4.2, equityScore: 65, status: "improving" },
{ name: "Community Health System", deliveries: 1856, smmRate: 5.1, equityScore: 48, status: "needs-focus" },
{ name: "Sacred Heart Medical", deliveries: 2104, smmRate: 3.4, equityScore: 78, status: "on-track" },
{ name: "Metropolitan General", deliveries: 4521, smmRate: 4.6, equityScore: 58, status: "improving" },
{ name: "Valley Regional", deliveries: 1234, smmRate: 3.9, equityScore: 69, status: "on-track" },
];
const narrativeData = [
{
theme: "Communication Barriers",
excerpt: "I expressed concerns about swelling for three visits before anyone took it seriously. By the time they did, my blood pressure was dangerously high.",
demographic: "First-time parent, Age 32",
outcome: "ICU admission, full recovery"
},
{
theme: "Delayed Response",
excerpt: "The nurses were wonderful, but the physician didn't come for hours after I started bleeding. I remember thinking this is how people die.",
demographic: "Second birth, Age 29",
outcome: "Transfusion required"
},
{
theme: "Advocacy Required",
excerpt: "My partner had to demand they check my labs again. The initial results had been filed without anyone noticing the critical values.",
demographic: "Third birth, Age 35",
outcome: "Early intervention, positive outcome"
},
{
theme: "Cultural Competence",
excerpt: "I didn't feel heard until I brought my sister who works in healthcare. The difference in how I was treated was stark and painful.",
demographic: "First-time parent, Age 27",
outcome: "Birth complications, ongoing trauma"
}
];
const themeData = [
{ name: "Communication Gaps", count: 47, color: "#0D5C63" },
{ name: "Delayed Response", count: 38, color: "#E07A5F" },
{ name: "Advocacy Barriers", count: 29, color: "#D4A574" },
{ name: "Cultural Mismatch", count: 24, color: "#5C5C5C" }
];
const commitmentData = [
{
title: "Implicit Bias Training",
description: "Mandatory training for all L&D staff with annual refreshers",
progress: 85,
status: "on-track"
},
{
title: "Diverse Workforce",
description: "Recruitment initiative to increase BIPOC representation in maternal health",
progress: 42,
status: "in-progress"
},
{
title: "Standardized Protocols",
description: "Evidence-based hemorrhage and hypertension bundles",
progress: 91,
status: "on-track"
},
{
title: "Patient Navigation",
description: "Doulas and community health workers for high-risk patients",
progress: 67,
status: "improving"
}
];
const disparityData = [
{ group: "Black birthing people", ratio: 2.4, trend: "improving", description: "SMM rate compared to white birthing people" },
{ group: "Indigenous patients", ratio: 2.1, trend: "stagnant", description: "SMM rate compared to white birthing people" },
{ group: "Medicaid recipients", ratio: 1.6, trend: "improving", description: "SMM rate compared to private insurance" },
{ group: "Rural residents", ratio: 1.4, trend: "worsening", description: "SMM rate compared to urban residents" }
];
const chartData = {
race: [
{ label: "Non-Hispanic White", value: 3.2, color: "#0D5C63" },
{ label: "Non-Hispanic Black", value: 7.7, color: "#E07A5F" },
{ label: "Hispanic/Latina", value: 4.8, color: "#D4A574" },
{ label: "Asian/Pacific Islander", value: 4.1, color: "#5C5C5C" },
{ label: "Indigenous", value: 6.7, color: "#148A8F" }
],
age: [
{ label: "Under 20", value: 5.2, color: "#0D5C63" },
{ label: "20-29", value: 3.8, color: "#E07A5F" },
{ label: "30-34", value: 4.1, color: "#D4A574" },
{ label: "35-39", value: 5.6, color: "#5C5C5C" },
{ label: "40+", value: 8.3, color: "#148A8F" }
]
};
// === INITIALIZATION ===
let currentChartFilter = 'race';
let animatedCounters = false;
let animatedProgress = false;
// Initialize on DOM ready
document.addEventListener('DOMContentLoaded', function() {
initTabs();
renderHospitalTable();
renderNarratives();
renderThemes();
renderCommitments();
renderDisparities();
initChartFilter();
initScrollReveal();
drawChart();
});
// === TABS ===
function initTabs() {
const tabs = document.querySelectorAll('.tab-btn');
tabs.forEach(tab => {
tab.addEventListener('click', function() {
const targetId = this.dataset.tab;
tabs.forEach(t => {
t.classList.remove('active');
t.setAttribute('aria-selected', 'false');
});
this.classList.add('active');
this.setAttribute('aria-selected', 'true');
document.querySelectorAll('.tab-panel').forEach(panel => {
panel.classList.add('hidden');
});
const targetPanel = document.getElementById(targetId + '-panel');
if (targetPanel) {
targetPanel.classList.remove('hidden');
triggerReveal(targetPanel);
}
});
});
}
function triggerReveal(container) {
const reveals = container.querySelectorAll('.reveal');
reveals.forEach(el => {
el.classList.remove('visible');
setTimeout(() => el.classList.add('visible'), 50);
});
}
// === COUNTERS ===
function animateCounters() {
if (animatedCounters) return;
animatedCounters = true;
const counters = document.querySelectorAll('[data-counter]');
counters.forEach(counter => {
const target = parseFloat(counter.dataset.counter);
const isDecimal = target % 1 !== 0;
const duration = 2000;
const startTime = performance.now();
function update(currentTime) {
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
const eased = 1 - Math.pow(1 - progress, 3);
const current = target * eased;
counter.textContent = isDecimal ? current.toFixed(1) : Math.round(current);
if (progress < 1) {
requestAnimationFrame(update);
}
}
requestAnimationFrame(update);
});
}
// === PROGRESS BARS ===
function animateProgressBars() {
if (animatedProgress) return;
animatedProgress = true;
const bars = document.querySelectorAll('.progress-fill[data-width]');
bars.forEach(bar => {
const targetWidth = bar.dataset.width;
setTimeout(() => {
bar.style.width = targetWidth;
}, 300);
});
const equityMarker = document.querySelector('.equity-marker[data-position]');
if (equityMarker) {
setTimeout(() => {
equityMarker.style.left = equityMarker.dataset.position;
}, 500);
}
}
// === HOSPITAL TABLE ===
function renderHospitalTable() {
const tbody = document.getElementById('hospitalTable');
if (!tbody) return;
tbody.innerHTML = hospitalData.map(h => {
const statusBadge = h.status === 'on-track'
? '<span class="badge badge-success">On Track</span>'
: h.status === 'improving'
? '<span class="badge badge-warning">Improving</span>'
: '<span class="badge badge-danger">Needs Focus</span>';
const equityColor = h.equityScore >= 70 ? 'var(--success)'
: h.equityScore >= 50 ? 'var(--gold)'
: 'var(--danger)';
return `
<tr class="hover:bg-gray-50 transition-colors">
<td class="px-6 py-4 font-medium">${h.name}</td>
<td class="px-6 py-4 text-right metric-value">${h.deliveries.toLocaleString()}</td>
<td class="px-6 py-4 text-right metric-value">${h.smmRate}%</td>
<td class="px-6 py-4">
<div class="flex items-center justify-center gap-2">
<span class="font-semibold" style="color: ${equityColor}">${h.equityScore}</span>
</div>
</td>
<td class="px-6 py-4 text-center">${statusBadge}</td>
</tr>
`;
}).join('');
}
// === NARRATIVES ===
function renderNarratives() {
const grid = document.getElementById('narrativesGrid');
if (!grid) return;
grid.innerHTML = narrativeData.map(n => `
<article class="narrative-card rounded-xl p-6 shadow-sm">
<span class="text-xs uppercase tracking-wide" style="color: var(--coral)">${n.theme}</span>
<blockquote class="mt-3 text-gray-700 leading-relaxed">
"${n.excerpt}"
</blockquote>
<div class="mt-4 pt-4 border-t border-gray-100 flex justify-between text-xs text-gray-500">
<span>${n.demographic}</span>
<span>${n.outcome}</span>
</div>
</article>
`).join('');
}
// === THEMES ===
function renderThemes() {
const grid = document.getElementById('themesGrid');
if (!grid) return;
grid.innerHTML = themeData.map(t => `
<div class="bg-gray-50 rounded-lg p-4">
<div class="flex items-center gap-3 mb-2">
<div class="w-3 h-3 rounded-full" style="background: ${t.color}"></div>
<span class="font-medium text-sm">${t.name}</span>
</div>
<p class="text-2xl font-bold" style="color: ${t.color}">${t.count}</p>
<p class="text-xs text-gray-500">mentions</p>
</div>
`).join('');
}
// === COMMITMENTS ===
function renderCommitments() {
const grid = document.getElementById('commitmentsGrid');
if (!grid) return;
grid.innerHTML = commitmentData.map(c => `
<div class="stat-card rounded-xl p-6">
<div class="flex items-start justify-between mb-3">
<h4 class="font-semibold">${c.title}</h4>
<span class="text-lg font-bold" style="color: var(--accent)">${c.progress}%</span>
</div>
<p class="text-sm text-gray-600 mb-4">${c.description}</p>
<div class="progress-bar h-2">
<div class="progress-fill" style="background: var(--accent); width: ${c.progress}%;"></div>
</div>
</div>
`).join('');
}
// === DISPARITIES ===
function renderDisparities() {
const list = document.getElementById('disparityList');
if (!list) return;
list.innerHTML = disparityData.map(d => {
const trendIcon = d.trend === 'improving'
? '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"></path></svg>'
: d.trend === 'worsening'
? '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 17h8m0 0V9m0 8l-8-8-4 4-6-6"></path></svg>'
: '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h14"></path></svg>';
const trendColor = d.trend === 'improving' ? 'text-green-600'
: d.trend === 'worsening' ? 'text-red-600'
: 'text-amber-600';
const ratioColor = d.ratio >= 2 ? 'var(--danger)'
: d.ratio >= 1.5 ? 'var(--warning)'
: 'var(--success)';
return `
<div class="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
<div class="flex-1">
<div class="flex items-center gap-3">
<h4 class="font-medium">${d.group}</h4>
<span class="${trendColor}">${trendIcon}</span>
</div>
<p class="text-sm text-gray-500 mt-1">${d.description}</p>
</div>
<div class="text-right ml-6">
<p class="text-2xl font-bold metric-value" style="color: ${ratioColor}">${d.ratio}x</p>
<p class="text-xs text-gray-500">disparity ratio</p>
</div>
</div>
`;
}).join('');
}
// === CHART ===
function initChartFilter() {
const filters = document.querySelectorAll('.chart-filter');
filters.forEach(filter => {
filter.addEventListener('click', function() {
filters.forEach(f => {
f.classList.remove('bg-teal-100', 'text-teal-800');
f.classList.add('bg-gray-100', 'text-gray-600');
});
this.classList.remove('bg-gray-100', 'text-gray-600');
this.classList.add('bg-teal-100', 'text-teal-800');
currentChartFilter = this.dataset.filter;
drawChart();
});
});
}
function drawChart() {
const canvas = document.getElementById('demographicsChart');
if (!canvas) return;
const ctx = canvas.getContext('2d');
const dpr = window.devicePixelRatio || 1;
const rect = canvas.getBoundingClientRect();
canvas.width = rect.width * dpr;
canvas.height = rect.height * dpr;
ctx.scale(dpr, dpr);
const width = rect.width;
const height = rect.height;
const padding = { top: 20, right: 20, bottom: 60, left: 50 };
const chartWidth = width - padding.left - padding.right;
const chartHeight = height - padding.top - padding.bottom;
const data = chartData[currentChartFilter];
const maxValue = Math.max(...data.map(d => d.value));
const barWidth = Math.max(1, chartWidth / data.length - 20);
ctx.clearRect(0, 0, width, height);
// Y-axis grid
ctx.strokeStyle = '#E5E5E5';
ctx.lineWidth = 1;
for (let i = 0; i <= 4; i++) {
const y = padding.top + (chartHeight / 4) * i;
ctx.beginPath();
ctx.moveTo(padding.left, y);
ctx.lineTo(width - padding.right, y);
ctx.stroke();
ctx.fillStyle = '#6B7280';
ctx.font = '11px IBM Plex Sans';
ctx.textAlign = 'right';
const labelValue = (maxValue * (1 - i / 4)).toFixed(1);
ctx.fillText(labelValue, padding.left - 10, y + 4);
}
// Bars with animation
data.forEach((d, i) => {
const x = padding.left + (chartWidth / data.length) * i + (chartWidth / data.length - barWidth) / 2;
const barHeight = Math.max(0, (d.value / maxValue) * chartHeight);
const y = padding.top + chartHeight - barHeight;
// Bar shadow
ctx.fillStyle = 'rgba(0,0,0,0.05)';
ctx.fillRect(x + 2, y + 2, barWidth, barHeight);
// Bar
ctx.fillStyle = d.color;
ctx.fillRect(x, y, barWidth, barHeight);
// Value label
ctx.fillStyle = '#1A1A1A';
ctx.font = '600 12px IBM Plex Sans';
ctx.textAlign = 'center';
ctx.fillText(d.value.toFixed(1), x + barWidth / 2, y - 8);
// X-axis label
ctx.fillStyle = '#6B7280';
ctx.font = '11px IBM Plex Sans';
ctx.save();
ctx.translate(x + barWidth / 2, padding.top + chartHeight + 15);
ctx.rotate(-0.3);
ctx.fillText(d.label, 0, 0);
ctx.restore();
});
}
// === SCROLL REVEAL ===
function initScrollReveal() {
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (prefersReducedMotion) {
document.querySelectorAll('.reveal').forEach(el => el.classList.add('visible'));
animateCounters();
animateProgressBars();
return;
}
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
if (entry.target.closest('#metrics-panel')) {
animateCounters();
animateProgressBars();
}
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.reveal').forEach(el => observer.observe(el));
// Initial trigger for visible panel
setTimeout(() => {
document.querySelectorAll('.tab-panel:not(.hidden) .reveal').forEach(el => {
el.classList.add('visible');
});
animateCounters();
animateProgressBars();
}, 100);
}
// Resize handler
window.addEventListener('resize', drawChart);
</script>
</body>
</html>