region

A canvas environment that draws a map: boundaries, and the overlays set over them.

regionNode
On this page
A map zoomed on the Tasman Sea, Australia and New Zealand filled and outlined in teal, with markers at Sydney and Auckland drawn over the route joining them.A map zoomed on the Tasman Sea, Australia and New Zealand filled and outlined in teal, with markers at Sydney and Auckland drawn over the route joining them.

#Boundaries and projections

region is a map. Its implicit attribute is basemap, the boundaries drawn beneath everything else, so region:world{ } is already a world map. The packs are world (Natural Earth's 1:110m countries) and six sets of first-level divisions: us-states, canada-provinces, australia-states, uk-counties, nz-regions and europe-admin1. Without basemap, nothing is drawn but the overlays.

A map of western Europe on the Equal Earth projection, titled Where the survey ran, centred on a marker at Paris.A map of western Europe on the Equal Earth projection, titled Where the survey ran, centred on a marker at Paris.
region:world{
    marker(at: 48.85, 2.35; label: Paris)
}(
    title: Where the survey ran
    centre: 48.85, 2.35
    zoom: 4
)

Boundaries no pack carries, such as electorates, catchments or council wards, arrive as an attached .geojson file declared with @data, and basemap names it as it names a pack: basemap: #wards. name-property and codes say which property of each feature holds its name and its code. Every boundary is drawn from data the internote carries, and nothing is fetched from a tile server, so a map renders offline and the same in years to come.

projection chooses how the sphere is laid flat, and each choice keeps something true at the cost of something else:

  • equal-earth, the default, keeps areas true across the world.
  • mercator keeps angles true, and is the frame on which a great-circle route visibly bends. It stops at 85° north and south.
  • equirectangular plots latitude and longitude as a plain grid.
  • conic is an equal-area conic whose standard parallels are set from the band of latitude the map frames, for one country or region.
  • albers-usa is the standard United States composite: the lower 48 on an equal-area conic, with Alaska at 35% scale and Hawaii as insets.
  • globe is the sphere seen from space, the far hemisphere behind the horizon.

show-scale, on unless turned off, puts a scale bar at the end of the footer saying what a length at the middle of the map is worth on the ground.

#Drawing and picking out regions

The map's own attributes say which regions of its pack are drawn and how. only draws the listed regions and leaves the rest as open ground; except leaves the listed ones out. Both take names or ISO alpha-3 codes, ignoring case and accents: France, DEU and Côte d'Ivoire all read, and on world common names such as Ivory Coast too.

highlight picks regions out, named the same way: they take fill and stroke, and the rest of the map stays plain land. A highlight with no fill is teal, and one with no stroke is outlined in its fill. Without a highlight, fill and stroke paint every region drawn, and border-width sets the width of what stroke paints. The camera opens on what is highlighted, or on what only and except leave.

A world map without Antarctica, France, Germany and Italy filled and outlined in teal, the rest plain land.A world map without Antarctica, France, Germany and Italy filled and outlined in teal, the rest plain land.
region:world(
    except: Antarctica
    highlight: France, Germany, Italy
    centre: 0, 0
    zoom: 1
)
Warning
A name in only, except or highlight that matches nothing draws nothing.

A map has one set of boundaries. Data on a second pack is a choropleth with its own basemap, below.

#centre, zoom and the fly-to

The frame is a camera: centre, latitude first, and zoom, in web-map levels where each level halves the span. On equal-earth, mercator and equirectangular, zoom: 1 fits the world's width; on a globe it fits the sphere; on albers-usa it fits the composite. Zoom runs from 0.5 to 9.

Omit them and the environment fits what it draws across every step, keyframes included, so a marker that travels stays in frame for its whole journey. Markers placed with at, arc ends, choropleth packs and the regions the map picks out count; data-bound markers do not. A single marker opens at zoom 0.5, centred on it. albers-usa does not fit: it opens on the lower 48.

Both are animatable, and a !cue.to on each with the same anchor flies the camera from one frame to the other. centre may also name a marker the map draws, centre: #tokyo, so a map framed on a place it also pins states the place once; a keyframe from one marker to another glides between them.

Three frames of a map flying from the whole world in to France and Germany, filled teal.Three frames of a map flying from the whole world in to France and Germany, filled teal.
region#tour:world(
    highlight: France, Germany
    centre: 20, 0 !cue.to{50.5, 15}(at: 1; duration: 900ms)
    zoom: 1 !cue.to{4}(at: 1; duration: 900ms)
)

interactive hands the camera to the reader: scroll to zoom, drag to pan, double-click to reset. The reader cannot zoom out past the frame that fits the map's subject, or past 0.5 on a world map or a globe, nor pan away from it. Their camera then overrides the authored one for the session, and continue: #id carries it into a later region environment that is itself interactive. The scene's parameters do not travel with it.

#Overlays

Everything drawn over the boundaries is an overlay, and the three take opacity and hidden, which is animatable, so hidden: true !cue.to{false}(at: 2) is a reveal. Of the cues, a region body takes cue and cue.draw, plus the controls and their cue twins; cue.highlight and cue.spotlight are refused.

#Joining a dataset to regions

choropleth joins a dataset onto a pack's regions and shades them. regions names the column of region names or codes, matched as only matches, and value the column to shade by. A region the data does not cover keeps the plain land fill.

value is a column of numbers: what each region reads. colour is the ramp it is shaded along: multicolour (the default, violet to red), temperature (blue through white to red), a single hue's own intensity, or a list of stops, low end first, over the least and greatest values. The value column applied to an interval and a ramp pins the ends instead, colour: #gdp.gdppc -> 0..50000 -> multicolour.

Warning
A value column of words compiles but shades nothing.

A column of categories applied to a map colours each region flat in the colour its category is mapped to (Styling marks from data). Each category is one entry in the legend, under its own name, and a category the map does not name takes its otherwise, one entry for them all, or without one keeps the plain land fill.

region:australia-states{
    choropleth(
        regions: #vote.state
        value: #vote.margin
        colour: #vote.party -> (Labor: red; Coalition: blue)
    )
}(
    title: Who led each state
)

A map whose keys are intervals classes the regions instead: each is painted flat in the colour of the band its reading falls in, and each band is a name in the key.

region:world{
    choropleth(
        regions: #gdp.country
        value: #gdp.gdppc
        colour: #gdp.gdppc -> (..<5000: red; 5000..<20000: orange; 20000..: green)
    )
}

#Places

marker is a point on the earth, in two forms. Singly, at takes a coordinate, latitude first, with an optional label; either half may be an expression of the scene's parameters, so a marker rides a slider or a keyframe. Data-bound, lat and lon name columns and the one node draws every row. size, colour and opacity are style attributes: a column applied to an interval and a size makes a proportional-symbol map, size: #quakes.magnitude -> 6..9 -> 4 + 12_ drawing magnitude 6 at size 4 and 9 at size 16. A row whose size is zero or less draws nothing.

