@cfasim-ui/charts 0.7.8 → 0.8.0

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 (63) hide show
  1. package/dist/BarChart/BarChart.d.ts +9 -26
  2. package/dist/ChartMenu/ChartMenu.d.ts +3 -2
  3. package/dist/ChartTooltip/ChartTooltip.d.ts +9 -12
  4. package/dist/ChoroplethMap/ChoroplethMap.d.ts +28 -189
  5. package/dist/ChoroplethMap/ChoroplethTooltip.d.ts +20 -27
  6. package/dist/ChoroplethMap/canvasLayer.d.ts +23 -6
  7. package/dist/DataTable/DataTable.d.ts +3 -2
  8. package/dist/LineChart/LineChart.d.ts +9 -26
  9. package/dist/_shared/ChartAnnotations.d.ts +3 -2
  10. package/dist/_shared/ChartZoomControls.d.ts +3 -2
  11. package/dist/_shared/index.d.ts +2 -1
  12. package/dist/_shared/mapTheme.d.ts +159 -0
  13. package/dist/_shared/mapTheme.test.d.ts +1 -0
  14. package/dist/index.css +1 -1
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +1669 -1425
  17. package/docs/BarChart.md +776 -0
  18. package/docs/ChoroplethMap.md +1267 -0
  19. package/docs/DataTable.md +386 -0
  20. package/docs/LineChart.md +1267 -0
  21. package/docs/index.json +56 -0
  22. package/package.json +25 -21
  23. package/src/BarChart/BarChart.md +743 -0
  24. package/src/BarChart/BarChart.vue +1901 -0
  25. package/src/ChartMenu/ChartMenu.vue +220 -0
  26. package/src/ChartMenu/download.ts +120 -0
  27. package/src/ChartTooltip/ChartTooltip.vue +97 -0
  28. package/src/ChoroplethMap/ChoroplethMap.md +1227 -0
  29. package/src/ChoroplethMap/ChoroplethMap.vue +3676 -0
  30. package/src/ChoroplethMap/ChoroplethTooltip.vue +103 -0
  31. package/src/ChoroplethMap/canvasLayer.ts +373 -0
  32. package/src/ChoroplethMap/cityLayout.ts +261 -0
  33. package/src/ChoroplethMap/hsaMapping.ts +4116 -0
  34. package/src/DataTable/DataTable.md +372 -0
  35. package/src/DataTable/DataTable.vue +406 -0
  36. package/src/LineChart/LineChart.md +1225 -0
  37. package/src/LineChart/LineChart.vue +1555 -0
  38. package/src/_shared/ChartAnnotations.vue +420 -0
  39. package/src/_shared/ChartZoomControls.vue +138 -0
  40. package/src/_shared/annotations.ts +106 -0
  41. package/src/_shared/axes.ts +69 -0
  42. package/src/_shared/chartProps.ts +201 -0
  43. package/src/_shared/computeTicks.ts +42 -0
  44. package/src/_shared/contrast.ts +100 -0
  45. package/src/_shared/dateAxis.ts +501 -0
  46. package/src/_shared/index.ts +78 -0
  47. package/src/_shared/mapTheme.ts +551 -0
  48. package/src/_shared/scale.ts +86 -0
  49. package/src/_shared/seriesCsv.ts +68 -0
  50. package/src/_shared/touch.ts +8 -0
  51. package/src/_shared/useChartFoundation.ts +175 -0
  52. package/src/_shared/useChartFullscreen.ts +254 -0
  53. package/src/_shared/useChartMenu.ts +111 -0
  54. package/src/_shared/useChartPadding.ts +235 -0
  55. package/src/_shared/useChartSize.ts +58 -0
  56. package/src/_shared/useChartTooltip.ts +205 -0
  57. package/src/env.d.ts +4 -0
  58. package/src/hsa-mapping.ts +1 -0
  59. package/src/index.ts +41 -0
  60. package/src/tooltip-position.ts +55 -0
  61. package/src/us-cities/data.ts +1371 -0
  62. package/src/us-cities/index.ts +122 -0
  63. package/src/us-cities.ts +7 -0
