LMS — Instructor Dashboard
A polished instructor analytics dashboard for an online course platform. Four animated KPI cards track enrollments, net revenue, completion rate, and average rating, with trend pills and a progress bar. An interactive SVG revenue chart redraws as you switch the 7d, 30d, 90d, and 12-month timeframe, and a top-courses table drills into a slide-in panel with a completion ring and lesson check-offs. A live enrollment feed and a student-questions thread with inline replies round out a friendly, focused-reading learning workspace.
MCP
Code
:root {
--brand: #5b5bd6;
--brand-d: #4444c2;
--brand-50: #eeeefc;
--accent: #13b981;
--amber: #f59e0b;
--ink: #1a1a2e;
--ink-2: #44465f;
--muted: #6b6e87;
--bg: #f7f7fb;
--surface: #ffffff;
--line: rgba(26, 26, 46, 0.1);
--ok: #13b981;
--danger: #e05656;
--r-sm: 8px;
--r-md: 14px;
--r-lg: 20px;
--sh-1: 0 1px 2px rgba(26, 26, 46, 0.05), 0 1px 3px rgba(26, 26, 46, 0.06);
--sh-2: 0 6px 22px rgba(26, 26, 46, 0.08);
--sh-3: 0 18px 50px rgba(26, 26, 46, 0.18);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
margin: 0;
font-family: "Inter", system-ui, -apple-system, sans-serif;
background: var(--bg);
color: var(--ink);
line-height: 1.5;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
h1, h2, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
/* ---------- Sidebar ---------- */
.sidebar {
width: 244px;
flex: 0 0 244px;
background: var(--surface);
border-right: 1px solid var(--line);
padding: 22px 16px;
display: flex;
flex-direction: column;
gap: 26px;
position: sticky;
top: 0;
height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand-mark {
width: 34px; height: 34px;
display: grid; place-items: center;
border-radius: 10px;
background: linear-gradient(135deg, var(--brand), var(--brand-d));
color: #fff; font-weight: 800; font-size: 18px;
box-shadow: 0 4px 12px rgba(91, 91, 214, 0.35);
}
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -0.02em; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
display: flex; align-items: center; gap: 11px;
padding: 10px 12px;
border-radius: var(--r-sm);
color: var(--ink-2);
font-weight: 500; font-size: 14px;
transition: background .15s, color .15s;
}
.nav-item .ni-ico { font-size: 14px; width: 16px; text-align: center; color: var(--muted); }
.nav-item:hover { background: var(--brand-50); color: var(--brand-d); }
.nav-item.is-active { background: var(--brand-50); color: var(--brand-d); font-weight: 600; }
.nav-item.is-active .ni-ico { color: var(--brand); }
.side-card {
margin-top: auto;
background: linear-gradient(160deg, #f3f3ff, #ffffff);
border: 1px solid var(--line);
border-radius: var(--r-md);
padding: 16px;
}
.side-card-eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--brand); font-weight: 700; }
.side-card-title { font-weight: 700; font-size: 15px; margin-top: 4px; }
.side-card-sub { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
display: flex; align-items: center; justify-content: space-between;
gap: 16px;
padding: 18px 28px;
background: rgba(247, 247, 251, 0.85);
backdrop-filter: blur(8px);
border-bottom: 1px solid var(--line);
position: sticky; top: 0; z-index: 20;
}
.topbar-lead { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h1 { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.topbar .sub { font-size: 13px; color: var(--muted); }
.menu-btn { display: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); width: 38px; height: 38px; font-size: 16px; color: var(--ink-2); }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.seg {
display: inline-flex; background: var(--surface);
border: 1px solid var(--line); border-radius: 999px;
padding: 3px; box-shadow: var(--sh-1);
}
.seg-btn {
border: 0; background: transparent; color: var(--ink-2);
font-size: 13px; font-weight: 600;
padding: 6px 13px; border-radius: 999px;
transition: background .15s, color .15s;
}
.seg-btn:hover { color: var(--brand-d); }
.seg-btn.is-active { background: var(--brand); color: #fff; box-shadow: 0 2px 8px rgba(91,91,214,.4); }
.avatar {
width: 40px; height: 40px; border-radius: 50%;
background: linear-gradient(135deg, #8a6df0, var(--brand-d));
color: #fff; font-weight: 700; font-size: 14px;
display: grid; place-items: center; flex: 0 0 auto;
}
.content { padding: 24px 28px 40px; display: flex; flex-direction: column; gap: 20px; }
/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi {
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--r-md);
padding: 18px;
box-shadow: var(--sh-1);
transition: transform .15s, box-shadow .15s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--sh-2); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 17px; }
.ico-brand { background: var(--brand-50); color: var(--brand); }
.ico-accent { background: #e1f7ee; color: var(--accent); }
.ico-amber { background: #fdf0d9; color: var(--amber); }
.ico-rate { background: #fdeef0; color: var(--danger); }
.kpi-trend { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.kpi-trend.up { background: #e1f7ee; color: #0a8f63; }
.kpi-trend.down { background: #fdeef0; color: #c0392b; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 500; margin-top: 14px; }
.kpi-value { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; margin-top: 2px; }
.kpi-foot { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi-bar { height: 6px; border-radius: 999px; background: var(--brand-50); margin-top: 10px; overflow: hidden; }
.kpi-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--amber), #f7b955); border-radius: 999px; transition: width .9s cubic-bezier(.2,.8,.2,1); }
/* ---------- Grid ---------- */
.grid-2 { display: grid; grid-template-columns: 1.55fr 1fr; gap: 20px; }
.grid-2-wide { grid-template-columns: 1.35fr 1fr; }
.card {
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--r-lg);
padding: 20px;
box-shadow: var(--sh-1);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h2 { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.card-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.pill { font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--brand-50); color: var(--brand-d); white-space: nowrap; }
.pill-accent { background: #e1f7ee; color: #0a8f63; }
.pill-amber { background: #fdf0d9; color: #a76a06; }
.pill-danger { background: #fdeef0; color: #c0392b; }
/* ---------- Chart ---------- */
.chart-card { display: flex; flex-direction: column; }
.chart-legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.lg-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); display: inline-block; }
.chart-wrap { position: relative; flex: 1; }
#chart { width: 100%; height: 230px; display: block; overflow: visible; }
.chart-line { fill: none; stroke: var(--brand); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { fill: #fff; stroke: var(--brand); stroke-width: 2.5; cursor: pointer; transition: r .12s; }
.chart-dot:hover { r: 6; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-tip {
position: absolute; transform: translate(-50%, -120%);
background: var(--ink); color: #fff;
font-size: 12px; font-weight: 600;
padding: 6px 10px; border-radius: var(--r-sm);
pointer-events: none; white-space: nowrap;
box-shadow: var(--sh-2); z-index: 5;
}
.chart-tip span { color: #c7c7ff; font-weight: 500; }
.chart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 8px; padding: 0 4px; }
.chart-axis span { flex: 1; text-align: center; }
/* ---------- Questions ---------- */
.q-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; max-height: 286px; overflow-y: auto; }
.q-item { border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 13px; transition: border-color .15s, background .15s; }
.q-item.answered { background: #f9fdfb; border-color: #cdeede; }
.q-top { display: flex; align-items: center; gap: 9px; }
.q-ava { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; flex: 0 0 auto; }
.q-who { font-size: 13px; font-weight: 600; }
.q-course { font-size: 11.5px; color: var(--muted); }
.q-time { margin-left: auto; font-size: 11px; color: var(--muted); }
.q-text { font-size: 13px; color: var(--ink-2); margin-top: 7px; }
.q-actions { margin-top: 9px; display: flex; gap: 8px; align-items: center; }
.btn-sm {
border: 1px solid var(--line); background: var(--surface);
color: var(--ink-2); font-size: 12px; font-weight: 600;
padding: 5px 11px; border-radius: var(--r-sm);
transition: background .15s, border-color .15s, color .15s;
}
.btn-sm:hover { background: var(--brand-50); border-color: var(--brand); color: var(--brand-d); }
.btn-sm.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-sm.primary:hover { background: var(--brand-d); }
.q-answered-tag { font-size: 11.5px; font-weight: 700; color: #0a8f63; display: flex; align-items: center; gap: 5px; }
.q-reply-box { margin-top: 9px; display: flex; gap: 8px; }
.q-reply-box textarea {
flex: 1; resize: none; min-height: 38px;
border: 1px solid var(--line); border-radius: var(--r-sm);
padding: 8px 10px; font-family: inherit; font-size: 12.5px; color: var(--ink);
}
.q-reply-box textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 0 12px 10px; }
.table th.num, .table td.num { text-align: right; }
.table tbody tr { cursor: pointer; transition: background .12s; }
.table tbody tr:hover { background: var(--brand-50); }
.table td { padding: 12px; border-top: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
.c-name { display: flex; align-items: center; gap: 11px; }
.c-thumb { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; font-size: 16px; color: #fff; flex: 0 0 auto; }
.c-title { font-weight: 600; }
.c-cat { font-size: 11.5px; color: var(--muted); }
.c-rate { font-weight: 700; }
.c-rate::after { content: " ★"; color: var(--amber); }
.mini-bar { display: inline-block; width: 52px; height: 6px; border-radius: 999px; background: var(--brand-50); vertical-align: middle; margin-left: 6px; overflow: hidden; }
.mini-bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
/* ---------- Enrollments ---------- */
.enroll-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }
.enroll-item { display: flex; align-items: center; gap: 11px; padding: 9px 6px; border-bottom: 1px solid var(--line); animation: fadeIn .35s ease; }
.enroll-item:last-child { border-bottom: 0; }
.enroll-ava { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; flex: 0 0 auto; }
.enroll-main { min-width: 0; }
.enroll-who { font-size: 13.5px; font-weight: 600; }
.enroll-course { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.enroll-amt { margin-left: auto; font-weight: 700; font-size: 13.5px; color: var(--accent); }
.enroll-time { font-size: 11px; color: var(--muted); }
.enroll-meta { margin-left: auto; text-align: right; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
#liveBadge { animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
/* ---------- Drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(26,26,46,.4); z-index: 40; backdrop-filter: blur(2px); }
.drawer {
position: fixed; top: 0; right: 0; height: 100vh; width: 420px; max-width: 92vw;
background: var(--surface); z-index: 50;
box-shadow: var(--sh-3);
transform: translateX(105%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 22px 22px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 19px; font-weight: 800; margin-top: 8px; letter-spacing: -0.02em; }
.icon-btn { width: 34px; height: 34px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-size: 14px; flex: 0 0 auto; }
.icon-btn:hover { background: var(--brand-50); color: var(--brand-d); }
.drawer-body { padding: 20px 22px; overflow-y: auto; }
.dstat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.dstat { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md); padding: 13px; }
.dstat-label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.dstat-value { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; margin-top: 3px; }
.ring-wrap { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px; }
.ring { width: 86px; height: 86px; flex: 0 0 auto; }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 9; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset 1s cubic-bezier(.2,.8,.2,1); }
.ring-txt { font-size: 18px; font-weight: 800; fill: var(--ink); }
.ring-cap-title { font-weight: 700; font-size: 14px; }
.ring-cap-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.dsection-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 4px 0 10px; }
.lesson { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.lesson:last-child { border-bottom: 0; }
.lesson-check { width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--line); display: grid; place-items: center; font-size: 12px; flex: 0 0 auto; cursor: pointer; transition: all .15s; }
.lesson-check.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.lesson-name { flex: 1; }
.lesson.done .lesson-name { color: var(--muted); text-decoration: line-through; }
.lesson-dur { font-size: 12px; color: var(--muted); }
/* ---------- Toast ---------- */
.toast-stack { position: fixed; bottom: 22px; right: 22px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast {
background: var(--ink); color: #fff;
font-size: 13.5px; font-weight: 500;
padding: 12px 16px; border-radius: var(--r-md);
box-shadow: var(--sh-3);
display: flex; align-items: center; gap: 9px;
animation: toastIn .3s cubic-bezier(.2,.8,.2,1);
}
.toast::before { content: "✓"; color: var(--accent); font-weight: 800; }
.toast.out { animation: toastOut .3s forwards; }
@keyframes toastIn { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateY(16px); opacity: 0; } }
/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
.kpis { grid-template-columns: repeat(2, 1fr); }
.grid-2, .grid-2-wide { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
.sidebar {
position: fixed; z-index: 60; left: 0; top: 0;
transform: translateX(-105%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
box-shadow: var(--sh-3);
}
.sidebar.open { transform: none; }
.menu-btn { display: grid; place-items: center; }
}
@media (max-width: 520px) {
.topbar { padding: 14px 16px; }
.topbar h1 { font-size: 16px; }
.topbar .sub { display: none; }
.content { padding: 16px 16px 32px; }
.kpis { grid-template-columns: 1fr; }
.kpi-value { font-size: 25px; }
.seg-btn { padding: 6px 10px; }
.avatar { display: none; }
.card { padding: 16px; }
}/* ==========================================================================
LMS — Instructor Dashboard
Vanilla JS. Fictional data. Timeframe toggle, SVG chart, course drill,
recent-enrollment feed, student-question replies, toasts.
========================================================================== */
(function () {
"use strict";
/* ----------------------------- Data ----------------------------------- */
var AVATAR_COLORS = ["#5b5bd6", "#13b981", "#f59e0b", "#e05656", "#8a6df0", "#0ea5b7", "#d6588a"];
function colorFor(name) {
var h = 0;
for (var i = 0; i < name.length; i++) h = (h * 31 + name.charCodeAt(i)) >>> 0;
return AVATAR_COLORS[h % AVATAR_COLORS.length];
}
function initials(name) {
return name.split(" ").filter(Boolean).slice(0, 2).map(function (p) { return p[0]; }).join("").toUpperCase();
}
function money(n) { return "$" + Math.round(n).toLocaleString("en-US"); }
// KPI base values + multipliers per timeframe
var RANGES = {
"7d": { label: "Last 7 days", enroll: 412, rev: 9840, comp: 68, rate: 4.78, pts: 7, axis: ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"] },
"30d": { label: "Last 30 days", enroll: 1830, rev: 41200, comp: 66, rate: 4.80, pts: 10, axis: ["W1","W2","W3","W4","W5","W6","W7","W8","W9","W10"] },
"90d": { label: "Last 90 days", enroll: 5240, rev: 121500, comp: 64, rate: 4.79, pts: 12, axis: ["Jan","","Feb","","Mar","","Apr","","May","","Jun",""] },
"12m": { label: "Last 12 months",enroll: 21800, rev: 498000, comp: 65, rate: 4.81, pts: 12, axis: ["J","F","M","A","M","J","J","A","S","O","N","D"] }
};
// deterministic pseudo-random series so each range looks distinct but stable
function seriesFor(range) {
var cfg = RANGES[range];
var seed = range.charCodeAt(0) * 7 + range.length * 13;
var out = [], base = cfg.rev / cfg.pts;
for (var i = 0; i < cfg.pts; i++) {
seed = (seed * 1103515245 + 12345) & 0x7fffffff;
var noise = (seed / 0x7fffffff - 0.5) * 0.5;
var trend = 0.7 + (i / cfg.pts) * 0.7;
out.push(Math.max(base * 0.4, base * trend * (1 + noise)));
}
return out;
}
var COURSES = [
{ id: "c1", title: "Modern JavaScript: From Zero to Pro", cat: "Web Development", icon: "⚛", color: "#5b5bd6", level: "Intermediate",
students: 9420, rev: 184300, comp: 71, rate: 4.84,
lessons: [["Setup & tooling",true],["Variables & scope",true],["Async / await",true],["DOM patterns",false],["Testing basics",false]] },
{ id: "c2", title: "UX Foundations for Developers", cat: "Design", icon: "✎", color: "#13b981", level: "Beginner",
students: 6180, rev: 121800, comp: 64, rate: 4.79,
lessons: [["Design thinking",true],["Wireframing",true],["Color & type",false],["Usability testing",false]] },
{ id: "c3", title: "Data Visualization with D3", cat: "Data Science", icon: "▣", color: "#f59e0b", level: "Advanced",
students: 4055, rev: 98700, comp: 58, rate: 4.72,
lessons: [["SVG primer",true],["Scales & axes",true],["Transitions",false],["Force layouts",false],["Maps",false]] },
{ id: "c4", title: "Practical Python for Automation", cat: "Programming", icon: "🐍", color: "#0ea5b7", level: "Beginner",
students: 7740, rev: 142600, comp: 69, rate: 4.81,
lessons: [["Syntax tour",true],["Files & paths",true],["Web scraping",true],["Schedulers",false]] },
{ id: "c5", title: "System Design Interview Crash Course", cat: "Engineering", icon: "▤", color: "#e05656", level: "Advanced",
students: 3210, rev: 88900, comp: 52, rate: 4.69,
lessons: [["Estimation",true],["Load balancing",false],["Caching",false],["Sharding",false]] }
];
var QUESTIONS = [
{ id: "q1", who: "Priya Raman", course: "Modern JavaScript", time: "12m ago", text: "In the async lesson, why does the await inside the loop block each iteration? Should I use Promise.all instead?", answered: false },
{ id: "q2", who: "Diego Salas", course: "Practical Python", time: "48m ago", text: "My scraper returns an empty list on the pagination example — is the selector outdated?", answered: false },
{ id: "q3", who: "Hana Ito", course: "Data Visualization with D3", time: "1h ago", text: "How do I keep the axis labels from overlapping when the dataset is dense?", answered: false },
{ id: "q4", who: "Marcus Bell", course: "UX Foundations", time: "3h ago", text: "Loved module 2! Quick one — is there a recommended Figma plugin for the contrast checks you showed?", answered: true },
{ id: "q5", who: " Feng Liang", course: "System Design", time: "5h ago", text: "Could you clarify when to pick consistent hashing over a simple modulo strategy?", answered: false }
];
var FIRST = ["Amara","Leo","Sofia","Noah","Yuki","Omar","Ingrid","Tariq","Lucia","Mateo","Nadia","Ravi","Elena","Kwame","Ana"];
var LAST = ["Okafor","Nguyen","Costa","Schmidt","Tanaka","Haddad","Berg","Khan","Moreno","Silva","Petrov","Mehta","Rossi","Mensah","Cruz"];
/* ----------------------------- State ---------------------------------- */
var current = "7d";
/* ----------------------------- Toast ---------------------------------- */
function toast(msg) {
var stack = document.getElementById("toastStack");
var el = document.createElement("div");
el.className = "toast";
el.textContent = msg;
stack.appendChild(el);
setTimeout(function () {
el.classList.add("out");
setTimeout(function () { el.remove(); }, 300);
}, 2600);
}
/* --------------------------- KPI counters ----------------------------- */
function animateValue(el, to) {
var prefix = el.getAttribute("data-prefix") || "";
var suffix = el.getAttribute("data-suffix") || "";
var dec = parseInt(el.getAttribute("data-decimals") || "0", 10);
var from = 0, start = null, dur = 750;
function step(ts) {
if (!start) start = ts;
var p = Math.min((ts - start) / dur, 1);
var eased = 1 - Math.pow(1 - p, 3);
var v = from + (to - from) * eased;
var txt = dec > 0 ? v.toFixed(dec) : Math.round(v).toLocaleString("en-US");
el.textContent = prefix + txt + suffix;
if (p < 1) requestAnimationFrame(step);
}
requestAnimationFrame(step);
}
function renderKPIs() {
var cfg = RANGES[current];
animateValue(document.querySelector('[data-kpi="enroll"]'), cfg.enroll);
animateValue(document.querySelector('[data-kpi="rev"]'), cfg.rev);
animateValue(document.querySelector('[data-kpi="comp"]'), cfg.comp);
animateValue(document.querySelector('[data-kpi="rate"]'), cfg.rate);
requestAnimationFrame(function () {
document.getElementById("compBar").style.width = cfg.comp + "%";
});
var full = Math.round(cfg.rate);
document.getElementById("rateStars").textContent =
"★".repeat(full) + "☆".repeat(5 - full) + " · from " + (4200 + cfg.pts * 51).toLocaleString("en-US") + " reviews";
}
/* ----------------------------- Chart ---------------------------------- */
var W = 640, H = 230, PAD_L = 8, PAD_R = 8, PAD_T = 18, PAD_B = 18;
function drawChart() {
var svg = document.getElementById("chart");
var data = seriesFor(current);
var cfg = RANGES[current];
var max = Math.max.apply(null, data) * 1.12;
var min = 0;
var innerW = W - PAD_L - PAD_R;
var innerH = H - PAD_T - PAD_B;
function x(i) { return PAD_L + (innerW * i) / (data.length - 1); }
function y(v) { return PAD_T + innerH - ((v - min) / (max - min)) * innerH; }
var parts = [];
// gridlines
for (var g = 0; g <= 3; g++) {
var gy = PAD_T + (innerH * g) / 3;
parts.push('<line class="chart-grid" x1="' + PAD_L + '" y1="' + gy + '" x2="' + (W - PAD_R) + '" y2="' + gy + '"/>');
}
// area gradient
parts.push('<defs><linearGradient id="areaFill" x1="0" y1="0" x2="0" y2="1">' +
'<stop offset="0%" stop-color="#5b5bd6" stop-opacity="0.22"/>' +
'<stop offset="100%" stop-color="#5b5bd6" stop-opacity="0"/></linearGradient></defs>');
var linePts = data.map(function (v, i) { return x(i) + "," + y(v); });
var area = "M" + linePts[0] + " L" + linePts.join(" L") +
" L" + x(data.length - 1) + "," + (PAD_T + innerH) + " L" + PAD_L + "," + (PAD_T + innerH) + " Z";
parts.push('<path d="' + area + '" fill="url(#areaFill)"/>');
parts.push('<path class="chart-line" d="M' + linePts.join(" L") + '"/>');
// dots
data.forEach(function (v, i) {
parts.push('<circle class="chart-dot" cx="' + x(i) + '" cy="' + y(v) + '" r="4" ' +
'data-i="' + i + '" data-v="' + Math.round(v) + '" data-x="' + (x(i) / W * 100) + '" data-y="' + (y(v) / H * 100) + '"/>');
});
svg.innerHTML = parts.join("");
document.getElementById("chartSub").textContent = cfg.label;
// axis labels
var axis = document.getElementById("chartAxis");
axis.innerHTML = cfg.axis.map(function (a) { return "<span>" + a + "</span>"; }).join("");
// tooltips
var tip = document.getElementById("chartTip");
var wrap = svg.parentElement;
Array.prototype.forEach.call(svg.querySelectorAll(".chart-dot"), function (dot) {
dot.addEventListener("mouseenter", function () {
var rect = wrap.getBoundingClientRect();
var px = parseFloat(dot.getAttribute("data-x")) / 100 * rect.width;
var py = parseFloat(dot.getAttribute("data-y")) / 100 * rect.height;
tip.hidden = false;
tip.innerHTML = money(dot.getAttribute("data-v")) + " <span>· " + (cfg.axis[dot.getAttribute("data-i")] || "") + "</span>";
tip.style.left = px + "px";
tip.style.top = py + "px";
});
dot.addEventListener("mouseleave", function () { tip.hidden = true; });
});
}
/* --------------------------- Course table ----------------------------- */
function renderCourses() {
var body = document.getElementById("courseBody");
body.innerHTML = "";
COURSES.slice().sort(function (a, b) { return b.rev - a.rev; }).forEach(function (c) {
var tr = document.createElement("tr");
tr.setAttribute("tabindex", "0");
tr.setAttribute("role", "button");
tr.innerHTML =
'<td><div class="c-name">' +
'<span class="c-thumb" style="background:' + c.color + '">' + c.icon + '</span>' +
'<span><span class="c-title">' + c.title + '</span><br><span class="c-cat">' + c.cat + '</span></span>' +
'</div></td>' +
'<td class="num">' + c.students.toLocaleString("en-US") + '</td>' +
'<td class="num">' + money(c.rev) + '</td>' +
'<td class="num">' + c.comp + '%<span class="mini-bar"><i style="width:' + c.comp + '%"></i></span></td>' +
'<td class="num"><span class="c-rate">' + c.rate.toFixed(2) + '</span></td>';
tr.addEventListener("click", function () { openDrawer(c); });
tr.addEventListener("keydown", function (e) {
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); openDrawer(c); }
});
body.appendChild(tr);
});
}
/* ------------------------------ Drawer -------------------------------- */
var drawer = document.getElementById("drawer");
var backdrop = document.getElementById("drawerBackdrop");
function openDrawer(c) {
document.getElementById("drawerTitle").textContent = c.title;
document.getElementById("drawerLevel").textContent = c.level;
var done = c.lessons.filter(function (l) { return l[1]; }).length;
var pct = Math.round((done / c.lessons.length) * 100);
var circ = 2 * Math.PI * 38;
var body = document.getElementById("drawerBody");
body.innerHTML =
'<div class="dstat-grid">' +
'<div class="dstat"><div class="dstat-label">Students</div><div class="dstat-value">' + c.students.toLocaleString("en-US") + '</div></div>' +
'<div class="dstat"><div class="dstat-label">Revenue</div><div class="dstat-value">' + money(c.rev) + '</div></div>' +
'<div class="dstat"><div class="dstat-label">Avg rating</div><div class="dstat-value">' + c.rate.toFixed(2) + ' ★</div></div>' +
'<div class="dstat"><div class="dstat-label">Category</div><div class="dstat-value" style="font-size:15px">' + c.cat + '</div></div>' +
'</div>' +
'<div class="ring-wrap">' +
'<svg class="ring" viewBox="0 0 90 90">' +
'<circle class="ring-bg" cx="45" cy="45" r="38"/>' +
'<circle class="ring-fg" cx="45" cy="45" r="38" stroke-dasharray="' + circ + '" stroke-dashoffset="' + circ + '" id="dRing"/>' +
'<text class="ring-txt" x="45" y="51" text-anchor="middle">' + c.comp + '%</text>' +
'</svg>' +
'<div><div class="ring-cap-title">Completion rate</div>' +
'<div class="ring-cap-sub">' + Math.round(c.students * c.comp / 100).toLocaleString("en-US") + ' learners finished the course.</div></div>' +
'</div>' +
'<div class="dsection-title">Curriculum · ' + done + '/' + c.lessons.length + ' published</div>' +
'<div id="lessonList"></div>';
var list = document.getElementById("lessonList");
c.lessons.forEach(function (l, i) {
var row = document.createElement("div");
row.className = "lesson" + (l[1] ? " done" : "");
var durs = ["8 min", "14 min", "11 min", "22 min", "9 min", "17 min"];
row.innerHTML =
'<span class="lesson-check' + (l[1] ? " done" : "") + '" role="checkbox" tabindex="0" aria-checked="' + l[1] + '">' + (l[1] ? "✓" : "") + '</span>' +
'<span class="lesson-name">' + l[0] + '</span>' +
'<span class="lesson-dur">' + durs[i % durs.length] + '</span>';
var chk = row.querySelector(".lesson-check");
function toggle() {
var on = chk.classList.toggle("done");
row.classList.toggle("done", on);
chk.textContent = on ? "✓" : "";
chk.setAttribute("aria-checked", String(on));
toast(on ? "Lesson published" : "Lesson unpublished");
}
chk.addEventListener("click", toggle);
chk.addEventListener("keydown", function (e) { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); toggle(); } });
list.appendChild(row);
});
drawer.classList.add("open");
drawer.setAttribute("aria-hidden", "false");
backdrop.hidden = false;
requestAnimationFrame(function () {
var ring = document.getElementById("dRing");
ring.style.strokeDashoffset = circ * (1 - c.comp / 100);
});
}
function closeDrawer() {
drawer.classList.remove("open");
drawer.setAttribute("aria-hidden", "true");
backdrop.hidden = true;
}
document.getElementById("drawerClose").addEventListener("click", closeDrawer);
backdrop.addEventListener("click", closeDrawer);
document.addEventListener("keydown", function (e) { if (e.key === "Escape") closeDrawer(); });
/* ---------------------------- Questions ------------------------------- */
function renderQuestions() {
var list = document.getElementById("qList");
list.innerHTML = "";
QUESTIONS.forEach(function (q) {
var li = document.createElement("li");
li.className = "q-item" + (q.answered ? " answered" : "");
li.innerHTML =
'<div class="q-top">' +
'<span class="q-ava" style="background:' + colorFor(q.who) + '">' + initials(q.who) + '</span>' +
'<span><span class="q-who">' + q.who + '</span><br><span class="q-course">' + q.course + '</span></span>' +
'<span class="q-time">' + q.time + '</span>' +
'</div>' +
'<p class="q-text">' + q.text + '</p>' +
'<div class="q-actions"></div>';
var actions = li.querySelector(".q-actions");
if (q.answered) {
actions.innerHTML = '<span class="q-answered-tag">✓ Replied</span>';
} else {
var replyBtn = document.createElement("button");
replyBtn.className = "btn-sm primary";
replyBtn.textContent = "Reply";
var laterBtn = document.createElement("button");
laterBtn.className = "btn-sm";
laterBtn.textContent = "Mark later";
actions.appendChild(replyBtn);
actions.appendChild(laterBtn);
replyBtn.addEventListener("click", function () { showReplyBox(li, q); });
laterBtn.addEventListener("click", function () { toast("Saved to follow-up list"); });
}
list.appendChild(li);
});
updateQStats();
}
function showReplyBox(li, q) {
var actions = li.querySelector(".q-actions");
if (li.querySelector(".q-reply-box")) { li.querySelector("textarea").focus(); return; }
actions.style.display = "none";
var box = document.createElement("div");
box.className = "q-reply-box";
box.innerHTML = '<textarea placeholder="Reply to ' + q.who.split(" ")[0] + '…" aria-label="Reply"></textarea>' +
'<button class="btn-sm primary" type="button">Send</button>';
var ta = box.querySelector("textarea");
var send = box.querySelector("button");
li.appendChild(box);
ta.focus();
function submit() {
if (!ta.value.trim()) { ta.focus(); toast("Write a reply first"); return; }
q.answered = true;
box.remove();
li.classList.add("answered");
actions.style.display = "";
actions.innerHTML = '<span class="q-answered-tag">✓ Replied</span>';
toast("Reply sent to " + q.who.split(" ")[0]);
updateQStats();
}
send.addEventListener("click", submit);
ta.addEventListener("keydown", function (e) {
if ((e.metaKey || e.ctrlKey) && e.key === "Enter") submit();
});
}
function updateQStats() {
var open = QUESTIONS.filter(function (q) { return !q.answered; }).length;
var answered = QUESTIONS.length - open;
document.getElementById("qOpen").textContent = open;
var rate = Math.round((answered / QUESTIONS.length) * 100);
document.getElementById("qReplyRate").textContent = rate + "% reply rate";
}
/* -------------------------- Recent enrollments ------------------------ */
function makeEnrollment() {
var name = FIRST[Math.floor(Math.random() * FIRST.length)] + " " + LAST[Math.floor(Math.random() * LAST.length)];
var course = COURSES[Math.floor(Math.random() * COURSES.length)];
var prices = [19, 24, 29, 39, 49];
var amt = prices[Math.floor(Math.random() * prices.length)];
return { name: name, course: course.title, amt: amt };
}
function renderEnrollItem(e, isNew) {
var li = document.createElement("li");
li.className = "enroll-item";
li.innerHTML =
'<span class="enroll-ava" style="background:' + colorFor(e.name) + '">' + initials(e.name) + '</span>' +
'<div class="enroll-main"><div class="enroll-who">' + e.name + '</div>' +
'<div class="enroll-course">' + e.course + '</div></div>' +
'<div class="enroll-meta"><div class="enroll-amt">+' + money(e.amt) + '</div>' +
'<div class="enroll-time">' + (isNew ? "just now" : "") + '</div></div>';
return li;
}
function seedEnrollments() {
var list = document.getElementById("enrollList");
var seed = [
{ name: "Amara Okafor", course: "Modern JavaScript: From Zero to Pro", amt: 49, t: "2 min ago" },
{ name: "Leo Nguyen", course: "Practical Python for Automation", amt: 29, t: "6 min ago" },
{ name: "Sofia Costa", course: "UX Foundations for Developers", amt: 24, t: "11 min ago" },
{ name: "Noah Schmidt", course: "Data Visualization with D3", amt: 39, t: "18 min ago" },
{ name: "Yuki Tanaka", course: "System Design Interview Crash Course", amt: 49, t: "25 min ago" }
];
seed.forEach(function (e) {
var li = renderEnrollItem(e, false);
li.querySelector(".enroll-time").textContent = e.t;
list.appendChild(li);
});
}
function startEnrollFeed() {
var list = document.getElementById("enrollList");
setInterval(function () {
var e = makeEnrollment();
var li = renderEnrollItem(e, true);
list.insertBefore(li, list.firstChild);
while (list.children.length > 8) list.removeChild(list.lastChild);
// age previous "just now" labels
Array.prototype.slice.call(list.children, 1).forEach(function (row) {
var t = row.querySelector(".enroll-time");
if (t.textContent === "just now") t.textContent = "1 min ago";
});
}, 6500);
}
/* --------------------------- Timeframe toggle ------------------------- */
document.querySelectorAll(".seg-btn").forEach(function (btn) {
btn.addEventListener("click", function () {
if (btn.classList.contains("is-active")) return;
document.querySelectorAll(".seg-btn").forEach(function (b) { b.classList.remove("is-active"); });
btn.classList.add("is-active");
current = btn.getAttribute("data-range");
renderKPIs();
drawChart();
toast("Showing " + RANGES[current].label.toLowerCase());
});
});
/* --------------------------- Mobile menu ------------------------------ */
document.getElementById("menuBtn").addEventListener("click", function () {
document.querySelector(".sidebar").classList.toggle("open");
});
/* ------------------------------- Init --------------------------------- */
renderKPIs();
drawChart();
renderCourses();
renderQuestions();
seedEnrollments();
startEnrollFeed();
window.addEventListener("resize", function () {
clearTimeout(window.__rcTimer);
window.__rcTimer = setTimeout(drawChart, 180);
});
})();<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>LMS — Instructor Dashboard</title>
<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=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="shell">
<!-- Sidebar -->
<aside class="sidebar" aria-label="Primary">
<div class="brand">
<span class="brand-mark" aria-hidden="true">L</span>
<span class="brand-name">Learnable</span>
</div>
<nav class="nav" aria-label="Instructor navigation">
<a href="#" class="nav-item is-active" aria-current="page"><span class="ni-ico" aria-hidden="true">▦</span> Dashboard</a>
<a href="#" class="nav-item"><span class="ni-ico" aria-hidden="true">▤</span> My Courses</a>
<a href="#" class="nav-item"><span class="ni-ico" aria-hidden="true">◉</span> Students</a>
<a href="#" class="nav-item"><span class="ni-ico" aria-hidden="true">✦</span> Reviews</a>
<a href="#" class="nav-item"><span class="ni-ico" aria-hidden="true">⬡</span> Earnings</a>
<a href="#" class="nav-item"><span class="ni-ico" aria-hidden="true">⚙</span> Settings</a>
</nav>
<div class="side-card">
<p class="side-card-eyebrow">This term</p>
<p class="side-card-title">Top 3% instructor</p>
<p class="side-card-sub">Keep your reply rate above 90% to stay featured.</p>
</div>
</aside>
<!-- Main -->
<div class="main">
<header class="topbar">
<div class="topbar-lead">
<button class="menu-btn" id="menuBtn" aria-label="Toggle navigation">☰</button>
<div>
<h1>Welcome back, Dr. Marisol Vega</h1>
<p class="sub">Here's how your courses are performing.</p>
</div>
</div>
<div class="topbar-actions">
<div class="seg" role="group" aria-label="Timeframe">
<button class="seg-btn is-active" data-range="7d">7d</button>
<button class="seg-btn" data-range="30d">30d</button>
<button class="seg-btn" data-range="90d">90d</button>
<button class="seg-btn" data-range="12m">12m</button>
</div>
<div class="avatar" title="Marisol Vega" aria-hidden="true">MV</div>
</div>
</header>
<main class="content">
<!-- KPIs -->
<section class="kpis" aria-label="Key metrics">
<article class="kpi">
<div class="kpi-top">
<span class="kpi-ico ico-brand" aria-hidden="true">◉</span>
<span class="kpi-trend up" id="trendEnroll">▲ 12.4%</span>
</div>
<p class="kpi-label">Enrollments</p>
<p class="kpi-value" data-kpi="enroll">0</p>
<p class="kpi-foot">vs previous period</p>
</article>
<article class="kpi">
<div class="kpi-top">
<span class="kpi-ico ico-accent" aria-hidden="true">⬡</span>
<span class="kpi-trend up" id="trendRev">▲ 8.1%</span>
</div>
<p class="kpi-label">Revenue</p>
<p class="kpi-value" data-kpi="rev" data-prefix="$">0</p>
<p class="kpi-foot">net after platform fee</p>
</article>
<article class="kpi">
<div class="kpi-top">
<span class="kpi-ico ico-amber" aria-hidden="true">◑</span>
<span class="kpi-trend down" id="trendComp">▼ 1.2%</span>
</div>
<p class="kpi-label">Completion rate</p>
<p class="kpi-value" data-kpi="comp" data-suffix="%">0</p>
<div class="kpi-bar"><span id="compBar" style="width:0%"></span></div>
</article>
<article class="kpi">
<div class="kpi-top">
<span class="kpi-ico ico-rate" aria-hidden="true">★</span>
<span class="kpi-trend up" id="trendRate">▲ 0.1</span>
</div>
<p class="kpi-label">Avg rating</p>
<p class="kpi-value" data-kpi="rate" data-decimals="2">0</p>
<p class="kpi-foot" id="rateStars">from 4,812 reviews</p>
</article>
</section>
<!-- Chart + Questions -->
<div class="grid-2">
<section class="card chart-card" aria-label="Revenue over time">
<div class="card-head">
<div>
<h2>Revenue</h2>
<p class="card-sub" id="chartSub">Last 7 days</p>
</div>
<div class="chart-legend">
<span class="lg-dot"></span> Net revenue
</div>
</div>
<div class="chart-wrap">
<svg id="chart" viewBox="0 0 640 260" preserveAspectRatio="none" role="img" aria-label="Revenue line chart"></svg>
<div class="chart-tip" id="chartTip" hidden></div>
</div>
<div class="chart-axis" id="chartAxis" aria-hidden="true"></div>
</section>
<section class="card q-card" aria-label="Student questions">
<div class="card-head">
<div>
<h2>Student questions</h2>
<p class="card-sub"><span id="qOpen">0</span> awaiting reply</p>
</div>
<span class="pill pill-amber" id="qReplyRate">94% reply rate</span>
</div>
<ul class="q-list" id="qList"></ul>
</section>
</div>
<!-- Top courses + recent enrollments -->
<div class="grid-2 grid-2-wide">
<section class="card" aria-label="Top courses">
<div class="card-head">
<h2>Top courses</h2>
<span class="card-sub">Click a row for details</span>
</div>
<div class="table-wrap">
<table class="table" id="courseTable">
<thead>
<tr>
<th>Course</th>
<th class="num">Students</th>
<th class="num">Revenue</th>
<th class="num">Completion</th>
<th class="num">Rating</th>
</tr>
</thead>
<tbody id="courseBody"></tbody>
</table>
</div>
</section>
<section class="card" aria-label="Recent enrollments">
<div class="card-head">
<h2>Recent enrollments</h2>
<span class="pill pill-accent" id="liveBadge">● Live</span>
</div>
<ul class="enroll-list" id="enrollList"></ul>
</section>
</div>
</main>
</div>
</div>
<!-- Course drill drawer -->
<div class="drawer-backdrop" id="drawerBackdrop" hidden></div>
<aside class="drawer" id="drawer" aria-hidden="true" aria-labelledby="drawerTitle" role="dialog">
<div class="drawer-head">
<div>
<span class="pill" id="drawerLevel">Intermediate</span>
<h2 id="drawerTitle">Course</h2>
</div>
<button class="icon-btn" id="drawerClose" aria-label="Close details">✕</button>
</div>
<div class="drawer-body" id="drawerBody"></div>
</aside>
<div class="toast-stack" id="toastStack" aria-live="polite"></div>
<script src="script.js"></script>
</body>
</html>Instructor Dashboard
A calm, light-themed analytics workspace for an online-course instructor. The top row of KPI cards counts up on load — enrollments, net revenue, completion rate, and average rating — each with an up or down trend pill, an inline progress bar, and a star summary. A sticky sidebar carries the brand mark, primary navigation, and a “top instructor” status card to anchor the page.
The centerpiece is an interactive SVG revenue chart with a gradient area fill, gridlines, and hover tooltips on every data point. Switching the timeframe segmented control (7d / 30d / 90d / 12m) regenerates the series, redraws the line and axis, and re-runs the KPI counters. Beside it, a student-questions thread lets you reply inline — opening a compose box, sending a reply (Cmd/Ctrl+Enter works too), and updating the live reply-rate pill.
Below, a sortable top-courses table opens a slide-in drawer when you click or keyboard-activate a row. The drawer shows revenue and rating stats, an animated completion ring, and a curriculum list where each lesson can be checked off and published. A recent-enrollments feed streams new fictional sign-ups every few seconds, and every action surfaces a small toast. Everything is keyboard reachable, responsive down to ~360px, and built with vanilla JS — no frameworks or build step.
Illustrative UI only — fictional courses, not a real learning platform.