data-analyst-mcp 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +262 -262
  2. package/dist/report/method_audit.js +7 -1
  3. package/dist/report/method_audit.js.map +1 -1
  4. package/dist/report/scan_secrets.d.ts +4 -1
  5. package/dist/report/scan_secrets.js +36 -5
  6. package/dist/report/scan_secrets.js.map +1 -1
  7. package/dist/server.d.ts +1 -1
  8. package/dist/server.js +3 -2
  9. package/dist/server.js.map +1 -1
  10. package/guide/WORKFLOW.md +134 -134
  11. package/guide/assets/disclaimer.txt +1 -1
  12. package/guide/assets/download_data.ps1 +162 -162
  13. package/guide/assets/report_template.html +597 -597
  14. package/guide/references/routing.md +171 -171
  15. package/guide/references/style_guide.md +398 -398
  16. package/package.json +56 -56
  17. package/packs/acf/endpoints.json +114 -114
  18. package/packs/acf/policy.json +104 -104
  19. package/packs/actuaries/endpoints.json +82 -82
  20. package/packs/actuaries/policy.json +109 -109
  21. package/packs/bea/assets/download_bea.ps1 +182 -182
  22. package/packs/bea/docs/bea_api.md +461 -461
  23. package/packs/bea/docs/datasets.md +157 -157
  24. package/packs/bea/docs/report_patterns.md +112 -112
  25. package/packs/bea/policy.json +170 -170
  26. package/packs/bea/source.md +152 -152
  27. package/packs/bls/assets/download_bls.ps1 +152 -152
  28. package/packs/bls/docs/analysis_patterns.md +108 -108
  29. package/packs/bls/docs/bls_api.md +73 -73
  30. package/packs/bls/docs/series_ids.md +149 -149
  31. package/packs/bls/policy.json +238 -238
  32. package/packs/bts/endpoints.json +346 -346
  33. package/packs/bts/policy.json +94 -94
  34. package/packs/cdc/endpoints.json +197 -197
  35. package/packs/cdc/policy.json +83 -83
  36. package/packs/census/endpoints.json +99 -99
  37. package/packs/cfpb/endpoints.json +326 -326
  38. package/packs/cfpb/policy.json +119 -119
  39. package/packs/clinical-trials/endpoints.json +166 -166
  40. package/packs/clinical-trials/policy.json +84 -84
  41. package/packs/cms/endpoints.json +69 -69
  42. package/packs/cms/policy.json +96 -96
  43. package/packs/college-scorecard/endpoints.json +252 -252
  44. package/packs/college-scorecard/policy.json +106 -106
  45. package/packs/congress/endpoints.json +1701 -1701
  46. package/packs/congress/policy.json +117 -117
  47. package/packs/dhs-ohss/endpoints.json +66 -66
  48. package/packs/dhs-ohss/policy.json +107 -107
  49. package/packs/doj-news/endpoints.json +59 -59
  50. package/packs/doj-news/policy.json +96 -96
  51. package/packs/dol/endpoints.json +817 -817
  52. package/packs/dol/policy.json +135 -135
  53. package/packs/eia/endpoints.json +717 -717
  54. package/packs/eia/policy.json +112 -112
  55. package/packs/epa/endpoints.json +291 -291
  56. package/packs/epa/policy.json +99 -99
  57. package/packs/epa-aqs/endpoints.json +173 -173
  58. package/packs/epa-aqs/policy.json +96 -96
  59. package/packs/fbi/endpoints.json +1841 -1841
  60. package/packs/fbi/policy.json +118 -118
  61. package/packs/fda/endpoints.json +237 -237
  62. package/packs/fda/policy.json +121 -121
  63. package/packs/fdic/endpoints.json +416 -416
  64. package/packs/fdic/policy.json +83 -83
  65. package/packs/fec/endpoints.json +707 -707
  66. package/packs/fec/policy.json +93 -93
  67. package/packs/fed-board/endpoints.json +89 -89
  68. package/packs/fed-board/policy.json +136 -136
  69. package/packs/federal-register/endpoints.json +143 -143
  70. package/packs/federal-register/policy.json +86 -86
  71. package/packs/fema/endpoints.json +645 -645
  72. package/packs/fema/policy.json +103 -103
  73. package/packs/fhfa/endpoints.json +105 -105
  74. package/packs/fhfa/policy.json +109 -109
  75. package/packs/fred/assets/download_fred.ps1 +122 -122
  76. package/packs/fred/docs/analysis_patterns.md +124 -124
  77. package/packs/fred/docs/fred_api.md +94 -94
  78. package/packs/fred/docs/series.md +188 -188
  79. package/packs/fred/policy.json +253 -253
  80. package/packs/fsa/endpoints.json +150 -150
  81. package/packs/fsa/policy.json +99 -99
  82. package/packs/govinfo/endpoints.json +519 -519
  83. package/packs/gsa-calc/endpoints.json +93 -93
  84. package/packs/gsa-calc/policy.json +97 -97
  85. package/packs/hud/endpoints.json +146 -146
  86. package/packs/hud/policy.json +84 -84
  87. package/packs/ipums/docs/report_patterns.md +117 -117
  88. package/packs/irs-soi/endpoints.json +114 -114
  89. package/packs/irs-soi/policy.json +107 -107
  90. package/packs/medicaid/endpoints.json +412 -412
  91. package/packs/medicaid/policy.json +108 -108
  92. package/packs/naep/endpoints.json +217 -217
  93. package/packs/naep/policy.json +100 -100
  94. package/packs/nhtsa/endpoints.json +132 -132
  95. package/packs/nhtsa/policy.json +93 -93
  96. package/packs/nih/endpoints.json +452 -452
  97. package/packs/nih/policy.json +86 -86
  98. package/packs/noaa/endpoints.json +431 -431
  99. package/packs/noaa/policy.json +95 -95
  100. package/packs/nrel/endpoints.json +327 -327
  101. package/packs/nrel/policy.json +96 -96
  102. package/packs/nws/endpoints.json +271 -271
  103. package/packs/nws/policy.json +82 -82
  104. package/packs/nyfed/endpoints.json +80 -80
  105. package/packs/nyfed/policy.json +92 -92
  106. package/packs/omb/endpoints.json +460 -460
  107. package/packs/omb/policy.json +106 -106
  108. package/packs/open-payments/endpoints.json +297 -297
  109. package/packs/open-payments/policy.json +101 -101
  110. package/packs/opm/assets/download_opm.ps1 +125 -125
  111. package/packs/opm/docs/fields.md +184 -184
  112. package/packs/opm/docs/opm_api.md +71 -71
  113. package/packs/opm/docs/report_patterns.md +83 -83
  114. package/packs/opm/lib/data_dictionary.csv +73 -73
  115. package/packs/pbgc/endpoints.json +483 -483
  116. package/packs/pbgc/policy.json +94 -94
  117. package/packs/philfed/endpoints.json +85 -85
  118. package/packs/philfed/policy.json +94 -94
  119. package/packs/regulations/endpoints.json +287 -287
  120. package/packs/regulations/policy.json +86 -86
  121. package/packs/sec/endpoints.json +236 -236
  122. package/packs/sec/policy.json +86 -86
  123. package/packs/senate-lobbying/endpoints.json +553 -553
  124. package/packs/senate-lobbying/policy.json +99 -99
  125. package/packs/snapqc/endpoints.json +1426 -1426
  126. package/packs/snapqc/policy.json +92 -92
  127. package/packs/treasury/catalog.json +2267 -2267
  128. package/packs/treasury/docs/api_guide.md +245 -245
  129. package/packs/treasury/docs/datasets.md +56 -56
  130. package/packs/treasury/docs/report_patterns.md +126 -126
  131. package/packs/treasury/policy.json +159 -159
  132. package/packs/treasury/source.md +170 -165
  133. package/packs/treasury-yields/endpoints.json +226 -226
  134. package/packs/treasury-yields/policy.json +86 -86
  135. package/packs/usaspending/endpoints.json +1315 -1315
  136. package/packs/usaspending/policy.json +109 -109
  137. package/packs/usda-fna/policy.json +133 -133
  138. package/packs/usda-fooddata/endpoints.json +180 -180
  139. package/packs/usda-fooddata/policy.json +94 -94
  140. package/packs/usda-nass/endpoints.json +323 -323
  141. package/packs/usda-nass/policy.json +95 -95
  142. package/packs/usda-outlook/endpoints.json +86 -86
  143. package/packs/usda-outlook/policy.json +109 -109
  144. package/packs/usgs/endpoints.json +313 -313
  145. package/packs/usgs/policy.json +95 -95
  146. package/packs/usitc/endpoints.json +74 -74
  147. package/packs/usitc/policy.json +111 -111
  148. package/packs/uspto/endpoints.json +141 -141
  149. package/packs/uspto/policy.json +95 -95
  150. package/packs/va/endpoints.json +414 -414
  151. package/packs/va/policy.json +101 -101
  152. package/packs/world-bank/endpoints.json +122 -122
  153. package/packs/world-bank/policy.json +101 -101
