Platform
Resources
Pricing
Sign in
Get started
Eric Field
Building and Using Tools to See. UVA Architecture + Data Science. IT Director. Instructor.
Workspace
Fork
Public
Maps
By
Eric Field
Edited
Apr 3, 2022
Fork of
Maps (Geographic)
•
5 forks
1
Insert cell
Insert cell
Insert cell
viewof
year
=
Inputs
.
range
(
[
1961
,
2011
]
,
{
label
:
"Year"
,
step
:
1
,
value
:
1994
}
)
Insert cell
map
=
d3
.
select
(
mapContainer
)
Insert cell
import
{
getMapData
,
drawMapLayer
}
from
"@emfielduva/dvlib_maps"
Insert cell
world
=
getMapData
(
"world110m"
)
Insert cell
mapLayers
=
{
let
mapLayers
=
[
]
;
mapLayers
[
"countries"
]
=
drawMapLayer
(
map
,
"countries"
,
world
.
features
,
world
.
idField
)
;
return
mapLayers
;
}
Insert cell
<
style
>
#
countries
path
{
fill
:
#eeeeee
;
stroke
:
#ccc
}
</
style
>
Insert cell
Insert cell
Insert cell
gdp
=
FileAttachment
(
"world-gdp-growth.csv"
)
.
csv
(
)
Insert cell
Insert cell
import
{
colorByID
,
toNum
}
from
"@emfielduva/dvlib"
Insert cell
Insert cell
colorScale
=
d3
.
scaleLinear
(
)
.
domain
(
[
-
25
,
0
,
25
]
)
.
range
(
[
"red"
,
"gray"
,
"green"
]
)
Insert cell
Insert cell
//year = "1994" // this is commented out to use the range slider at the top to define year
Insert cell
Now invoke the colorByID function imported.
This connects the "Country Code" in the gdp dataset to the "id" in the geographic map data.
The syntax of this command is:
Insert cell
colorByID
Insert cell
Insert cell
colorByID
(
mapLayers
[
"countries"
]
,
gdp
,
"id"
,
"Country Code"
,
year
,
''
,
colorScale
)
Insert cell
Insert cell
Insert cell
// data.forEach(d => {
// objectSet.filter(o=>o[objectIDfield] == d[dataIDfield])
// .style("fill",colorScale(toNum(d[dataValueField])))
// })
Insert cell
Insert cell
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
mapContainer
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
year
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
map
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
world
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
mapLayers
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
gdp
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
colorScale
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML