David Pomerenke commited on
Commit
00e463a
·
1 Parent(s): 867080c

Chloropleth map based on NaturalEarth

Browse files
frontend/public/LICENSE CHANGED
@@ -1 +1 @@
1
- un.*.json: https://geoportal.un.org/arcgis/apps/sites/#/geohub/datasets/d7caaff3ef4b4f7c82689b7c4694ad92/about
 
1
+ world.*.json: official UN country boundaries from https://geoportal.un.org/arcgis/apps/sites/#/geohub/datasets/d7caaff3ef4b4f7c82689b7c4694ad92/about, transformed using https://observablehq.com/@bumbeishvili/rewind-geojson, https://github.com/topojson/topojson-client, and https://github.com/topojson/topojson-simplify
frontend/public/un.topo.json DELETED
The diff for this file is too large to render. See raw diff
 
frontend/public/world.geo.json ADDED
The diff for this file is too large to render. See raw diff
 
frontend/src/components/WorldMap.js CHANGED
@@ -2,44 +2,52 @@ import { useRef, useEffect, useState } from 'react'
2
  import * as topojson from 'topojson-client'
3
  import * as Plot from '@observablehq/plot'
4
 
5
- const WorldMap = () => {
6
  const containerRef = useRef()
7
- const [data, setData] = useState()
8
 
9
  useEffect(() => {
10
- fetch('/un.topo.json')
11
  .then(res => res.json())
12
- .then(setData)
13
  }, [])
14
 
15
  useEffect(() => {
16
- if (data === undefined) return
17
- // const plot = Plot.plot({
18
- // y: {grid: true},
19
- // color: {scheme: "burd"},
20
- // marks: [
21
- // Plot.ruleY([0]),
22
- // Plot.dot(data, {x: "Date", y: "Anomaly", stroke: "Anomaly"})
23
- // ]
24
- // });
25
- const countries = topojson.feature(data, data.objects.un)
26
  const plot = Plot.plot({
27
  width: 750,
28
  height: 400,
29
  projection: 'equal-earth',
30
  marks: [
31
  Plot.geo(countries, {
32
- // fill: d => console.log(d.properties?.iso2cd),
33
- // title: d => d.properties?.iso2cd
34
- // tip: true
 
 
 
35
  })
36
- ]
 
 
 
 
 
 
 
 
 
37
  })
38
  containerRef.current.append(plot)
39
  return () => plot.remove()
40
- }, [data])
41
 
42
- return <svg ref={containerRef} style={{ width: '100%', height: '100%' }} />
43
  }
44
 
45
  export default WorldMap
 
2
  import * as topojson from 'topojson-client'
3
  import * as Plot from '@observablehq/plot'
4
 
5
+ const WorldMap = ({ data }) => {
6
  const containerRef = useRef()
7
+ const [mapData, setMapData] = useState()
8
 
9
  useEffect(() => {
10
+ fetch('/world.geo.json')
11
  .then(res => res.json())
12
+ .then(setMapData)
13
  }, [])
14
 
15
  useEffect(() => {
16
+ if (mapData === undefined) return
17
+ const countries = mapData
18
+ // const countries = topojson.feature(mapData, mapData.objects["world.geo"])
19
+ console.log(countries)
20
+ const codes = countries.features.map(d => d.properties?.ISO_A2_EH)
21
+ console.log(codes.toSorted().join(', '))
 
 
 
 
22
  const plot = Plot.plot({
23
  width: 750,
24
  height: 400,
25
  projection: 'equal-earth',
26
  marks: [
27
  Plot.geo(countries, {
28
+ fill: d => {
29
+ const score = data.countries[d.properties?.ISO_A2_EH]?.score
30
+ return score
31
+ },
32
+ title: d => `<b>${d.properties?.ISO_A2_EH}</b> (${d.properties?.NAME_EN})`,
33
+ tip: true
34
  })
35
+ ],
36
+ color: {
37
+ range: ["red", "blue"],
38
+ unknown: 'gray',
39
+ // type: 'linear',
40
+ label: 'Score',
41
+ legend: true,
42
+ // percent: true,
43
+ domain: [0, 0.5]
44
+ }
45
  })
46
  containerRef.current.append(plot)
47
  return () => plot.remove()
48
+ }, [mapData])
49
 
50
+ return <div ref={containerRef} style={{ width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' }} />
51
  }
52
 
53
  export default WorldMap
maps.md ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Possible sources for maps:
2
+
3
+ - [Natural Earth](https://www.naturalearthdata.com/): Their main version is not politically correct, and they do provide additional "orld view" data, including for Germany, but not for UN or other international organizations, and it's not very straightforward to use. Also has some issues with ISO2 codes, one can use [`ISO_A2_EH`](https://github.com/nvkelso/natural-earth-vector/issues/284) to work around that; still lacking Somalia though.
4
+ - [UN](https://geoportal.un.org/arcgis/apps/sites/#/geohub/datasets/d7caaff3ef4b4f7c82689b7c4694ad92/about): Has some countries inverted, we can mostly [correct for that](https://observablehq.com/@bumbeishvili/rewind-geojson), but it still leaves some artifacts in Norway and the Gulf of Amerxico.
5
+ - [World Bank](https://datacatalog.worldbank.org/search/dataset/0038272): Has missing ISO2 country codes for France and Norway.
6
+ - [EU](https://ec.europa.eu/eurostat/web/gisco/geodata/administrative-units/countries): Displays very weirdly, haven't looked into the details.