@cfasim-ui/docs 0.4.1 → 0.4.3
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.
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
|
+
import countiesTopoForPerf from "us-atlas/counties-10m.json";
|
|
4
|
+
|
|
5
|
+
// Build one row per county (~3,143) with a deterministic-ish value so the
|
|
6
|
+
// perf example can render every region with a custom tooltip.
|
|
7
|
+
const denseCountyData = computed(() => {
|
|
8
|
+
const geoms = countiesTopoForPerf.objects.counties.geometries;
|
|
9
|
+
return geoms.map((g, i) => ({
|
|
10
|
+
id: String(g.id).padStart(5, "0"),
|
|
11
|
+
value: (i * 37) % 100,
|
|
12
|
+
}));
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Focus demo state — bound directly to v-model:focus. The component
|
|
16
|
+
// handles click-to-toggle and emits null when the focused feature is
|
|
17
|
+
// re-clicked.
|
|
18
|
+
const focused = ref(null);
|
|
19
|
+
</script>
|
|
20
|
+
|
|
1
21
|
# ChoroplethMap
|
|
2
22
|
|
|
3
23
|
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.
|
|
@@ -322,12 +342,76 @@ Set `geoType="hsas"` to render Health Service Area boundaries. HSAs are dissolve
|
|
|
322
342
|
</template>
|
|
323
343
|
</ComponentDemo>
|
|
324
344
|
|
|
345
|
+
### Click to focus (`v-model:focus`)
|
|
346
|
+
|
|
347
|
+
Bind the `focus` prop to pan and zoom to a specific feature. Pass a feature
|
|
348
|
+
id (FIPS code, HSA code, or name) — or an array of ids to focus on a region.
|
|
349
|
+
With `v-model:focus`, clicking an unfocused feature focuses it and clicking
|
|
350
|
+
the focused feature toggles back off. If a tooltip is configured, focusing
|
|
351
|
+
shows that feature's tooltip. Users can pan/zoom freely around the focused
|
|
352
|
+
area; the built-in **Reset** button clears focus and snaps back.
|
|
353
|
+
|
|
354
|
+
Counties are tiny without a zoom — focus is a natural fit for drill-down.
|
|
355
|
+
|
|
356
|
+
<ComponentDemo>
|
|
357
|
+
<ChoroplethMap
|
|
358
|
+
:topology="countiesTopo"
|
|
359
|
+
geo-type="counties"
|
|
360
|
+
v-model:focus="focused"
|
|
361
|
+
:focus-zoom-level="8"
|
|
362
|
+
:data="[
|
|
363
|
+
{ id: '06037', value: 100 },
|
|
364
|
+
{ id: '06073', value: 80 },
|
|
365
|
+
{ id: '36061', value: 90 },
|
|
366
|
+
{ id: '17031', value: 85 },
|
|
367
|
+
{ id: '48201', value: 65 },
|
|
368
|
+
{ id: '04013', value: 60 },
|
|
369
|
+
{ id: '12086', value: 55 },
|
|
370
|
+
{ id: '53033', value: 50 },
|
|
371
|
+
]"
|
|
372
|
+
title="Click a county to focus"
|
|
373
|
+
:legend-title="'Cases'"
|
|
374
|
+
:height="400"
|
|
375
|
+
>
|
|
376
|
+
<template #tooltip="{ name, value }">
|
|
377
|
+
<div style="font-weight: 600">{{ name }}</div>
|
|
378
|
+
<div v-if="value != null">Cases: {{ value }}</div>
|
|
379
|
+
<div v-else style="opacity: 0.6">No data</div>
|
|
380
|
+
</template>
|
|
381
|
+
</ChoroplethMap>
|
|
382
|
+
|
|
383
|
+
<template #code>
|
|
384
|
+
|
|
385
|
+
```vue
|
|
386
|
+
<script setup>
|
|
387
|
+
import { ref } from "vue";
|
|
388
|
+
const focused = ref(null);
|
|
389
|
+
</script>
|
|
390
|
+
|
|
391
|
+
<ChoroplethMap
|
|
392
|
+
:topology="countiesTopo"
|
|
393
|
+
geo-type="counties"
|
|
394
|
+
v-model:focus="focused"
|
|
395
|
+
:focus-zoom-level="8"
|
|
396
|
+
:data="data"
|
|
397
|
+
title="Click a county to focus"
|
|
398
|
+
>
|
|
399
|
+
<template #tooltip="{ name, value }">
|
|
400
|
+
<div style="font-weight: 600">{{ name }}</div>
|
|
401
|
+
<div v-if="value != null">Cases: {{ value }}</div>
|
|
402
|
+
<div v-else style="opacity: 0.6">No data</div>
|
|
403
|
+
</template>
|
|
404
|
+
</ChoroplethMap>
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
</template>
|
|
408
|
+
</ComponentDemo>
|
|
409
|
+
|
|
325
410
|
### Custom tooltip number format
|
|
326
411
|
|
|
327
412
|
Pass `tooltip-value-format` to format numeric values shown in the tooltip
|
|
328
|
-
(both the native SVG `<title>` and the interactive HTML tooltip
|
|
329
|
-
|
|
330
|
-
control over the tooltip's HTML.
|
|
413
|
+
(both the native SVG `<title>` and the interactive HTML tooltip). Use the
|
|
414
|
+
`#tooltip` slot if you want full control over the tooltip's content.
|
|
331
415
|
|
|
332
416
|
<ComponentDemo>
|
|
333
417
|
<ChoroplethMap
|
|
@@ -363,6 +447,106 @@ control over the tooltip's HTML.
|
|
|
363
447
|
</template>
|
|
364
448
|
</ComponentDemo>
|
|
365
449
|
|
|
450
|
+
### Dense county map
|
|
451
|
+
|
|
452
|
+
Renders every US county with a value and a custom tooltip slot.
|
|
453
|
+
|
|
454
|
+
<ComponentDemo>
|
|
455
|
+
<ChoroplethMap
|
|
456
|
+
:topology="countiesTopo"
|
|
457
|
+
geo-type="counties"
|
|
458
|
+
:data="denseCountyData"
|
|
459
|
+
:pan="true"
|
|
460
|
+
:zoom="true"
|
|
461
|
+
:color-scale="{ min: '#f0f5ff', max: '#08306b' }"
|
|
462
|
+
title="All US counties — tooltip perf demo"
|
|
463
|
+
:height="500"
|
|
464
|
+
>
|
|
465
|
+
<template #tooltip="{ id, name, value }">
|
|
466
|
+
<div style="font-weight: 600">{{ name }}</div>
|
|
467
|
+
<div style="opacity: 0.7; font-size: 0.85em">FIPS {{ id }}</div>
|
|
468
|
+
<div>Value: {{ value }}</div>
|
|
469
|
+
</template>
|
|
470
|
+
</ChoroplethMap>
|
|
471
|
+
|
|
472
|
+
<template #code>
|
|
473
|
+
|
|
474
|
+
```vue
|
|
475
|
+
<script setup>
|
|
476
|
+
import countiesTopo from "us-atlas/counties-10m.json";
|
|
477
|
+
|
|
478
|
+
// One row per county
|
|
479
|
+
const data = countiesTopo.objects.counties.geometries.map((g, i) => ({
|
|
480
|
+
id: String(g.id).padStart(5, "0"),
|
|
481
|
+
value: (i * 37) % 100,
|
|
482
|
+
}));
|
|
483
|
+
</script>
|
|
484
|
+
|
|
485
|
+
<ChoroplethMap
|
|
486
|
+
:topology="countiesTopo"
|
|
487
|
+
geo-type="counties"
|
|
488
|
+
:data="data"
|
|
489
|
+
pan
|
|
490
|
+
zoom
|
|
491
|
+
>
|
|
492
|
+
<template #tooltip="{ id, name, value }">
|
|
493
|
+
<div style="font-weight: 600">{{ name }}</div>
|
|
494
|
+
<div style="opacity: 0.7; font-size: 0.85em">FIPS {{ id }}</div>
|
|
495
|
+
<div>Value: {{ value }}</div>
|
|
496
|
+
</template>
|
|
497
|
+
</ChoroplethMap>
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
</template>
|
|
501
|
+
</ComponentDemo>
|
|
502
|
+
|
|
503
|
+
### Custom tooltip content (`#tooltip` slot)
|
|
504
|
+
|
|
505
|
+
Use the `#tooltip` slot to render any Vue template — components, scoped
|
|
506
|
+
styles, multi-line layouts — instead of the default `name: value`. The slot
|
|
507
|
+
receives `{ id, name, value, feature }` for the hovered region. Providing the
|
|
508
|
+
slot automatically enables interactive (HTML) tooltips, so you don't need to
|
|
509
|
+
set `tooltip-trigger`.
|
|
510
|
+
|
|
511
|
+
<ComponentDemo>
|
|
512
|
+
<ChoroplethMap
|
|
513
|
+
:topology="statesTopo"
|
|
514
|
+
:data="[
|
|
515
|
+
{ id: '06', value: 39538223 },
|
|
516
|
+
{ id: '48', value: 29145505 },
|
|
517
|
+
{ id: '12', value: 21538187 },
|
|
518
|
+
{ id: '36', value: 20201249 },
|
|
519
|
+
{ id: '17', value: 12812508 },
|
|
520
|
+
]"
|
|
521
|
+
title="US population (2020)"
|
|
522
|
+
:height="300"
|
|
523
|
+
>
|
|
524
|
+
<template #tooltip="{ name, value }">
|
|
525
|
+
<div style="font-weight:600">{{ name }}</div>
|
|
526
|
+
<div v-if="typeof value === 'number'">
|
|
527
|
+
Pop: {{ value.toLocaleString('en-US') }}
|
|
528
|
+
</div>
|
|
529
|
+
<div v-else style="opacity:0.6">No data</div>
|
|
530
|
+
</template>
|
|
531
|
+
</ChoroplethMap>
|
|
532
|
+
|
|
533
|
+
<template #code>
|
|
534
|
+
|
|
535
|
+
```vue
|
|
536
|
+
<ChoroplethMap :topology="statesTopo" :data="data" title="US population (2020)">
|
|
537
|
+
<template #tooltip="{ name, value }">
|
|
538
|
+
<div style="font-weight: 600">{{ name }}</div>
|
|
539
|
+
<div v-if="typeof value === 'number'">
|
|
540
|
+
Pop: {{ value.toLocaleString("en-US") }}
|
|
541
|
+
</div>
|
|
542
|
+
<div v-else style="opacity: 0.6">No data</div>
|
|
543
|
+
</template>
|
|
544
|
+
</ChoroplethMap>
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
</template>
|
|
548
|
+
</ComponentDemo>
|
|
549
|
+
|
|
366
550
|
## Props
|
|
367
551
|
|
|
368
552
|
| Prop | Type | Required | Default |
|
|
@@ -389,6 +573,8 @@ control over the tooltip's HTML.
|
|
|
389
573
|
| `value` | `number \| string` | No | — |
|
|
390
574
|
| `tooltipValueFormat` | `(value: number) => string` | No | — |
|
|
391
575
|
| `tooltipClamp` | `"none" \| "chart" \| "window"` | No | `"chart"` |
|
|
576
|
+
| `focus` | `string \| string[] \| null` | No | — |
|
|
577
|
+
| `focusZoomLevel` | `number` | No | `4` |
|
|
392
578
|
|
|
393
579
|
|
|
394
580
|
### StateData
|