The user wants a graduate pathways dashboard focusing on time, attrition, and outcomes. This is an academic analytics visualization, so I'll create a sophisticated, professional dashboard with multiple data visualizations.
Let me build this with Canvas-based charts and CSS animations for a dynamic feel.
A professional academic analytics dashboard with interactive visualizations for time-to-degree, attrition patterns, and career outcomes.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Graduate Pathways 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=Space+Grotesk:wght@400;500;600;700&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0f14;
--bg-elevated: #111920;
--card: #151d26;
--card-hover: #1a2530;
--border: #243040;
--fg: #e8edf3;
--muted: #7a8b9c;
--accent: #00d4aa;
--accent-dim: rgba(0, 212, 170, 0.15);
--warning: #ffb84d;
--danger: #ff6b6b;
--info: #4dabf7;
}
* {
box-sizing: border-box;
}
body {
font-family: 'IBM Plex Sans', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
}
h1, h2, h3, h4, .metric-value {
font-family: 'Space Grotesk', sans-serif;
}
.bg-pattern {
background-image:
radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 212, 170, 0.08), transparent),
radial-gradient(ellipse 60% 40% at 100% 100%, rgba(77, 171, 247, 0.05), transparent),
linear-gradient(180deg, var(--bg) 0%, var(--bg-elevated) 100%);
}
.grid-overlay {
background-image:
linear-gradient(rgba(36, 48, 64, 0.3) 1px, transparent 1px),
linear-gradient(90deg, rgba(36, 48, 64, 0.3) 1px, transparent 1px);
background-size: 40px 40px;
}
.card {
background: var(--card);
border: 1px solid var(--border);
border-radius: 12px;
transition: all 0.3s ease;
}
.card:hover {
background: var(--card-hover);
border-color: rgba(0, 212, 170, 0.3);
}
.metric-card {
position: relative;
overflow: hidden;
}
.metric-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 3px;
background: linear-gradient(90deg, var(--accent), var(--info));
opacity: 0;
transition: opacity 0.3s ease;
}
.metric-card:hover::before {
opacity: 1;
}
.filter-btn {
background: transparent;
border: 1px solid var(--border);
color: var(--muted);
padding: 8px 16px;
border-radius: 6px;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.filter-btn:hover {
border-color: var(--accent);
color: var(--fg);
}
.filter-btn.active {
background: var(--accent-dim);
border-color: var(--accent);
color: var(--accent);
}
.filter-btn:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.chart-container {
position: relative;
width: 100%;
}
canvas {
display: block;
}
.legend-dot {
width: 10px;
height: 10px;
border-radius: 50%;
flex-shrink: 0;
}
.progress-bar {
height: 8px;
background: var(--border);
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
border-radius: 4px;
transition: width 1s ease-out;
}
.tooltip {
position: fixed;
background: var(--bg-elevated);
border: 1px solid var(--border);
padding: 10px 14px;
border-radius: 8px;
font-size: 13px;
pointer-events: none;
opacity: 0;
transform: translateY(4px);
transition: all 0.15s ease;
z-index: 1000;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
.tooltip.visible {
opacity: 1;
transform: translateY(0);
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes countUp {
from { opacity: 0; }
to { opacity: 1; }
}
.animate-in {
animation: fadeInUp 0.6s ease forwards;
}
.stagger-1 { animation-delay: 0.1s; opacity: 0; }
.stagger-2 { animation-delay: 0.2s; opacity: 0; }
.stagger-3 { animation-delay: 0.3s; opacity: 0; }
.stagger-4 { animation-delay: 0.4s; opacity: 0; }
.stagger-5 { animation-delay: 0.5s; opacity: 0; }
@media (prefers-reduced-motion: reduce) {
.animate-in {
animation: none;
opacity: 1;
}
.stagger-1, .stagger-2, .stagger-3, .stagger-4, .stagger-5 {
animation: none;
opacity: 1;
}
}
.outcome-bar {
height: 32px;
border-radius: 6px;
position: relative;
overflow: hidden;
cursor: pointer;
transition: transform 0.2s ease;
}
.outcome-bar:hover {
transform: scaleX(1.02);
}
.outcome-bar-fill {
height: 100%;
border-radius: 6px;
transition: width 1s ease-out;
}
.trend-line {
stroke-dasharray: 1000;
stroke-dashoffset: 1000;
animation: drawLine 2s ease forwards;
}
@keyframes drawLine {
to {
stroke-dashoffset: 0;
}
}
.attrition-step {
transition: all 0.3s ease;
}
.attrition-step:hover {
transform: translateY(-2px);
}
</style>
</head>
<body class="bg-pattern">
<div class="grid-overlay min-h-screen">
<!-- Header -->
<header class="border-b border-[var(--border)] px-6 py-4">
<div class="max-w-7xl mx-auto flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
<div class="animate-in stagger-1">
<h1 class="text-2xl font-bold tracking-tight">Graduate Pathways</h1>
<p class="text-[var(--muted)] text-sm mt-1">Doctoral cohort analysis 2018-2024</p>
</div>
<div class="flex items-center gap-3 animate-in stagger-2">
<select id="cohortSelect" class="filter-btn bg-[var(--card)]" aria-label="Select cohort year">
<option value="all">All Cohorts</option>
<option value="2018">2018 Cohort</option>
<option value="2019">2019 Cohort</option>
<option value="2020">2020 Cohort</option>
<option value="2021">2021 Cohort</option>
<option value="2022">2022 Cohort</option>
</select>
<select id="programSelect" class="filter-btn bg-[var(--card)]" aria-label="Select program">
<option value="all">All Programs</option>
<option value="STEM">STEM</option>
<option value="Humanities">Humanities</option>
<option value="Social Sciences">Social Sciences</option>
</select>
</div>
</div>
</header>
<main class="max-w-7xl mx-auto px-6 py-8">
<!-- Key Metrics -->
<section class="grid grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
<article class="card metric-card p-5 animate-in stagger-1" role="figure" aria-label="Total Students">
<p class="text-[var(--muted)] text-xs uppercase tracking-wider mb-2">Total Enrolled</p>
<p class="metric-value text-3xl font-bold" data-count="2847">0</p>
<p class="text-[var(--accent)] text-sm mt-2 flex items-center gap-1">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M7 17l9.2-9.2M17 17V7H7"/>
</svg>
+12% from prior period
</p>
</article>
<article class="card metric-card p-5 animate-in stagger-2" role="figure" aria-label="Completion Rate">
<p class="text-[var(--muted)] text-xs uppercase tracking-wider mb-2">Completion Rate</p>
<p class="metric-value text-3xl font-bold" data-count="78" data-suffix="%">0%</p>
<p class="text-[var(--info)] text-sm mt-2">10-year average</p>
</article>
<article class="card metric-card p-5 animate-in stagger-3" role="figure" aria-label="Median Time to Degree">
<p class="text-[var(--muted)] text-xs uppercase tracking-wider mb-2">Median Time</p>
<p class="metric-value text-3xl font-bold" data-count="5.8" data-suffix=" yrs">0 yrs</p>
<p class="text-[var(--warning)] text-sm mt-2">STEM: 5.2 | Hum: 7.1</p>
</article>
<article class="card metric-card p-5 animate-in stagger-4" role="figure" aria-label="Attrition Rate">
<p class="text-[var(--muted)] text-xs uppercase tracking-wider mb-2">Attrition Rate</p>
<p class="metric-value text-3xl font-bold" data-count="22" data-suffix="%">0%</p>
<p class="text-[var(--danger)] text-sm mt-2">Year 2-3 highest risk</p>
</article>
</section>
<!-- Main Charts Grid -->
<div class="grid lg:grid-cols-3 gap-6 mb-8">
<!-- Time to Degree Distribution -->
<section class="lg:col-span-2 card p-6 animate-in stagger-3">
<div class="flex items-center justify-between mb-6">
<div>
<h2 class="text-lg font-semibold">Time to Degree Distribution</h2>
<p class="text-[var(--muted)] text-sm">Years from enrollment to graduation</p>
</div>
<div class="flex gap-4 text-xs">
<span class="flex items-center gap-2"><span class="legend-dot" style="background: var(--accent)"></span>STEM</span>
<span class="flex items-center gap-2"><span class="legend-dot" style="background: var(--info)"></span>Humanities</span>
<span class="flex items-center gap-2"><span class="legend-dot" style="background: var(--warning)"></span>Social Sci</span>
</div>
</div>
<div class="chart-container h-64">
<canvas id="timeChart" aria-label="Bar chart showing time to degree distribution"></canvas>
</div>
</section>
<!-- Attrition Funnel -->
<section class="card p-6 animate-in stagger-4">
<h2 class="text-lg font-semibold mb-2">Cohort Attrition</h2>
<p class="text-[var(--muted)] text-sm mb-6">Student retention by year</p>
<div id="attritionFunnel" class="space-y-3">
<!-- Rendered by JS -->
</div>
</section>
</div>
<!-- Outcomes Section -->
<div class="grid lg:grid-cols-2 gap-6 mb-8">
<!-- Career Outcomes -->
<section class="card p-6 animate-in stagger-4">
<div class="flex items-center justify-between mb-6">
<div>
<h2 class="text-lg font-semibold">Career Outcomes</h2>
<p class="text-[var(--muted)] text-sm">Primary employment within 6 months</p>
</div>
<span class="text-[var(--accent)] text-sm font-medium">n=1,842</span>
</div>
<div id="outcomesChart" class="space-y-4">
<!-- Rendered by JS -->
</div>
</section>
<!-- Attrition by Stage -->
<section class="card p-6 animate-in stagger-5">
<div class="flex items-center justify-between mb-6">
<div>
<h2 class="text-lg font-semibold">Attrition by Stage</h2>
<p class="text-[var(--muted)] text-sm">When students leave the program</p>
</div>
</div>
<div class="chart-container h-52">
<canvas id="attritionStageChart" aria-label="Chart showing attrition by academic stage"></canvas>
</div>
<div class="grid grid-cols-3 gap-4 mt-6 pt-4 border-t border-[var(--border)]">
<div class="text-center">
<p class="text-2xl font-bold text-[var(--danger)]">38%</p>
<p class="text-[var(--muted)] text-xs">Year 1-2</p>
</div>
<div class="text-center">
<p class="text-2xl font-bold text-[var(--warning)]">45%</p>
<p class="text-[var(--muted)] text-xs">Year 3-4</p>
</div>
<div class="text-center">
<p class="text-2xl font-bold text-[var(--muted)]">17%</p>
<p class="text-[var(--muted)] text-xs">Year 5+</p>
</div>
</div>
</section>
</div>
<!-- Trend Analysis -->
<section class="card p-6 animate-in stagger-5">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6">
<div>
<h2 class="text-lg font-semibold">Completion Rate Trend</h2>
<p class="text-[var(--muted)] text-sm">6-year completion rate by cohort year</p>
</div>
<div class="flex gap-2">
<button class="filter-btn active" data-trend="completion">Completion</button>
<button class="filter-btn" data-trend="time">Time to Degree</button>
<button class="filter-btn" data-trend="attrition">Attrition</button>
</div>
</div>
<div class="chart-container h-56">
<canvas id="trendChart" aria-label="Line chart showing completion rate trends"></canvas>
</div>
</section>
</main>
<!-- Footer -->
<footer class="border-t border-[var(--border)] px-6 py-4 mt-8">
<div class="max-w-7xl mx-auto flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 text-sm text-[var(--muted)]">
<p>Data refreshed: December 2024</p>
<p>Graduate School Institutional Research</p>
</div>
</footer>
</div>
<div id="tooltip" class="tooltip" role="tooltip"></div>
<script>
// === DATA ===
const timeToDegreeData = {
labels: ['4 yrs', '5 yrs', '6 yrs', '7 yrs', '8+ yrs'],
STEM: [12, 35, 28, 18, 7],
Humanities: [5, 15, 25, 32, 23],
SocialScience: [8, 28, 32, 22, 10]
};
const attritionFunnelData = [
{ year: 'Year 1', retained: 100, label: 'Enrolled' },
{ year: 'Year 2', retained: 89, label: '89% retained' },
{ year: 'Year 3', retained: 78, label: '78% retained' },
{ year: 'Year 4', retained: 72, label: '72% retained' },
{ year: 'Year 5', retained: 68, label: '68% retained' },
{ year: 'Year 6', retained: 65, label: '65% retained' }
];
const careerOutcomesData = [
{ category: 'Academic (TT)', percentage: 34, color: '#00d4aa' },
{ category: 'Academic (NTT)', percentage: 18, color: '#00b894' },
{ category: 'Industry R&D', percentage: 22, color: '#4dabf7' },
{ category: 'Government', percentage: 12, color: '#a78bfa' },
{ category: 'Nonprofit', percentage: 8, color: '#f59e0b' },
{ category: 'Other/Seeking', percentage: 6, color: '#6b7280' }
];
const attritionByStage = [
{ stage: 'Coursework', percentage: 28 },
{ stage: 'Qualifying Exam', percentage: 22 },
{ stage: 'Proposal', percentage: 18 },
{ stage: 'Dissertation', percentage: 32 }
];
const trendData = {
years: ['2018', '2019', '2020', '2021', '2022', '2023'],
completion: [72, 74, 76, 75, 78, 81],
timeToDegree: [6.2, 6.0, 5.9, 5.8, 5.7, 5.8],
attrition: [28, 26, 24, 25, 22, 19]
};
// === UTILITIES ===
const tooltip = document.getElementById('tooltip');
let reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
function showTooltip(e, content) {
tooltip.innerHTML = content;
tooltip.classList.add('visible');
const rect = tooltip.getBoundingClientRect();
let x = e.clientX + 10;
let y = e.clientY + 10;
if (x + rect.width > window.innerWidth) x = e.clientX - rect.width - 10;
if (y + rect.height > window.innerHeight) y = e.clientY - rect.height - 10;
tooltip.style.left = x + 'px';
tooltip.style.top = y + 'px';
}
function hideTooltip() {
tooltip.classList.remove('visible');
}
function animateValue(el, target, duration, suffix = '') {
if (reducedMotion) {
el.textContent = target + suffix;
return;
}
const start = 0;
const startTime = performance.now();
const isFloat = target % 1 !== 0;
function update(currentTime) {
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
const eased = 1 - Math.pow(1 - progress, 3);
const current = start + (target - start) * eased;
el.textContent = (isFloat ? current.toFixed(1) : Math.floor(current)) + suffix;
if (progress < 1) requestAnimationFrame(update);
}
requestAnimationFrame(update);
}
// === RENDER FUNCTIONS ===
function renderMetrics() {
document.querySelectorAll('.metric-value[data-count]').forEach((el, i) => {
const target = parseFloat(el.dataset.count);
const suffix = el.dataset.suffix || '';
setTimeout(() => animateValue(el, target, 1500, suffix), i * 150);
});
}
function renderTimeChart() {
const canvas = document.getElementById('timeChart');
const ctx = canvas.getContext('2d');
const dpr = window.devicePixelRatio || 1;
const rect = canvas.parentElement.getBoundingClientRect();
canvas.width = rect.width * dpr;
canvas.height = rect.height * dpr;
canvas.style.width = rect.width + 'px';
canvas.style.height = rect.height + 'px';
ctx.scale(dpr, dpr);
const width = rect.width;
const height = rect.height;
const padding = { top: 20, right: 20, bottom: 40, left: 50 };
const chartWidth = width - padding.left - padding.right;
const chartHeight = height - padding.top - padding.bottom;
ctx.clearRect(0, 0, width, height);
// Grid lines
ctx.strokeStyle = 'rgba(36, 48, 64, 0.5)';
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();
}
// Y-axis labels
ctx.fillStyle = '#7a8b9c';
ctx.font = '11px IBM Plex Sans';
ctx.textAlign = 'right';
for (let i = 0; i <= 4; i++) {
const y = padding.top + (chartHeight / 4) * i;
const value = 40 - i * 10;
ctx.fillText(value + '%', padding.left - 10, y + 4);
}
// X-axis labels
ctx.textAlign = 'center';
const barGroupWidth = chartWidth / timeToDegreeData.labels.length;
timeToDegreeData.labels.forEach((label, i) => {
const x = padding.left + barGroupWidth * i + barGroupWidth / 2;
ctx.fillText(label, x, height - 15);
});
// Bars
const barWidth = Math.max(8, (barGroupWidth - 30) / 3);
const colors = {
STEM: '#00d4aa',
Humanities: '#4dabf7',
SocialScience: '#ffb84d'
};
const datasets = ['STEM', 'Humanities', 'SocialScience'];
const maxVal = 40;
datasets.forEach((dataset, di) => {
timeToDegreeData[dataset].forEach((value, i) => {
const barHeight = (value / maxVal) * chartHeight;
const x = padding.left + barGroupWidth * i + 15 + di * (barWidth + 4);
const y = padding.top + chartHeight - barHeight;
ctx.fillStyle = colors[dataset];
ctx.beginPath();
const radius = Math.max(1, Math.min(4, barWidth / 2));
ctx.roundRect(x, y, barWidth, barHeight, [radius, radius, 0, 0]);
ctx.fill();
});
});
// Hover interaction
canvas.onmousemove = (e) => {
const canvasRect = canvas.getBoundingClientRect();
const mx = e.clientX - canvasRect.left;
const my = e.clientY - canvasRect.top;
datasets.forEach((dataset, di) => {
timeToDegreeData[dataset].forEach((value, i) => {
const barHeight = (value / maxVal) * chartHeight;
const x = padding.left + barGroupWidth * i + 15 + di * (barWidth + 4);
const y = padding.top + chartHeight - barHeight;
if (mx >= x && mx <= x + barWidth && my >= y && my <= y + barHeight) {
showTooltip(e, `<strong>${dataset}</strong><br>Time: ${timeToDegreeData.labels[i]}<br>Students: ${value}%`);
}
});
});
};
canvas.onmouseleave = hideTooltip;
}
function renderAttritionFunnel() {
const container = document.getElementById('attritionFunnel');
container.innerHTML = '';
attritionFunnelData.forEach((item, index) => {
const width = item.retained;
const isLast = index === attritionFunnelData.length - 1;
const lost = index > 0 ? attritionFunnelData[index - 1].retained - item.retained : 0;
const step = document.createElement('div');
step.className = 'attrition-step';
step.style.animationDelay = `${index * 0.1}s`;
let color;
if (item.retained >= 80) color = 'var(--accent)';
else if (item.retained >= 60) color = 'var(--warning)';
else color = 'var(--danger)';
step.innerHTML = `
<div class="flex justify-between items-center mb-1">
<span class="text-sm font-medium">${item.year}</span>
<span class="text-xs text-[var(--muted)]">${item.label}</span>
</div>
<div class="progress-bar">
<div class="progress-fill" style="width: 0%; background: ${color};"></div>
</div>
${lost > 0 ? `<p class="text-xs text-[var(--danger)] mt-1">-${lost}% attrited</p>` : ''}
`;
container.appendChild(step);
// Animate
setTimeout(() => {
const fill = step.querySelector('.progress-fill');
fill.style.width = width + '%';
}, 300 + index * 100);
});
}
function renderOutcomes() {
const container = document.getElementById('outcomesChart');
container.innerHTML = '';
careerOutcomesData.forEach((item, index) => {
const bar = document.createElement('div');
bar.className = 'outcome-bar';
bar.style.background = 'var(--border)';
bar.setAttribute('role', 'button');
bar.setAttribute('tabindex', '0');
bar.setAttribute('aria-label', `${item.category}: ${item.percentage}%`);
bar.innerHTML = `
<div class="outcome-bar-fill" style="width: 0%; background: ${item.color}; display: flex; align-items: center; padding-left: 12px;">
<span class="text-xs font-medium text-white">${item.category}</span>
</div>
<span class="absolute right-3 top-1/2 -translate-y-1/2 text-sm font-semibold">${item.percentage}%</span>
`;
container.appendChild(bar);
// Animate
setTimeout(() => {
bar.querySelector('.outcome-bar-fill').style.width = item.percentage + '%';
}, 400 + index * 80);
// Interaction
bar.onmouseenter = (e) => showTooltip(e, `<strong>${item.category}</strong><br>${item.percentage}% of graduates`);
bar.onmouseleave = hideTooltip;
bar.onfocus = (e) => showTooltip(e, `<strong>${item.category}</strong><br>${item.percentage}% of graduates`);
bar.onblur = hideTooltip;
});
}
function renderAttritionStageChart() {
const canvas = document.getElementById('attritionStageChart');
const ctx = canvas.getContext('2d');
const dpr = window.devicePixelRatio || 1;
const rect = canvas.parentElement.getBoundingClientRect();
canvas.width = rect.width * dpr;
canvas.height = rect.height * dpr;
canvas.style.width = rect.width + 'px';
canvas.style.height = rect.height + 'px';
ctx.scale(dpr, dpr);
const width = rect.width;
const height = rect.height;
const centerX = width / 2;
const centerY = height / 2;
const radius = Math.min(width, height) / 2 - 40;
ctx.clearRect(0, 0, width, height);
const colors = ['#ff6b6b', '#ffb84d', '#4dabf7', '#00d4aa'];
let currentAngle = -Math.PI / 2;
const total = attritionByStage.reduce((sum, d) => sum + d.percentage, 0);
attritionByStage.forEach((item, index) => {
const sliceAngle = (item.percentage / total) * 2 * Math.PI;
ctx.beginPath();
ctx.moveTo(centerX, centerY);
ctx.arc(centerX, centerY, Math.max(1, radius), currentAngle, currentAngle + sliceAngle);
ctx.closePath();
ctx.fillStyle = colors[index];
ctx.fill();
// Label
const labelAngle = currentAngle + sliceAngle / 2;
const labelRadius = radius * 0.65;
const labelX = centerX + Math.cos(labelAngle) * labelRadius;
const labelY = centerY + Math.sin(labelAngle) * labelRadius;
ctx.fillStyle = '#0a0f14';
ctx.font = 'bold 12px IBM Plex Sans';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(item.percentage + '%', labelX, labelY);
currentAngle += sliceAngle;
});
// Center hole
ctx.beginPath();
ctx.arc(centerX, centerY, Math.max(1, radius * 0.45), 0, 2 * Math.PI);
ctx.fillStyle = '#151d26';
ctx.fill();
// Center text
ctx.fillStyle = '#e8edf3';
ctx.font = 'bold 20px Space Grotesk';
ctx.fillText('22%', centerX, centerY - 8);
ctx.fillStyle = '#7a8b9c';
ctx.font = '11px IBM Plex Sans';
ctx.fillText('Total Attrition', centerX, centerY + 12);
}
function renderTrendChart(metric = 'completion') {
const canvas = document.getElementById('trendChart');
const ctx = canvas.getContext('2d');
const dpr = window.devicePixelRatio || 1;
const rect = canvas.parentElement.getBoundingClientRect();
canvas.width = rect.width * dpr;
canvas.height = rect.height * dpr;
canvas.style.width = rect.width + 'px';
canvas.style.height = rect.height + 'px';
ctx.scale(dpr, dpr);
const width = rect.width;
const height = rect.height;
const padding = { top: 30, right: 30, bottom: 40, left: 50 };
const chartWidth = width - padding.left - padding.right;
const chartHeight = height - padding.top - padding.bottom;
ctx.clearRect(0, 0, width, height);
const data = trendData[metric];
const labels = trendData.years;
let maxVal, minVal, suffix, color;
if (metric === 'completion') {
maxVal = 100; minVal = 60; suffix = '%'; color = '#00d4aa';
} else if (metric === 'timeToDegree') {
maxVal = 7; minVal = 5; suffix = ' yrs'; color = '#4dabf7';
} else {
maxVal = 35; minVal = 15; suffix = '%'; color = '#ff6b6b';
}
// Grid
ctx.strokeStyle = 'rgba(36, 48, 64, 0.5)';
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();
const value = maxVal - ((maxVal - minVal) / 4) * i;
ctx.fillStyle = '#7a8b9c';
ctx.font = '11px IBM Plex Sans';
ctx.textAlign = 'right';
ctx.fillText(value.toFixed(0) + (metric === 'timeToDegree' ? '' : '%'), padding.left - 10, y + 4);
}
// X labels
ctx.textAlign = 'center';
const stepX = chartWidth / (labels.length - 1);
labels.forEach((label, i) => {
const x = padding.left + stepX * i;
ctx.fillText(label, x, height - 15);
});
// Line
ctx.beginPath();
ctx.strokeStyle = color;
ctx.lineWidth = 3;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
data.forEach((value, i) => {
const x = padding.left + stepX * i;
const y = padding.top + chartHeight - ((value - minVal) / (maxVal - minVal)) * chartHeight;
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
});
ctx.stroke();
// Gradient fill
const gradient = ctx.createLinearGradient(0, padding.top, 0, padding.top + chartHeight);
gradient.addColorStop(0, color.replace(')', ', 0.3)').replace('rgb', 'rgba'));
gradient.addColorStop(1, color.replace(')', ', 0)').replace('rgb', 'rgba'));
ctx.lineTo(padding.left + stepX * (data.length - 1), padding.top + chartHeight);
ctx.lineTo(padding.left, padding.top + chartHeight);
ctx.closePath();
ctx.fillStyle = `${color}15`;
ctx.fill();
// Points
data.forEach((value, i) => {
const x = padding.left + stepX * i;
const y = padding.top + chartHeight - ((value - minVal) / (maxVal - minVal)) * chartHeight;
ctx.beginPath();
ctx.arc(x, y, 6, 0, 2 * Math.PI);
ctx.fillStyle = '#151d26';
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 2;
ctx.stroke();
});
// Hover
canvas.onmousemove = (e) => {
const canvasRect = canvas.getBoundingClientRect();
const mx = e.clientX - canvasRect.left;
data.forEach((value, i) => {
const x = padding.left + stepX * i;
const y = padding.top + chartHeight - ((value - minVal) / (maxVal - minVal)) * chartHeight;
if (Math.abs(mx - x) < 20) {
showTooltip(e, `<strong>${labels[i]}</strong><br>${metric === 'timeToDegree' ? value.toFixed(1) : value + suffix}`);
}
});
};
canvas.onmouseleave = hideTooltip;
}
// === EVENT LISTENERS ===
document.querySelectorAll('[data-trend]').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('[data-trend]').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
const metric = btn.dataset.trend === 'time' ? 'timeToDegree' : btn.dataset.trend;
renderTrendChart(metric);
});
});
document.getElementById('cohortSelect').addEventListener('change', (e) => {
// Simulate filter - in real app would re-fetch data
console.log('Filtering by cohort:', e.target.value);
});
document.getElementById('programSelect').addEventListener('change', (e) => {
console.log('Filtering by program:', e.target.value);
});
// === INIT ===
function init() {
renderMetrics();
renderTimeChart();
renderAttritionFunnel();
renderOutcomes();
renderAttritionStageChart();
renderTrendChart('completion');
}
// Handle resize
let resizeTimeout;
window.addEventListener('resize', () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(() => {
renderTimeChart();
renderAttritionStageChart();
renderTrendChart('completion');
}, 200);
});
// Intersection Observer for scroll reveals
if (!reducedMotion) {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.card, section').forEach(el => {
observer.observe(el);
});
}
init();
</script>
</body>
</html>