-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
7379 lines (6927 loc) · 461 KB
/
index.html
File metadata and controls
7379 lines (6927 loc) · 461 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WRIA 1 Riparian Data Explorer</title>
<!--
To run this dashboard:
1. Run preprocess_dashboard.py to generate dashboard_data.json
2. Start a local server: python -m http.server 8000
(from the directory containing this file)
3. Open http://localhost:8000/dashboard.html in your browser
Multi-file site -- serve via HTTP (python -m http.server) or deploy to GitHub Pages.
-->
<script src="https://cdn.tailwindcss.com"></script>
<script src="js/methods_citations.js"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: { extend: {
colors: {
forest: '#264914', herb: '#F5F57A', imperv: '#6c757d',
shrub: '#F3CF8B', shrubwood: '#C6A871', canopyimp: '#adb5bd',
water: '#457b9d', gravel: '#d4a373', railway: '#bc4749',
esa: {
navy: '#004562', teal: '#1193BA', 'teal-light': '#66CAD8',
gray: '#7F7B7A', orange: '#F9A134', green: '#8FCEA5',
'teal-green': '#00A79D',
},
}
}}
};
</script>
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/prop-types@15/prop-types.min.js"></script>
<script src="https://unpkg.com/recharts@2.12.7/umd/Recharts.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<style>
body { font-family: Arial, Helvetica, sans-serif; }
.dark body { background: #111827; color: #f3f4f6; }
/* Dual-range slider thumbs */
.drs input[type="range"] { -webkit-appearance: none; appearance: none; background: transparent; pointer-events: none; position: absolute; width: 100%; height: 20px; margin: 0; padding: 0; z-index: 2; }
.drs input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; pointer-events: all; cursor: pointer; width: 12px; height: 12px; border-radius: 50%; background: #1193BA; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); margin-top: -5px; }
.drs input[type="range"]::-moz-range-thumb { pointer-events: all; cursor: pointer; width: 12px; height: 12px; border-radius: 50%; background: #1193BA; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.drs input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: transparent; }
.drs input[type="range"]::-moz-range-track { height: 4px; background: transparent; border: none; }
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.10.3/sql-wasm.js"></script>
<script>if(typeof initSqlJs==="undefined"&&typeof exports==="object")window.initSqlJs=exports.initSqlJs||exports;</script>
</head>
<body class="bg-gray-50 text-gray-900 dark:bg-gray-900 dark:text-gray-100 min-h-screen">
<div id="root"></div>
<script type="text/babel">
const {
BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend,
PieChart, Pie, Cell, ResponsiveContainer, ReferenceLine,
ComposedChart, Area, AreaChart, Line, LineChart,
RadarChart, Radar, PolarGrid, PolarAngleAxis, PolarRadiusAxis,
ScatterChart, Scatter, ZAxis, Treemap, LabelList
} = Recharts;
// ============================================================
// Constants
// ============================================================
const LC_COLORS = {
'Forest': '#2d6a4f', 'Ground/Herbaceous': '#a7c957',
'Impervious': '#6c757d', 'Shrub': '#95d5b2',
'Shrub/Woodland': '#52b788', 'Canopy over Impervious': '#adb5bd',
'Water': '#457b9d', 'Gravel/Abandoned Channel': '#d4a373',
'Railway': '#bc4749',
};
const DOMAIN_COLORS = {
'D1_Forest': '#2d6a4f', 'D2_Shrub_Comp': '#52b788',
'D3_Shrub_NoComp': '#95d5b2', 'D4_HerbGround': '#a7c957',
'Excluded': '#adb5bd',
};
const DOMAIN_LABELS = {
'D1_Forest': 'Forest (0-55)',
'D2_Shrub_Comp': 'Shrub w/ Comp (55-70)',
'D3_Shrub_NoComp': 'Shrub w/o Comp (65-80)',
'D4_HerbGround': 'Herb/Ground (80-95)',
'Excluded': 'Excluded',
};
const ZONE_ORDER = ['50', '100', '300', 'hmz', 'hmz300', 'river', 'lake'];
const ZONE_COLORS = {'50':'#004562','100':'#0B7A9E','300':'#1193BA','hmz':'#66CAD8','hmz300':'#A8DDE8','river':'#457b9d','lake':'#7dd3fc'};
const NR_COLORS = {
'Water': '#457b9d', 'Impervious': '#6c757d',
'Canopy over Impervious': '#adb5bd', 'Gravel/Abandoned Channel': '#d4a373',
'Railway': '#bc4749',
};
const SR_ZONE_COLORS = {
'Lower Mainstem Nooksack': '#002D42', 'Upper Mainstem Nooksack': '#004562',
'Lower NF Nooksack': '#0B7A9E', 'Upper NF Nooksack': '#1193BA',
'Lower MF Nooksack': '#66CAD8', 'Upper MF Nooksack': '#A8DDE8',
'Lower SF Nooksack': '#00A79D', 'Upper SF Nooksack': '#8FCEA5',
'Frontal/Coastal multiple': '#F9A134', 'Fraser River Tributaries': '#7F7B7A',
'Lake Whatcom': '#dc2626', 'Unknown': '#B2B2B2',
};
const CHINOOK_COLORS = { 'Y': '#dc2626', 'N': '#6b7280' };
const FISH_COLORS = { 'fish': '#1193BA', 'gradient': '#F9A134' };
const TEMP_COLORS = { 'Y': '#dc2626', 'N': '#6b7280' };
const MANAGER_CAT_COLORS = {
'Federal': '#38A800', 'State': '#0070FF', 'Tribal': '#A87000',
'Local': '#FFAA00', 'NGO': '#7A00E6', 'Private/Unknown': '#B2B2B2',
};
const ZONING_COLORS = {
'Commercial Forest': '#267300', 'Rural Forest': '#4DA84D',
'Agriculture': '#E8D74D', 'Rural Residential': '#FFAA00',
'Urban/UGA': '#E60000',
'Federal Forest': '#8400A8', 'Public/Open Space': '#B0D1A8',
'Industrial': '#9C1FB0', 'Unknown': '#B2B2B2',
};
const TIER_COLORS = {
'P1': '#dc2626', 'P2': '#f59e0b', 'P3': '#1193BA', 'P4': '#059669', 'P5': '#9ca3af',
};
const TIER_LABELS = {
'P1': 'P1: Chinook + Temp Impaired',
'P2': 'P2: Chinook (no temp) / Fish + Temp',
'P3': 'P3: Fish-bearing mixed',
'P4': 'P4: Fish-bearing other (no temp)',
'P5': 'P5: Gradient-accessible',
};
const fmtN = (n) => n == null ? '--' : Number(n).toLocaleString();
const fmtPct = (n, total) => total ? `${((n / total) * 100).toFixed(1)}%` : '--';
const fmtAcres = (sqft) => `${(sqft / 43560).toLocaleString(undefined, {maximumFractionDigits: 0})} ac`;
const fmtDec = (n, d=2) => n == null ? '--' : Number(n).toFixed(d);
// ============================================================
// Shared Components
// ============================================================
function StatCard({ label, value, sub }) {
return (
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4 text-center">
<div className="text-2xl font-bold" style={{ color: '#1193BA' }}>{value}</div>
<div className="text-sm text-gray-500 dark:text-gray-400 mt-1">{label}</div>
{sub && <div className="text-xs text-gray-400 dark:text-gray-500 mt-0.5">{sub}</div>}
</div>
);
}
function HistogramChart({ histData, title, xLabel, color = '#1193BA', height = 250, showStats, stats }) {
if (!histData || !histData.bins || !histData.counts) return null;
const data = histData.counts.map((c, i) => ({
bin: histData.log_scale
? `1e${histData.bins[i]}`
: histData.bins[i + 1] - histData.bins[i] < 1
? fmtDec(histData.bins[i], 2)
: Math.round(histData.bins[i]),
count: c,
}));
return (
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
{title && <h4 className="text-sm font-semibold mb-2 text-gray-700 dark:text-gray-300">{title}</h4>}
<ResponsiveContainer width="100%" height={height}>
<BarChart data={data} margin={{ top: 5, right: 5, left: 5, bottom: xLabel ? 18 : 5 }}>
<CartesianGrid strokeDasharray="3 3" stroke="#374151" opacity={0.3} />
<XAxis dataKey="bin" tick={{ fontSize: 9 }} interval="preserveStartEnd"
label={xLabel ? { value: xLabel, position: 'bottom', offset: 2, fontSize: 11, fill: '#6b7280' } : undefined} />
<YAxis tick={{ fontSize: 10 }}
label={{ value: 'Count', angle: -90, position: 'insideLeft', offset: 10, fontSize: 10, fill: '#9ca3af' }} />
<Tooltip formatter={(v) => fmtN(v)} />
<Bar dataKey="count" fill={color} radius={[2, 2, 0, 0]} />
</BarChart>
</ResponsiveContainer>
{showStats && stats && (
<div className="flex gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1 flex-wrap">
<span>n={fmtN(stats.count)}</span>
<span>mean={fmtDec(stats.mean)}</span>
<span>med={fmtDec(stats.p50)}</span>
<span>std={fmtDec(stats.std)}</span>
</div>
)}
</div>
);
}
function SectionTitle({ children }) {
return <h3 className="text-base font-semibold mt-6 mb-3" style={{ color: '#004562' }}>{children}</h3>;
}
function CiteRef({ id }) {
const cite = (typeof CITATIONS !== 'undefined' && CITATIONS[id]) || null;
if (!cite) return <sup className="text-red-400 text-xs">[?]</sup>;
const [show, setShow] = React.useState(false);
const [above, setAbove] = React.useState(true);
const ref = React.useRef(null);
const handleEnter = React.useCallback(() => {
if (ref.current) { setAbove(ref.current.getBoundingClientRect().top > 280); }
setShow(true);
}, []);
return (
<span className="relative inline-block" ref={ref}
onMouseEnter={handleEnter} onMouseLeave={() => setShow(false)}>
<sup className="cursor-help hover:opacity-70 transition-colors"
style={{ fontSize: '10px', color: '#1193BA' }}>
[{cite.shortLabel}]
</sup>
{show && (
<div style={{ position: 'absolute', zIndex: 50, background: 'white', border: '1px solid #e2e8f0',
borderRadius: 8, padding: '12px 14px', width: 380, maxWidth: '90vw',
boxShadow: '0 8px 24px rgba(0,0,0,0.15)', fontSize: 13, lineHeight: 1.5,
pointerEvents: 'none', ...(above ? { bottom: '100%', marginBottom: 6 } : { top: '100%', marginTop: 6 }) }}>
<div style={{ fontWeight: 700, color: '#004562', marginBottom: 6 }}>{cite.shortLabel}</div>
<div style={{ color: '#4b5563', fontStyle: 'italic' }}>"{cite.quote}"</div>
{cite.pdfFilename && <div style={{ color: '#9ca3af', fontSize: 11, marginTop: 6 }}>PDF: {cite.pdfFilename}</div>}
</div>
)}
</span>
);
}
function Formula({ children }) {
return <pre className="text-xs font-mono bg-gray-50 dark:bg-gray-700/50 rounded p-3 text-gray-600 dark:text-gray-400 overflow-x-auto my-3" style={{ lineHeight: 1.6 }}>{children}</pre>;
}
function SliderRow({ label, value, onChange, min, max, step }) {
return (
<div className="flex items-center gap-3 mb-2">
<label className="text-sm w-44 text-gray-600 dark:text-gray-400">{label}</label>
<input type="range" min={min} max={max} step={step} value={value}
onChange={e => onChange(parseFloat(e.target.value))}
className="flex-1 accent-esa-teal" />
<span className="text-sm w-12 text-right font-mono">{typeof value === 'number' ? value.toFixed(2) : value}</span>
</div>
);
}
// ============================================================
// Curve helper (used by Forest Scoring tab)
// ============================================================
const CURVE_TYPES = [
{ value: 'linear', label: 'Linear' },
{ value: 'concave', label: 'Concave (FEMAT)' },
{ value: 'convex', label: 'Convex (late-seral)' },
{ value: 'scurve', label: 'S-curve (sigmoid)' },
];
function applyCurve(x, type, strength) {
if (type === 'linear' || strength <= 1.001) return x;
if (type === 'concave') return Math.pow(Math.max(x, 0), 1 / strength);
if (type === 'convex') return Math.pow(Math.max(x, 0), strength);
if (type === 'scurve') {
const xs = Math.pow(Math.max(x, 0), strength);
const xs1 = Math.pow(Math.max(1 - x, 0), strength);
return (xs + xs1) === 0 ? 0.5 : xs / (xs + xs1);
}
return x;
}
// ============================================================
// Tab 1: Overview (merged: Overview + Domain Routing + NR summary)
// ============================================================
function OverviewPanel({ data, setActiveTab }) {
const tabDirectory = [
{ name: 'Data Summary', id: 'data_summary', desc: 'Dataset statistics, landcover and zone distributions, domain routing table, and non-restorable breakdown.' },
{ name: 'Score Distributions', id: 'scores', desc: 'Histograms and statistics for base RP, solar-adjusted, and final RP scores. Compare score distributions across domains and identify scoring patterns.' },
{ name: 'Zone & BID Analysis', id: 'zones', desc: 'Zone-level breakdowns of landcover, scoring metrics (M, D, C, I), and area. Includes BID-level score distributions and per-zone box plots.' },
{ name: 'Radar Profiles', id: 'radar', desc: 'Radar charts showing zone condition profiles across buffer distances. Compare how landcover composition and scoring metrics change from streamside to upland.' },
{ name: 'Chinook & Fish', id: 'chinook', desc: 'Score distributions segmented by Spring Chinook presence, fish-bearing status, and temperature impairment. Identifies priority overlaps for habitat protection.' },
{ name: 'SR Zones', id: 'sr_zones', desc: 'Breakdown by Salmon Recovery Zone — score distributions, solar exposure, HMZ presence, and landcover composition for each zone in the watershed.' },
{ name: 'Manager', id: 'managers', desc: 'Score distributions by land manager category (Federal, State, Private, Tribal, etc.). Shows which management entities hold the highest-priority restoration opportunities.' },
{ name: 'BFW & River Size', id: 'bfw', desc: 'Analysis by bankfull width class — how stream size relates to riparian condition, HMZ presence, and scoring. Includes BFW distribution histograms.' },
{ name: 'Landuse & Zoning', id: 'zoning', desc: 'Score distributions by zoning group and city/UGA. Shows how land use designations correlate with riparian condition and restoration potential.' },
{ name: 'Priority Reaches', id: 'priority', desc: 'BIDs ranked by RP score within priority tiers (P1–P4), derived from salmon recovery criteria aligned with SRFB strategy matrices. Filterable by tier, SR zone, and fish status.' },
];
const labDirectory = [
{ name: 'Methodology', id: 'methodology', desc: 'Full scoring methodology documentation including RP framework, domain definitions, zone aggregation, push factor formulas, priority tier thresholds, and data sources.' },
{ name: 'Scoring Lab', id: 'scoring_lab', desc: 'Interactive scenario comparison tool. Pick two riparian scenarios and adjust forest scoring weights and curves in real time to see how they affect Restoration Priority scores.' },
{ name: 'Bank Explorer', id: 'bank_explorer', desc: 'Search any of the 24,000+ BIDs by ID, stream name, or SR Zone. View per-BID landcover grids, score breakdowns, tier criteria, zone tables, and solar push context.' },
{ name: 'Solar Comparison', id: 'solar_compare', desc: 'Explore the solar radiation push mechanism. Adjust the max push and curve exponent to see how solar exposure modifies RP scores across the watershed.' },
{ name: 'Bivariate Analysis', id: 'bivariate', desc: 'Scatterplot and heatmap of two selected variables. Examine correlations between any pair of scoring metrics, solar, slope, composition, and more.' },
{ name: 'BID Query', id: 'bid_query', desc: 'Filter and rank BIDs by score range, priority tier, SR zone, fish status, land manager, and more. Export filtered results to CSV or jump directly to a BID in the Bank Explorer.' },
{ name: 'Model Reference', id: 'model_ref', desc: 'Random Forest model performance — feature importance (MDI and MDA), confusion matrix, precision/recall by class, OOB convergence, and training evolution across iterative feature screening.' },
];
return (
<div>
{/* Banner Photo */}
<div className="rounded-lg overflow-hidden mb-6 shadow">
<img src="images/banner.jpg" alt="WRIA 1 Nooksack Watershed" className="w-full h-auto" style={{ maxHeight: 280, objectFit: 'cover', objectPosition: 'center top' }} />
</div>
{/* Purpose Statement */}
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-6 mb-6">
<h2 className="text-lg font-bold text-gray-800 dark:text-gray-100 mb-3">WRIA 1 Riparian Restoration Prioritization</h2>
<p className="text-sm text-gray-600 dark:text-gray-300 leading-relaxed">
This dashboard supports the WRIA 1 riparian restoration prioritization effort by providing interactive exploration of landcover condition, restoration potential, and priority scoring across the Nooksack watershed.
It is designed as a companion to the <a href="https://arcg.is/1mKiOq0" target="_blank" rel="noopener noreferrer" style={{ color: '#1193BA', fontWeight: 600 }}>ArcGIS Online web map</a> — a place to understand the methodology behind the scoring system and how it was applied, explore high-level trends by theme (e.g., priority tiers, salmon recovery zones, land management), and dive into individual reaches to examine existing conditions and how they translate into each bank's final Restoration Priority score.
It is recommended to start with the <span onClick={() => setActiveTab('methodology')} style={{ color: '#1193BA', cursor: 'pointer', textDecoration: 'underline', fontWeight: 600 }}>Methodology</span> tab to fully understand how the scoring system was built before exploring the analytical and interactive tabs.
</p>
<p className="text-sm text-gray-600 dark:text-gray-300 leading-relaxed mt-3">
Each stream bank (BID) is scored using a <strong>Restoration Priority (RP)</strong> framework — a higher RP score indicates more degraded riparian condition and greater potential to restore.
The framework evaluates landcover composition, forest structure, canopy density, and height across multiple buffer zones (0–50 ft, 50–100 ft, 100–300 ft, HMZ, and HMZ+300).
Scores are organized into four domains — Forest, Shrub/Woodland, Shrub, and Herb/Ground — where lower base scores indicate better existing condition and higher scores indicate greater restoration need.
Base scores are then adjusted by three push factors — solar radiation deficit (shade need), bank slope (erosion risk), and wetland proximity (ecological connectivity) — which increase priority for banks with greater restoration benefit.
Final scores are stratified into priority tiers (P1–P5) based on Chinook habitat, Nooksack zone membership, fish-bearing status, and temperature impairment.
</p>
</div>
{/* Tab Directory */}
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-5 mb-6">
<h3 className="text-sm font-bold text-gray-700 dark:text-gray-200 mb-3">Dashboard Guide</h3>
<table className="w-full text-sm mb-4">
<thead>
<tr className="border-b-2" style={{ borderColor: '#1193BA' }}>
<th className="text-left py-2 pr-4 font-semibold w-44" style={{ color: '#004562' }}>Analytical Tabs</th>
<th className="text-left py-2 text-gray-400 dark:text-gray-500 font-normal text-xs italic">Summary statistics, distributions, and cross-cutting comparisons</th>
</tr>
</thead>
<tbody>
{tabDirectory.map((t, i) => (
<tr key={t.name} className={i < tabDirectory.length - 1 ? 'border-b border-gray-100 dark:border-gray-700/50' : ''}>
<td className="py-2 pr-4 font-medium align-top">
<span onClick={() => setActiveTab(t.id)} style={{ color: '#1193BA', cursor: 'pointer', textDecoration: 'underline' }}>{t.name}</span>
</td>
<td className="py-2 text-gray-500 dark:text-gray-400">{t.desc}</td>
</tr>
))}
</tbody>
</table>
<table className="w-full text-sm">
<thead>
<tr className="border-b-2" style={{ borderColor: '#F9A134' }}>
<th className="text-left py-2 pr-4 font-semibold w-44" style={{ color: '#F9A134' }}>Interactive Tools</th>
<th className="text-left py-2 text-gray-400 dark:text-gray-500 font-normal text-xs italic">Hands-on exploration, scenario testing, and per-BID deep dives</th>
</tr>
</thead>
<tbody>
{labDirectory.map((t, i) => (
<tr key={t.name} className={i < labDirectory.length - 1 ? 'border-b border-gray-100 dark:border-gray-700/50' : ''}>
<td className="py-2 pr-4 font-medium align-top">
<span onClick={() => setActiveTab(t.id)} style={{ color: '#C07A1C', cursor: 'pointer', textDecoration: 'underline' }}>{t.name}</span>
</td>
<td className="py-2 text-gray-500 dark:text-gray-400">{t.desc}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
);
}
// ============================================================
// Tab: Data Summary (charts/stats moved from Overview)
// ============================================================
function DataSummaryPanel({ data }) {
const { meta, counts, area } = data;
const [showNR, setShowNR] = React.useState(false);
const nr = data.non_restorable;
const lcData = Object.entries(area.by_landcover)
.sort((a, b) => b[1] - a[1])
.map(([name, sqft]) => ({ name, value: Math.round(sqft / 43560) }));
const zoneData = ZONE_ORDER.filter(z => counts.by_zone[z])
.map(z => ({ zone: z, count: counts.by_zone[z], acres: Math.round((area.by_zone[z] || 0) / 43560) }));
const domains = ['D1_Forest', 'D2_Shrub_Comp', 'D3_Shrub_NoComp', 'D4_HerbGround'];
const domainInfo = {
'D1_Forest': { range: '0-55', lcs: ['Forest'] },
'D2_Shrub_Comp': { range: '55-70', lcs: ['Shrub/Woodland (w/ comp)'] },
'D3_Shrub_NoComp': { range: '65-80', lcs: ['Shrub', 'Shrub/Woodland (w/o comp)'] },
'D4_HerbGround': { range: '80-95', lcs: ['Ground/Herbaceous (SPTH-stratified)'] },
};
const excludedCount = counts.by_domain['Excluded'] || 0;
const NR_ORDER = ['Impervious', 'Water', 'Canopy over Impervious', 'Gravel/Abandoned Channel', 'Railway'];
const nrPieData = nr ? NR_ORDER
.filter(lc => nr.by_landcover[lc])
.map(lc => ({ name: lc, value: Math.round(nr.by_landcover[lc].area / 43560) })) : [];
// Precompute pie label positions with collision avoidance
const PIE_OR = 110, LABEL_R = PIE_OR + 35, LABEL_GAP = 16;
const lcLabelPos = React.useMemo(() => {
if (!lcData.length) return [];
const R = Math.PI / 180;
const total = lcData.reduce((s, d) => s + d.value, 0);
if (!total) return [];
let angle = 0;
const items = lcData.map(d => {
const sweep = (d.value / total) * 360;
const mid = angle + sweep / 2;
angle += sweep;
const cos = Math.cos(-mid * R), sin = Math.sin(-mid * R);
return { idealY: LABEL_R * sin, adjustedY: LABEL_R * sin, isRight: cos > 0 };
});
[true, false].forEach(side => {
const g = items.filter(it => it.isRight === side).sort((a, b) => a.idealY - b.idealY);
for (let i = 1; i < g.length; i++) {
if (g[i].adjustedY - g[i - 1].adjustedY < LABEL_GAP)
g[i].adjustedY = g[i - 1].adjustedY + LABEL_GAP;
}
});
return items;
}, [lcData]);
return (
<div>
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
<StatCard label="Total Polygons" value={fmtN(meta.total_polygons)} sub="count of polygons · all zones & classes" />
<StatCard label="Scored Polygons" value={fmtN(meta.scored_polygons)} sub="count of polygons · restorable only" />
<StatCard label="Unique BIDs" value={fmtN(meta.scored_bids)} sub="count of scored BIDs" />
<StatCard label="Unique Reaches" value={fmtN(meta.unique_rids)} sub="count of RIDs" />
</div>
<div className="bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700 rounded-lg p-3 mb-6 text-sm text-amber-800 dark:text-amber-300">
Non-restorable classes (Water, Impervious, Canopy over Impervious, Gravel, Railway) and river/lake zones are excluded from scoring. {fmtN(excludedCount)} polygons excluded.
</div>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
<h4 className="text-sm font-semibold mb-2 text-gray-700 dark:text-gray-300">Landcover Distribution (Area)</h4>
<ResponsiveContainer width="100%" height={400}>
<PieChart>
<Pie data={lcData} dataKey="value" nameKey="name" cx="50%" cy="50%" outerRadius={PIE_OR}
label={({ name, percent, cx: pcx, cy: pcy, midAngle, outerRadius: or, index }) => {
const pos = lcLabelPos[index]; if (!pos) return null;
const R = Math.PI / 180;
const sx = pcx + or * Math.cos(-midAngle * R);
const sy = pcy + or * Math.sin(-midAngle * R);
const mx = pcx + (or + 15) * Math.cos(-midAngle * R);
const my = pcy + (or + 15) * Math.sin(-midAngle * R);
const tx = pcx + (pos.isRight ? LABEL_R : -LABEL_R);
const ty = pcy + pos.adjustedY;
return (<g>
<path d={`M${sx},${sy} L${mx},${my} L${tx},${ty}`} stroke="#9ca3af" strokeWidth={1} fill="none" />
<text x={tx + (pos.isRight ? 4 : -4)} y={ty} textAnchor={pos.isRight ? 'start' : 'end'}
dominantBaseline="central" fontSize={10} fill="#6b7280">
{`${name} (${(percent * 100).toFixed(0)}%)`}
</text>
</g>);
}} labelLine={false}>
{lcData.map((e, i) => <Cell key={i} fill={LC_COLORS[e.name] || '#999'} />)}
</Pie>
<Tooltip formatter={(v) => `${fmtN(v)} acres`} />
</PieChart>
</ResponsiveContainer>
</div>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
<h4 className="text-sm font-semibold mb-2 text-gray-700 dark:text-gray-300">Zone Distribution (Area)</h4>
<ResponsiveContainer width="100%" height={300}>
<BarChart data={zoneData} margin={{ top: 5, right: 10, left: 35, bottom: 30 }}>
<CartesianGrid strokeDasharray="3 3" stroke="#374151" opacity={0.3} />
<XAxis dataKey="zone" label={{ value: 'Buffer Zone (ft)', position: 'bottom', offset: 3, fontSize: 11, fill: '#6b7280' }} />
<YAxis tickFormatter={(v) => `${fmtN(v)} ac`} tick={{ fontSize: 11 }}
label={{ value: 'Area (acres)', angle: -90, position: 'insideLeft', offset: -10, fontSize: 11, fill: '#9ca3af' }} />
<Tooltip formatter={(v) => `${fmtN(v)} acres`} />
<Bar dataKey="acres" radius={[4, 4, 0, 0]}>
{zoneData.map((e, i) => <Cell key={i} fill={ZONE_COLORS[e.zone] || '#1193BA'} />)}
</Bar>
</BarChart>
</ResponsiveContainer>
</div>
</div>
<SectionTitle>Domain Routing Summary</SectionTitle>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4 overflow-x-auto">
<table className="w-full text-sm">
<thead>
<tr className="border-b dark:border-gray-700">
<th className="text-left py-2 px-2">Domain</th>
<th className="text-center py-2 px-2">RP Range</th>
<th className="text-right py-2 px-2">Count</th>
<th className="text-right py-2 px-2">%</th>
<th className="text-right py-2 px-2">Area</th>
<th className="text-left py-2 px-2">Landcovers</th>
</tr>
</thead>
<tbody>
{domains.map(d => (
<tr key={d} className="border-b dark:border-gray-700/50">
<td className="py-1.5 px-2 flex items-center gap-2">
<span className="inline-block w-3 h-3 rounded" style={{ background: DOMAIN_COLORS[d] }}></span>
{DOMAIN_LABELS[d]}
</td>
<td className="text-center py-1.5 px-2">{domainInfo[d].range}</td>
<td className="text-right py-1.5 px-2">{fmtN(counts.by_domain[d] || 0)}</td>
<td className="text-right py-1.5 px-2">{fmtPct(counts.by_domain[d] || 0, meta.scored_polygons)}</td>
<td className="text-right py-1.5 px-2">{fmtAcres(area.by_domain[d] || 0)}</td>
<td className="text-left py-1.5 px-2 text-xs text-gray-500 dark:text-gray-400">{domainInfo[d].lcs.join(', ')}</td>
</tr>
))}
</tbody>
</table>
</div>
{/* Collapsible Non-Restorable Summary */}
{nr && (
<div className="mt-6">
<button onClick={() => setShowNR(!showNR)}
className="flex items-center gap-2 text-sm font-semibold text-gray-700 dark:text-gray-300 hover:text-esa-teal transition-colors">
<span className="text-lg">{showNR ? '\u25BC' : '\u25B6'}</span>
Non-Restorable Summary ({fmtN(nr.total_count)} polygons, {fmtAcres(nr.total_area)})
</button>
{showNR && (
<div className="mt-3">
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-4">
<StatCard label="NR Polygons" value={fmtN(nr.total_count)} sub="count of non-restorable polygons" />
<StatCard label="NR Area" value={fmtAcres(nr.total_area)} sub="acres · non-restorable total" />
<StatCard label="Impervious" value={fmtN(nr.by_landcover['Impervious']?.count || 0)} sub={`count of polygons · ${fmtAcres(nr.by_landcover['Impervious']?.area || 0)}`} />
<StatCard label="Water (in buffer)" value={fmtN(nr.by_landcover['Water']?.count || 0)} sub={`count of polygons · ${fmtAcres(nr.by_landcover['Water']?.area || 0)}`} />
</div>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
<h4 className="text-sm font-semibold mb-2 text-gray-700 dark:text-gray-300">Area by Type (acres)</h4>
<ResponsiveContainer width="100%" height={300}>
<PieChart>
<Pie data={nrPieData} dataKey="value" nameKey="name" cx="50%" cy="50%" outerRadius={100}
label={({ name, percent, x, y, textAnchor }) => (
<text x={x} y={y} textAnchor={textAnchor} fontSize={10} fill="#6b7280">
{`${name} (${(percent * 100).toFixed(0)}%)`}
</text>
)} labelLine={true}>
{nrPieData.map((e, i) => <Cell key={i} fill={NR_COLORS[e.name] || '#999'} />)}
</Pie>
<Tooltip formatter={(v, name) => [`${fmtN(v)} acres`, name]} />
</PieChart>
</ResponsiveContainer>
</div>
</div>
)}
</div>
)}
</div>
);
}
// ============================================================
// Tab 2: Score Distributions (merged: Scoring Preview + Distributions)
// ============================================================
function ScoreDistributionsPanel({ data }) {
const domains = ['D1_Forest', 'D2_Shrub_Comp', 'D3_Shrub_NoComp', 'D4_HerbGround'];
const rpAll = data.histograms.RP_all;
const rpByDomain = data.histograms.RP_by_domain;
// Stacked RP chart data
const bins = rpAll.bins;
const combined = rpAll.counts.map((_, i) => {
const obj = { bin: Math.round(bins[i]) };
domains.forEach(d => {
obj[d] = rpByDomain[d] ? rpByDomain[d].counts[i] || 0 : 0;
});
return obj;
});
// Input distribution filters
const [lcFilter, setLcFilter] = React.useState('All');
const [zoneFilter, setZoneFilter] = React.useState('All');
const scorableLCs = ['Forest', 'Shrub/Woodland', 'Shrub', 'Ground/Herbaceous'];
const zones = ['50', '100', '300', 'hmz', 'hmz300'];
function getHist(field) {
if (lcFilter !== 'All' && data.histograms_by_landcover[lcFilter]) {
return data.histograms_by_landcover[lcFilter][field] || null;
}
if (zoneFilter !== 'All' && data.histograms_by_zone[zoneFilter]) {
return data.histograms_by_zone[zoneFilter][field] || null;
}
return data.histograms[field];
}
function getStats(field) {
if (lcFilter !== 'All' && data.stats_by_landcover[lcFilter]) return data.stats_by_landcover[lcFilter][field];
if (zoneFilter !== 'All' && data.stats_by_zone[zoneFilter]) return data.stats_by_zone[zoneFilter][field];
return null;
}
return (
<div>
<SectionTitle>Polygon-Level RP Scores - Pre-Solar, Pre-Aggregation (All Domains, 0-100)</SectionTitle>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
<ResponsiveContainer width="100%" height={400}>
<BarChart data={combined} margin={{ top: 30, right: 10, left: 0, bottom: 30 }}>
<CartesianGrid strokeDasharray="3 3" stroke="#374151" opacity={0.3} />
<XAxis dataKey="bin" tick={{ fontSize: 10 }} label={{ value: 'RP Score (pre-solar)', position: 'bottom', offset: 10, fontSize: 11, fill: '#6b7280' }} />
<YAxis tick={{ fontSize: 10 }}
label={{ value: 'Polygon Count', angle: -90, position: 'insideLeft', offset: 10, fontSize: 11, fill: '#9ca3af' }} />
<Tooltip />
<Legend verticalAlign="top" height={36} />
<ReferenceLine x={55} stroke="#ef4444" strokeDasharray="5 5" label={{ value: 'D1|D2', position: 'top', fontSize: 10, fill: '#ef4444' }} />
<ReferenceLine x={70} stroke="#52b788" strokeDasharray="3 3" label={{ value: 'D2 cap', position: 'top', fontSize: 9, fill: '#52b788' }} />
<ReferenceLine x={65} stroke="#95d5b2" strokeDasharray="3 3" label={{ value: 'D3 floor', position: 'bottom', fontSize: 9, fill: '#95d5b2' }} />
<ReferenceLine x={80} stroke="#f59e0b" strokeDasharray="5 5" label={{ value: 'D3|D4', position: 'top', fontSize: 10, fill: '#f59e0b' }} />
{domains.map(d => (
<Bar key={d} dataKey={d} stackId="a" fill={DOMAIN_COLORS[d]} name={DOMAIN_LABELS[d]} />
))}
</BarChart>
</ResponsiveContainer>
</div>
<SectionTitle>Per-Domain Detail</SectionTitle>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<HistogramChart histData={rpByDomain['D1_Forest']} title={DOMAIN_LABELS['D1_Forest']}
xLabel="RP Score" color={DOMAIN_COLORS['D1_Forest']} showStats stats={data.stats_by_domain['D1_Forest']?.RP} />
{/* Combined Shrub chart: D2 + D3 stacked */}
{(() => {
const d2 = rpByDomain['D2_Shrub_Comp'];
const d3 = rpByDomain['D3_Shrub_NoComp'];
if (!d2 && !d3) return null;
const ref = d2 || d3;
const shrubData = ref.counts.map((_, i) => ({
bin: ref.bins[i + 1] - ref.bins[i] < 1 ? fmtDec(ref.bins[i], 2) : Math.round(ref.bins[i]),
'w/ Comp': d2 ? d2.counts[i] : 0,
'w/o Comp': d3 ? d3.counts[i] : 0,
}));
const d2st = data.stats_by_domain['D2_Shrub_Comp']?.RP;
const d3st = data.stats_by_domain['D3_Shrub_NoComp']?.RP;
return (
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
<h4 className="text-sm font-semibold mb-2 text-gray-700 dark:text-gray-300">Shrub Combined (55-80)</h4>
<ResponsiveContainer width="100%" height={250}>
<BarChart data={shrubData} margin={{ top: 5, right: 5, left: 5, bottom: 18 }}>
<CartesianGrid strokeDasharray="3 3" stroke="#374151" opacity={0.3} />
<XAxis dataKey="bin" tick={{ fontSize: 9 }} interval="preserveStartEnd"
label={{ value: 'RP Score', position: 'bottom', offset: 2, fontSize: 11, fill: '#6b7280' }} />
<YAxis tick={{ fontSize: 10 }}
label={{ value: 'Count', angle: -90, position: 'insideLeft', offset: 10, fontSize: 10, fill: '#9ca3af' }} />
<Tooltip />
<Legend verticalAlign="top" height={24} />
<Bar dataKey="w/ Comp" stackId="s" fill={DOMAIN_COLORS['D2_Shrub_Comp']} name="w/ Comp (55-70)" />
<Bar dataKey="w/o Comp" stackId="s" fill={DOMAIN_COLORS['D3_Shrub_NoComp']} name="w/o Comp (65-80)" radius={[2, 2, 0, 0]} />
</BarChart>
</ResponsiveContainer>
<div className="flex gap-4 text-xs text-gray-500 dark:text-gray-400 mt-1 flex-wrap">
<span className="font-medium" style={{ color: DOMAIN_COLORS['D2_Shrub_Comp'] }}>w/ Comp:</span>
<span>n={fmtN(d2st?.count)}</span><span>mean={fmtDec(d2st?.mean)}</span><span>med={fmtDec(d2st?.p50)}</span>
<span className="ml-2 font-medium" style={{ color: DOMAIN_COLORS['D3_Shrub_NoComp'] }}>w/o Comp:</span>
<span>n={fmtN(d3st?.count)}</span><span>mean={fmtDec(d3st?.mean)}</span><span>med={fmtDec(d3st?.p50)}</span>
</div>
</div>
);
})()}
<HistogramChart histData={rpByDomain['D4_HerbGround']} title={DOMAIN_LABELS['D4_HerbGround']}
xLabel="RP Score" color={DOMAIN_COLORS['D4_HerbGround']} showStats stats={data.stats_by_domain['D4_HerbGround']?.RP} />
</div>
<SectionTitle>Domain Statistics</SectionTitle>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4 overflow-x-auto">
<table className="w-full text-sm">
<thead>
<tr className="border-b dark:border-gray-700">
<th className="text-left py-2 px-2">Domain</th>
<th className="text-right py-2 px-2">Count</th>
<th className="text-right py-2 px-2">Mean RP</th>
<th className="text-right py-2 px-2">Median</th>
<th className="text-right py-2 px-2">Std</th>
<th className="text-right py-2 px-2">P10</th>
<th className="text-right py-2 px-2">P90</th>
</tr>
</thead>
<tbody>
{domains.map(d => {
const st = data.stats_by_domain[d]?.RP;
return (
<tr key={d} className="border-b dark:border-gray-700/50">
<td className="py-1.5 px-2">{DOMAIN_LABELS[d]}</td>
<td className="text-right py-1.5 px-2">{fmtN(st?.count)}</td>
<td className="text-right py-1.5 px-2">{fmtDec(st?.mean)}</td>
<td className="text-right py-1.5 px-2">{fmtDec(st?.p50)}</td>
<td className="text-right py-1.5 px-2">{fmtDec(st?.std)}</td>
<td className="text-right py-1.5 px-2">{fmtDec(st?.p10)}</td>
<td className="text-right py-1.5 px-2">{fmtDec(st?.p90)}</td>
</tr>
);
})}
</tbody>
</table>
</div>
<SectionTitle>Intactness Components (D1 + D2)</SectionTitle>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<HistogramChart histData={data.histograms.M_maturity} title="Canopy Height M (0-1)" xLabel="Canopy Height Score" color="#dc2626" />
<HistogramChart histData={data.histograms.D_density} title="Density D (0-1)" xLabel="Density Score" color="#ea580c" />
<HistogramChart histData={data.histograms.I_intactness} title="Intactness I (0-1)" xLabel="Intactness Score" color="#7c3aed" />
</div>
<SectionTitle>Input Distributions</SectionTitle>
<div className="flex gap-4 mb-4 items-center flex-wrap">
<label className="text-sm font-medium">Landcover:
<select value={lcFilter} onChange={e => { setLcFilter(e.target.value); setZoneFilter('All'); }}
className="ml-2 rounded border dark:bg-gray-800 dark:border-gray-600 px-2 py-1 text-sm">
<option value="All">All</option>
{scorableLCs.map(lc => <option key={lc} value={lc}>{lc}</option>)}
</select>
</label>
<label className="text-sm font-medium">Zone:
<select value={zoneFilter} onChange={e => { setZoneFilter(e.target.value); setLcFilter('All'); }}
className="ml-2 rounded border dark:bg-gray-800 dark:border-gray-600 px-2 py-1 text-sm">
<option value="All">All</option>
{zones.map(z => <option key={z} value={z}>{z}</option>)}
</select>
</label>
<span className="text-xs text-gray-400">
{lcFilter !== 'All' ? `Filtered: ${lcFilter}` : zoneFilter !== 'All' ? `Filtered: Zone ${zoneFilter}` : 'Showing all scored polygons'}
</span>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<HistogramChart histData={getHist('ForestHeight')} title="Forest Height (ft)" xLabel="Height (ft)" color="#004562" showStats stats={getStats('ForestHeight')} />
<HistogramChart histData={getHist('Den')} title="Density / Pct Ground (0-1)" xLabel="Fraction (0-1)" color="#a7c957" showStats stats={getStats('Den')} />
<HistogramChart histData={getHist('Composition')} title="Composition (raw, -1 to 1)" xLabel="Gradient Score" color="#52b788" showStats stats={getStats('Composition')} />
<HistogramChart histData={getHist('SiteIndex200Years')} title="Site Potential Tree Height (ft)" xLabel="SPTH (ft)" color="#7c3aed" showStats stats={getStats('SiteIndex200Years')} />
<HistogramChart histData={getHist('M_maturity')} title="Canopy Height M = Height/SPTH (0-1)" xLabel="Canopy Height (0-1)" color="#dc2626" showStats stats={getStats('M')} />
<HistogramChart histData={getHist('D_density')} title="Density D = 1 - Den (0-1)" xLabel="Density (0-1)" color="#ea580c" showStats stats={getStats('D_norm')} />
</div>
</div>
);
}
// ============================================================
// Tab 3: Zone & BID Analysis (merged: Zone Analysis + BID Scores)
// ============================================================
function ZoneBidPanel({ data }) {
const zones = ['50', '100', '300', 'hmz', 'hmz300'];
const bs = data.bid_scores;
// Landcover composition per zone
const lcZone = data.cross_tabs.landcover_zone || [];
const scorableLCs = ['Forest', 'Shrub/Woodland', 'Shrub', 'Ground/Herbaceous'];
const zoneComposition = zones.map(z => {
const obj = { zone: z };
scorableLCs.forEach(lc => {
const match = lcZone.find(r => r.Zone === z && r.Landcover === lc);
obj[lc] = match ? Math.round(match.area / 43560) : 0;
});
return obj;
});
// Zone-level RP
const zoneAgg = data.zone_aggregation;
// Distance-decay curves
const ZONE_LABELS_DECAY = {'50': '0-50 ft', '100': '50-100 ft', '300': '100-300 ft', 'hmz': 'HMZ', 'hmz300': 'HMZ-300'};
const decayCurves = [
{ name: 'Linear', weights: [5, 4, 3, 2, 1] },
{ name: 'Moderate', weights: [10, 6, 3, 2, 1] },
{ name: 'Squared', weights: [25, 16, 9, 4, 1] },
];
const decayData = zones.map((z, i) => {
const obj = { zone: ZONE_LABELS_DECAY[z] || z };
decayCurves.forEach(c => {
const total = c.weights.reduce((a, b) => a + b, 0);
obj[c.name] = parseFloat(((c.weights[i] / total) * 100).toFixed(1));
});
return obj;
});
return (
<div>
{/* Zone Analysis Section */}
<SectionTitle>Landcover Composition by Zone (Area)</SectionTitle>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
<ResponsiveContainer width="100%" height={340}>
<BarChart data={zoneComposition} margin={{ top: 10, right: 10, left: 35, bottom: 30 }}>
<CartesianGrid strokeDasharray="3 3" stroke="#374151" opacity={0.3} />
<XAxis dataKey="zone" label={{ value: 'Buffer Zone (ft)', position: 'bottom', offset: 3, fontSize: 11, fill: '#6b7280' }} />
<YAxis tickFormatter={(v) => `${fmtN(v)} ac`} tick={{ fontSize: 11 }}
label={{ value: 'Area (acres)', angle: -90, position: 'insideLeft', offset: -10, fontSize: 11, fill: '#9ca3af' }} />
<Tooltip formatter={(v) => `${fmtN(v)} acres`} />
<Legend verticalAlign="top" wrapperStyle={{ fontSize: 11, paddingBottom: 6 }} />
{scorableLCs.map(lc => (
<Bar key={lc} dataKey={lc} stackId="a" fill={LC_COLORS[lc]} />
))}
</BarChart>
</ResponsiveContainer>
</div>
<SectionTitle>Zone-Level RP Distributions (Area-Weighted Mean per BID)</SectionTitle>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{zones.map(z => zoneAgg[z] && (
<HistogramChart key={z} histData={zoneAgg[z].rp_hist}
title={`Zone ${z} (${fmtN(zoneAgg[z].bid_count)} BIDs)`}
xLabel="RP Score" color={ZONE_COLORS[z]} showStats stats={zoneAgg[z].rp_stats} />
))}
</div>
<SectionTitle>Distance-Decay Weight Profiles (% of total weight)</SectionTitle>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
<ResponsiveContainer width="100%" height={280}>
<LineChart data={decayData} margin={{ top: 10, right: 30, left: 20, bottom: 30 }}>
<CartesianGrid strokeDasharray="3 3" stroke="#374151" opacity={0.3} />
<XAxis dataKey="zone" tick={{ fontSize: 11 }} label={{ value: 'Buffer Zone', position: 'bottom', offset: 3, fontSize: 11, fill: '#6b7280' }} />
<YAxis domain={[0, 50]} tickFormatter={(v) => `${v}%`}
label={{ value: '% Weight', angle: -90, position: 'insideLeft', fontSize: 12 }} />
<Tooltip formatter={(v) => `${v}%`} />
<Legend verticalAlign="top" wrapperStyle={{ fontSize: 11, paddingBottom: 6 }} />
<Line type="monotone" dataKey="Linear" stroke="#1193BA" strokeWidth={2} dot={{ r: 5 }} />
<Line type="monotone" dataKey="Moderate" stroke="#f59e0b" strokeWidth={2} dot={{ r: 5 }} />
<Line type="monotone" dataKey="Squared" stroke="#ef4444" strokeWidth={2} dot={{ r: 5 }} />
</LineChart>
</ResponsiveContainer>
<div className="text-xs text-gray-500 dark:text-gray-400 mt-2">
Active: <strong>Moderate</strong> (10, 6, 3, 2, 1). Steeper curves prioritize near-channel condition.
</div>
</div>
<SectionTitle>Zone Statistics</SectionTitle>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4 overflow-x-auto">
<table className="w-full text-sm">
<thead>
<tr className="border-b dark:border-gray-700">
<th className="text-left py-2 px-2">Zone</th>
<th className="text-right py-2 px-2">Polygons</th>
<th className="text-right py-2 px-2">Area</th>
<th className="text-right py-2 px-2">Mean RP</th>
<th className="text-right py-2 px-2">Mean Height</th>
<th className="text-right py-2 px-2">Mean Density</th>
</tr>
</thead>
<tbody>
{zones.map(z => {
const st = data.stats_by_zone[z];
return st ? (
<tr key={z} className="border-b dark:border-gray-700/50">
<td className="py-1.5 px-2">{z}</td>
<td className="text-right py-1.5 px-2">{fmtN(st.count)}</td>
<td className="text-right py-1.5 px-2">{fmtAcres(st.area_total)}</td>
<td className="text-right py-1.5 px-2">{fmtDec(st.RP?.mean)}</td>
<td className="text-right py-1.5 px-2">{fmtDec(st.ForestHeight?.mean)}</td>
<td className="text-right py-1.5 px-2">{fmtDec(st.Den?.mean)}</td>
</tr>
) : null;
})}
</tbody>
</table>
</div>
{/* BID Scores Section */}
<SectionTitle>BID-Level Score Distribution (Solar-Adjusted)</SectionTitle>
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-4">
<StatCard label="BIDs Scored" value={fmtN(bs.total_bids_scored)} sub="count of BIDs" />
<StatCard label="Mean RP" value={fmtDec(bs.rp_solar_stats?.mean || bs.rp_normalized_stats?.mean)} sub="RP score · 0 = best, 100 = worst" />
<StatCard label="Median RP" value={fmtDec(bs.rp_solar_stats?.p50 || bs.rp_normalized_stats?.p50)} sub="RP score · 0 = best, 100 = worst" />
<StatCard label="RP Range" value={`${fmtDec((bs.rp_solar_stats?.min ?? bs.rp_normalized_stats?.min), 0)} – ${fmtDec((bs.rp_solar_stats?.max ?? bs.rp_normalized_stats?.max), 0)}`} sub="min – max score" />
</div>
<HistogramChart histData={bs.rp_solar_hist || bs.rp_normalized_hist} title="BID RP Score (solar-adjusted, distance-decay weighted)"
xLabel="RP Score (0-100)" color="#1193BA" height={300} showStats stats={bs.rp_solar_stats || bs.rp_normalized_stats} />
<SectionTitle>BID-Level Area-Weighted Raw Score (log scale)</SectionTitle>
{(() => {
const raw = bs.rp_area_raw_hist;
if (!raw || !raw.bins || !raw.counts) return null;
const totalBins = raw.counts.length;
const rawData = raw.counts.map((c, i) => {
const pctile = (i / totalBins) * 100;
return {
bin: `1e${raw.bins[i]}`,
count: c,
fill: pctile < 25 ? '#22c55e' : pctile < 50 ? '#1193BA' : pctile < 75 ? '#f59e0b' : '#ef4444',
};
});
return (
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
<p className="text-xs text-gray-500 dark:text-gray-400 mb-2">
Raw decay-weighted area score. Color: <span className="text-green-500">low</span> to <span className="text-red-500">high</span> need.
</p>
<ResponsiveContainer width="100%" height={280}>
<BarChart data={rawData} margin={{ top: 5, right: 10, left: 0, bottom: 20 }}>
<CartesianGrid strokeDasharray="3 3" stroke="#374151" opacity={0.3} />
<XAxis dataKey="bin" tick={{ fontSize: 9 }} angle={-45} textAnchor="end" interval="preserveStartEnd"
label={{ value: 'Raw Score (log scale)', position: 'bottom', offset: 5, fontSize: 11, fill: '#6b7280' }} />
<YAxis tick={{ fontSize: 10 }}
label={{ value: 'BID Count', angle: -90, position: 'insideLeft', offset: 10, fontSize: 10, fill: '#9ca3af' }} />
<Tooltip formatter={(v) => fmtN(v)} />
<Bar dataKey="count" radius={[2, 2, 0, 0]}>
{rawData.map((e, i) => <Cell key={i} fill={e.fill} />)}
</Bar>
</BarChart>
</ResponsiveContainer>
</div>
);
})()}
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6 mt-6">
<div>
<SectionTitle>BID Score Statistics</SectionTitle>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4 overflow-x-auto">
<table className="w-full text-sm">
<thead>
<tr className="border-b dark:border-gray-700">
<th className="text-left py-2 px-2">Metric</th>
<th className="text-right py-2 px-2">RP (0-100)</th>
<th className="text-right py-2 px-2">Area Raw</th>
</tr>
</thead>
<tbody>
{['mean', 'p10', 'p25', 'p50', 'p75', 'p90'].map(m => (
<tr key={m} className="border-b dark:border-gray-700/50">
<td className="py-1.5 px-2">{m}</td>
<td className="text-right py-1.5 px-2">{fmtDec((bs.rp_solar_stats || bs.rp_normalized_stats)?.[m])}</td>
<td className="text-right py-1.5 px-2">{fmtN(Math.round(bs.rp_area_raw_stats?.[m] || 0))}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
<div>
<SectionTitle>Zones per BID</SectionTitle>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow p-4">
<ResponsiveContainer width="100%" height={250}>
<BarChart data={Object.entries(bs.zone_count_dist).sort((a,b)=>a[0]-b[0]).map(([z,c])=>({zones: z, count: c}))}
margin={{ top: 5, right: 10, left: 5, bottom: 18 }}>
<CartesianGrid strokeDasharray="3 3" stroke="#374151" opacity={0.3} />
<XAxis dataKey="zones" label={{ value: '# Zones per BID', position: 'bottom', offset: 2, fontSize: 11, fill: '#6b7280' }} />
<YAxis label={{ value: 'BID Count', angle: -90, position: 'insideLeft', offset: 10, fontSize: 10, fill: '#9ca3af' }} />
<Tooltip formatter={(v) => fmtN(v)} />
<Bar dataKey="count" fill="#1193BA" radius={[4, 4, 0, 0]} />
</BarChart>
</ResponsiveContainer>
</div>
</div>
</div>
</div>
);
}
// ============================================================
// Tab 4: Radar Profiles (kept intact)
// ============================================================
function RadarProfilePanel({ data }) {
const radar = data.radar;
if (!radar) return <div className="text-gray-500">No radar data available. Regenerate dashboard_data.json.</div>;
const ZONE_LABELS = {'50': '0-50 ft', '100': '50-100 ft', '300': '100-300 ft', 'hmz': 'HMZ', 'hmz300': 'HMZ-300', 'river': 'In-Channel'};
const ZONE_RADAR_COLORS = {'50':'#004562','100':'#0B7A9E','300':'#1193BA','hmz':'#F9A134','hmz300':'#f97316','river':'#dc2626'};
const REACH_RADAR_COLORS = {'flowline':'#2d6a4f', 'Stream/river':'#52b788', 'Lake/pond':'#457b9d'};
const axisLabels = {
pct_forest: '% Forest',
pct_shrub: '% Shrub',
pct_herb: '% Herb/Ground',
pct_non_restorable: '% Non-Restorable',
mean_maturity: 'Canopy Height',
mean_density: 'Density',
mean_rp: 'Mean RP',
};
const axes = Object.keys(axisLabels);
function buildRadarData(profileMap) {
return axes.map(axis => {
const row = { axis: axisLabels[axis] };
Object.keys(profileMap).forEach(k => {
row[k] = profileMap[k][axis] || 0;
});
return row;
});
}
const zoneRadarData = buildRadarData(radar.by_zone);
const reachRadarData = buildRadarData(radar.by_reach);
const zoneKeys = Object.keys(radar.by_zone);
const reachKeys = Object.keys(radar.by_reach);
const tableHeaders = [
{ key: 'pct_forest', label: '% Forest', fmt: v => `${v}%` },
{ key: 'pct_shrub', label: '% Shrub', fmt: v => `${v}%` },
{ key: 'pct_herb', label: '% Herb', fmt: v => `${v}%` },
{ key: 'pct_non_restorable', label: '% Non-Rest.', fmt: v => `${v}%` },
{ key: 'mean_maturity', label: 'Canopy Height', fmt: v => v },
{ key: 'mean_density', label: 'Density', fmt: v => v },
{ key: 'mean_rp', label: 'Mean RP', fmt: v => v },
];
function ProfileTable({ profileMap, keys, labelFn }) {
return (
<table className="w-full text-sm">
<thead>
<tr className="border-b dark:border-gray-700">
<th className="text-left py-2 px-2">Name</th>
{tableHeaders.map(h => (
<th key={h.key} className="text-right py-2 px-2">{h.label}</th>
))}
<th className="text-right py-2 px-2">Polygons</th>
</tr>
</thead>
<tbody>
{keys.map(k => {
const r = profileMap[k];
return (
<tr key={k} className="border-b dark:border-gray-700/50">
<td className="py-1.5 px-2 font-medium">{labelFn(k)}</td>
{tableHeaders.map(h => (
<td key={h.key} className="text-right py-1.5 px-2">{h.fmt(r[h.key])}</td>
))}
<td className="text-right py-1.5 px-2">{fmtN(r.count)}</td>
</tr>
);
})}
</tbody>
</table>
);
}