@cfasim-ui/docs 0.7.4 → 0.7.6

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.
@@ -104,6 +104,17 @@ export function savePng(svg: SVGSVGElement, filename: string) {
104
104
  img.src = url;
105
105
  }
106
106
 
107
+ /**
108
+ * Downloads a rendering canvas's current contents as a PNG — no SVG
109
+ * round-trip. The canvas backing store is already sized at
110
+ * devicePixelRatio, so the export is naturally high-resolution.
111
+ */
112
+ export function saveCanvasPng(canvas: HTMLCanvasElement, filename: string) {
113
+ canvas.toBlob((blob) => {
114
+ if (blob) downloadBlob(blob, `${filename}.png`);
115
+ }, "image/png");
116
+ }
117
+
107
118
  export function downloadCsv(csv: string, filename: string) {
108
119
  downloadBlob(new Blob([csv], { type: "text/csv" }), `${filename}.csv`);
109
120
  }
@@ -370,6 +370,41 @@ before and after zooming in.
370
370
  </template>
371
371
  </ComponentDemo>
372
372
 
373
+ ### Tighter national fit (`tight-fit`)
374
+
375
+ 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.
376
+
377
+ Only affects the national (multi-state) view — it's a no-op in single-state mode and on national HSA maps (HSA ids aren't FIPS codes, so Alaska/Hawaii can't be split out).
378
+
379
+ <ComponentDemo>
380
+ <ChoroplethMap
381
+ :topology="statesTopo"
382
+ tight-fit
383
+ :data="[
384
+ { id: '06', value: 100 },
385
+ { id: '36', value: 80 },
386
+ { id: '48', value: 90 },
387
+ { id: '12', value: 70 },
388
+ { id: '17', value: 60 },
389
+ ]"
390
+ title="Cases by State (tight fit)"
391
+ :legend-title="'Cases'"
392
+ :height="400"
393
+ />
394
+
395
+ <template #code>
396
+
397
+ ```vue
398
+ <!-- Crop Alaska's overhang so the lower-48 fills the frame -->
399
+ <ChoroplethMap :topology="statesTopo" tight-fit :data="data" />
400
+
401
+ <!-- ...or crop only partway -->
402
+ <ChoroplethMap :topology="statesTopo" :tight-fit="0.5" :data="data" />
403
+ ```
404
+
405
+ </template>
406
+ </ComponentDemo>
407
+
373
408
  ### HSA-level map
374
409
 
375
410
  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.
@@ -607,6 +642,7 @@ on top with a `FocusItem`.
607
642
  geo-type="counties"
608
643
  data-geo-type="hsas"
609
644
  zoom
645
+ renderer="canvas"
610
646
  :touch-expand="false"
611
647
  :data="[
612
648
  { id: '060737', value: 80 },
@@ -634,6 +670,7 @@ on top with a `FocusItem`.
634
670
  geo-type="counties"
635
671
  data-geo-type="hsas"
636
672
  zoom
673
+ renderer="canvas"
637
674
  :touch-expand="false"
638
675
  :data="hsaData"
639
676
  :focus="[{ id: '06043' }, { id: '060737', geoType: 'hsas', style: 'dashed' }]"
@@ -759,9 +796,31 @@ Pass `tooltip-value-format` to format numeric values shown in the tooltip
759
796
  </template>
760
797
  </ComponentDemo>
761
798
 
799
+ ### Canvas rendering (`renderer="canvas"`)
800
+
801
+ For dense maps — every US county, HSAs, or anything that feels sluggish on
802
+ mobile — set `renderer="canvas"`. Instead of one DOM path per feature, the
803
+ whole map paints into a single `<canvas>`: zooming, panning, and hover/tap
804
+ highlights redraw in a few milliseconds regardless of feature count, and
805
+ DOM memory stays flat. Interactions are identical (hover, click/tap
806
+ selection, `focus`, every zoom mode and touch flow); hit-testing runs
807
+ through an offscreen picking bitmap, so it stays pixel-accurate.
808
+
809
+ Differences from the default SVG renderer:
810
+
811
+ - The menu offers **Fullscreen** and **Save as PNG** only (there is no SVG
812
+ DOM to serialize; the PNG exports straight off the rendering canvas).
813
+ - There is no per-feature `<title>` fallback or per-feature DOM for
814
+ assistive tech — configure an interactive tooltip (`tooltip-trigger` or
815
+ the `#tooltip` slot), or stay on SVG where that fallback matters.
816
+ - `renderer` is fixed at mount.
817
+
818
+ The dense county demo below uses it.
819
+
762
820
  ### Dense county map
763
821
 
764
- Renders every US county with a value and a custom tooltip slot.
822
+ Renders every US county with a value and a custom tooltip slot, on the
823
+ canvas backend.
765
824
 
766
825
  <ComponentDemo>
767
826
  <ChoroplethMap
@@ -769,6 +828,7 @@ Renders every US county with a value and a custom tooltip slot.
769
828
  geo-type="counties"
770
829
  :data="denseCountyData"
771
830
  zoom
831
+ renderer="canvas"
772
832
  :color-scale="{ min: '#f0f5ff', max: '#08306b' }"
773
833
  title="All US counties — tooltip perf demo"
774
834
  :height="500"
@@ -793,7 +853,13 @@ const data = countiesTopo.objects.counties.geometries.map((g, i) => ({
793
853
  }));
794
854
  </script>
795
855
 
796
- <ChoroplethMap :topology="countiesTopo" geo-type="counties" :data="data" zoom>
856
+ <ChoroplethMap
857
+ :topology="countiesTopo"
858
+ geo-type="counties"
859
+ :data="data"
860
+ zoom
861
+ renderer="canvas"
862
+ >
797
863
  <template #tooltip="{ id, name, value }">
798
864
  <div style="font-weight: 600">{{ name }}</div>
799
865
  <div style="opacity: 0.7; font-size: 0.85em">FIPS {{ id }}</div>
@@ -887,6 +953,7 @@ tech).
887
953
  | `state` | `string` | No | — |
888
954
  | `width` | `number` | No | — |
889
955
  | `height` | `number` | No | — |
956
+ | `tightFit` | `boolean \| number` | No | `false` |
890
957
  | `colorScale` | `ChoroplethColorScale \| ThresholdStop[] \| CategoricalStop[]` | No | — |
891
958
  | `title` | `string` | No | — |
892
959
  | `titleStyle` | `TitleStyle` | No | — |
@@ -913,6 +980,7 @@ tech).
913
980
  | `focus` | `FocusValue` | No | — |
914
981
  | `focusZoomLevel` | `number` | No | `4` |
915
982
  | `focusZoom` | `boolean` | No | `true` |
983
+ | `renderer` | `"svg" \| "canvas"` | No | `"svg"` |
916
984
  | `fullscreenTarget` | `string \| HTMLElement` | No | — |
917
985
 
918
986