Skip to content

Choroplethenkaart API

Een wereld-/regiokaart met choropleten: je eigen GeoJSON, gekleurd via een drempel-kleurschaal of een expliciete categoriekaart - zie de Choroplethenkaart-demo.

Import

ts
import "@michi-vz/wc/choropleth-map-chart";
// <michi-vz-choropleth-map-chart> is now defined
ts
import { mountChoroplethMapChart } from "@michi-vz/core";

const chart = mountChoroplethMapChart(el, props);

Props

PropTypeDefaultDescription
timelineboolean | TimelinePeriodConfig-Opt-in "play through years": snapshots one period at a time over the distinct per-row `date` values, with a headless controller (`chart.timeline()`) plus an optional built-in play button + scrubber. Off by default; requires rows with `date`. Values tween between periods unless `interpolate: false`.
geography*GeoJSON.FeatureCollection | GeoFeatureItem[]-The world/region geography to draw. A full GeoJSON FeatureCollection (its per-feature `id`/`properties.name` are read automatically) or a pre-normalized flat array. Core bundles NO topology data - import your own (e.g. a `world-atlas` TopoJSON converted via `topojson-client`, or a hand-curated GeoJSON) and pass it here.
dataSet*ChoroplethDataItem[]-Choropleth values/colours, joined against `geography` (see `joinBy`).
titlestring-Optional chart title rendered above the map
projectionGeoProjectionName-d3-geo / d3-geo-projection projection to use (default "geoRobinson", the legacy sdg-trade MapChoropleth default). `geoAlbersUsa` is a fixed composite projection - it ignores `rotate`/`center`/`parallels`.
projectionConfigGeoProjectionConfig-Fine-tunes the chosen projection. Omitted fields fall back to the legacy MapChoropleth defaults (rotate [-18, 0], center [0, 10], base scale derived from width) rather than `projection.fitSize` - this matches the legacy chart's visual result exactly; pass your own values to frame a different geography extent (e.g. a single-region subset).
colorScale{ domain: number[]; range: string[] }-Continuous choropleth encoding: a resolved hex `range` keyed to a numeric `domain`, built into a d3 `scaleThreshold`. Pass already-resolved colours (NOT a d3-scale-chromatic scheme name - core stays free of that dependency); generate the range yourself (e.g. via `d3-scale-chromatic` in your app) if you want a named scheme. Loses to `colorsMapping`.
noDataColorstringDEFAULT_NO_DATA_COLORFill for features with no matching `dataSet` row (default `#d2d7dd`).
joinBy"id" | "name""id"How `dataSet` rows join `geography` features: "id" (default) matches `ChoroplethDataItem.id` against `GeoFeatureItem.id` / GeoJSON `Feature.id` (stable codes such as ISO-A3), while "name" matches `label` against `GeoFeatureItem.name` / `properties.name` for data keyed by display name.
strokeColorstringDEFAULT_STROKE_COLORCountry border colour (legacy default: `#F4F7FC`, `colors.WHITE_SMOKE`)
strokeWidthnumber1Country border width in px (default 1)
tooltipFormatter(d: ChoroplethDataItem | { id: string; name?: string }) => string-Formats the tooltip for a hovered region. Matched rows receive the full `ChoroplethDataItem`; regions with no matching row receive the fallback `{ id, name }` shape (mirrors the legacy chart's "N/A" tooltip).
isLoadingboolean-Loading overlay (stale regions hidden while true)
isNodataboolean | ((dataSet: ChoroplethDataItem[] | null | undefined) => boolean)-No-data predicate/flag; default = empty dataSet
noDataLabelstring-Text for the built-in no-data overlay
suppressDefaultOverlayboolean-Set by a framework wrapper passing its own overlay node - suppresses the default overlay
onHighlightItem(labels: string[]) => void-Called when the hovered/highlighted label(s) change
Common props - shared by every chart (14)
PropTypeDefaultDescription
widthnumber900Chart width in pixels
heightnumber520Chart height in pixels
marginMargin{ top: 40, right: 10, bottom: 10, left: 10 }Inner margins (top/right/bottom/left, in px) reserved for axes, titles, and labels
colorsMappingRecord<string, string>-Explicit label -> colour map; takes precedence over the palette and per-item colours
colorsstring[]-Categorical palette for series/labels without an explicit colour or colorsMapping entry
highlightItemsstring[]-Labels to emphasise; all other marks dim
disabledItemsstring[]-Labels to hide and exclude from scales/stacks
renderer"svg" | "canvas" | "webgpu""svg"Render as inline SVG (default) or to a canvas (faster for large datasets); getContext() is identical either way
localestring-BCP-47 locale used for number and date formatting
skipColorMappingDispatchbooleanfalseExternal-CSS mode: unmapped labels resolve to transparent and onColorMappingGenerated is not emitted, so mark colours come from your CSS via the data-label-safe contract
enableTransitionsbooleantrueAnimate updates with CSS transitions (default true)
onColorMappingGenerated(mapping: Record<string, string>) => void-Called with the resolved label -> colour map after the chart assigns colours
onChartDataProcessed(context: ChartContext) => void-Called with the renderer-agnostic ChartContext whenever the data is (re)processed
onDataWarning(warnings: DataWarning[]) => void-Called with any non-fatal data warnings (duplicate labels, non-finite values, non-monotonic dates, ...)

Gebeurtenissen

De webcomponent verzendt deze bubbelende CustomEvents (de engine biedt dezelfde functionaliteit via de on*-callbacks in de tabel hierboven):

GebeurtenisDetailTreedt op wanneer
michi-vz:highlightstring[]de highlight bij hover verandert
michi-vz:colormappingRecord<string, string>er een kleurtoewijzing wordt gegenereerd
michi-vz:dataprocessedChartContextgegevens worden (opnieuw) verwerkt
michi-vz:datawarningDataWarning[]waarschuwingen worden gedetecteerd (niet-gekoppelde dataSet-ids, features zonder id, ongeldige geometrie)

getContext()

mountChoroplethMapChart(el, props).getContext() retourneert een renderer-onafhankelijke ChoroplethMapChartContext: stats.featureCount / matchedCount / unmatchedCount / valueDomain / min / max, een regions[]-array (één rij per feature: id, label, value?, color, matched), de opgeloste projection-naam, een deterministische samenvatting in gewone taal, en een a11yTable met elke regio + waarde + koppelingsstatus. Zie LLM-context.

Bron

Props zijn getypeerd als ChoroplethMapChartProps in @michi-vz/core.