root = Card([header, kpiSection, engagementSection, enrollmentSection, riskSection, cohortActions, followups])
header = CardHeader("Training Analytics", "Platform performance across all cohorts")
kpiSection = Card([kpiHeading, kpis], "sunk")
kpiHeading = Heading("Key metrics", "h2")
kpis = Table([kpiName, kpiValue])
kpiName = Col("Metric", ["Active learners (this week)", "Course completion rate", "Average quiz score"])
kpiValue = Col("Value", ["1,248", "78.4%", "86.2%"])
engagementSection = Card([engagementHeading, engagementChart], "sunk")
engagementHeading = Heading("Engagement — last 8 weeks", "h2")
engagementChart = LineChart(["W1", "W2", "W3", "W4", "W5", "W6", "W7", "W8"], [engagementSeries], "natural", "Week", "Active learners")
engagementSeries = Series("Active learners", [820, 910, 980, 1040, 1100, 1160, 1205, 1248])
enrollmentSection = Card([enrollmentHeading, enrollmentChart], "sunk")
enrollmentHeading = Heading("Courses by enrollment", "h2")
enrollmentChart = HorizontalBarChart(["Python for Data Science", "SQL Fundamentals", "Machine Learning Intro", "Cloud Architecture", "Agile Basics"], [enrollmentSeries], "grouped", "Enrollments", "Course")
enrollmentSeries = Series("Enrolled", [540, 485, 402, 318, 276])
riskSection = Card([riskHeading, riskTable, riskCallout], "sunk")
riskHeading = Heading("Learners at risk of dropping out", "h2")
riskTable = Table([riskName, riskCourse, riskProgress, riskStatus])
riskName = Col("Learner", ["A. Patel", "M. Nguyen", "J. Okafor", "S. Kim"])
riskCourse = Col("Course", ["Machine Learning Intro", "Python for Data Science", "Cloud Architecture", "SQL Fundamentals"])
riskProgress = Col("Progress", ["32%", "41%", "28%", "55%"])
riskStatus = Col("Status", ["At risk", "At risk", "Critical", "At risk"])
riskCallout = Callout("warning", "4 learners flagged", "Engagement dropped below 30% in the last two weeks. Consider reaching out to these cohorts.")
cohortActions = Card([cohortHeading, cohortSelect, messageButtons], "sunk")
cohortHeading = Heading("Narrow by cohort", "h2")
cohortSelect = FormControl("Cohort", cohortDropdown, "Filter all metrics above to one cohort")
cohortDropdown = Select("cohort", [cohortAll, cohortJan, cohortFeb, cohortMar], "All cohorts")
cohortAll = SelectItem("all", "All cohorts")
cohortJan = SelectItem("jan", "January 2025")
cohortFeb = SelectItem("feb", "February 2025")
cohortMar = SelectItem("mar", "March 2025")
messageButtons = Buttons([messageCohort])
messageCohort = Button("Message this cohort", null, "primary")
followups = FollowUpBlock([follow1, follow2, follow3])
follow1 = FollowUpItem("Show completion rate by cohort")
follow2 = FollowUpItem("List learners in the January cohort")
follow3 = FollowUpItem("Compare quiz scores across courses")