@@ -1,597 +1,597 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>__TITLE__</title>
7
- <style>
8
- :root {
9
- color-scheme: light;
10
- --page: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink2: #52514e; --muted: #898781;
11
- --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11,11,11,.10);
12
- --accent: #1d3b63; --accent-soft: #eaf0f7; --badge: #7a4b00; --badge-bg: #fbefd6;
13
- --warn-bg: #fff8e6; --warn-border: #f2dca4;
14
- --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
15
- --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
16
- }
17
- @media (prefers-color-scheme: dark) {
18
- :root:where(:not([data-theme="light"])) {
19
- color-scheme: dark;
20
- --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink2: #c3c2b7; --muted: #898781;
21
- --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,.10);
22
- --accent: #9cc2f0; --accent-soft: #16202c; --badge: #f5c66b; --badge-bg: #33270f;
23
- --warn-bg: #2a2214; --warn-border: #5a4520;
24
- --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
25
- --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
26
- }
27
- }
28
- :root[data-theme="dark"] {
29
- color-scheme: dark;
30
- --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink2: #c3c2b7; --muted: #898781;
31
- --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,.10);
32
- --accent: #9cc2f0; --accent-soft: #16202c; --badge: #f5c66b; --badge-bg: #33270f;
33
- --warn-bg: #2a2214; --warn-border: #5a4520;
34
- --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
35
- --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
36
- }
37
- * { box-sizing: border-box; }
38
- html { -webkit-text-size-adjust: 100%; }
39
- body {
40
- margin: 0; background: var(--page); color: var(--ink);
41
- font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
42
- }
43
- main { max-width: 880px; margin: 0 auto; padding: 32px 16px 64px; }
44
- a { color: var(--accent); }
45
- code { font: 0.88em ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
46
- h1, h2, h3 { line-height: 1.25; text-wrap: balance; }
47
- h1 { font-size: clamp(1.6rem, 4.5vw, 2.25rem); margin: 0.2em 0 0.3em; color: var(--accent); }
48
- h2 { font-size: 1.3rem; margin: 2.2em 0 0.6em; color: var(--accent); }
49
- h3 { font-size: 1.05rem; margin: 1.6em 0 0.4em; }
50
- .masthead { border-bottom: 3px solid var(--accent); padding-bottom: 18px; }
51
- .kicker { margin: 0; color: var(--ink2); font-size: 0.9rem; letter-spacing: .02em; }
52
- .badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
53
- background: var(--badge-bg); color: var(--badge); font-size: 0.78rem; font-weight: 600; }
54
- .dek { margin: 0; color: var(--ink2); font-size: 1.08rem; max-width: 70ch; }
55
- .summary { background: var(--accent-soft); border-radius: 10px; padding: 4px 20px 12px; margin-top: 24px; }
56
- .summary h2 { margin-top: 0.9em; }
57
- .findings { padding-left: 1.2em; margin: 0.4em 0; }
58
- .findings li { margin: 0.45em 0; max-width: 72ch; }
59
- .tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 8px 0 14px; }
60
- .tile { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
61
- .tile p { margin: 0; }
62
- .t-label { color: var(--ink2); font-size: 0.85rem; }
63
- .t-value { font-size: 1.75rem; font-weight: 650; line-height: 1.2; margin: 2px 0 !important; }
64
- .t-note { color: var(--muted); font-size: 0.8rem; }
65
- .toc ol { padding-left: 1.4em; margin: 0; }
66
- .toc li { margin: 0.25em 0; }
67
- .prose p, .prose li { max-width: 72ch; }
68
- .exhibit { background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
69
- padding: 18px 18px 12px; margin: 22px 0; }
70
- .ex-num { margin: 0; font-size: 0.8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
71
- .exhibit h3 { margin: 2px 0 2px; font-size: 1.12rem; }
72
- .ex-sub { margin: 0 0 8px; color: var(--ink2); font-size: 0.9rem; }
73
- .legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 4px 0 6px; font-size: 0.85rem; color: var(--ink2); }
74
- .legend span { display: inline-flex; align-items: center; gap: 6px; }
75
- .legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
76
- .legend i.line { height: 3px; width: 16px; border-radius: 2px; }
77
- .chart { position: relative; width: 100%; min-height: 40px; }
78
- .chart svg { display: block; overflow: visible; max-width: 100%; height: auto; }
79
- .chart text { font: 12px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; fill: var(--muted); font-variant-numeric: tabular-nums; }
80
- .chart text.lab { fill: var(--ink2); }
81
- .chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
82
- .chart .base { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
83
- .chart .guide { stroke: var(--axis); stroke-width: 1; }
84
- .chart .hit { fill: transparent; cursor: default; }
85
- .chart .rec { fill: var(--ink); opacity: .07; }
86
- .chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
87
- .chart .dot { stroke: var(--surface); stroke-width: 2; }
88
- .chart .bar.dim { opacity: .45; }
89
- .f1{fill:var(--s1)} .f2{fill:var(--s2)} .f3{fill:var(--s3)} .f4{fill:var(--s4)}
90
- .f5{fill:var(--s5)} .f6{fill:var(--s6)} .f7{fill:var(--s7)} .f8{fill:var(--s8)}
91
- .k1{stroke:var(--s1)} .k2{stroke:var(--s2)} .k3{stroke:var(--s3)} .k4{stroke:var(--s4)}
92
- .k5{stroke:var(--s5)} .k6{stroke:var(--s6)} .k7{stroke:var(--s7)} .k8{stroke:var(--s8)}
93
- .b1{background:var(--s1)} .b2{background:var(--s2)} .b3{background:var(--s3)} .b4{background:var(--s4)}
94
- .b5{background:var(--s5)} .b6{background:var(--s6)} .b7{background:var(--s7)} .b8{background:var(--s8)}
95
- .tip { position: absolute; pointer-events: none; z-index: 5; background: var(--surface); color: var(--ink);
96
- border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.8rem; line-height: 1.4;
97
- box-shadow: 0 4px 16px rgba(0,0,0,.14); min-width: 120px; max-width: 260px; display: none; }
98
- .tip b { display: block; margin-bottom: 2px; }
99
- .tip .row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
100
- .tip .row i { width: 9px; height: 9px; border-radius: 2px; flex: none; }
101
- .tip .row span:last-child { margin-left: auto; padding-left: 10px; font-variant-numeric: tabular-nums; font-weight: 600; }
102
- .notes, .source { font-size: 0.82rem; color: var(--ink2); margin: 8px 0 0; }
103
- .notes span, .source span { font-weight: 600; }
104
- .table-view { margin-top: 10px; font-size: 0.85rem; }
105
- .table-view summary { cursor: pointer; color: var(--accent); font-weight: 600; }
106
- .table-wrap { overflow-x: auto; margin: 8px 0; max-height: 420px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }
107
- table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
108
- th, td { padding: 5px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
109
- th:first-child, td:first-child { text-align: left; }
110
- .table-view th, .table-view td:first-child { white-space: normal; } /* long headers and row labels wrap, so wide tables fit the page */
111
- .table-view td:first-child { min-width: 12ch; }
112
- th { position: sticky; top: 0; background: var(--surface); color: var(--ink2); font-weight: 600; }
113
- .dl { font: inherit; font-size: 0.82rem; color: var(--accent); background: transparent; border: 1px solid var(--border);
114
- border-radius: 6px; padding: 4px 10px; cursor: pointer; }
115
- .dl:hover { background: var(--accent-soft); }
116
- blockquote { margin: 0.5em 0; padding: 8px 14px; border-left: 3px solid var(--axis); color: var(--ink2); }
117
- .cite { font-size: 0.88rem; color: var(--ink2); }
118
- .files li { margin: 0.3em 0; }
119
- .files code { color: var(--muted); margin-left: 4px; }
120
- .disclaimer { margin: 0 0 22px; padding: 12px 16px; border: 1px solid var(--warn-border);
121
- border-radius: 8px; background: var(--warn-bg); color: var(--ink); font-size: 0.88rem; line-height: 1.5; }
122
- .disclaimer p { margin: 0; }
123
- .disclaimer p + p { margin-top: 6px; }
124
- .footnotes ol { padding-left: 1.4em; font-size: 0.88rem; color: var(--ink2); }
125
- .footnotes li { margin: 0.35em 0; }
126
- sup.fn { font-size: 0.72em; line-height: 0; }
127
- sup.fn a { text-decoration: none; }
128
- .about { font-size: 0.92rem; color: var(--ink2); border-top: 1px solid var(--grid); margin-top: 2.4em; }
129
- /* publication typography in both modes; charts stay in the UI sans */
130
- :is(.mode-paper, .mode-report) .prose, :is(.mode-paper, .mode-report) .summary, :is(.mode-paper, .mode-report) .dek {
131
- font-family: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif; }
132
- :is(.mode-paper, .mode-report) .prose p, :is(.mode-paper, .mode-report) .summary p { font-size: 1.06rem; line-height: 1.6; }
133
- :is(.mode-paper, .mode-report) .summary { background: transparent; border-radius: 0; padding: 0; border-bottom: 1px solid var(--grid); }
134
- :is(.mode-paper, .mode-report) .summary h2 { margin-top: 1.4em; }
135
- :is(.mode-paper, .mode-report) .summary p { max-width: 70ch; margin: 0.7em 0; }
136
- :is(.mode-paper, .mode-report) .summary strong { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--accent); }
137
- :is(.mode-paper, .mode-report) .masthead h1 { font-size: clamp(1.7rem, 4.8vw, 2.5rem); }
138
- :is(.mode-paper, .mode-report) .prose > .exhibit { margin: 26px 0; }
139
- /* report mode: exhibit chartbook */
140
- .mode-report main { max-width: 1120px; }
141
- .mode-report .masthead.cover { border-bottom: 0; padding: 28px 0 8px; }
142
- .mode-report .cover h1 { font-size: clamp(1.9rem, 5vw, 2.9rem); max-width: 26ch; }
143
- .mode-report .cover .dek { font-size: 1.15rem; margin-top: 4px; }
144
- .cover-chart { margin: 26px 0 0; padding: 18px; background: var(--surface); border: 1px solid var(--border);
145
- border-top: 4px solid var(--accent); border-radius: 0 0 10px 10px; }
146
- .cover-chart-title { margin: 0; font-weight: 650; }
147
- .mode-report .glance, .mode-report .contents, .mode-report .exhibit-list, .mode-report .notes-page,
148
- .mode-report .intro, .mode-report .section-opener, .mode-report .appendix, .mode-report .about,
149
- .mode-report .references, .mode-report .footnotes:not(.part-notes) {
150
- border-top: 3px solid var(--accent); margin-top: 48px; padding-top: 4px; }
151
- .glance { font-family: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif; }
152
- .glance > p { font-size: 1.08rem; line-height: 1.6; max-width: 76ch; }
153
- .glance-findings { padding-left: 1.1em; margin: 0.6em 0; }
154
- .glance-findings li { margin: 0.7em 0; max-width: 76ch; line-height: 1.6; }
155
- .glance-findings strong { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--accent); }
156
- .contents-list { padding-left: 1.4em; margin: 0; }
157
- .contents-list > li { margin: 0.45em 0; }
158
- .contents-list ul { margin: 0.2em 0; padding-left: 1.2em; font-size: 0.92rem; }
159
- .contents-list .ex-range { display: block; color: var(--ink2); font-size: 0.85rem; }
160
- .contents-list li.supp { list-style: none; margin-top: 1em; color: var(--ink2); font-size: 0.9rem; }
161
- .exhibit-list h3 { margin: 1.1em 0 0.3em; font-size: 0.98rem; color: var(--ink2); }
162
- .ex-list { list-style: none; padding-left: 0; margin: 0; }
163
- .ex-list li { margin: 0.3em 0; }
164
- .ex-list a { text-decoration: none; }
165
- .ex-list .ex-n { display: inline-block; min-width: 2.2em; font-weight: 600; }
166
- .mode-report .section-opener p { font-size: 1.1rem; }
167
- .exhibit-page { display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.55fr); gap: 32px;
168
- align-items: start; margin: 40px 0; padding-top: 18px; border-top: 1px solid var(--grid); }
169
- .exhibit-page.no-text { grid-template-columns: minmax(0, 1fr); }
170
- .exhibit-page .ex-text p { margin: 0 0 0.9em; font-size: 1.02rem; }
171
- .exhibit-page .exhibit { margin: 0; }
172
- .part-notes { border-top: 1px solid var(--grid); margin-top: 24px; }
173
- .part-notes ol { margin-top: 10px; }
174
- .supplementary { margin-top: 64px; padding-top: 6px; border-top: 1px dashed var(--axis); }
175
- .supp-label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: .06em; margin: 0; }
176
- @media (max-width: 760px) {
177
- .exhibit-page { grid-template-columns: minmax(0, 1fr); gap: 8px; }
178
- }
179
- .audit-trail details > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
180
- table.audit { font-size: 0.8rem; }
181
- table.audit th, table.audit td { text-align: left; vertical-align: top; white-space: normal; }
182
- table.audit th[scope="row"] { color: var(--ink2); font-weight: 600; white-space: nowrap; position: static; }
183
- table.audit code { font-size: 0.92em; overflow-wrap: anywhere; }
184
- .muted { color: var(--muted); font-size: 0.9em; }
185
- .audit-note { font-size: 0.85rem; color: var(--ink2); }
186
- pre.code { max-height: 420px; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
187
- padding: 10px 12px; font: 0.78rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre; }
188
- .code-list { list-style: none; padding-left: 0; }
189
- .code-list summary { cursor: pointer; }
190
- .code-list .dl { margin: 6px 0; }
191
- a.pkg { font-weight: 600; }
192
- a.cite { text-decoration: none; }
193
- .references li { margin: 0.5em 0; overflow-wrap: anywhere; }
194
- footer { margin-top: 40px; color: var(--muted); font-size: 0.8rem; }
195
- footer p { margin: 0.3em 0; }
196
- .notices li { margin: 0.3em 0; }
197
- @media (max-width: 560px) {
198
- main { padding: 20px 16px 48px; }
199
- .exhibit { padding: 14px 12px 10px; }
200
- .summary { padding: 2px 14px 10px; }
201
- }
202
- @media print {
203
- body { background: #fff; }
204
- .exhibit { break-inside: avoid; border: none; padding: 0; }
205
- .mode-report main { max-width: none; padding: 0; }
206
- .mode-report .glance, .mode-report .contents, .mode-report .exhibit-list, .mode-report .notes-page,
207
- .mode-report .intro, .mode-report .section-opener, .mode-report .exhibit-page, .mode-report .appendix,
208
- .mode-report .about, .mode-report .supplementary { break-before: page; }
209
- .exhibit-page { break-inside: avoid; border-top: 0; }
210
- .cover-chart { break-inside: avoid; }
211
- .dl { display: none; }
212
- .disclaimer { border: 1px solid #999; background: #fff; }
213
- }
214
- </style>
215
- </head>
216
- <body class="mode-__MODE__">
217
- <main>
218
- <!--__BODY__-->
219
- <footer><!--__FOOTER__--></footer>
220
- </main>
221
- <script>
222
- (() => {
223
- const DATA = /*__DATA__*/null;
224
- const NS = "http://www.w3.org/2000/svg";
225
- const ctx = document.createElement("canvas").getContext("2d");
226
- const FONT = '12px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
227
- const tw = s => { ctx.font = FONT; return ctx.measureText(String(s)).width; };
228
- const el = (tag, attrs, parent) => {
229
- const e = document.createElementNS(NS, tag);
230
- for (const k in attrs) e.setAttribute(k, attrs[k]);
231
- if (parent) parent.appendChild(e);
232
- return e;
233
- };
234
- const isNum = v => v !== null && v !== undefined && v !== "" && !isNaN(v);
235
-
236
- // The style guide never uses "%" in text: the units line ("Percent") carries the unit.
237
- const PCT = "";
238
- function fmt(v, f, d, axis) {
239
- if (!isNum(v)) return "–";
240
- v = +v;
241
- if (f === "pct") return (v * 100).toFixed(d ?? 0) + PCT;
242
- if (f === "pct100") return v.toFixed(d ?? 0) + PCT;
243
- if (f === "dollars") {
244
- const a = Math.abs(v), s = v < 0 ? "−$" : "$";
245
- if (axis && a >= 1e6) return s + (a / 1e6).toLocaleString("en-US", {maximumFractionDigits: 1}) + "M";
246
- return s + a.toLocaleString("en-US", {minimumFractionDigits: d ?? 0, maximumFractionDigits: d ?? 0});
247
- }
248
- const dd = d ?? (Math.abs(v) >= 100 || Number.isInteger(v) ? 0 : 1);
249
- return (v < 0 ? "−" : "") + Math.abs(v).toLocaleString("en-US", {minimumFractionDigits: axis ? 0 : dd, maximumFractionDigits: dd});
250
- }
251
- function axisFmt(v, f) {
252
- if (f === "pct") return fmt(v, f, Math.abs(v * 100 - Math.round(v * 100)) > 1e-6 ? 1 : 0, true);
253
- if (f === "pct100") return fmt(v, f, Number.isInteger(+(+v).toFixed(6)) ? 0 : 1, true);
254
- if (f === "dollars") return fmt(v, f, Number.isInteger(+(+v).toFixed(6)) ? 0 : 2, true);
255
- return fmt(v, f, Number.isInteger(+(+v).toFixed(6)) ? 0 : 1, true);
256
- }
257
- function niceTicks(lo, hi, n) {
258
- if (lo === hi) { hi = lo + 1; }
259
- const raw = (hi - lo) / n, mag = Math.pow(10, Math.floor(Math.log10(raw))), r = raw / mag;
260
- const step = (r < 1.5 ? 1 : r < 3 ? 2 : r < 7 ? 5 : 10) * mag;
261
- const t0 = Math.floor(lo / step + 1e-9) * step, t1 = Math.ceil(hi / step - 1e-9) * step, out = [];
262
- for (let t = t0; t <= t1 + step / 2; t += step) out.push(+t.toFixed(10));
263
- return out;
264
- }
265
- function wrap(label, maxW, maxLines = 3) {
266
- const words = String(label).split(/\s+/), lines = [];
267
- let cur = "";
268
- for (const w of words) {
269
- const t = cur ? cur + " " + w : w;
270
- if (tw(t) <= maxW || !cur) cur = t; else { lines.push(cur); cur = w; }
271
- }
272
- if (cur) lines.push(cur);
273
- if (lines.length > maxLines) { lines.length = maxLines; lines[maxLines - 1] += "…"; }
274
- return lines;
275
- }
276
- function textLines(parent, lines, x, y, anchor, cls, lh = 14) {
277
- const t = el("text", {x, y, "text-anchor": anchor}, parent);
278
- if (cls) t.setAttribute("class", cls);
279
- lines.forEach((l, i) => { const s = el("tspan", {x, dy: i ? lh : 0}, t); s.textContent = l; });
280
- return t;
281
- }
282
-
283
- // ---------- tooltip
284
- function tooltip(box) {
285
- let tip = box.querySelector(".tip");
286
- if (!tip) { tip = document.createElement("div"); tip.className = "tip"; box.appendChild(tip); }
287
- return {
288
- show(html, px, py) {
289
- tip.innerHTML = html; tip.style.display = "block";
290
- const bw = box.clientWidth, w = tip.offsetWidth, h = tip.offsetHeight;
291
- let x = px + 14; if (x + w > bw) x = px - w - 14; if (x < 0) x = Math.max(0, bw - w);
292
- let y = py - h - 10; if (y < 0) y = py + 16;
293
- tip.style.left = x + "px"; tip.style.top = y + "px";
294
- },
295
- hide() { tip.style.display = "none"; }
296
- };
297
- }
298
- const row = (k, name, val) => `<div class="row"><i class="b${k}"></i><span>${esc(name)}</span><span>${val}</span></div>`;
299
- const esc = s => String(s).replace(/[&<>"]/g, c => ({"&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;"}[c]));
300
- const pointer = (ev, box) => { const r = box.getBoundingClientRect(); return [ev.clientX - r.left, ev.clientY - r.top]; };
301
-
302
- // ---------- domain
303
- function domain(spec, stacked, zero) {
304
- let vals = [];
305
- if (stacked) {
306
- spec.categories.forEach((_, i) => {
307
- let p = 0, n = 0;
308
- spec.series.forEach(s => { const v = s.values[i]; if (isNum(v)) { if (v >= 0) p += +v; else n += +v; } });
309
- vals.push(p, n);
310
- });
311
- } else spec.series.forEach(s => s.values.forEach(v => { if (isNum(v)) vals.push(+v); }));
312
- if (!vals.length) vals = [0, 1];
313
- let lo = Math.min(...vals), hi = Math.max(...vals);
314
- if (zero) { lo = Math.min(0, lo); hi = Math.max(0, hi); }
315
- else if (lo >= 0 && lo < 0.5 * hi) lo = 0;
316
- else { const pad = (hi - lo) * 0.08 || Math.abs(hi) * 0.1 || 1; lo -= pad; hi += pad; }
317
- if (isNum(spec.y_min)) lo = +spec.y_min;
318
- if (isNum(spec.y_max)) hi = +spec.y_max;
319
- const ticks = niceTicks(lo, hi, 5).filter(t => (!isNum(spec.y_min) || t >= +spec.y_min - 1e-9) && (!isNum(spec.y_max) || t <= +spec.y_max + 1e-9));
320
- return {ticks, lo: Math.min(ticks[0], lo), hi: Math.max(ticks[ticks.length - 1], hi)};
321
- }
322
-
323
- // ---------- line chart
324
- function lineChart(box, spec) {
325
- const W = box.clientWidth, H = W < 520 ? 250 : 310, cats = spec.categories, S = spec.series;
326
- const {ticks, lo, hi} = domain(spec, false, false);
327
- const ml = Math.max(...ticks.map(t => tw(axisFmt(t, spec.format)))) + 10;
328
- const last = s => { for (let i = s.values.length - 1; i >= 0; i--) if (isNum(s.values[i])) return i; return -1; };
329
- // direct end labels only if they fit and do not collide (legend always carries identity)
330
- let labelW = S.length <= 4 ? Math.max(...S.map(s => tw(s.name))) + 12 : 0;
331
- if (labelW > W * 0.32) labelW = 0;
332
- const mr = Math.max(labelW, 12), mt = 10, mb = 30, pw = W - ml - mr, ph = H - mt - mb;
333
- // A real date axis when the builder passed ISO dates (time series): spacing follows the calendar, so
334
- // a gap in the dates is a gap on the axis, and recessions can be shaded at their true dates.
335
- const T = (spec.dates && spec.dates.length === cats.length && spec.dates.every(d => !isNaN(Date.parse(d))))
336
- ? spec.dates.map(d => Date.parse(d)) : null;
337
- const t0 = T ? T[0] : 0, t1 = T ? T[T.length - 1] : 1;
338
- const X = T ? (i => ml + (t1 === t0 ? pw / 2 : (T[i] - t0) / (t1 - t0) * pw))
339
- : (i => ml + (cats.length === 1 ? pw / 2 : i * pw / (cats.length - 1)));
340
- const Xt = t => ml + (t - t0) / ((t1 - t0) || 1) * pw;
341
- const Y = v => mt + ph - (v - lo) / (hi - lo) * ph;
342
- const svg = el("svg", {width: W, height: H, viewBox: `0 0 ${W} ${H}`}, box);
343
- if (T && spec.recessions) spec.recessions.forEach(([a, b]) => {
344
- const s = Math.max(Date.parse(a), t0), e0 = new Date(Date.parse(b)); e0.setUTCMonth(e0.getUTCMonth() + 1);
345
- const e = Math.min(e0.getTime(), t1);
346
- if (e > s) el("rect", {x: Xt(s), y: mt, width: Math.max(1, Xt(e) - Xt(s)), height: ph, class: "rec"}, svg);
347
- });
348
- ticks.forEach(t => {
349
- el("line", {x1: ml, x2: ml + pw, y1: Y(t), y2: Y(t), class: Math.abs(t) < 1e-12 ? "base" : "grid"}, svg);
350
- el("text", {x: ml - 8, y: Y(t) + 4, "text-anchor": "end"}, svg).textContent = axisFmt(t, spec.format);
351
- });
352
- if (T) {
353
- // year ticks at a step that fits (1, 2, 5, 10, 20 years); months when the span is under two years
354
- const y0 = new Date(t0).getUTCFullYear(), y1 = new Date(t1).getUTCFullYear(), span = (t1 - t0) / 31557600000;
355
- let labels = [];
356
- if (span < 2) {
357
- for (let d = new Date(Date.UTC(y0, new Date(t0).getUTCMonth(), 1)); d.getTime() <= t1; d.setUTCMonth(d.getUTCMonth() + 3))
358
- labels.push([d.getTime(), d.toLocaleString("en-US", {month: "short", timeZone: "UTC"}) + " " + d.getUTCFullYear()]);
359
- } else {
360
- const fit = Math.max(1, Math.floor(pw / (tw("2000") + 18)));
361
- const step = [1, 2, 5, 10, 20, 50].find(s => (y1 - y0) / s + 1 <= fit) || 100;
362
- for (let y = Math.ceil(y0 / step) * step; y <= y1; y += step) labels.push([Date.UTC(y, 0, 1), String(y)]);
363
- }
364
- const lw = Math.max(...labels.map(l => tw(l[1]))) + 10;
365
- labels = labels.filter((l, i) => l[0] >= t0 && l[0] <= t1 && (i === 0 || Xt(l[0]) - Xt(labels[i - 1][0]) >= lw));
366
- labels.forEach(([t, s]) => {
367
- el("line", {x1: Xt(t), x2: Xt(t), y1: mt + ph, y2: mt + ph + 4, class: "base"}, svg);
368
- el("text", {x: Xt(t), y: H - 10, "text-anchor": "middle"}, svg).textContent = s;
369
- });
370
- } else {
371
- const maxLab = Math.max(...cats.map(c => tw(c))) + 10;
372
- const every = Math.max(1, Math.ceil(cats.length * maxLab / pw));
373
- cats.forEach((c, i) => {
374
- if (i % every && i !== cats.length - 1) return;
375
- if (i !== cats.length - 1 && cats.length - 1 - i < every && (cats.length - 1) % every) return;
376
- el("text", {x: X(i), y: H - 10, "text-anchor": "middle"}, svg).textContent = c;
377
- });
378
- }
379
- S.forEach((s, k) => {
380
- let d = "", pen = false;
381
- s.values.forEach((v, i) => { if (isNum(v)) { d += (pen ? "L" : "M") + X(i).toFixed(1) + "," + Y(+v).toFixed(1); pen = true; } else pen = false; });
382
- el("path", {d, class: `ln k${k + 1}`}, svg);
383
- if (cats.length <= 12) s.values.forEach((v, i) => { if (isNum(v) && cats.length <= 4) el("circle", {cx: X(i), cy: Y(+v), r: 4, class: `dot f${k + 1}`}, svg); });
384
- const li = last(s);
385
- if (li >= 0) el("circle", {cx: X(li), cy: Y(+s.values[li]), r: 4, class: `dot f${k + 1}`}, svg);
386
- });
387
- if (labelW) {
388
- const ends = S.map((s, k) => ({k, y: last(s) >= 0 ? Y(+s.values[last(s)]) : null, s})).filter(e => e.y !== null).sort((a, b) => a.y - b.y);
389
- const ok = ends.every((e, i) => i === 0 || e.y - ends[i - 1].y >= 14);
390
- if (ok) ends.forEach(e => {
391
- const li = last(e.s);
392
- const t = el("text", {x: X(li) + 8, y: e.y + 4, class: "lab"}, svg);
393
- t.textContent = S.length > 1 ? e.s.name : fmt(e.s.values[li], spec.format, spec.decimals);
394
- });
395
- }
396
- // hover: crosshair + all-series tooltip
397
- const tip = tooltip(box), guide = el("line", {y1: mt, y2: mt + ph, class: "guide", visibility: "hidden"}, svg);
398
- const marks = S.map((s, k) => el("circle", {r: 5, class: `dot f${k + 1}`, visibility: "hidden"}, svg));
399
- cats.forEach((c, i) => {
400
- // hit area: halfway to each neighbor (uneven on a date axis)
401
- const a = i ? (X(i - 1) + X(i)) / 2 : ml, b = i < cats.length - 1 ? (X(i) + X(i + 1)) / 2 : ml + pw;
402
- const hit = el("rect", {x: Math.min(a, X(i)), y: mt, width: Math.max(1, b - a), height: ph, class: "hit"}, svg);
403
- const on = ev => {
404
- guide.setAttribute("x1", X(i)); guide.setAttribute("x2", X(i)); guide.setAttribute("visibility", "visible");
405
- S.forEach((s, k) => { const v = s.values[i]; const m = marks[k];
406
- if (isNum(v)) { m.setAttribute("cx", X(i)); m.setAttribute("cy", Y(+v)); m.setAttribute("visibility", "visible"); } else m.setAttribute("visibility", "hidden"); });
407
- const [px, py] = pointer(ev, box);
408
- tip.show(`<b>${esc(c)}</b>` + S.map((s, k) => row(k + 1, s.name, fmt(s.values[i], spec.format, spec.decimals))).join(""), px, py);
409
- };
410
- hit.addEventListener("pointermove", on); hit.addEventListener("pointerdown", on);
411
- hit.addEventListener("pointerleave", () => { tip.hide(); guide.setAttribute("visibility", "hidden"); marks.forEach(m => m.setAttribute("visibility", "hidden")); });
412
- });
413
- }
414
-
415
- // ---------- bar charts: vertical/horizontal × grouped/stacked
416
- function barPath(horiz, a0, a1, b0, b1, r) {
417
- // a = value axis from baseline a0 to data end a1; b = category axis b0..b1. Round only the data end.
418
- const len = Math.abs(a1 - a0), th = Math.abs(b1 - b0); r = Math.min(r, len, th / 2);
419
- const s = Math.sign(a1 - a0) || 1, e = a1, q = e - s * r;
420
- if (!horiz) return `M${b0},${a0}V${q}Q${b0},${e} ${b0 + r},${e}H${b1 - r}Q${b1},${e} ${b1},${q}V${a0}Z`;
421
- return `M${a0},${b0}H${q}Q${e},${b0} ${e},${b0 + r}V${b1 - r}Q${e},${b1} ${q},${b1}H${a0}Z`;
422
- }
423
- function barChart(box, spec, horiz, stacked) {
424
- const W = box.clientWidth, cats = spec.categories, S = spec.series, nS = S.length;
425
- const {ticks, lo, hi} = domain(spec, stacked, true);
426
- const GAP = 2, tip = tooltip(box);
427
- const valLabels = !stacked && nS * cats.length <= 24;
428
- let ml, mr, mt, mb, pw, ph, H, band, thick;
429
- if (horiz) {
430
- thick = stacked ? 22 : (nS > 3 ? 14 : 18);
431
- const groupT = stacked ? thick : nS * thick + (nS - 1) * GAP;
432
- const catW = Math.min(W * 0.38, Math.max(...cats.map(c => tw(c))) + 12);
433
- const lines = cats.map(c => wrap(c, catW - 12));
434
- band = Math.max(groupT + 16, Math.max(...lines.map(l => l.length)) * 14 + 10);
435
- ml = catW; mt = 6; mb = 26;
436
- const maxVal = valLabels ? Math.max(...S.flatMap(s => s.values.filter(isNum).map(v => tw(fmt(v, spec.format, spec.decimals))))) + 10 : 12;
437
- mr = Math.min(maxVal, W * 0.22);
438
- pw = W - ml - mr; ph = band * cats.length; H = mt + ph + mb;
439
- const svg = el("svg", {width: W, height: H, viewBox: `0 0 ${W} ${H}`}, box);
440
- const V = v => ml + (v - lo) / (hi - lo) * pw;
441
- ticks.forEach(t => {
442
- el("line", {x1: V(t), x2: V(t), y1: mt, y2: mt + ph, class: Math.abs(t) < 1e-12 ? "base" : "grid"}, svg);
443
- });
444
- const tickEvery = Math.max(1, Math.ceil(ticks.length * (Math.max(...ticks.map(t => tw(axisFmt(t, spec.format)))) + 12) / pw));
445
- ticks.forEach((t, i) => { if (i % tickEvery === 0) el("text", {x: V(t), y: H - 8, "text-anchor": "middle"}, svg).textContent = axisFmt(t, spec.format); });
446
- cats.forEach((c, i) => {
447
- const cy = mt + i * band + band / 2;
448
- textLines(svg, lines[i], ml - 10, cy + 4 - (lines[i].length - 1) * 7, "end", "lab");
449
- let start = cy - groupT / 2, pos = 0, neg = 0;
450
- S.forEach((s, k) => {
451
- const v = s.values[i]; if (!isNum(v)) { if (!stacked) start += thick + GAP; return; }
452
- let a0, a1;
453
- if (stacked) { a0 = v >= 0 ? V(pos) : V(neg); if (v >= 0) pos += +v; else neg += +v; a1 = v >= 0 ? V(pos) - (k < nS - 1 ? GAP : 0) : V(neg); }
454
- else { a0 = V(0); a1 = V(+v); }
455
- const b0 = stacked ? cy - thick / 2 : start, b1 = b0 + thick;
456
- const topSeg = !stacked || S.slice(k + 1).every(t => !isNum(t.values[i]) || +t.values[i] === 0);
457
- const p = el("path", {d: barPath(true, a0, a1, b0, b1, topSeg ? 4 : 0), class: `bar f${k + 1}`}, svg);
458
- if (valLabels) el("text", {x: a1 + (v >= 0 ? 6 : -6), y: (b0 + b1) / 2 + 4, "text-anchor": v >= 0 ? "start" : "end", class: "lab"}, svg).textContent = fmt(v, spec.format, spec.decimals);
459
- const hit = el("rect", {x: ml, y: b0 - GAP / 2, width: pw, height: thick + GAP, class: "hit"}, svg);
460
- const on = ev => { const [px, py] = pointer(ev, box);
461
- tip.show(`<b>${esc(c)}</b>` + (stacked ? S.map((t, j) => row(j + 1, t.name, fmt(t.values[i], spec.format, spec.decimals))).join("") : row(k + 1, s.name, fmt(v, spec.format, spec.decimals))), px, py); p.classList.remove("dim"); };
462
- hit.addEventListener("pointermove", on); hit.addEventListener("pointerdown", on); hit.addEventListener("pointerleave", () => tip.hide());
463
- if (!stacked) start += thick + GAP;
464
- });
465
- });
466
- return;
467
- }
468
- // vertical
469
- H = W < 520 ? 260 : 320; mt = 18; mr = 8;
470
- ml = Math.max(...ticks.map(t => tw(axisFmt(t, spec.format)))) + 10;
471
- pw = W - ml - mr; band = pw / cats.length;
472
- const groupW = Math.min(band * 0.8, stacked ? 48 : nS * 24 + (nS - 1) * GAP);
473
- thick = stacked ? Math.min(48, band * 0.6) : Math.min(24, (groupW - (nS - 1) * GAP) / nS);
474
- // many categories (a monthly series): one-line labels, thinned so they never overlap
475
- const maxLab = Math.max(...cats.map(c => tw(c))) + 8, thin = cats.length > 12 && maxLab > band;
476
- const every = thin ? Math.ceil(maxLab / band) : 1;
477
- const lines = cats.map(c => thin ? [c] : wrap(c, band - 6));
478
- mb = Math.max(...lines.map(l => l.length)) * 14 + 14;
479
- ph = H - mt - mb;
480
- const svg = el("svg", {width: W, height: H, viewBox: `0 0 ${W} ${H}`}, box);
481
- const V = v => mt + ph - (v - lo) / (hi - lo) * ph;
482
- ticks.forEach(t => {
483
- el("line", {x1: ml, x2: ml + pw, y1: V(t), y2: V(t), class: Math.abs(t) < 1e-12 ? "base" : "grid"}, svg);
484
- el("text", {x: ml - 8, y: V(t) + 4, "text-anchor": "end"}, svg).textContent = axisFmt(t, spec.format);
485
- });
486
- const capOk = valLabels && Math.max(...S.flatMap(s => s.values.filter(isNum).map(v => tw(fmt(v, spec.format, spec.decimals))))) < (nS === 1 ? band * 0.9 : thick + GAP + 6);
487
- cats.forEach((c, i) => {
488
- const cx = ml + i * band + band / 2;
489
- if (!thin || i % every === 0) textLines(svg, lines[i], cx, mt + ph + 18, "middle", "lab");
490
- const used = stacked ? thick : nS * thick + (nS - 1) * GAP;
491
- let start = cx - used / 2, pos = 0, neg = 0;
492
- S.forEach((s, k) => {
493
- const v = s.values[i]; if (!isNum(v)) { if (!stacked) start += thick + GAP; return; }
494
- let a0, a1;
495
- if (stacked) { a0 = v >= 0 ? V(pos) : V(neg); if (v >= 0) pos += +v; else neg += +v; a1 = v >= 0 ? V(pos) + (k < nS - 1 ? GAP : 0) : V(neg); }
496
- else { a0 = V(0); a1 = V(+v); }
497
- const b0 = stacked ? cx - thick / 2 : start, b1 = b0 + thick;
498
- const topSeg = !stacked || S.slice(k + 1).every(t => !isNum(t.values[i]) || +t.values[i] === 0);
499
- el("path", {d: barPath(false, a0, a1, b0, b1, topSeg ? 4 : 0), class: `bar f${k + 1}`}, svg);
500
- if (capOk) el("text", {x: (b0 + b1) / 2, y: v >= 0 ? a1 - 6 : a1 + 14, "text-anchor": "middle", class: "lab"}, svg).textContent = fmt(v, spec.format, spec.decimals);
501
- const hit = el("rect", {x: b0 - GAP / 2, y: mt, width: thick + GAP, height: ph, class: "hit"}, svg);
502
- const on = ev => { const [px, py] = pointer(ev, box);
503
- tip.show(`<b>${esc(c)}</b>` + (stacked ? S.map((t, j) => row(j + 1, t.name, fmt(t.values[i], spec.format, spec.decimals))).join("") : row(k + 1, s.name, fmt(v, spec.format, spec.decimals))), px, py); };
504
- hit.addEventListener("pointermove", on); hit.addEventListener("pointerdown", on); hit.addEventListener("pointerleave", () => tip.hide());
505
- if (!stacked) start += thick + GAP;
506
- });
507
- });
508
- }
509
-
510
- function legend(node, spec) {
511
- if (!spec || spec.series.length < 2) return;
512
- const line = spec.type === "line";
513
- node.innerHTML = spec.series.map((s, k) => `<span><i class="b${k + 1}${line ? " line" : ""}"></i>${esc(s.name)}</span>`).join("");
514
- }
515
-
516
- // ---------- table + CSV download
517
- function parseCSV(text) {
518
- const rows = []; let row = [], cur = "", q = false;
519
- for (let i = 0; i < text.length; i++) {
520
- const c = text[i];
521
- if (q) { if (c === '"') { if (text[i + 1] === '"') { cur += '"'; i++; } else q = false; } else cur += c; }
522
- else if (c === '"') q = true;
523
- else if (c === ",") { row.push(cur); cur = ""; }
524
- else if (c === "\n" || c === "\r") { if (c === "\r" && text[i + 1] === "\n") i++; row.push(cur); rows.push(row); row = []; cur = ""; }
525
- else cur += c;
526
- }
527
- if (cur !== "" || row.length) { row.push(cur); rows.push(row); }
528
- return rows.filter(r => r.length > 1 || r[0] !== "");
529
- }
530
- function cell(v) {
531
- if (!isNum(v) || /^0\d/.test(v)) return esc(v);
532
- if (/^\+/.test(String(v).trim())) return "+" + cell(String(v).trim().slice(1)); // keep explicit + signs
533
- const n = +v;
534
- // keep the decimals the analysis wrote (80.0 stays 80.0), capped at three for unrounded values
535
- const written = (String(v).split(".")[1] || "").length, d = Math.min(written, 3);
536
- if (!written) return Math.abs(n) >= 10000 ? n.toLocaleString("en-US") : String(n);
537
- return n.toLocaleString("en-US", {minimumFractionDigits: d, maximumFractionDigits: d});
538
- }
539
- function table(node, csv) {
540
- const rows = parseCSV(csv); if (!rows.length) return;
541
- const [h, ...b] = rows;
542
- node.innerHTML = `<table><thead><tr>${h.map(x => `<th scope="col">${esc(x)}</th>`).join("")}</tr></thead><tbody>` +
543
- b.map(r => `<tr>${r.map(cell).map(x => `<td>${x}</td>`).join("")}</tr>`).join("") + "</tbody></table>";
544
- }
545
-
546
- function render(ex) {
547
- const box = document.querySelector(`[data-chart="${ex.id}"]`);
548
- if (!box) return;
549
- const spec = ex.chart;
550
- if (!spec) { box.style.display = "none"; return; }
551
- if (!box.clientWidth) { // not laid out yet: retry briefly (resize hooks also cover it)
552
- ex.tries = (ex.tries || 0) + 1;
553
- if (ex.tries < 40) setTimeout(() => render(ex), 100);
554
- return;
555
- }
556
- box.querySelectorAll("svg").forEach(s => s.remove());
557
- box.dataset.w = box.clientWidth;
558
- if (spec.type === "line") lineChart(box, spec);
559
- else barChart(box, spec, spec.type === "hbar" || spec.type === "stacked_h", spec.type === "stacked" || spec.type === "stacked_h");
560
- }
561
-
562
- (DATA || []).forEach(ex => {
563
- legend(document.querySelector(`[data-legend="${ex.id}"]`), ex.chart);
564
- table(document.querySelector(`[data-table="${ex.id}"]`), ex.csv);
565
- const btn = document.querySelector(`[data-download="${ex.id}"]`);
566
- if (btn) btn.addEventListener("click", () => {
567
- const url = URL.createObjectURL(new Blob([ex.csv], {type: "text/csv"}));
568
- const a = document.createElement("a"); a.href = url; a.download = ex.csv_name; a.click();
569
- setTimeout(() => URL.revokeObjectURL(url), 1000);
570
- });
571
- render(ex);
572
- const box = document.querySelector(`[data-chart="${ex.id}"]`);
573
- if (box && window.ResizeObserver) {
574
- let timer = 0;
575
- new ResizeObserver(() => { if (String(box.clientWidth) !== box.dataset.w) { clearTimeout(timer); timer = setTimeout(() => render(ex), 60); } }).observe(box);
576
- }
577
- });
578
- const ATTACH = /*__ATTACH__*/null;
579
- (ATTACH || []).forEach(a => {
580
- const b = document.querySelector(`[data-attach="${a.id}"]`);
581
- if (b) b.addEventListener("click", () => {
582
- const url = URL.createObjectURL(new Blob([a.text], {type: "text/plain"}));
583
- const l = document.createElement("a"); l.href = url; l.download = a.name; l.click();
584
- setTimeout(() => URL.revokeObjectURL(url), 1000);
585
- });
586
- });
587
- const rerender = () => (DATA || []).forEach(ex => {
588
- const box = document.querySelector(`[data-chart="${ex.id}"]`);
589
- if (box && String(box.clientWidth) !== box.dataset.w) render(ex);
590
- });
591
- window.addEventListener("load", rerender);
592
- window.addEventListener("resize", rerender);
593
- window.addEventListener("beforeprint", () => { document.querySelectorAll("details").forEach(d => d.open = true); rerender(); });
594
- })();
595
- </script>
596
- </body>
597
- </html>
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>__TITLE__</title>
7
+ <style>
8
+ :root {
9
+ color-scheme: light;
10
+ --page: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink2: #52514e; --muted: #898781;
11
+ --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11,11,11,.10);
12
+ --accent: #1d3b63; --accent-soft: #eaf0f7; --badge: #7a4b00; --badge-bg: #fbefd6;
13
+ --warn-bg: #fff8e6; --warn-border: #f2dca4;
14
+ --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
15
+ --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
16
+ }
17
+ @media (prefers-color-scheme: dark) {
18
+ :root:where(:not([data-theme="light"])) {
19
+ color-scheme: dark;
20
+ --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink2: #c3c2b7; --muted: #898781;
21
+ --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,.10);
22
+ --accent: #9cc2f0; --accent-soft: #16202c; --badge: #f5c66b; --badge-bg: #33270f;
23
+ --warn-bg: #2a2214; --warn-border: #5a4520;
24
+ --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
25
+ --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
26
+ }
27
+ }
28
+ :root[data-theme="dark"] {
29
+ color-scheme: dark;
30
+ --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink2: #c3c2b7; --muted: #898781;
31
+ --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,.10);
32
+ --accent: #9cc2f0; --accent-soft: #16202c; --badge: #f5c66b; --badge-bg: #33270f;
33
+ --warn-bg: #2a2214; --warn-border: #5a4520;
34
+ --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
35
+ --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
36
+ }
37
+ * { box-sizing: border-box; }
38
+ html { -webkit-text-size-adjust: 100%; }
39
+ body {
40
+ margin: 0; background: var(--page); color: var(--ink);
41
+ font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
42
+ }
43
+ main { max-width: 880px; margin: 0 auto; padding: 32px 16px 64px; }
44
+ a { color: var(--accent); }
45
+ code { font: 0.88em ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
46
+ h1, h2, h3 { line-height: 1.25; text-wrap: balance; }
47
+ h1 { font-size: clamp(1.6rem, 4.5vw, 2.25rem); margin: 0.2em 0 0.3em; color: var(--accent); }
48
+ h2 { font-size: 1.3rem; margin: 2.2em 0 0.6em; color: var(--accent); }
49
+ h3 { font-size: 1.05rem; margin: 1.6em 0 0.4em; }
50
+ .masthead { border-bottom: 3px solid var(--accent); padding-bottom: 18px; }
51
+ .kicker { margin: 0; color: var(--ink2); font-size: 0.9rem; letter-spacing: .02em; }
52
+ .badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
53
+ background: var(--badge-bg); color: var(--badge); font-size: 0.78rem; font-weight: 600; }
54
+ .dek { margin: 0; color: var(--ink2); font-size: 1.08rem; max-width: 70ch; }
55
+ .summary { background: var(--accent-soft); border-radius: 10px; padding: 4px 20px 12px; margin-top: 24px; }
56
+ .summary h2 { margin-top: 0.9em; }
57
+ .findings { padding-left: 1.2em; margin: 0.4em 0; }
58
+ .findings li { margin: 0.45em 0; max-width: 72ch; }
59
+ .tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 8px 0 14px; }
60
+ .tile { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
61
+ .tile p { margin: 0; }
62
+ .t-label { color: var(--ink2); font-size: 0.85rem; }
63
+ .t-value { font-size: 1.75rem; font-weight: 650; line-height: 1.2; margin: 2px 0 !important; }
64
+ .t-note { color: var(--muted); font-size: 0.8rem; }
65
+ .toc ol { padding-left: 1.4em; margin: 0; }
66
+ .toc li { margin: 0.25em 0; }
67
+ .prose p, .prose li { max-width: 72ch; }
68
+ .exhibit { background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
69
+ padding: 18px 18px 12px; margin: 22px 0; }
70
+ .ex-num { margin: 0; font-size: 0.8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
71
+ .exhibit h3 { margin: 2px 0 2px; font-size: 1.12rem; }
72
+ .ex-sub { margin: 0 0 8px; color: var(--ink2); font-size: 0.9rem; }
73
+ .legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 4px 0 6px; font-size: 0.85rem; color: var(--ink2); }
74
+ .legend span { display: inline-flex; align-items: center; gap: 6px; }
75
+ .legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
76
+ .legend i.line { height: 3px; width: 16px; border-radius: 2px; }
77
+ .chart { position: relative; width: 100%; min-height: 40px; }
78
+ .chart svg { display: block; overflow: visible; max-width: 100%; height: auto; }
79
+ .chart text { font: 12px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; fill: var(--muted); font-variant-numeric: tabular-nums; }
80
+ .chart text.lab { fill: var(--ink2); }
81
+ .chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
82
+ .chart .base { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
83
+ .chart .guide { stroke: var(--axis); stroke-width: 1; }
84
+ .chart .hit { fill: transparent; cursor: default; }
85
+ .chart .rec { fill: var(--ink); opacity: .07; }
86
+ .chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
87
+ .chart .dot { stroke: var(--surface); stroke-width: 2; }
88
+ .chart .bar.dim { opacity: .45; }
89
+ .f1{fill:var(--s1)} .f2{fill:var(--s2)} .f3{fill:var(--s3)} .f4{fill:var(--s4)}
90
+ .f5{fill:var(--s5)} .f6{fill:var(--s6)} .f7{fill:var(--s7)} .f8{fill:var(--s8)}
91
+ .k1{stroke:var(--s1)} .k2{stroke:var(--s2)} .k3{stroke:var(--s3)} .k4{stroke:var(--s4)}
92
+ .k5{stroke:var(--s5)} .k6{stroke:var(--s6)} .k7{stroke:var(--s7)} .k8{stroke:var(--s8)}
93
+ .b1{background:var(--s1)} .b2{background:var(--s2)} .b3{background:var(--s3)} .b4{background:var(--s4)}
94
+ .b5{background:var(--s5)} .b6{background:var(--s6)} .b7{background:var(--s7)} .b8{background:var(--s8)}
95
+ .tip { position: absolute; pointer-events: none; z-index: 5; background: var(--surface); color: var(--ink);
96
+ border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.8rem; line-height: 1.4;
97
+ box-shadow: 0 4px 16px rgba(0,0,0,.14); min-width: 120px; max-width: 260px; display: none; }
98
+ .tip b { display: block; margin-bottom: 2px; }
99
+ .tip .row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
100
+ .tip .row i { width: 9px; height: 9px; border-radius: 2px; flex: none; }
101
+ .tip .row span:last-child { margin-left: auto; padding-left: 10px; font-variant-numeric: tabular-nums; font-weight: 600; }
102
+ .notes, .source { font-size: 0.82rem; color: var(--ink2); margin: 8px 0 0; }
103
+ .notes span, .source span { font-weight: 600; }
104
+ .table-view { margin-top: 10px; font-size: 0.85rem; }
105
+ .table-view summary { cursor: pointer; color: var(--accent); font-weight: 600; }
106
+ .table-wrap { overflow-x: auto; margin: 8px 0; max-height: 420px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }
107
+ table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
108
+ th, td { padding: 5px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
109
+ th:first-child, td:first-child { text-align: left; }
110
+ .table-view th, .table-view td:first-child { white-space: normal; } /* long headers and row labels wrap, so wide tables fit the page */
111
+ .table-view td:first-child { min-width: 12ch; }
112
+ th { position: sticky; top: 0; background: var(--surface); color: var(--ink2); font-weight: 600; }
113
+ .dl { font: inherit; font-size: 0.82rem; color: var(--accent); background: transparent; border: 1px solid var(--border);
114
+ border-radius: 6px; padding: 4px 10px; cursor: pointer; }
115
+ .dl:hover { background: var(--accent-soft); }
116
+ blockquote { margin: 0.5em 0; padding: 8px 14px; border-left: 3px solid var(--axis); color: var(--ink2); }
117
+ .cite { font-size: 0.88rem; color: var(--ink2); }
118
+ .files li { margin: 0.3em 0; }
119
+ .files code { color: var(--muted); margin-left: 4px; }
120
+ .disclaimer { margin: 0 0 22px; padding: 12px 16px; border: 1px solid var(--warn-border);
121
+ border-radius: 8px; background: var(--warn-bg); color: var(--ink); font-size: 0.88rem; line-height: 1.5; }
122
+ .disclaimer p { margin: 0; }
123
+ .disclaimer p + p { margin-top: 6px; }
124
+ .footnotes ol { padding-left: 1.4em; font-size: 0.88rem; color: var(--ink2); }
125
+ .footnotes li { margin: 0.35em 0; }
126
+ sup.fn { font-size: 0.72em; line-height: 0; }
127
+ sup.fn a { text-decoration: none; }
128
+ .about { font-size: 0.92rem; color: var(--ink2); border-top: 1px solid var(--grid); margin-top: 2.4em; }
129
+ /* publication typography in both modes; charts stay in the UI sans */
130
+ :is(.mode-paper, .mode-report) .prose, :is(.mode-paper, .mode-report) .summary, :is(.mode-paper, .mode-report) .dek {
131
+ font-family: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif; }
132
+ :is(.mode-paper, .mode-report) .prose p, :is(.mode-paper, .mode-report) .summary p { font-size: 1.06rem; line-height: 1.6; }
133
+ :is(.mode-paper, .mode-report) .summary { background: transparent; border-radius: 0; padding: 0; border-bottom: 1px solid var(--grid); }
134
+ :is(.mode-paper, .mode-report) .summary h2 { margin-top: 1.4em; }
135
+ :is(.mode-paper, .mode-report) .summary p { max-width: 70ch; margin: 0.7em 0; }
136
+ :is(.mode-paper, .mode-report) .summary strong { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--accent); }
137
+ :is(.mode-paper, .mode-report) .masthead h1 { font-size: clamp(1.7rem, 4.8vw, 2.5rem); }
138
+ :is(.mode-paper, .mode-report) .prose > .exhibit { margin: 26px 0; }
139
+ /* report mode: exhibit chartbook */
140
+ .mode-report main { max-width: 1120px; }
141
+ .mode-report .masthead.cover { border-bottom: 0; padding: 28px 0 8px; }
142
+ .mode-report .cover h1 { font-size: clamp(1.9rem, 5vw, 2.9rem); max-width: 26ch; }
143
+ .mode-report .cover .dek { font-size: 1.15rem; margin-top: 4px; }
144
+ .cover-chart { margin: 26px 0 0; padding: 18px; background: var(--surface); border: 1px solid var(--border);
145
+ border-top: 4px solid var(--accent); border-radius: 0 0 10px 10px; }
146
+ .cover-chart-title { margin: 0; font-weight: 650; }
147
+ .mode-report .glance, .mode-report .contents, .mode-report .exhibit-list, .mode-report .notes-page,
148
+ .mode-report .intro, .mode-report .section-opener, .mode-report .appendix, .mode-report .about,
149
+ .mode-report .references, .mode-report .footnotes:not(.part-notes) {
150
+ border-top: 3px solid var(--accent); margin-top: 48px; padding-top: 4px; }
151
+ .glance { font-family: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif; }
152
+ .glance > p { font-size: 1.08rem; line-height: 1.6; max-width: 76ch; }
153
+ .glance-findings { padding-left: 1.1em; margin: 0.6em 0; }
154
+ .glance-findings li { margin: 0.7em 0; max-width: 76ch; line-height: 1.6; }
155
+ .glance-findings strong { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--accent); }
156
+ .contents-list { padding-left: 1.4em; margin: 0; }
157
+ .contents-list > li { margin: 0.45em 0; }
158
+ .contents-list ul { margin: 0.2em 0; padding-left: 1.2em; font-size: 0.92rem; }
159
+ .contents-list .ex-range { display: block; color: var(--ink2); font-size: 0.85rem; }
160
+ .contents-list li.supp { list-style: none; margin-top: 1em; color: var(--ink2); font-size: 0.9rem; }
161
+ .exhibit-list h3 { margin: 1.1em 0 0.3em; font-size: 0.98rem; color: var(--ink2); }
162
+ .ex-list { list-style: none; padding-left: 0; margin: 0; }
163
+ .ex-list li { margin: 0.3em 0; }
164
+ .ex-list a { text-decoration: none; }
165
+ .ex-list .ex-n { display: inline-block; min-width: 2.2em; font-weight: 600; }
166
+ .mode-report .section-opener p { font-size: 1.1rem; }
167
+ .exhibit-page { display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.55fr); gap: 32px;
168
+ align-items: start; margin: 40px 0; padding-top: 18px; border-top: 1px solid var(--grid); }
169
+ .exhibit-page.no-text { grid-template-columns: minmax(0, 1fr); }
170
+ .exhibit-page .ex-text p { margin: 0 0 0.9em; font-size: 1.02rem; }
171
+ .exhibit-page .exhibit { margin: 0; }
172
+ .part-notes { border-top: 1px solid var(--grid); margin-top: 24px; }
173
+ .part-notes ol { margin-top: 10px; }
174
+ .supplementary { margin-top: 64px; padding-top: 6px; border-top: 1px dashed var(--axis); }
175
+ .supp-label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: .06em; margin: 0; }
176
+ @media (max-width: 760px) {
177
+ .exhibit-page { grid-template-columns: minmax(0, 1fr); gap: 8px; }
178
+ }
179
+ .audit-trail details > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
180
+ table.audit { font-size: 0.8rem; }
181
+ table.audit th, table.audit td { text-align: left; vertical-align: top; white-space: normal; }
182
+ table.audit th[scope="row"] { color: var(--ink2); font-weight: 600; white-space: nowrap; position: static; }
183
+ table.audit code { font-size: 0.92em; overflow-wrap: anywhere; }
184
+ .muted { color: var(--muted); font-size: 0.9em; }
185
+ .audit-note { font-size: 0.85rem; color: var(--ink2); }
186
+ pre.code { max-height: 420px; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
187
+ padding: 10px 12px; font: 0.78rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre; }
188
+ .code-list { list-style: none; padding-left: 0; }
189
+ .code-list summary { cursor: pointer; }
190
+ .code-list .dl { margin: 6px 0; }
191
+ a.pkg { font-weight: 600; }
192
+ a.cite { text-decoration: none; }
193
+ .references li { margin: 0.5em 0; overflow-wrap: anywhere; }
194
+ footer { margin-top: 40px; color: var(--muted); font-size: 0.8rem; }
195
+ footer p { margin: 0.3em 0; }
196
+ .notices li { margin: 0.3em 0; }
197
+ @media (max-width: 560px) {
198
+ main { padding: 20px 16px 48px; }
199
+ .exhibit { padding: 14px 12px 10px; }
200
+ .summary { padding: 2px 14px 10px; }
201
+ }
202
+ @media print {
203
+ body { background: #fff; }
204
+ .exhibit { break-inside: avoid; border: none; padding: 0; }
205
+ .mode-report main { max-width: none; padding: 0; }
206
+ .mode-report .glance, .mode-report .contents, .mode-report .exhibit-list, .mode-report .notes-page,
207
+ .mode-report .intro, .mode-report .section-opener, .mode-report .exhibit-page, .mode-report .appendix,
208
+ .mode-report .about, .mode-report .supplementary { break-before: page; }
209
+ .exhibit-page { break-inside: avoid; border-top: 0; }
210
+ .cover-chart { break-inside: avoid; }
211
+ .dl { display: none; }
212
+ .disclaimer { border: 1px solid #999; background: #fff; }
213
+ }
214
+ </style>
215
+ </head>
216
+ <body class="mode-__MODE__">
217
+ <main>
218
+ <!--__BODY__-->
219
+ <footer><!--__FOOTER__--></footer>
220
+ </main>
221
+ <script>
222
+ (() => {
223
+ const DATA = /*__DATA__*/null;
224
+ const NS = "http://www.w3.org/2000/svg";
225
+ const ctx = document.createElement("canvas").getContext("2d");
226
+ const FONT = '12px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
227
+ const tw = s => { ctx.font = FONT; return ctx.measureText(String(s)).width; };
228
+ const el = (tag, attrs, parent) => {
229
+ const e = document.createElementNS(NS, tag);
230
+ for (const k in attrs) e.setAttribute(k, attrs[k]);
231
+ if (parent) parent.appendChild(e);
232
+ return e;
233
+ };
234
+ const isNum = v => v !== null && v !== undefined && v !== "" && !isNaN(v);
235
+
236
+ // The style guide never uses "%" in text: the units line ("Percent") carries the unit.
237
+ const PCT = "";
238
+ function fmt(v, f, d, axis) {
239
+ if (!isNum(v)) return "–";
240
+ v = +v;
241
+ if (f === "pct") return (v * 100).toFixed(d ?? 0) + PCT;
242
+ if (f === "pct100") return v.toFixed(d ?? 0) + PCT;
243
+ if (f === "dollars") {
244
+ const a = Math.abs(v), s = v < 0 ? "−$" : "$";
245
+ if (axis && a >= 1e6) return s + (a / 1e6).toLocaleString("en-US", {maximumFractionDigits: 1}) + "M";
246
+ return s + a.toLocaleString("en-US", {minimumFractionDigits: d ?? 0, maximumFractionDigits: d ?? 0});
247
+ }
248
+ const dd = d ?? (Math.abs(v) >= 100 || Number.isInteger(v) ? 0 : 1);
249
+ return (v < 0 ? "−" : "") + Math.abs(v).toLocaleString("en-US", {minimumFractionDigits: axis ? 0 : dd, maximumFractionDigits: dd});
250
+ }
251
+ function axisFmt(v, f) {
252
+ if (f === "pct") return fmt(v, f, Math.abs(v * 100 - Math.round(v * 100)) > 1e-6 ? 1 : 0, true);
253
+ if (f === "pct100") return fmt(v, f, Number.isInteger(+(+v).toFixed(6)) ? 0 : 1, true);
254
+ if (f === "dollars") return fmt(v, f, Number.isInteger(+(+v).toFixed(6)) ? 0 : 2, true);
255
+ return fmt(v, f, Number.isInteger(+(+v).toFixed(6)) ? 0 : 1, true);
256
+ }
257
+ function niceTicks(lo, hi, n) {
258
+ if (lo === hi) { hi = lo + 1; }
259
+ const raw = (hi - lo) / n, mag = Math.pow(10, Math.floor(Math.log10(raw))), r = raw / mag;
260
+ const step = (r < 1.5 ? 1 : r < 3 ? 2 : r < 7 ? 5 : 10) * mag;
261
+ const t0 = Math.floor(lo / step + 1e-9) * step, t1 = Math.ceil(hi / step - 1e-9) * step, out = [];
262
+ for (let t = t0; t <= t1 + step / 2; t += step) out.push(+t.toFixed(10));
263
+ return out;
264
+ }
265
+ function wrap(label, maxW, maxLines = 3) {
266
+ const words = String(label).split(/\s+/), lines = [];
267
+ let cur = "";
268
+ for (const w of words) {
269
+ const t = cur ? cur + " " + w : w;
270
+ if (tw(t) <= maxW || !cur) cur = t; else { lines.push(cur); cur = w; }
271
+ }
272
+ if (cur) lines.push(cur);
273
+ if (lines.length > maxLines) { lines.length = maxLines; lines[maxLines - 1] += "…"; }
274
+ return lines;
275
+ }
276
+ function textLines(parent, lines, x, y, anchor, cls, lh = 14) {
277
+ const t = el("text", {x, y, "text-anchor": anchor}, parent);
278
+ if (cls) t.setAttribute("class", cls);
279
+ lines.forEach((l, i) => { const s = el("tspan", {x, dy: i ? lh : 0}, t); s.textContent = l; });
280
+ return t;
281
+ }
282
+
283
+ // ---------- tooltip
284
+ function tooltip(box) {
285
+ let tip = box.querySelector(".tip");
286
+ if (!tip) { tip = document.createElement("div"); tip.className = "tip"; box.appendChild(tip); }
287
+ return {
288
+ show(html, px, py) {
289
+ tip.innerHTML = html; tip.style.display = "block";
290
+ const bw = box.clientWidth, w = tip.offsetWidth, h = tip.offsetHeight;
291
+ let x = px + 14; if (x + w > bw) x = px - w - 14; if (x < 0) x = Math.max(0, bw - w);
292
+ let y = py - h - 10; if (y < 0) y = py + 16;
293
+ tip.style.left = x + "px"; tip.style.top = y + "px";
294
+ },
295
+ hide() { tip.style.display = "none"; }
296
+ };
297
+ }
298
+ const row = (k, name, val) => `<div class="row"><i class="b${k}"></i><span>${esc(name)}</span><span>${val}</span></div>`;
299
+ const esc = s => String(s).replace(/[&<>"]/g, c => ({"&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;"}[c]));
300
+ const pointer = (ev, box) => { const r = box.getBoundingClientRect(); return [ev.clientX - r.left, ev.clientY - r.top]; };
301
+
302
+ // ---------- domain
303
+ function domain(spec, stacked, zero) {
304
+ let vals = [];
305
+ if (stacked) {
306
+ spec.categories.forEach((_, i) => {
307
+ let p = 0, n = 0;
308
+ spec.series.forEach(s => { const v = s.values[i]; if (isNum(v)) { if (v >= 0) p += +v; else n += +v; } });
309
+ vals.push(p, n);
310
+ });
311
+ } else spec.series.forEach(s => s.values.forEach(v => { if (isNum(v)) vals.push(+v); }));
312
+ if (!vals.length) vals = [0, 1];
313
+ let lo = Math.min(...vals), hi = Math.max(...vals);
314
+ if (zero) { lo = Math.min(0, lo); hi = Math.max(0, hi); }
315
+ else if (lo >= 0 && lo < 0.5 * hi) lo = 0;
316
+ else { const pad = (hi - lo) * 0.08 || Math.abs(hi) * 0.1 || 1; lo -= pad; hi += pad; }
317
+ if (isNum(spec.y_min)) lo = +spec.y_min;
318
+ if (isNum(spec.y_max)) hi = +spec.y_max;
319
+ const ticks = niceTicks(lo, hi, 5).filter(t => (!isNum(spec.y_min) || t >= +spec.y_min - 1e-9) && (!isNum(spec.y_max) || t <= +spec.y_max + 1e-9));
320
+ return {ticks, lo: Math.min(ticks[0], lo), hi: Math.max(ticks[ticks.length - 1], hi)};
321
+ }
322
+
323
+ // ---------- line chart
324
+ function lineChart(box, spec) {
325
+ const W = box.clientWidth, H = W < 520 ? 250 : 310, cats = spec.categories, S = spec.series;
326
+ const {ticks, lo, hi} = domain(spec, false, false);
327
+ const ml = Math.max(...ticks.map(t => tw(axisFmt(t, spec.format)))) + 10;
328
+ const last = s => { for (let i = s.values.length - 1; i >= 0; i--) if (isNum(s.values[i])) return i; return -1; };
329
+ // direct end labels only if they fit and do not collide (legend always carries identity)
330
+ let labelW = S.length <= 4 ? Math.max(...S.map(s => tw(s.name))) + 12 : 0;
331
+ if (labelW > W * 0.32) labelW = 0;
332
+ const mr = Math.max(labelW, 12), mt = 10, mb = 30, pw = W - ml - mr, ph = H - mt - mb;
333
+ // A real date axis when the builder passed ISO dates (time series): spacing follows the calendar, so
334
+ // a gap in the dates is a gap on the axis, and recessions can be shaded at their true dates.
335
+ const T = (spec.dates && spec.dates.length === cats.length && spec.dates.every(d => !isNaN(Date.parse(d))))
336
+ ? spec.dates.map(d => Date.parse(d)) : null;
337
+ const t0 = T ? T[0] : 0, t1 = T ? T[T.length - 1] : 1;
338
+ const X = T ? (i => ml + (t1 === t0 ? pw / 2 : (T[i] - t0) / (t1 - t0) * pw))
339
+ : (i => ml + (cats.length === 1 ? pw / 2 : i * pw / (cats.length - 1)));
340
+ const Xt = t => ml + (t - t0) / ((t1 - t0) || 1) * pw;
341
+ const Y = v => mt + ph - (v - lo) / (hi - lo) * ph;
342
+ const svg = el("svg", {width: W, height: H, viewBox: `0 0 ${W} ${H}`}, box);
343
+ if (T && spec.recessions) spec.recessions.forEach(([a, b]) => {
344
+ const s = Math.max(Date.parse(a), t0), e0 = new Date(Date.parse(b)); e0.setUTCMonth(e0.getUTCMonth() + 1);
345
+ const e = Math.min(e0.getTime(), t1);
346
+ if (e > s) el("rect", {x: Xt(s), y: mt, width: Math.max(1, Xt(e) - Xt(s)), height: ph, class: "rec"}, svg);
347
+ });
348
+ ticks.forEach(t => {
349
+ el("line", {x1: ml, x2: ml + pw, y1: Y(t), y2: Y(t), class: Math.abs(t) < 1e-12 ? "base" : "grid"}, svg);
350
+ el("text", {x: ml - 8, y: Y(t) + 4, "text-anchor": "end"}, svg).textContent = axisFmt(t, spec.format);
351
+ });
352
+ if (T) {
353
+ // year ticks at a step that fits (1, 2, 5, 10, 20 years); months when the span is under two years
354
+ const y0 = new Date(t0).getUTCFullYear(), y1 = new Date(t1).getUTCFullYear(), span = (t1 - t0) / 31557600000;
355
+ let labels = [];
356
+ if (span < 2) {
357
+ for (let d = new Date(Date.UTC(y0, new Date(t0).getUTCMonth(), 1)); d.getTime() <= t1; d.setUTCMonth(d.getUTCMonth() + 3))
358
+ labels.push([d.getTime(), d.toLocaleString("en-US", {month: "short", timeZone: "UTC"}) + " " + d.getUTCFullYear()]);
359
+ } else {
360
+ const fit = Math.max(1, Math.floor(pw / (tw("2000") + 18)));
361
+ const step = [1, 2, 5, 10, 20, 50].find(s => (y1 - y0) / s + 1 <= fit) || 100;
362
+ for (let y = Math.ceil(y0 / step) * step; y <= y1; y += step) labels.push([Date.UTC(y, 0, 1), String(y)]);
363
+ }
364
+ const lw = Math.max(...labels.map(l => tw(l[1]))) + 10;
365
+ labels = labels.filter((l, i) => l[0] >= t0 && l[0] <= t1 && (i === 0 || Xt(l[0]) - Xt(labels[i - 1][0]) >= lw));
366
+ labels.forEach(([t, s]) => {
367
+ el("line", {x1: Xt(t), x2: Xt(t), y1: mt + ph, y2: mt + ph + 4, class: "base"}, svg);
368
+ el("text", {x: Xt(t), y: H - 10, "text-anchor": "middle"}, svg).textContent = s;
369
+ });
370
+ } else {
371
+ const maxLab = Math.max(...cats.map(c => tw(c))) + 10;
372
+ const every = Math.max(1, Math.ceil(cats.length * maxLab / pw));
373
+ cats.forEach((c, i) => {
374
+ if (i % every && i !== cats.length - 1) return;
375
+ if (i !== cats.length - 1 && cats.length - 1 - i < every && (cats.length - 1) % every) return;
376
+ el("text", {x: X(i), y: H - 10, "text-anchor": "middle"}, svg).textContent = c;
377
+ });
378
+ }
379
+ S.forEach((s, k) => {
380
+ let d = "", pen = false;
381
+ s.values.forEach((v, i) => { if (isNum(v)) { d += (pen ? "L" : "M") + X(i).toFixed(1) + "," + Y(+v).toFixed(1); pen = true; } else pen = false; });
382
+ el("path", {d, class: `ln k${k + 1}`}, svg);
383
+ if (cats.length <= 12) s.values.forEach((v, i) => { if (isNum(v) && cats.length <= 4) el("circle", {cx: X(i), cy: Y(+v), r: 4, class: `dot f${k + 1}`}, svg); });
384
+ const li = last(s);
385
+ if (li >= 0) el("circle", {cx: X(li), cy: Y(+s.values[li]), r: 4, class: `dot f${k + 1}`}, svg);
386
+ });
387
+ if (labelW) {
388
+ const ends = S.map((s, k) => ({k, y: last(s) >= 0 ? Y(+s.values[last(s)]) : null, s})).filter(e => e.y !== null).sort((a, b) => a.y - b.y);
389
+ const ok = ends.every((e, i) => i === 0 || e.y - ends[i - 1].y >= 14);
390
+ if (ok) ends.forEach(e => {
391
+ const li = last(e.s);
392
+ const t = el("text", {x: X(li) + 8, y: e.y + 4, class: "lab"}, svg);
393
+ t.textContent = S.length > 1 ? e.s.name : fmt(e.s.values[li], spec.format, spec.decimals);
394
+ });
395
+ }
396
+ // hover: crosshair + all-series tooltip
397
+ const tip = tooltip(box), guide = el("line", {y1: mt, y2: mt + ph, class: "guide", visibility: "hidden"}, svg);
398
+ const marks = S.map((s, k) => el("circle", {r: 5, class: `dot f${k + 1}`, visibility: "hidden"}, svg));
399
+ cats.forEach((c, i) => {
400
+ // hit area: halfway to each neighbor (uneven on a date axis)
401
+ const a = i ? (X(i - 1) + X(i)) / 2 : ml, b = i < cats.length - 1 ? (X(i) + X(i + 1)) / 2 : ml + pw;
402
+ const hit = el("rect", {x: Math.min(a, X(i)), y: mt, width: Math.max(1, b - a), height: ph, class: "hit"}, svg);
403
+ const on = ev => {
404
+ guide.setAttribute("x1", X(i)); guide.setAttribute("x2", X(i)); guide.setAttribute("visibility", "visible");
405
+ S.forEach((s, k) => { const v = s.values[i]; const m = marks[k];
406
+ if (isNum(v)) { m.setAttribute("cx", X(i)); m.setAttribute("cy", Y(+v)); m.setAttribute("visibility", "visible"); } else m.setAttribute("visibility", "hidden"); });
407
+ const [px, py] = pointer(ev, box);
408
+ tip.show(`<b>${esc(c)}</b>` + S.map((s, k) => row(k + 1, s.name, fmt(s.values[i], spec.format, spec.decimals))).join(""), px, py);
409
+ };
410
+ hit.addEventListener("pointermove", on); hit.addEventListener("pointerdown", on);
411
+ hit.addEventListener("pointerleave", () => { tip.hide(); guide.setAttribute("visibility", "hidden"); marks.forEach(m => m.setAttribute("visibility", "hidden")); });
412
+ });
413
+ }
414
+
415
+ // ---------- bar charts: vertical/horizontal × grouped/stacked
416
+ function barPath(horiz, a0, a1, b0, b1, r) {
417
+ // a = value axis from baseline a0 to data end a1; b = category axis b0..b1. Round only the data end.
418
+ const len = Math.abs(a1 - a0), th = Math.abs(b1 - b0); r = Math.min(r, len, th / 2);
419
+ const s = Math.sign(a1 - a0) || 1, e = a1, q = e - s * r;
420
+ if (!horiz) return `M${b0},${a0}V${q}Q${b0},${e} ${b0 + r},${e}H${b1 - r}Q${b1},${e} ${b1},${q}V${a0}Z`;
421
+ return `M${a0},${b0}H${q}Q${e},${b0} ${e},${b0 + r}V${b1 - r}Q${e},${b1} ${q},${b1}H${a0}Z`;
422
+ }
423
+ function barChart(box, spec, horiz, stacked) {
424
+ const W = box.clientWidth, cats = spec.categories, S = spec.series, nS = S.length;
425
+ const {ticks, lo, hi} = domain(spec, stacked, true);
426
+ const GAP = 2, tip = tooltip(box);
427
+ const valLabels = !stacked && nS * cats.length <= 24;
428
+ let ml, mr, mt, mb, pw, ph, H, band, thick;
429
+ if (horiz) {
430
+ thick = stacked ? 22 : (nS > 3 ? 14 : 18);
431
+ const groupT = stacked ? thick : nS * thick + (nS - 1) * GAP;
432
+ const catW = Math.min(W * 0.38, Math.max(...cats.map(c => tw(c))) + 12);
433
+ const lines = cats.map(c => wrap(c, catW - 12));
434
+ band = Math.max(groupT + 16, Math.max(...lines.map(l => l.length)) * 14 + 10);
435
+ ml = catW; mt = 6; mb = 26;
436
+ const maxVal = valLabels ? Math.max(...S.flatMap(s => s.values.filter(isNum).map(v => tw(fmt(v, spec.format, spec.decimals))))) + 10 : 12;
437
+ mr = Math.min(maxVal, W * 0.22);
438
+ pw = W - ml - mr; ph = band * cats.length; H = mt + ph + mb;
439
+ const svg = el("svg", {width: W, height: H, viewBox: `0 0 ${W} ${H}`}, box);
440
+ const V = v => ml + (v - lo) / (hi - lo) * pw;
441
+ ticks.forEach(t => {
442
+ el("line", {x1: V(t), x2: V(t), y1: mt, y2: mt + ph, class: Math.abs(t) < 1e-12 ? "base" : "grid"}, svg);
443
+ });
444
+ const tickEvery = Math.max(1, Math.ceil(ticks.length * (Math.max(...ticks.map(t => tw(axisFmt(t, spec.format)))) + 12) / pw));
445
+ ticks.forEach((t, i) => { if (i % tickEvery === 0) el("text", {x: V(t), y: H - 8, "text-anchor": "middle"}, svg).textContent = axisFmt(t, spec.format); });
446
+ cats.forEach((c, i) => {
447
+ const cy = mt + i * band + band / 2;
448
+ textLines(svg, lines[i], ml - 10, cy + 4 - (lines[i].length - 1) * 7, "end", "lab");
449
+ let start = cy - groupT / 2, pos = 0, neg = 0;
450
+ S.forEach((s, k) => {
451
+ const v = s.values[i]; if (!isNum(v)) { if (!stacked) start += thick + GAP; return; }
452
+ let a0, a1;
453
+ if (stacked) { a0 = v >= 0 ? V(pos) : V(neg); if (v >= 0) pos += +v; else neg += +v; a1 = v >= 0 ? V(pos) - (k < nS - 1 ? GAP : 0) : V(neg); }
454
+ else { a0 = V(0); a1 = V(+v); }
455
+ const b0 = stacked ? cy - thick / 2 : start, b1 = b0 + thick;
456
+ const topSeg = !stacked || S.slice(k + 1).every(t => !isNum(t.values[i]) || +t.values[i] === 0);
457
+ const p = el("path", {d: barPath(true, a0, a1, b0, b1, topSeg ? 4 : 0), class: `bar f${k + 1}`}, svg);
458
+ if (valLabels) el("text", {x: a1 + (v >= 0 ? 6 : -6), y: (b0 + b1) / 2 + 4, "text-anchor": v >= 0 ? "start" : "end", class: "lab"}, svg).textContent = fmt(v, spec.format, spec.decimals);
459
+ const hit = el("rect", {x: ml, y: b0 - GAP / 2, width: pw, height: thick + GAP, class: "hit"}, svg);
460
+ const on = ev => { const [px, py] = pointer(ev, box);
461
+ tip.show(`<b>${esc(c)}</b>` + (stacked ? S.map((t, j) => row(j + 1, t.name, fmt(t.values[i], spec.format, spec.decimals))).join("") : row(k + 1, s.name, fmt(v, spec.format, spec.decimals))), px, py); p.classList.remove("dim"); };
462
+ hit.addEventListener("pointermove", on); hit.addEventListener("pointerdown", on); hit.addEventListener("pointerleave", () => tip.hide());
463
+ if (!stacked) start += thick + GAP;
464
+ });
465
+ });
466
+ return;
467
+ }
468
+ // vertical
469
+ H = W < 520 ? 260 : 320; mt = 18; mr = 8;
470
+ ml = Math.max(...ticks.map(t => tw(axisFmt(t, spec.format)))) + 10;
471
+ pw = W - ml - mr; band = pw / cats.length;
472
+ const groupW = Math.min(band * 0.8, stacked ? 48 : nS * 24 + (nS - 1) * GAP);
473
+ thick = stacked ? Math.min(48, band * 0.6) : Math.min(24, (groupW - (nS - 1) * GAP) / nS);
474
+ // many categories (a monthly series): one-line labels, thinned so they never overlap
475
+ const maxLab = Math.max(...cats.map(c => tw(c))) + 8, thin = cats.length > 12 && maxLab > band;
476
+ const every = thin ? Math.ceil(maxLab / band) : 1;
477
+ const lines = cats.map(c => thin ? [c] : wrap(c, band - 6));
478
+ mb = Math.max(...lines.map(l => l.length)) * 14 + 14;
479
+ ph = H - mt - mb;
480
+ const svg = el("svg", {width: W, height: H, viewBox: `0 0 ${W} ${H}`}, box);
481
+ const V = v => mt + ph - (v - lo) / (hi - lo) * ph;
482
+ ticks.forEach(t => {
483
+ el("line", {x1: ml, x2: ml + pw, y1: V(t), y2: V(t), class: Math.abs(t) < 1e-12 ? "base" : "grid"}, svg);
484
+ el("text", {x: ml - 8, y: V(t) + 4, "text-anchor": "end"}, svg).textContent = axisFmt(t, spec.format);
485
+ });
486
+ const capOk = valLabels && Math.max(...S.flatMap(s => s.values.filter(isNum).map(v => tw(fmt(v, spec.format, spec.decimals))))) < (nS === 1 ? band * 0.9 : thick + GAP + 6);
487
+ cats.forEach((c, i) => {
488
+ const cx = ml + i * band + band / 2;
489
+ if (!thin || i % every === 0) textLines(svg, lines[i], cx, mt + ph + 18, "middle", "lab");
490
+ const used = stacked ? thick : nS * thick + (nS - 1) * GAP;
491
+ let start = cx - used / 2, pos = 0, neg = 0;
492
+ S.forEach((s, k) => {
493
+ const v = s.values[i]; if (!isNum(v)) { if (!stacked) start += thick + GAP; return; }
494
+ let a0, a1;
495
+ if (stacked) { a0 = v >= 0 ? V(pos) : V(neg); if (v >= 0) pos += +v; else neg += +v; a1 = v >= 0 ? V(pos) + (k < nS - 1 ? GAP : 0) : V(neg); }
496
+ else { a0 = V(0); a1 = V(+v); }
497
+ const b0 = stacked ? cx - thick / 2 : start, b1 = b0 + thick;
498
+ const topSeg = !stacked || S.slice(k + 1).every(t => !isNum(t.values[i]) || +t.values[i] === 0);
499
+ el("path", {d: barPath(false, a0, a1, b0, b1, topSeg ? 4 : 0), class: `bar f${k + 1}`}, svg);
500
+ if (capOk) el("text", {x: (b0 + b1) / 2, y: v >= 0 ? a1 - 6 : a1 + 14, "text-anchor": "middle", class: "lab"}, svg).textContent = fmt(v, spec.format, spec.decimals);
501
+ const hit = el("rect", {x: b0 - GAP / 2, y: mt, width: thick + GAP, height: ph, class: "hit"}, svg);
502
+ const on = ev => { const [px, py] = pointer(ev, box);
503
+ tip.show(`<b>${esc(c)}</b>` + (stacked ? S.map((t, j) => row(j + 1, t.name, fmt(t.values[i], spec.format, spec.decimals))).join("") : row(k + 1, s.name, fmt(v, spec.format, spec.decimals))), px, py); };
504
+ hit.addEventListener("pointermove", on); hit.addEventListener("pointerdown", on); hit.addEventListener("pointerleave", () => tip.hide());
505
+ if (!stacked) start += thick + GAP;
506
+ });
507
+ });
508
+ }
509
+
510
+ function legend(node, spec) {
511
+ if (!spec || spec.series.length < 2) return;
512
+ const line = spec.type === "line";
513
+ node.innerHTML = spec.series.map((s, k) => `<span><i class="b${k + 1}${line ? " line" : ""}"></i>${esc(s.name)}</span>`).join("");
514
+ }
515
+
516
+ // ---------- table + CSV download
517
+ function parseCSV(text) {
518
+ const rows = []; let row = [], cur = "", q = false;
519
+ for (let i = 0; i < text.length; i++) {
520
+ const c = text[i];
521
+ if (q) { if (c === '"') { if (text[i + 1] === '"') { cur += '"'; i++; } else q = false; } else cur += c; }
522
+ else if (c === '"') q = true;
523
+ else if (c === ",") { row.push(cur); cur = ""; }
524
+ else if (c === "\n" || c === "\r") { if (c === "\r" && text[i + 1] === "\n") i++; row.push(cur); rows.push(row); row = []; cur = ""; }
525
+ else cur += c;
526
+ }
527
+ if (cur !== "" || row.length) { row.push(cur); rows.push(row); }
528
+ return rows.filter(r => r.length > 1 || r[0] !== "");
529
+ }
530
+ function cell(v) {
531
+ if (!isNum(v) || /^0\d/.test(v)) return esc(v);
532
+ if (/^\+/.test(String(v).trim())) return "+" + cell(String(v).trim().slice(1)); // keep explicit + signs
533
+ const n = +v;
534
+ // keep the decimals the analysis wrote (80.0 stays 80.0), capped at three for unrounded values
535
+ const written = (String(v).split(".")[1] || "").length, d = Math.min(written, 3);
536
+ if (!written) return Math.abs(n) >= 10000 ? n.toLocaleString("en-US") : String(n);
537
+ return n.toLocaleString("en-US", {minimumFractionDigits: d, maximumFractionDigits: d});
538
+ }
539
+ function table(node, csv) {
540
+ const rows = parseCSV(csv); if (!rows.length) return;
541
+ const [h, ...b] = rows;
542
+ node.innerHTML = `<table><thead><tr>${h.map(x => `<th scope="col">${esc(x)}</th>`).join("")}</tr></thead><tbody>` +
543
+ b.map(r => `<tr>${r.map(cell).map(x => `<td>${x}</td>`).join("")}</tr>`).join("") + "</tbody></table>";
544
+ }
545
+
546
+ function render(ex) {
547
+ const box = document.querySelector(`[data-chart="${ex.id}"]`);
548
+ if (!box) return;
549
+ const spec = ex.chart;
550
+ if (!spec) { box.style.display = "none"; return; }
551
+ if (!box.clientWidth) { // not laid out yet: retry briefly (resize hooks also cover it)
552
+ ex.tries = (ex.tries || 0) + 1;
553
+ if (ex.tries < 40) setTimeout(() => render(ex), 100);
554
+ return;
555
+ }
556
+ box.querySelectorAll("svg").forEach(s => s.remove());
557
+ box.dataset.w = box.clientWidth;
558
+ if (spec.type === "line") lineChart(box, spec);
559
+ else barChart(box, spec, spec.type === "hbar" || spec.type === "stacked_h", spec.type === "stacked" || spec.type === "stacked_h");
560
+ }
561
+
562
+ (DATA || []).forEach(ex => {
563
+ legend(document.querySelector(`[data-legend="${ex.id}"]`), ex.chart);
564
+ table(document.querySelector(`[data-table="${ex.id}"]`), ex.csv);
565
+ const btn = document.querySelector(`[data-download="${ex.id}"]`);
566
+ if (btn) btn.addEventListener("click", () => {
567
+ const url = URL.createObjectURL(new Blob([ex.csv], {type: "text/csv"}));
568
+ const a = document.createElement("a"); a.href = url; a.download = ex.csv_name; a.click();
569
+ setTimeout(() => URL.revokeObjectURL(url), 1000);
570
+ });
571
+ render(ex);
572
+ const box = document.querySelector(`[data-chart="${ex.id}"]`);
573
+ if (box && window.ResizeObserver) {
574
+ let timer = 0;
575
+ new ResizeObserver(() => { if (String(box.clientWidth) !== box.dataset.w) { clearTimeout(timer); timer = setTimeout(() => render(ex), 60); } }).observe(box);
576
+ }
577
+ });
578
+ const ATTACH = /*__ATTACH__*/null;
579
+ (ATTACH || []).forEach(a => {
580
+ const b = document.querySelector(`[data-attach="${a.id}"]`);
581
+ if (b) b.addEventListener("click", () => {
582
+ const url = URL.createObjectURL(new Blob([a.text], {type: "text/plain"}));
583
+ const l = document.createElement("a"); l.href = url; l.download = a.name; l.click();
584
+ setTimeout(() => URL.revokeObjectURL(url), 1000);
585
+ });
586
+ });
587
+ const rerender = () => (DATA || []).forEach(ex => {
588
+ const box = document.querySelector(`[data-chart="${ex.id}"]`);
589
+ if (box && String(box.clientWidth) !== box.dataset.w) render(ex);
590
+ });
591
+ window.addEventListener("load", rerender);
592
+ window.addEventListener("resize", rerender);
593
+ window.addEventListener("beforeprint", () => { document.querySelectorAll("details").forEach(d => d.open = true); rerender(); });
594
+ })();
595
+ </script>
596
+ </body>
597
+ </html>