Choropleth Chart 3D

The regions of the land on a globe, each in the color of its class.

lowest fifth
second fifth
middle fifth
fourth fifth
highest fifth

The choropleth colors the regions of the land on a globe. An entry names a region by the id of its feature - in world-atlas the ISO 3166-1 numeric code, "276" for Germany - and the region takes the color of the entry's series, a config key per class; the value shows in its tooltip, titled by the label of the entry or the label of its series. A region without an entry stays land, and the last entry on a region wins. Nothing grows here: a region fades in with its entry and out without it, and one that changes its series leaves as one and enters as the other, since motion would mislead on a map.

The demos show the countries of the world from the admin 0 file of Natural Earth (public domain), each in the fifth of the countries its people fall in, in five steps of YlOrRd; France and Norway carry no ISO numeric code there and get theirs in docs/examples/countries.ts. The classes and the fifths live in docs/examples/regions.ts, not in the chart. The land is the one the globe takes, with the same winding, and it turns, pans and zooms with the regions. A few hundred rings draw fine on SVG, so the demos start there.

Installation

npx shadcn@latest add niekes/chart3dcn/choropleth-chart-3d#v1.2.0

Start at a place

The globe starts at the default view of the container, which looks at the Atlantic, at 30° west and 30° north. Hand the container defaultView={facing(lon, lat)}, in degrees, and the camera starts over that place - here Germany - and a reset returns it there. facing is an export of chart-3d:

<ChartContainer3D config={chartConfig} defaultView={facing(10, 51)}>
  <ChoroplethChart3D data={regions} land={land} id="id" value="population" />
</ChartContainer3D>

To turn the globe to a place later, as a tour does, give it a heading with view, see chart-3d.

Update

Press the button: the countries are classed by their GDP instead of their people, and every country that changes its fifth fades from the one color to the other, over the animationDuration of its container.

lowest fifth
second fifth
middle fifth
fourth fifth
highest fifth

Enter and leave

New data may also bring and drop regions. A country that arrives fades in over the land; one that goes fades back to it, the mirror of its entering (see Enter in the glossary). Here the world arrives country by country, from the ones of a hundred million people down to every country; the fifths are taken among the countries shown, so a country may change its color as others join.

lowest fifth
second fifth
middle fifth
fourth fifth
highest fifth

Renderers

The same chart on every renderer, side by side. The marks are data the chart hands to the container, and "svg" and "canvas" draw them all - where the browser has no canvas, as SVG.

SVG
Canvas

Many marks

Every country colored, on "canvas", the renderer for many marks, with the select for the same scene on SVG. The size of a choropleth is its land's, not its data's: the 177 regions of world-atlas at 110m are 10,600 points, which d3-geo cuts at the horizon on every turn of the camera, and a colored region is drawn once, in its color alone. At 50m the regions are 100,000 points, and the cut alone took 100 ms a frame on a laptop, so the demos stay at 110m; a finer land is where the budget of this chart ends.

API Reference

Prop

Type

Edit on GitHub

On this page