@@ -0,0 +1,1267 @@
1
+ <script setup>
2
+ import { computed, ref } from "vue";
3
+ import countiesTopoForPerf from "us-atlas/counties-10m.json";
4
+ import { fipsToHsa } from "@cfasim-ui/charts/hsa-mapping";
5
+ import { nationalCityMarkers, stateCityMarkers } from "@cfasim-ui/charts/us-cities";
6
+
7
+ // Capital + 100 most-populous US cities for the national demo, and
8
+ // California's capital + top cities for the single-state demo.
9
+ const nationalCities = nationalCityMarkers();
10
+ const californiaCities = stateCityMarkers("06");
11
+
12
+ // Build one row per county (~3,143) with a deterministic-ish value so the
13
+ // perf example can render every region with a custom tooltip.
14
+ const denseCountyData = computed(() => {
15
+ const geoms = countiesTopoForPerf.objects.counties.geometries;
16
+ return geoms.map((g, i) => ({
17
+ id: String(g.id).padStart(5, "0"),
18
+ value: (i * 37) % 100,
19
+ }));
20
+ });
21
+
22
+ // Focus demo state — bound directly to v-model:focus. The component
23
+ // handles click-to-toggle and emits null when the focused feature is
24
+ // re-clicked.
25
+ const focused = ref(null);
26
+
27
+ // "Outline a focused feature's parent" demo: focus is a county id;
28
+ // we derive the parent HSA and add it to the focus array as a dashed
29
+ // overlay so clicking a county also outlines its HSA.
30
+ const focusedCounty = ref(null);
31
+ const parentFocus = computed(() => {
32
+ const fips = focusedCounty.value;
33
+ if (!fips) return null;
34
+ const hsa = fipsToHsa[fips];
35
+ return hsa
36
+ ? [fips, { id: hsa, geoType: "hsas", style: "dashed", stroke: "#666" }]
37
+ : fips;
38
+ });
39
+ </script>
40
+
41
+ # ChoroplethMap
42
+
43
+ A US choropleth map using D3's Albers USA projection, which repositions Alaska and Hawaii to the bottom left. Supports state-level, county-level, and HSA-level (Health Service Areas) rendering via the `geoType` prop.
44
+
45
+ You must provide your own TopoJSON topology data via the `topology` prop. We recommend the [`us-atlas`](https://github.com/topojson/us-atlas) package:
46
+
47
+ ```sh
48
+ npm install us-atlas
49
+ ```
50
+
51
+ - **State-level maps**: use `us-atlas/states-10m.json`
52
+ - **County or HSA maps**: use `us-atlas/counties-10m.json` (includes both county and state boundaries)
53
+
54
+ ```vue
55
+ <script setup>
56
+ import { ChoroplethMap } from "@cfasim-ui/charts";
57
+ import statesTopo from "us-atlas/states-10m.json";
58
+ import countiesTopo from "us-atlas/counties-10m.json";
59
+ </script>
60
+
61
+ <!-- State map -->
62
+ <ChoroplethMap :topology="statesTopo" :data="stateData" />
63
+
64
+ <!-- County map -->
65
+ <ChoroplethMap
66
+ :topology="countiesTopo"
67
+ geo-type="counties"
68
+ :data="countyData"
69
+ />
70
+ ```
71
+
72
+ ## Examples
73
+
74
+ ### Basic with state data
75
+
76
+ <ComponentDemo>
77
+ <ChoroplethMap
78
+ :topology="statesTopo"
79
+ :data="[
80
+ { id: '06', value: 100 },
81
+ { id: '36', value: 80 },
82
+ { id: '48', value: 90 },
83
+ { id: '12', value: 70 },
84
+ { id: '17', value: 60 },
85
+ { id: '37', value: 50 },
86
+ { id: '42', value: 55 },
87
+ { id: '39', value: 45 },
88
+ { id: '13', value: 40 },
89
+ { id: '26', value: 35 },
90
+ ]"
91
+ title="Cases by State"
92
+ :legend-title="'Cases'"
93
+ :height="400"
94
+ />
95
+
96
+ <template #code>
97
+
98
+ ```vue
99
+ <script setup>
100
+ import statesTopo from "us-atlas/states-10m.json";
101
+ </script>
102
+
103
+ <ChoroplethMap
104
+ :topology="statesTopo"
105
+ :data="[
106
+ { id: '06', value: 100 },
107
+ { id: '36', value: 80 },
108
+ { id: '48', value: 90 },
109
+ { id: '12', value: 70 },
110
+ { id: '17', value: 60 },
111
+ ]"
112
+ title="Cases by State"
113
+ :legend-title="'Cases'"
114
+ :height="400"
115
+ />
116
+ ```
117
+
118
+ </template>
119
+ </ComponentDemo>
120
+
121
+ ### Custom color scale
122
+
123
+ <ComponentDemo>
124
+ <ChoroplethMap
125
+ :topology="statesTopo"
126
+ :data="[
127
+ { id: 'California', value: 100 },
128
+ { id: 'Texas', value: 85 },
129
+ { id: 'Florida', value: 70 },
130
+ { id: 'New York', value: 90 },
131
+ { id: 'Pennsylvania', value: 50 },
132
+ { id: 'Illinois', value: 60 },
133
+ { id: 'Ohio', value: 40 },
134
+ { id: 'Georgia', value: 55 },
135
+ { id: 'North Carolina', value: 45 },
136
+ { id: 'Michigan', value: 35 },
137
+ ]"
138
+ :color-scale="{ min: '#fff5f0', max: '#a50f15' }"
139
+ :legend-title="'Severity'"
140
+ :height="400"
141
+ />
142
+
143
+ <template #code>
144
+
145
+ ```vue
146
+ <ChoroplethMap
147
+ :topology="statesTopo"
148
+ :data="[
149
+ { id: 'California', value: 100 },
150
+ { id: 'Texas', value: 85 },
151
+ { id: 'Florida', value: 70 },
152
+ { id: 'New York', value: 90 },
153
+ ]"
154
+ :color-scale="{ min: '#fff5f0', max: '#a50f15' }"
155
+ :legend-title="'Severity'"
156
+ :height="400"
157
+ />
158
+ ```
159
+
160
+ </template>
161
+ </ComponentDemo>
162
+
163
+ ### Theming (`theme`)
164
+
165
+ All map paint styling lives in one `theme` prop: the base `fill` for features without data, the feature `stroke` (+ `strokeWidth`), the state-`borders` mesh over county/HSA maps (+ `bordersWidth`), an exterior `outline` (+ `outlineWidth`), a `background` wash, and the hover/focus `highlight`. Every color accepts any CSS color the page can express, including `var()`, `light-dark()`, and `color-mix()`, resolved against the map container's cascade. When the effective values change (a site light/dark toggle, an OS scheme flip, a custom-property redefinition), the map repaints on its own — in both the SVG and canvas renderers. `colorScale` colors resolve the same way, so theme tokens work there too.
166
+
167
+ The `outline` is the exterior boundary of the rendered geography — the national outline, or the selected state's boundary in single-state mode — drawn on top of interior borders with its own color and width. It's off by default and turns on when a visible color resolves.
168
+
169
+ <ComponentDemo>
170
+ <ChoroplethMap
171
+ :topology="statesTopo"
172
+ :data="[
173
+ { id: 'California', value: 100 },
174
+ { id: 'Texas', value: 85 },
175
+ { id: 'Florida', value: 70 },
176
+ { id: 'New York', value: 90 },
177
+ { id: 'Illinois', value: 60 },
178
+ { id: 'Ohio', value: 40 },
179
+ ]"
180
+ :theme="{
181
+ fill: 'light-dark(#e2e8f0, #334155)',
182
+ stroke: 'light-dark(#f8fafc, #0f172a)',
183
+ outline: 'light-dark(#334155, #cbd5e1)',
184
+ outlineWidth: 1.5,
185
+ }"
186
+ title="Themed map with an exterior outline"
187
+ :legend-title="'Cases'"
188
+ :height="400"
189
+ />
190
+
191
+ <template #code>
192
+
193
+ ```vue
194
+ <ChoroplethMap
195
+ :topology="statesTopo"
196
+ :data="stateData"
197
+ :theme="{
198
+ fill: 'light-dark(#e2e8f0, #334155)',
199
+ stroke: 'light-dark(#f8fafc, #0f172a)',
200
+ outline: 'light-dark(#334155, #cbd5e1)',
201
+ outlineWidth: 1.5,
202
+ }"
203
+ title="Themed map with an exterior outline"
204
+ :legend-title="'Cases'"
205
+ :height="400"
206
+ />
207
+ ```
208
+
209
+ </template>
210
+ </ComponentDemo>
211
+
212
+ Every channel's default routes through a `--choropleth-*` custom property, so a stylesheet alone can theme every map on a page — JS `theme` values always win:
213
+
214
+ ```css
215
+ :root {
216
+ color-scheme: light dark; /* required for light-dark() to engage */
217
+ --choropleth-fill: light-dark(#dbe4d7, #24332a);
218
+ --choropleth-stroke: light-dark(#f4f7f2, #131e17);
219
+ --choropleth-outline: light-dark(#3f5245, #93ac9b); /* enables the outline */
220
+ --choropleth-background: light-dark(
221
+ #f4f7f2,
222
+ #131e17
223
+ ); /* enables a background */
224
+ --choropleth-highlight: light-dark(#000, #fff);
225
+ --choropleth-borders: transparent; /* falls back to the stroke color */
226
+ }
227
+ ```
228
+
229
+ | Theme key | Default | Notes |
230
+ | ----------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------ |
231
+ | `fill` | `var(--choropleth-fill, light-dark(#ddd, #3f3f46))` | Fill for features without a data value |
232
+ | `stroke` | `var(--choropleth-stroke, light-dark(#fff, #18181b))` | Interior feature borders |
233
+ | `strokeWidth` | `0.5` (halved on county/HSA maps) | Explicit values apply as-is on every geoType; `0` disables |
234
+ | `borders` | `var(--choropleth-borders, transparent)` | State mesh over county/HSA maps; falls back to `stroke`; hide with `bordersWidth: 0` |
235
+ | `bordersWidth` | `1` | `0` disables |
236
+ | `outline` | `var(--choropleth-outline, transparent)` | Exterior boundary; off until a visible color resolves |
237
+ | `outlineWidth` | `1` | `0` disables |
238
+ | `background` | `var(--choropleth-background, transparent)` | Wash behind the map; off until a visible color resolves |
239
+ | `highlight` | `var(--choropleth-highlight, light-dark(#000, #fff))` | Hover/focus stroke; per-item `FocusItem.stroke` wins |
240
+ | `markerColor` | `--choropleth-city-marker` / `-label-color` vars | `cities` overlay dot + label color |
241
+ | `markerHalo` | `--choropleth-city-halo` var | Halo around marker dots and labels |
242
+ | `markerHaloWidth` | `0.9` | Dot halo width in CSS px; `0` disables |
243
+ | `markerOpacity` | `1` | Opacity of the whole marker layer |
244
+
245
+ ::: warning Breaking change
246
+ `theme` replaces the former `noDataColor`, `strokeColor`, and `strokeWidth` props: use `theme.fill`, `theme.stroke`, and `theme.strokeWidth` instead.
247
+ :::
248
+
249
+ ### Threshold color scale
250
+
251
+ Use an array of `ThresholdStop` objects instead of a linear scale. Each stop defines a `min` threshold — values at or above that threshold get the stop's color. The highest matching stop wins.
252
+
253
+ <ComponentDemo>
254
+ <ChoroplethMap
255
+ :topology="statesTopo"
256
+ :data="[
257
+ { id: 'California', value: 80 },
258
+ { id: 'Texas', value: 45 },
259
+ { id: 'Florida', value: 60 },
260
+ { id: 'New York', value: 25 },
261
+ { id: 'Pennsylvania', value: 8 },
262
+ { id: 'Illinois', value: 55 },
263
+ { id: 'Ohio', value: 30 },
264
+ { id: 'Georgia', value: 70 },
265
+ { id: 'North Carolina', value: 15 },
266
+ { id: 'Michigan', value: 3 },
267
+ ]"
268
+ :color-scale="[
269
+ { min: 0, color: '#fee5d9', label: 'Low' },
270
+ { min: 10, color: '#fcae91', label: 'Some' },
271
+ { min: 30, color: '#fb6a4a', label: 'Moderate' },
272
+ { min: 60, color: '#cb181d', label: 'High' },
273
+ ]"
274
+ title="Risk Level"
275
+ :legend-title="'Risk'"
276
+ :height="400"
277
+ />
278
+
279
+ <template #code>
280
+
281
+ ```vue
282
+ <ChoroplethMap
283
+ :topology="statesTopo"
284
+ :data="stateData"
285
+ :color-scale="[
286
+ { min: 0, color: '#fee5d9', label: 'Low' },
287
+ { min: 10, color: '#fcae91', label: 'Some' },
288
+ { min: 30, color: '#fb6a4a', label: 'Moderate' },
289
+ { min: 60, color: '#cb181d', label: 'High' },
290
+ ]"
291
+ title="Risk Level"
292
+ :legend-title="'Risk'"
293
+ :height="400"
294
+ />
295
+ ```
296
+
297
+ </template>
298
+ </ComponentDemo>
299
+
300
+ ### Categorical color scale
301
+
302
+ Use an array of `CategoricalStop` objects to map string values to colors. Each stop defines a `value` to match and a `color` to apply.
303
+
304
+ <ComponentDemo>
305
+ <ChoroplethMap
306
+ :topology="statesTopo"
307
+ :data="[
308
+ { id: 'California', value: 'high' },
309
+ { id: 'Texas', value: 'medium' },
310
+ { id: 'Florida', value: 'high' },
311
+ { id: 'New York', value: 'low' },
312
+ { id: 'Pennsylvania', value: 'low' },
313
+ { id: 'Illinois', value: 'medium' },
314
+ { id: 'Ohio', value: 'low' },
315
+ { id: 'Georgia', value: 'high' },
316
+ { id: 'North Carolina', value: 'medium' },
317
+ { id: 'Michigan', value: 'low' },
318
+ ]"
319
+ :color-scale="[
320
+ { value: 'low', color: '#fee5d9' },
321
+ { value: 'medium', color: '#fb6a4a' },
322
+ { value: 'high', color: '#cb181d' },
323
+ ]"
324
+ title="Risk Category"
325
+ :legend-title="'Risk'"
326
+ :height="400"
327
+ />
328
+
329
+ <template #code>
330
+
331
+ ```vue
332
+ <ChoroplethMap
333
+ :topology="statesTopo"
334
+ :data="stateData"
335
+ :color-scale="[
336
+ { value: 'low', color: '#fee5d9' },
337
+ { value: 'medium', color: '#fb6a4a' },
338
+ { value: 'high', color: '#cb181d' },
339
+ ]"
340
+ title="Risk Category"
341
+ :legend-title="'Risk'"
342
+ :height="400"
343
+ />
344
+ ```
345
+
346
+ </template>
347
+ </ComponentDemo>
348
+
349
+ ### Pan and zoom
350
+
351
+ Maps are **fully static by default** — tooltips, hover, click-select, and
352
+ programmatic `focus` zoom all work, but there are no zoom gestures and no
353
+ controls. That's the right mode when clicks mean navigation instead of
354
+ exploration (see the state-map pattern below); a parent driving `focus`
355
+ provides its own way back (e.g. a "Back" button that clears the focus).
356
+
357
+ Add the `zoom` prop to enable the interaction. The map is then **static
358
+ until the first zoom** — clicks and taps only ever select; it's the first
359
+ zoom gesture that switches panning on. The scroll wheel never zooms
360
+ inline, so the map can't hijack page scrolling. A grey hint overlaid on
361
+ the top of the map ("Double click to zoom" / "Double tap to zoom")
362
+ advertises the gesture until it's been used; pass `:zoom-hint="false"` to
363
+ hide it.
364
+
365
+ - **Desktop:** double-click zooms in place (shift+double-click zooms out),
366
+ or press **+** in the always-present **+ / − / reset** control stack in
367
+ the top-left corner. The first zoom — including a programmatic `focus`
368
+ zoom — starts the pan/zoom mode; from then on, drag pans the map. The
369
+ reset button (a counterclockwise arrow) animates back to the full extent
370
+ (clearing any `focus`); − and reset are disabled while the map is at its
371
+ full extent.
372
+ - **Touch:** a **double tap** expands the map to fill the window, zoomed
373
+ in on the tapped point; single taps select features inline. Inside the
374
+ expanded view, one finger pans, a pinch zooms, and a tap selects — its
375
+ tooltip slides up as a bottom sheet; the +/−/reset controls sit top-left
376
+ and a close (✕) button top-right returns to the inline map at full
377
+ extent. A single finger over the inline map still scrolls the page.
378
+
379
+ Filling the window is always an activated state: whether entered via the
380
+ menu's **Fullscreen** item or a double tap, pan/zoom works immediately and
381
+ the controls are present — no double-click needed first. The scroll wheel
382
+ (and trackpad pinch) zooms there too, since page scrolling is locked while
383
+ the map fills the window.
384
+
385
+ Prefer in-place zooming on touch? Set `:touch-expand="false"` — a double
386
+ tap (or a pinch) zooms the inline map on that point instead of expanding
387
+ it. From there one finger pans, a pinch zooms, and taps keep selecting;
388
+ the +/−/reset controls render inline, and reset restores the original
389
+ static, page-scrollable state. Fullscreen is unaffected: that view stays
390
+ continuously interactive and its reset only recenters.
391
+
392
+ #### Full-page mode (`zoom-mode="scroll"`)
393
+
394
+ When the map _is_ the page — a dedicated map route, a dashboard panel, a
395
+ kiosk — the activation step just gets in the way, and there's no page
396
+ scroll to protect. Pair `zoom` with `zoom-mode="scroll"` to make the map
397
+ immediately interactive: the wheel (and trackpad pinch) zooms, dragging
398
+ pans, and touch gestures work inline with no tap-to-expand step. The
399
+ +/−/reset controls are always shown and the hint is suppressed.
400
+
401
+ ```vue
402
+ <ChoroplethMap
403
+ :topology="statesTopo"
404
+ :data="stateData"
405
+ zoom
406
+ zoom-mode="scroll"
407
+ />
408
+ ```
409
+
410
+ ### County-level map
411
+
412
+ Set `geoType="counties"` to render county-level data using 5-digit FIPS codes. State borders are drawn on top for context. Double-click (or double-tap on touch) to explore — useful for dense county data.
413
+
414
+ This demo also wires up an interactive tooltip (`tooltip-trigger="hover"`):
415
+ hover a county on desktop, or tap one on touch, and it works the same
416
+ before and after zooming in.
417
+
418
+ <ComponentDemo>
419
+ <ChoroplethMap
420
+ :topology="countiesTopo"
421
+ geo-type="counties"
422
+ zoom
423
+ tooltip-trigger="hover"
424
+ :data="[
425
+ { id: '06037', value: 100 },
426
+ { id: '06073', value: 80 },
427
+ { id: '06059', value: 70 },
428
+ { id: '36061', value: 90 },
429
+ { id: '36047', value: 75 },
430
+ { id: '17031', value: 85 },
431
+ { id: '48201', value: 65 },
432
+ { id: '04013', value: 60 },
433
+ { id: '12086', value: 55 },
434
+ { id: '53033', value: 50 },
435
+ ]"
436
+ title="Cases by County"
437
+ :legend-title="'Cases'"
438
+ :height="400"
439
+ />
440
+
441
+ <template #code>
442
+
443
+ ```vue
444
+ <ChoroplethMap
445
+ :topology="countiesTopo"
446
+ geo-type="counties"
447
+ zoom
448
+ tooltip-trigger="hover"
449
+ :data="[
450
+ { id: '06037', value: 100 },
451
+ { id: '36061', value: 90 },
452
+ { id: '17031', value: 85 },
453
+ { id: '48201', value: 65 },
454
+ { id: '04013', value: 60 },
455
+ ]"
456
+ title="Cases by County"
457
+ :legend-title="'Cases'"
458
+ :height="400"
459
+ />
460
+ ```
461
+
462
+ </template>
463
+ </ComponentDemo>
464
+
465
+ ### Tighter national fit (`tight-fit`)
466
+
467
+ The Albers USA projection places Alaska and Hawaii in the bottom-left corner, and by default the whole composite is fit into view — so Alaska's western tail pushes the contiguous US in from the edges. Set `tight-fit` to crop that overhang and let the lower-48 fill more of the frame: Alaska's tail (and Hawaii) clip into the lower-left corner. Pass a number in `0`–`1` (e.g. `:tight-fit="0.5"`) to crop only partway.
468
+
469
+ Works on national state, county, and HSA maps — it's a no-op only in single-state mode. (County features are split by FIPS prefix; HSAs, whose ids are HSA codes rather than FIPS, are identified through the built-in FIPS-to-HSA table.)
470
+
471
+ <ComponentDemo>
472
+ <ChoroplethMap
473
+ :topology="statesTopo"
474
+ tight-fit
475
+ :data="[
476
+ { id: '06', value: 100 },
477
+ { id: '36', value: 80 },
478
+ { id: '48', value: 90 },
479
+ { id: '12', value: 70 },
480
+ { id: '17', value: 60 },
481
+ ]"
482
+ title="Cases by State (tight fit)"
483
+ :legend-title="'Cases'"
484
+ :height="400"
485
+ />
486
+
487
+ <template #code>
488
+
489
+ ```vue
490
+ <!-- Crop Alaska's overhang so the lower-48 fills the frame -->
491
+ <ChoroplethMap :topology="statesTopo" tight-fit :data="data" />
492
+
493
+ <!-- ...or crop only partway -->
494
+ <ChoroplethMap :topology="statesTopo" :tight-fit="0.5" :data="data" />
495
+ ```
496
+
497
+ </template>
498
+ </ComponentDemo>
499
+
500
+ ### City markers (`cities`)
501
+
502
+ Pass a `cities` array to overlay decorative point markers with name labels. Each entry is `{ name, coordinates: [lng, lat], capital?, minZoom? }`. Every city is a dot; `capital` cities are labeled first (with a lightly emphasized label) and never dropped, while any other label that can't be placed without overlapping is dropped (its dot stays), so labels never collide. The overlay is non-interactive — the choropleth's own hover/click is unaffected — and the markers pan/zoom with the map while staying a constant on-screen size. It works with both the SVG and canvas (`renderer`) backends.
503
+
504
+ **Level-of-detail:** on a zoomable map (`zoom`), each city has a `minZoom` and shows only once the map is zoomed to `scaleK >= minZoom`, so you can reveal the biggest cities first and progressively add more as the user zooms in. `nationalCityMarkers()` / `stateCityMarkers()` assign these tiers by population automatically (the capital always shows). A city without its own `minZoom` falls back to the `cities-min-zoom` prop (default `2`) — set that to `1` for a flat "always visible" layer, or pass `{ tiered: false }` to the selectors. **The overview below shows the biggest cities; double-click to zoom in and reveal more:**
505
+
506
+ <ComponentDemo>
507
+ <ChoroplethMap
508
+ :topology="statesTopo"
509
+ :cities="nationalCities"
510
+ zoom
511
+ title="100 most-populous US cities and the capital"
512
+ :legend="false"
513
+ :height="440"
514
+ />
515
+
516
+ <template #code>
517
+
518
+ ```vue
519
+ <script setup>
520
+ import { ChoroplethMap } from "@cfasim-ui/charts";
521
+ import { nationalCityMarkers } from "@cfasim-ui/charts/us-cities";
522
+ import statesTopo from "us-atlas/states-10m.json";
523
+
524
+ // Washington, DC (emphasized) + the 100 most-populous US cities.
525
+ const cities = nationalCityMarkers();
526
+ </script>
527
+
528
+ <!-- zoom in one level to reveal the cities -->
529
+ <ChoroplethMap :topology="statesTopo" :cities="cities" zoom />
530
+ ```
531
+
532
+ </template>
533
+ </ComponentDemo>
534
+
535
+ In a single-state map, pass that state's cities so its capital and top cities show:
536
+
537
+ <ComponentDemo>
538
+ <ChoroplethMap
539
+ :topology="countiesTopo"
540
+ state="California"
541
+ geo-type="counties"
542
+ :cities="californiaCities"
543
+ zoom
544
+ :legend="false"
545
+ :height="440"
546
+ />
547
+
548
+ <template #code>
549
+
550
+ ```vue
551
+ <!-- Sacramento (capital) + California's most-populous cities -->
552
+ <ChoroplethMap
553
+ :topology="countiesTopo"
554
+ state="California"
555
+ geo-type="counties"
556
+ :cities="stateCityMarkers('06')"
557
+ zoom
558
+ />
559
+ ```
560
+
561
+ </template>
562
+ </ComponentDemo>
563
+
564
+ #### Bundled US city data (`@cfasim-ui/charts/us-cities`)
565
+
566
+ `nationalCityMarkers()` and `stateCityMarkers()` come from the `@cfasim-ui/charts/us-cities` subpath — a ~5 KB gzipped dataset (Natural Earth, public domain) of the 100 most-populous US cities plus every state capital and DC. It's a separate entry point, so consumers who don't use it never pull it into their bundle.
567
+
568
+ ```js
569
+ import {
570
+ usCities,
571
+ nationalCityMarkers,
572
+ stateCityMarkers,
573
+ } from "@cfasim-ui/charts/us-cities";
574
+
575
+ nationalCityMarkers(); //=> DC (capital) + top 100 cities, tiered by population
576
+ nationalCityMarkers({ limit: 25 }); //=> DC + top 25
577
+ nationalCityMarkers({ tiered: false }); //=> flat layer, no per-city minZoom
578
+ stateCityMarkers("48"); //=> Austin (capital) + top Texas cities
579
+ usCities; //=> the raw UsCity[] to build your own selection
580
+ ```
581
+
582
+ Only the national capital is flagged on the national map; a state's own capital is flagged in its single-state view. A flagged capital's label is emphasized and never dropped for collisions — the marker itself is a plain dot like any other city.
583
+
584
+ **Styling:** the default marker style is dark dots and labels with a thin white halo, which reads over any map fill in either color scheme. The `theme` prop's marker keys configure the layer — `markerColor` (dots + labels), `markerHalo` (the halo around both), `markerHaloWidth` (dot halo width in CSS px), and `markerOpacity` (the whole layer). Any CSS color works. A stylesheet can alternatively set the CSS custom properties on `.choropleth-cities` (`--choropleth-city-marker`, `--choropleth-city-label-color`, `--choropleth-city-halo`); theme keys win when both are set.
585
+
586
+ ### HSA-level map
587
+
588
+ Set `geoType="hsas"` to render Health Service Area boundaries. HSAs are dissolved from county boundaries using a built-in FIPS-to-HSA mapping. Use 6-digit HSA codes as IDs. State borders are overlaid for context.
589
+
590
+ This demo pairs `tooltip-trigger="hover"` with a custom `#tooltip` slot —
591
+ hover an HSA on desktop, or tap one on touch, before or after zooming in.
592
+
593
+ <ComponentDemo>
594
+ <ChoroplethMap
595
+ :topology="countiesTopo"
596
+ geo-type="hsas"
597
+ zoom
598
+ tooltip-trigger="hover"
599
+ :data="[
600
+ { id: '010259', value: 100 },
601
+ { id: '060766', value: 90 },
602
+ { id: '120159', value: 85 },
603
+ { id: '090121', value: 70 },
604
+ { id: '110061', value: 60 },
605
+ { id: '040765', value: 55 },
606
+ { id: '080731', value: 50 },
607
+ { id: '050527', value: 45 },
608
+ { id: '100075', value: 40 },
609
+ { id: '020820', value: 35 },
610
+ ]"
611
+ title="Cases by HSA"
612
+ :legend-title="'Cases'"
613
+ :height="400"
614
+ >
615
+ <template #tooltip="{ id, name, value }">
616
+ <div style="font-weight: 600">{{ name }}</div>
617
+ <div style="opacity: 0.7; font-size: 0.85em">HSA {{ id }}</div>
618
+ <div v-if="value != null">Cases: {{ value }}</div>
619
+ <div v-else style="opacity: 0.6">No data</div>
620
+ </template>
621
+ </ChoroplethMap>
622
+
623
+ <template #code>
624
+
625
+ ```vue
626
+ <ChoroplethMap
627
+ :topology="countiesTopo"
628
+ geo-type="hsas"
629
+ zoom
630
+ tooltip-trigger="hover"
631
+ :data="[
632
+ { id: '010259', value: 100 },
633
+ { id: '060766', value: 90 },
634
+ { id: '120159', value: 85 },
635
+ { id: '090121', value: 70 },
636
+ { id: '110061', value: 60 },
637
+ ]"
638
+ title="Cases by HSA"
639
+ :legend-title="'Cases'"
640
+ :height="400"
641
+ >
642
+ <template #tooltip="{ id, name, value }">
643
+ <div style="font-weight: 600">{{ name }}</div>
644
+ <div style="opacity: 0.7; font-size: 0.85em">HSA {{ id }}</div>
645
+ <div v-if="value != null">Cases: {{ value }}</div>
646
+ <div v-else style="opacity: 0.6">No data</div>
647
+ </template>
648
+ </ChoroplethMap>
649
+ ```
650
+
651
+ </template>
652
+ </ComponentDemo>
653
+
654
+ ### Single-state map (`state`)
655
+
656
+ Set the `state` prop to render just one state's outline with its `counties` or
657
+ `hsas` inside it — no surrounding states — and the projection zooms to fit it.
658
+ Accepts a state **name** (`"California"`) or a 2-digit **FIPS code** (`"06"`).
659
+ This needs a counties topology (the same `us-atlas/counties-10m.json`). `data`
660
+ can stay national; only features inside the selected state are drawn and
661
+ colored.
662
+
663
+ This demo also opts for the quieter touch flow: `:touch-expand="false"` makes
664
+ a double tap (or pinch) zoom in place instead of expanding to fill the
665
+ window, and `:zoom-hint="false"` drops the grey gesture hint.
666
+
667
+ <ComponentDemo>
668
+ <ChoroplethMap
669
+ :topology="countiesTopo"
670
+ geo-type="counties"
671
+ state="California"
672
+ zoom
673
+ :touch-expand="false"
674
+ :zoom-hint="false"
675
+ :data="[
676
+ { id: '06037', value: 100 },
677
+ { id: '06073', value: 80 },
678
+ { id: '06059', value: 65 },
679
+ { id: '06065', value: 55 },
680
+ { id: '06001', value: 45 },
681
+ { id: '06085', value: 40 },
682
+ ]"
683
+ title="California cases by county"
684
+ :legend-title="'Cases'"
685
+ :height="400"
686
+ />
687
+
688
+ <template #code>
689
+
690
+ ```vue
691
+ <ChoroplethMap
692
+ :topology="countiesTopo"
693
+ geo-type="counties"
694
+ state="California"
695
+ zoom
696
+ :touch-expand="false"
697
+ :zoom-hint="false"
698
+ :data="[
699
+ { id: '06037', value: 100 }, // Los Angeles
700
+ { id: '06073', value: 80 }, // San Diego
701
+ { id: '06059', value: 65 }, // Orange
702
+ ]"
703
+ title="California cases by county"
704
+ :legend-title="'Cases'"
705
+ :height="400"
706
+ />
707
+ ```
708
+
709
+ </template>
710
+ </ComponentDemo>
711
+
712
+ Switch `geo-type="hsas"` to fill the same state with Health Service Areas
713
+ instead. An unrecognized `state` value logs a warning and falls back to the
714
+ full national map.
715
+
716
+ ### Click to focus (`v-model:focus`)
717
+
718
+ Bind the `focus` prop to pan and zoom to a specific feature. Pass a feature
719
+ id (FIPS code, HSA code, or name) — or an array of ids to focus on a region.
720
+ With `v-model:focus`, clicking an unfocused feature focuses it and clicking
721
+ the focused feature toggles back off. If a tooltip is configured, focusing
722
+ shows that feature's tooltip. Users can keep exploring around the focused
723
+ area; the built-in **reset** button clears focus and snaps back to the full
724
+ extent.
725
+
726
+ Each focus target's outline can be styled by passing a `FocusItem` object:
727
+ `style` picks the dash pattern (`"solid" | "dashed" | "dotted"`), `stroke`
728
+ the color, and `strokeWidth` the width in CSS px. In-place highlights
729
+ default to pure black/white following the theme (`light-dark(#000, #fff)`);
730
+ cross-geoType overlays default to white.
731
+
732
+ Set `:focus-zoom="false"` to highlight (and draw cross-geoType overlays)
733
+ **without** panning or zooming — useful for a click-to-select interaction
734
+ where the map should stay put while a side panel shows the details.
735
+
736
+ Selection works the same on touch: a single-finger **tap** on a feature
737
+ emits `stateClick` and toggles focus, inline or inside the expanded view.
738
+ (Inline with `zoom` on, the selection fires after the brief double-tap
739
+ window.) A tap also stands in for hover — it applies the hover highlight,
740
+ emits `stateHover`, and shows the feature's tooltip (anchored to the
741
+ feature inline; sliding up as a bottom sheet in the expanded view); only
742
+ continuous hover _tracking_ is off on touch, for performance.
743
+
744
+ Click-to-focus interactions usually pair best with `:touch-expand="false"`,
745
+ as in the demos below — a double tap zooms in place while taps keep
746
+ selecting, so the map stays in your layout instead of taking over the
747
+ window.
748
+
749
+ Counties are tiny without a zoom — focus is a natural fit for drill-down.
750
+
751
+ <ComponentDemo>
752
+ <ChoroplethMap
753
+ :topology="countiesTopo"
754
+ geo-type="counties"
755
+ v-model:focus="focused"
756
+ :focus-zoom-level="8"
757
+ zoom
758
+ :touch-expand="false"
759
+ :data="[
760
+ { id: '06037', value: 100 },
761
+ { id: '06073', value: 80 },
762
+ { id: '36061', value: 90 },
763
+ { id: '17031', value: 85 },
764
+ { id: '48201', value: 65 },
765
+ { id: '04013', value: 60 },
766
+ { id: '12086', value: 55 },
767
+ { id: '53033', value: 50 },
768
+ ]"
769
+ title="Click a county to focus"
770
+ :legend-title="'Cases'"
771
+ :height="400"
772
+ >
773
+ <template #tooltip="{ name, value }">
774
+ <div style="font-weight: 600">{{ name }}</div>
775
+ <div v-if="value != null">Cases: {{ value }}</div>
776
+ <div v-else style="opacity: 0.6">No data</div>
777
+ </template>
778
+ </ChoroplethMap>
779
+
780
+ <template #code>
781
+
782
+ ```vue
783
+ <script setup>
784
+ import { ref } from "vue";
785
+ const focused = ref(null);
786
+ </script>
787
+
788
+ <ChoroplethMap
789
+ :topology="countiesTopo"
790
+ geo-type="counties"
791
+ v-model:focus="focused"
792
+ :focus-zoom-level="8"
793
+ zoom
794
+ :touch-expand="false"
795
+ :data="data"
796
+ title="Click a county to focus"
797
+ >
798
+ <template #tooltip="{ name, value }">
799
+ <div style="font-weight: 600">{{ name }}</div>
800
+ <div v-if="value != null">Cases: {{ value }}</div>
801
+ <div v-else style="opacity: 0.6">No data</div>
802
+ </template>
803
+ </ChoroplethMap>
804
+ ```
805
+
806
+ </template>
807
+ </ComponentDemo>
808
+
809
+ ### Color by HSA, interact by county (`dataGeoType`)
810
+
811
+ Set `dataGeoType` when your data is keyed by a coarser geography than
812
+ the one you want to render. Each county fills with its parent HSA's
813
+ value (via the built-in FIPS → HSA mapping); hover, click, and `focus`
814
+ still operate on the county geometry, and you can layer an HSA outline
815
+ on top with a `FocusItem`.
816
+
817
+ <ComponentDemo>
818
+ <ChoroplethMap
819
+ :topology="countiesTopo"
820
+ geo-type="counties"
821
+ data-geo-type="hsas"
822
+ zoom
823
+ renderer="canvas"
824
+ :touch-expand="false"
825
+ :data="[
826
+ { id: '060737', value: 80 },
827
+ { id: '060723', value: 60 },
828
+ { id: '060757', value: 45 },
829
+ { id: '060807', value: 35 },
830
+ { id: '060768', value: 25 },
831
+ { id: '060774', value: 50 },
832
+ ]"
833
+ :focus="[
834
+ { id: '06043' },
835
+ { id: '060737', geoType: 'hsas', style: 'dashed' },
836
+ ]"
837
+ :focus-zoom-level="6"
838
+ title="HSA-keyed data on a county map"
839
+ :legend-title="'Cases'"
840
+ :height="400"
841
+ />
842
+
843
+ <template #code>
844
+
845
+ ```vue
846
+ <ChoroplethMap
847
+ :topology="countiesTopo"
848
+ geo-type="counties"
849
+ data-geo-type="hsas"
850
+ zoom
851
+ renderer="canvas"
852
+ :touch-expand="false"
853
+ :data="hsaData"
854
+ :focus="[{ id: '06043' }, { id: '060737', geoType: 'hsas', style: 'dashed' }]"
855
+ title="HSA-keyed data on a county map"
856
+ />
857
+ ```
858
+
859
+ </template>
860
+ </ComponentDemo>
861
+
862
+ ### Outline a focused feature's parent
863
+
864
+ Use `v-model:focus` together with a computed that derives a parent
865
+ feature (e.g. an HSA from a county via `fipsToHsa`). Pass both as a
866
+ `FocusItem` array — the focused county lights up as usual and the
867
+ parent HSA renders on top as a dashed overlay (`stroke: "#666"` here —
868
+ default is white).
869
+
870
+ `fipsToHsa` and `hsaNames` ship from the `@cfasim-ui/charts/hsa-mapping`
871
+ subpath so consumers that don't need HSA lookups don't pay for the
872
+ ~25 KB of mapping data.
873
+
874
+ <ComponentDemo>
875
+ <ChoroplethMap
876
+ :topology="countiesTopo"
877
+ geo-type="counties"
878
+ data-geo-type="hsas"
879
+ zoom
880
+ :touch-expand="false"
881
+ :focus="parentFocus"
882
+ @update:focus="focusedCounty = typeof $event === 'string' ? $event : null"
883
+ :data="[
884
+ { id: '060737', value: 80 },
885
+ { id: '060723', value: 60 },
886
+ { id: '060757', value: 45 },
887
+ { id: '060807', value: 35 },
888
+ { id: '060768', value: 25 },
889
+ { id: '060774', value: 50 },
890
+ ]"
891
+ :focus-zoom-level="6"
892
+ title="Click a county to outline its HSA"
893
+ :legend-title="'Cases'"
894
+ :height="400"
895
+ >
896
+ <template #tooltip="{ name, value }">
897
+ <div style="font-weight: 600">{{ name }}</div>
898
+ <div v-if="value != null">Cases: {{ value }}</div>
899
+ <div v-else style="opacity: 0.6">No data</div>
900
+ </template>
901
+ </ChoroplethMap>
902
+
903
+ <template #code>
904
+
905
+ ```vue
906
+ <script setup>
907
+ import { ref, computed } from "vue";
908
+ import { fipsToHsa } from "@cfasim-ui/charts/hsa-mapping";
909
+
910
+ const focusedCounty = ref(null);
911
+ const focus = computed(() => {
912
+ const fips = focusedCounty.value;
913
+ if (!fips) return null;
914
+ const hsa = fipsToHsa[fips];
915
+ return hsa
916
+ ? [fips, { id: hsa, geoType: "hsas", style: "dashed", stroke: "#666" }]
917
+ : fips;
918
+ });
919
+ </script>
920
+
921
+ <ChoroplethMap
922
+ :topology="countiesTopo"
923
+ geo-type="counties"
924
+ data-geo-type="hsas"
925
+ zoom
926
+ :touch-expand="false"
927
+ :data="hsaData"
928
+ :focus="focus"
929
+ @update:focus="focusedCounty = typeof $event === 'string' ? $event : null"
930
+ title="Click a county to outline its HSA"
931
+ />
932
+ ```
933
+
934
+ </template>
935
+ </ComponentDemo>
936
+
937
+ ### Custom tooltip number format
938
+
939
+ Pass `tooltip-value-format` to format numeric values shown in the tooltip
940
+ (both the native SVG `<title>` and the interactive HTML tooltip). Use the
941
+ `#tooltip` slot if you want full control over the tooltip's content.
942
+
943
+ <ComponentDemo>
944
+ <ChoroplethMap
945
+ :topology="statesTopo"
946
+ :data="[
947
+ { id: '06', value: 39538223 },
948
+ { id: '48', value: 29145505 },
949
+ { id: '12', value: 21538187 },
950
+ { id: '36', value: 20201249 },
951
+ ]"
952
+ :tooltip-value-format="(v) => v.toLocaleString('en-US')"
953
+ title="US population (2020)"
954
+ :height="300"
955
+ />
956
+
957
+ <template #code>
958
+
959
+ ```vue
960
+ <ChoroplethMap
961
+ :topology="statesTopo"
962
+ :data="[
963
+ { id: '06', value: 39538223 },
964
+ { id: '48', value: 29145505 },
965
+ { id: '12', value: 21538187 },
966
+ { id: '36', value: 20201249 },
967
+ ]"
968
+ :tooltip-value-format="(v) => v.toLocaleString('en-US')"
969
+ title="US population (2020)"
970
+ :height="300"
971
+ />
972
+ ```
973
+
974
+ </template>
975
+ </ComponentDemo>
976
+
977
+ ### Canvas rendering (`renderer="canvas"`)
978
+
979
+ For dense maps — every US county, HSAs, or anything that feels sluggish on
980
+ mobile — set `renderer="canvas"`. Instead of one DOM path per feature, the
981
+ whole map paints into a single `<canvas>`: zooming, panning, and hover/tap
982
+ highlights redraw in a few milliseconds regardless of feature count, and
983
+ DOM memory stays flat. Interactions are identical (hover, click/tap
984
+ selection, `focus`, every zoom mode and touch flow); hit-testing runs
985
+ through an offscreen picking bitmap, so it stays pixel-accurate.
986
+
987
+ Differences from the default SVG renderer:
988
+
989
+ - The menu offers **Fullscreen** and **Save as PNG** only (there is no SVG
990
+ DOM to serialize; the PNG exports straight off the rendering canvas).
991
+ - There is no per-feature `<title>` fallback or per-feature DOM for
992
+ assistive tech — configure an interactive tooltip (`tooltip-trigger` or
993
+ the `#tooltip` slot), or stay on SVG where that fallback matters.
994
+ - `renderer` is fixed at mount.
995
+
996
+ The dense county demo below uses it.
997
+
998
+ ### Dense county map
999
+
1000
+ Renders every US county with a value and a custom tooltip slot, on the
1001
+ canvas backend.
1002
+
1003
+ <ComponentDemo>
1004
+ <ChoroplethMap
1005
+ :topology="countiesTopo"
1006
+ geo-type="counties"
1007
+ :data="denseCountyData"
1008
+ zoom
1009
+ renderer="canvas"
1010
+ :color-scale="{ min: '#f0f5ff', max: '#08306b' }"
1011
+ title="All US counties — tooltip perf demo"
1012
+ :height="500"
1013
+ >
1014
+ <template #tooltip="{ id, name, value }">
1015
+ <div style="font-weight: 600">{{ name }}</div>
1016
+ <div style="opacity: 0.7; font-size: 0.85em">FIPS {{ id }}</div>
1017
+ <div>Value: {{ value }}</div>
1018
+ </template>
1019
+ </ChoroplethMap>
1020
+
1021
+ <template #code>
1022
+
1023
+ ```vue
1024
+ <script setup>
1025
+ import countiesTopo from "us-atlas/counties-10m.json";
1026
+
1027
+ // One row per county
1028
+ const data = countiesTopo.objects.counties.geometries.map((g, i) => ({
1029
+ id: String(g.id).padStart(5, "0"),
1030
+ value: (i * 37) % 100,
1031
+ }));
1032
+ </script>
1033
+
1034
+ <ChoroplethMap
1035
+ :topology="countiesTopo"
1036
+ geo-type="counties"
1037
+ :data="data"
1038
+ zoom
1039
+ renderer="canvas"
1040
+ >
1041
+ <template #tooltip="{ id, name, value }">
1042
+ <div style="font-weight: 600">{{ name }}</div>
1043
+ <div style="opacity: 0.7; font-size: 0.85em">FIPS {{ id }}</div>
1044
+ <div>Value: {{ value }}</div>
1045
+ </template>
1046
+ </ChoroplethMap>
1047
+ ```
1048
+
1049
+ </template>
1050
+ </ComponentDemo>
1051
+
1052
+ ### Custom tooltip content (`#tooltip` slot)
1053
+
1054
+ Use the `#tooltip` slot to render any Vue template — components, scoped
1055
+ styles, multi-line layouts — instead of the default `name: value`. The slot
1056
+ receives `{ id, name, value, feature }` for the hovered region. Providing the
1057
+ slot automatically enables interactive (HTML) tooltips, so you don't need to
1058
+ set `tooltip-trigger`.
1059
+
1060
+ <ComponentDemo>
1061
+ <ChoroplethMap
1062
+ :topology="statesTopo"
1063
+ :data="[
1064
+ { id: '06', value: 39538223 },
1065
+ { id: '48', value: 29145505 },
1066
+ { id: '12', value: 21538187 },
1067
+ { id: '36', value: 20201249 },
1068
+ { id: '17', value: 12812508 },
1069
+ ]"
1070
+ title="US population (2020)"
1071
+ :height="300"
1072
+ >
1073
+ <template #tooltip="{ name, value }">
1074
+ <div style="font-weight:600">{{ name }}</div>
1075
+ <div v-if="typeof value === 'number'">
1076
+ Pop: {{ value.toLocaleString('en-US') }}
1077
+ </div>
1078
+ <div v-else style="opacity:0.6">No data</div>
1079
+ </template>
1080
+ </ChoroplethMap>
1081
+
1082
+ <template #code>
1083
+
1084
+ ```vue
1085
+ <ChoroplethMap :topology="statesTopo" :data="data" title="US population (2020)">
1086
+ <template #tooltip="{ name, value }">
1087
+ <div style="font-weight: 600">{{ name }}</div>
1088
+ <div v-if="typeof value === 'number'">
1089
+ Pop: {{ value.toLocaleString("en-US") }}
1090
+ </div>
1091
+ <div v-else style="opacity: 0.6">No data</div>
1092
+ </template>
1093
+ </ChoroplethMap>
1094
+ ```
1095
+
1096
+ </template>
1097
+ </ComponentDemo>
1098
+
1099
+ ## Accessibility
1100
+
1101
+ The map's individual regions aren't exposed to assistive tech, so the map
1102
+ announces itself with a single accessible name. When it has a `title`, the root
1103
+ element gets `role="figure"` and an `aria-label` set to the title, so screen
1104
+ readers announce it as a labeled figure while the menu and reset controls stay
1105
+ reachable.
1106
+
1107
+ Set `ariaLabel` to give screen readers a fuller summary than the visible title
1108
+ (it overrides `title` for the accessible name only):
1109
+
1110
+ ```vue
1111
+ <ChoroplethMap
1112
+ :topology="usStates"
1113
+ :data="cases"
1114
+ title="Cases by state"
1115
+ aria-label="US map shaded by case count per state, highest in the Southeast"
1116
+ />
1117
+ ```
1118
+
1119
+ Pass `role` to override the default, e.g. `role="img"` to expose the map as a
1120
+ single image (note this hides the inner menu/reset controls from assistive
1121
+ tech).
1122
+
1123
+ ## Props
1124
+
1125
+ | Prop | Type | Required | Default |
1126
+ |------|------|----------|---------|
1127
+ | `topology` | `Topology` | Yes | — |
1128
+ | `data` | `StateData[]` | No | — |
1129
+ | `geoType` | `GeoType` | No | `"states"` |
1130
+ | `dataGeoType` | `GeoType` | No | — |
1131
+ | `state` | `string` | No | — |
1132
+ | `width` | `number` | No | — |
1133
+ | `height` | `number` | No | — |
1134
+ | `tightFit` | `boolean \| number` | No | `false` |
1135
+ | `colorScale` | `ChoroplethColorScale \| ThresholdStop[] \| CategoricalStop[]` | No | — |
1136
+ | `title` | `string` | No | — |
1137
+ | `titleStyle` | `TitleStyle` | No | — |
1138
+ | `role` | `string` | No | — |
1139
+ | `ariaLabel` | `string` | No | — |
1140
+ | `legendStyle` | `LabelStyle` | No | — |
1141
+ | `theme` | `MapTheme` | No | — |
1142
+ | `menu` | `boolean \| string` | No | `true` |
1143
+ | `legend` | `boolean` | No | `true` |
1144
+ | `legendTitle` | `string` | No | — |
1145
+ | `zoom` | `boolean` | No | `false` |
1146
+ | `zoomMode` | `"activate" \| "scroll"` | No | `"activate"` |
1147
+ | `touchExpand` | `boolean` | No | `true` |
1148
+ | `zoomHint` | `boolean` | No | `true` |
1149
+ | `tooltipTrigger` | `"hover" \| "click"` | No | — |
1150
+ | `tooltipFormat` | `(data: {
1151
+ id: string` | No | — |
1152
+ | `name` | `string` | Yes | — |
1153
+ | `value` | `number \| string` | No | — |
1154
+ | `tooltipValueFormat` | `NumberFormat` | No | — |
1155
+ | `tooltipClamp` | `"none" \| "chart" \| "window"` | No | `"window"` |
1156
+ | `focus` | `FocusValue` | No | — |
1157
+ | `focusZoomLevel` | `number` | No | `4` |
1158
+ | `focusZoom` | `boolean` | No | `true` |
1159
+ | `renderer` | `"svg" \| "canvas"` | No | `"svg"` |
1160
+ | `fullscreenTarget` | `string \| HTMLElement` | No | — |
1161
+ | `cities` | `CityMarker[]` | No | — |
1162
+ | `citiesMinZoom` | `number` | No | `2` |
1163
+
1164
+
1165
+ ### StateData
1166
+
1167
+ ```ts
1168
+ interface StateData {
1169
+ /** FIPS code (e.g. "06" for California, "06037" for LA County) or name */
1170
+ id: string;
1171
+ value: number | string;
1172
+ }
1173
+ ```
1174
+
1175
+ ### ChoroplethColorScale
1176
+
1177
+ Any CSS color works, including `var()` and `light-dark()` — scale colors resolve against the map's container and re-resolve on page theme changes.
1178
+
1179
+ ```ts
1180
+ interface ChoroplethColorScale {
1181
+ /** Minimum color (any CSS color). Default: "#e5f0fa" */
1182
+ min?: string;
1183
+ /** Maximum color (any CSS color). Default: "#08519c" */
1184
+ max?: string;
1185
+ }
1186
+ ```
1187
+
1188
+ ### ThresholdStop
1189
+
1190
+ Pass an array of `ThresholdStop` as `colorScale` for discrete color buckets instead of a linear gradient. The highest matching `min` wins.
1191
+
1192
+ ```ts
1193
+ interface ThresholdStop {
1194
+ /** Lower bound (inclusive). Values at or above this get this color. */
1195
+ min: number;
1196
+ color: string;
1197
+ /** Optional label for the legend (defaults to the min value) */
1198
+ label?: string;
1199
+ }
1200
+ ```
1201
+
1202
+ ### CategoricalStop
1203
+
1204
+ Pass an array of `CategoricalStop` as `colorScale` to map string values to colors. States whose `value` matches a stop's `value` get that color; unmatched values get the theme's base `fill`.
1205
+
1206
+ ```ts
1207
+ interface CategoricalStop {
1208
+ /** The categorical value to match */
1209
+ value: string;
1210
+ /** CSS color string */
1211
+ color: string;
1212
+ }
1213
+ ```
1214
+
1215
+ ### MapTheme
1216
+
1217
+ All keys are optional; unset keys fall back to their `--choropleth-*` custom property (see [Theming](#theming-theme)).
1218
+
1219
+ ```ts
1220
+ interface MapTheme {
1221
+ /** Base fill for features without a data value (any CSS color). */
1222
+ fill?: string;
1223
+ /** Interior feature borders (any CSS color). */
1224
+ stroke?: string;
1225
+ /** Feature border width in CSS px, constant at any zoom. 0 disables. */
1226
+ strokeWidth?: number;
1227
+ /** State-boundary mesh over county/HSA maps. Falls back to `stroke`. */
1228
+ borders?: string;
1229
+ /** State-borders mesh width in CSS px. Default 1; 0 disables. */
1230
+ bordersWidth?: number;
1231
+ /** Exterior boundary, drawn on top of interior borders. Off by default. */
1232
+ outline?: string;
1233
+ /** Exterior outline width in CSS px. Default 1; 0 disables. */
1234
+ outlineWidth?: number;
1235
+ /** Background wash behind the map features. Off by default. */
1236
+ background?: string;
1237
+ /** Hover/focus highlight stroke. */
1238
+ highlight?: string;
1239
+ /** Marker overlay (`cities` prop): dot + label color. */
1240
+ markerColor?: string;
1241
+ /** Marker overlay: halo color around dots and labels. */
1242
+ markerHalo?: string;
1243
+ /** Dot halo width in CSS px. Default 0.9; 0 disables. */
1244
+ markerHaloWidth?: number;
1245
+ /** Opacity of the whole marker layer. Default 1. */
1246
+ markerOpacity?: number;
1247
+ }
1248
+ ```
1249
+
1250
+ ### FocusItem
1251
+
1252
+ The `focus` prop accepts a bare id, a `FocusItem`, or an array of either. Use objects when you want to pin features from a different `geoType` than the base map, or pick a non-default outline style.
1253
+
1254
+ ```ts
1255
+ interface FocusItem {
1256
+ /** Feature id (FIPS code, HSA code) or name. */
1257
+ id: string;
1258
+ /** Defaults to the map's geoType. Cross-geoType items render as
1259
+ * non-interactive outlines on top of the base map. */
1260
+ geoType?: "states" | "counties" | "hsas";
1261
+ /** Outline style. "solid" (default) matches the hover highlight;
1262
+ * "dashed" uses long dashes; "dotted" uses small round dots. */
1263
+ style?: "solid" | "dashed" | "dotted";
1264
+ /** Stroke color for cross-geoType overlay paths. Default: "#fff". */
1265
+ stroke?: string;
1266
+ }
1267
+ ```