remold/ui

Globe

A dotted Earth that turns on its own, spins under a finger, pulses where things happen and flies arcs between places. Pass events in and pick colours; the projection, the land, the frame loop and the dragging are done.

The globe above is one <Remold.Globe>. The arcs are a list of journeys passed as arcs, and each look is a different colors prop. Nothing else changes.

Installation

npm install @remold-ui/react

Import the globe from @remold-ui/react/canvas so canvas rendering stays opt-in.

Using plain JavaScript? Install @remold-ui/canvas instead, and use globe().

Usage

Give every event an id. Each id it hasn't seen sends out one pulse or flies one arc, so pass your recent events as they are.

import { Remold } from '@remold-ui/react/canvas';

<Remold.Globe
  colors={{ sphere: "#0c1633", glow: "#3d6bff", land: "#7d9be0", arc: ["#ff7ac6", "#5ab0ff"] }}
  pulses={signups.map((s) => ({ id: s.id, lat: s.lat, lon: s.lon }))}
  arcs={merges.map((m) => ({ id: m.id, from: m.author, to: m.repo }))}
  markers={offices}
  focus={city && { lat: city.lat, lon: city.lon, label: city.name }}
  scale={0.8}
  className="aspect-square w-full"
/>

What you don't write:

  • The Earth. Continent outlines ship with it and are filled with evenly spread dots. The side facing you is bright and the far side is faint, so it reads as round.
  • Turning. It spins slowly and leans towards you. A drag spins it, a flick coasts and settles back into the slow turn, and focus turns to a place and holds there.
  • Arcs. Each one rises off the surface along the shortest route, a bright head draws it out, and its tail follows it home. It goes behind the globe when the route does, and pulses where it lands.
  • Pulses and markers. A pulse rings out, then stays lit for a few seconds. Markers stay lit. Both wait on the far side until they come round.
  • The plumbing. It stays sharp at every size, sleeps while off screen, and holds still for reduced motion: no spin, arcs drawn whole, and pulses as dots without rings.

Colours

Pass colors, or leave any of them out and set them in CSS. Changing them recolours everything already on the globe, arcs in flight included.

ColourCSS fallbackPaints
landcolorThe land dots.
sphere--globe-sphereThe ocean, as a solid ball. It also hides the far side.
glow--globe-glowA halo around the edge. Use scale to leave room for it.
accentaccent-colorPulses, markers and the focus tag. The tag's text turns dark or light to stay readable.
arc--globe-arcArcs. Pass a list and they take turns, like GitHub's pink and blue.

A single arc, pulse or marker can also take its own color.

Options

PropDefault
pulsesRecent events, each { id, lat, lon, color? }.
arcsRecent journeys, each { id, from, to, color?, pulse? }. Set pulse: false to land quietly.
markersPlaces that stay lit, each { lat, lon, color?, size? }.
focusnull{ lat, lon, label? } to turn to and hold.
colorsSee above.
spin7Degrees per second. 0 holds it still.
tilt18Degrees it leans towards you.
scale1How much of the canvas the globe fills.
dotSize1Scales every land dot.
start0The longitude facing you at first.
draggabletrueLet a drag spin it.
dots14000Dots over the whole sphere; land keeps about a third.
labelThe canvas's accessible name.

globe() takes the same options apart from pulses, arcs and focus, and returns pulse, arc, focus, set (for colours, markers, spin, tilt, scale and dot size), redraw (after a CSS change) and destroy.

On this page