import { MODEL_QUADRANTS } from '../hooks/useApi.js' import ChartLegend from '../components/ChartLegend.jsx' import { OBSERVED_MARK_COLOR, MODELED_AGGREGATE_COLOR } from '../utils/colors.js' /** * Chart 4: Modeled vs. observed arrests, faceted by the four model-quadrant * specifications (one-year/three-year × baseline/+referral-rate covariate). * Plain SVG (no D3) — the quadrant label already conveys 1yr/3yr, so all * four panels share one ink-diamond/navy-point-range convention rather than * doubling up with a redundant per-quadrant hue. */ const WAVE_LABELS = { '15-16': '2015–16', '17-18': '2017–18', '21-22': '2021–22' } const ALL_WAVES = ['15-16', '17-18', '21-22'] export default function ModelDrawsComparison({ data, waves = ALL_WAVES, districtName }) { const waveData = waves.map((year) => { const rows = (data.waves && data.waves[year]) || [] return { year, arrests: rows.reduce((sum, r) => sum + (r.observed_arrests || 0), 0) } }) const quadModels = (data && data.quadData) || {} const allValues = waveData.map((d) => d.arrests) Object.values(quadModels).forEach((rows) => { ;(rows || []).forEach((r) => { allValues.push(r.count_median || 0, r.count_upper || 0) }) }) const maxArrests = Math.min(Math.max(...allValues, 1), 50) // cap for readability return (
Three-year models span all three CRDC waves; one-year models show 2021–22 only.{' '} {districtName ? `District: ${districtName}.` : ''}