region:world{
    marker(lat: #quakes.lat; lon: #quakes.lon; size: #quakes.magnitude -> 6..9 -> 4 + 12_; colour: red; opacity: 0.6)
}

#Great-circle routes

arc draws the great-circle route between two places, the shortest way over the earth. On a mercator map the London–Tokyo arc bends far north of the straight line between them. Either end may name a marker placed with at, and then follows it.

Three frames of a Mercator world map with markers at London and Tokyo, the great-circle route between them drawing in beneath the markers.Three frames of a Mercator world map with markers at London and Tokyo, the great-circle route between them drawing in beneath the markers.
region:world{
    cue.draw{
        arc#route(from: #london; to: #tokyo; label: {{round(#route.length, 0)}} km)
    }(
        in: 1
        in-duration: 1200ms
    )
    marker#london(at: 51.47, -0.46; label: London)
    marker#tokyo(at: 35.55, 139.78; label: Tokyo)
}(
    projection: mercator
)

#Moving a map through time

A map moves through its data in one of two ways, and the shape of the data decides which. For a handful of columns side by side, chain them: value is animatable, so #y1990.rate !cue.to{#y2000.rate}(at: 1) eases each region between its two readings.

Tip
Pin the window when you chain columns, colour: #y1990.rate -> 0..220 -> multicolour, or the scale is re-fitted every frame and the change hides itself.

For long-format data, one row per region per year, a control whose column: is the year column takes its range, stops and format from the data, and a choropleth given slice on the same column reads itself against it, easing each region between the two readings either side of the control. As a cue.slider the scene runs the years itself from its anchor, on the step's own transport.

region:world{
    cue.slider#years:t(column: #rates.year; name: Year; at: 1; duration: 12s)
    choropleth(regions: #rates.country; value: #rates.rate; slice: #rates.year; colour: #rates.rate -> 0..220 -> multicolour)
}

A slice column of names rather than years cannot be eased between, so its control is a selector, and the map shows the rows carrying the name the reader picked. With no control over its column, a sliced choropleth shows each region's first row.

#Derived values

Two overlays publish what they compute. A choropleth publishes min, max, mean and count over the regions its data covered, and an arc publishes length, in kilometres along the great circle. A control publishes value, the year or the name it stands on. Each is read on an overlay or control with an id, and not while it is hidden: #route.length in an attribute, {{#route.length}} in prose. The environment itself publishes area, the land its basemap draws in square kilometres, only: and except: applied. Derived attributes covers how they behave.

Prose can cite the spread a choropleth's shading spans instead of a number typed in beside it: choropleth#gdp(…), then {{#gdp.max}}.

#Attributes

basemapImplicit
The boundaries drawn beneath the overlays, inherited by every choropleth.
worldus-statescanada-provincesaustralia-statesuk-countiesnz-regionseurope-admin1
Can be written as shorthand: region:value
only
Restricts the map to these regions, by name or ISO alpha-3 code.
except
Leaves these regions off the map.
highlight
Picks these regions out; they take fill: and stroke:.
fillAnimatable
The fill colour of the highlighted regions, or of every region drawn when nothing is highlighted.
paint
strokeAnimatable
The border colour of the highlighted regions, or of every region drawn when nothing is highlighted.
paint
border-widthAnimatable
The width of the borders stroke: paints.
Default1
name-property
The feature property holding each region's name, which a choropleth joins on.
codes
A feature property holding a short join code, like a pack region's ISO alpha-3.
simplify
Douglas-Peucker tolerance in degrees, thinning boundary detail as the file is read.
Default0
title
The caption over the map's top left.
projection
How the sphere is laid flat.
equal-earthmercatorequirectangularconicalbers-usaglobe
Defaultequal-earth
centreAnimatable
Where the camera looks: a latitude and longitude, or a marker's #id.
Also written: center
zoomAnimatable
The camera's zoom, in web-map levels that each halve the span.
interactive
Lets the reader zoom, pan and reset the map.
Defaultfalse
show-scaleAnimatable
The scale bar at the end of the footer.
Also written: scale
Defaulttrue
show-graticuleAnimatable
Draws the latitude and longitude grid over the map.
Also written: graticule
Defaultfalse
graticule-spacing
The degrees between graticule lines.
Default15
continue
An earlier region environment whose reader camera this one starts from.

#Derived attributes

Computed while the element renders — read one with #id.name in attribute position or {{#id.name}} in prose, never set.

areaDerived
The land the basemap draws, in square kilometres.

#Allowed content

#Allowed in

#Examples

The world on the Equal Earth projection, titled The world.The world on the Equal Earth projection, titled The world.
region:world(title: The world)
The Australian states shaded by the winning party’s margin, red for Labor and blue for the Coalition, titled Who led each state.The Australian states shaded by the winning party’s margin, red for Labor and blue for the Coalition, titled Who led each state.
region:australia-states{
    choropleth(regions: #vote.state; value: #vote.margin; colour: #vote.party -> (Labor: red; Coalition: blue))
}(
    title: Who led each state
)
The world as a globe seen from space, centred on Australia, the far hemisphere hidden behind the horizon.The world as a globe seen from space, centred on Australia, the far hemisphere hidden behind the horizon.
region:world{ }(
    projection: globe
    centre: -20, 135
)
The Canadian provinces on a conic projection, shaded by unemployment, Newfoundland and Labrador reddest, at the top of the scale.The Canadian provinces on a conic projection, shaded by unemployment, Newfoundland and Labrador reddest, at the top of the scale.
region:canada-provinces{
    choropleth(regions: #d.province; value: #d.rate)
}(
    projection: conic
)
The United States by state, every border drawn grey.The United States by state, every border drawn grey.
region:us-states(
    projection: albers-usa
    stroke: grey
)
Quebec and Ontario filled and outlined in orange among the plain Canadian provinces, on a conic projection.Quebec and Ontario filled and outlined in orange among the plain Canadian provinces, on a conic projection.
region:canada-provinces(
    projection: conic
    highlight: Quebec, Ontario
    fill: orange
)

#Notes

  • An environment's own id is written on the node — region#europe{…} — and continue: points back at it with #europe.
  • Of the cues, a region body takes cue and cue.draw, which traces an arc along its length; cue.highlight and cue.spotlight are refused.
  • There is no boundary node, so a map has one set of boundaries; data on a second pack is a choropleth with its own basemap:.
  • The cursor's coordinates, and the name of the region beneath it, read out at the start of the footer; the scale bar sits at its end.

#Writing guidance

  • Selecting canvas content — A mark belongs on the canvas when seeing it changes what the reader understands, and the detail holds as a picture on its own.

Last updated