Routes Chart 3D

Routes over a globe, from stop to stop along the great circle.

By air
By sea

The routes chart joins the entries of data over the globe: every entry is a stop at its lon and lat, and a leg runs from each stop to the next along the great circle, the shortest way over the surface. series names the field that tells the routes apart; without it all the entries are one route. What lies on the far side is hidden by the globe, so a leg ends at the horizon. id names a stop, in the tooltip and through updates; a route may come back to a stop, since a name that repeats is a stop of its own. Pointing at a leg lights that leg alone and says its two stops; a stop lights and says itself. An entry whose lon or lat is missing or not a number is no stop, and its route ends before it and starts again after it.

A route has the color of its series. leg names a field that gives a leg a color of its own: its value, at the stop a leg arrives at, is the config key of that leg - how it was travelled, here by air or by sea. The leg and that stop take the color, the first stop of a route takes that of the leg that leaves it, and the tooltip names it in its title. A stop that names no leg, and one no leg touches, keeps the color of its route. With a leg named at every stop, as here, the config needs the keys of the legs only: series still tells the routes apart.

The tip

The last stop of a route is its tip: where the route stands now. A config key may carry a symbol, and the tip is drawn as the symbol of the key that colors it - its leg, or else its route - in place of the circle; every stop before it stays a circle, and a key without a symbol keeps the circle on the tip too. Here the route round the Atlantic comes home by air and ends on a plane; the one to the east ends by sea, on a ship off Canberra - turn the globe to see it.

const chartConfig = {
  air: {
    label: "By air",
    color: "var(--chart-1)",
    symbol: { path: "M17.8 19.2 16 11...", points: 45, fill: true },
  },
  sea: { label: "By sea", color: "var(--chart-2)", symbol: { path: "M12 2v2 M12 9.189V13..." } },
} satisfies ChartConfig

A symbol is the outline of an icon as path data, in a box of 24: the d of its <path>, as Lucide, Tabler, Heroicons or Phosphor write it, the ds of several paths joined by a space. The registry brings no icon package: copy the path from your set. An icon that draws with a <circle> or a <rect>, as the wheels of Lucide's car, has to become a path first, which SVGO does. It is drawn in the one color of the tip, as an outline, the way Lucide draws its icons, or filled with fill: true, as the icons of a solid set; ringed by the background, as large on the screen from every side, and it lights on hover as a stop does.

points says where the symbol points as it is drawn, in degrees clockwise from up: 45 for the plane of Lucide. A symbol that names it turns to its bearing - the leg that arrives at the tip, as the camera shows it - so the plane points the way it flew. One that names none stays upright, as a ship or a car seen from the side. A tip without a leg points the way it moves - a route of one stop whose place changes is a vehicle on its way - and where it stands it keeps the bearing it came with, as one whose leg has drawn back into it on a tour that drops the stops behind it. A tip that never came from anywhere shows its symbol as it is drawn.

The tip moves with the data. A stop that joins the end of a route takes the symbol at once and flies its leg from the stop it stood on, whole all the way. Its bearing never jumps: the symbol sets out the way it pointed and turns into its new bearing as it flies, the shorter way round, and has turned when about a quarter of the leg is flown - so with the pace of the animationDuration. A stop that joins while it still turns turns it on from where it points, and a tip that flies back the way it came turns clockwise. A tip that takes over from one that left, one on its first leg, which starts the way it is drawn, and one without a leg that sets out for another place turn the same way; one that leaves the data draws back along its leg as it fades, and the stop before it is the tip once it is gone. See it fly under Enter and leave. The chart draws no flag: a flag has many colors, and belongs in the text beside a stop.

The demos travel between the capitals of Natural Earth, public domain. The land under the routes is the one every globe takes, cut at the horizon by d3-geo; see the globe for where it comes from and how its regions must be wound. For places without a route between them, see the places chart.

Installation

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

Update

Press Update: every stop keeps its number and moves to another capital, the legs following along, over the animationDuration of the container.

Enter and leave

A stop that joins the end of its route grows its leg out of the stop before it, along the great circle, as it fades in; a stop that goes draws its leg back into its neighbour, the mirror of its entering (see Enter in the glossary). Here a tour rests on one stop. A step adds the next stop, so its leg grows out of the stop the tour is on - the plane, the symbol of the route, flies it - and then drops the stop left behind, so the leg draws back towards the new one. The globe turns to the new stop through the view of the container, set to facing(lon, lat): a heading, so you can turn the globe away at any time (see chart-3d). Steps may come faster than they end: every stop goes on from where it is, a new one starting on the stop before it wherever that has come to, and each step drops only what lies behind the stop it added.

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 place of half a million people and more on one route, each time on to the nearest one not yet visited: a thousand stops and the pieces of a thousand legs, nearly three thousand marks - and the chart stays interactive. The scene is one list of marks, so the demo starts on "canvas", the renderer for many marks, and the select shows the same scene on SVG.

API Reference

Prop

Type

Edit on GitHub

On this page