Platform
Resources
Pricing
Sign in
Get started
Luke Murray
MIT Ph.D. Candidate in HCI
Workspace
Fork
Published
By
Luke Murray
Edited
Dec 8, 2020
1 star
2
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
canvas
.
update
(
activeLocations
)
// this cell is what fires the transition!
Insert cell
Insert cell
activeLocations
=
{
const
lowerName
=
name
.
toLocaleLowerCase
(
)
;
return
projectedLocations
.
map
(
v
=>
{
return
{
...
v
,
active
:
lowerName
.
length
===
0
?
false
:
v
.
name
.
toLocaleLowerCase
(
)
.
startsWith
(
lowerName
)
}
;
}
)
;
}
Insert cell
Insert cell
projectedLocations
=
locations
.
value
.
map
(
v
=>
{
return
{
...
v
,
...
projection
(
[
v
.
lon
,
v
.
lat
]
)
}
;
}
)
Insert cell
projection
=
d3
.
geoAlbersUsa
(
)
.
scale
(
width
)
.
translate
(
[
width
/
2
,
height
/
2
]
)
Insert cell
height
=
500
Insert cell
Insert cell
states
=
topojson
.
feature
(
us
,
us
.
objects
.
states
)
.
features
Insert cell
topojson
.
feature
(
us
,
us
.
objects
.
states
)
Insert cell
us
=
FileAttachment
(
"states-10m.json"
)
.
json
(
)
Insert cell
Insert cell
locations
=
{
// shortcut file attachment so this doesn't have to load on everyone's computer
// you can run the query yourself by uncommenting the code below
// and commenting out the file attachment
return
FileAttachment
(
"locations.json"
)
.
json
(
)
;
// const locations = [];
// let i = 0;
// for (const stateId of stateIds) {
// await queryDispatcher
// .query(
// `
// SELECT DISTINCT ?item ?name ?lat ?lon WHERE {
// hint:Query hint:optimizer "None". # subclass before getting items located in state
// ?item (wdt:P131+) wd:${stateId}; # items which are located in state
// (wdt:P31/(wdt:P279*)) wd:Q486972; # which are subclass of human settlement
// wdt:P625 ?coord; # get the coordinate location
// p:P625 ?coordinate. # get the coordinate location property statement
// ?coordinate psv:P625 ?coordinate_node. # get the coordinate location node
// ?coordinate_node wikibase:geoLatitude ?lat; # get the latitude
// wikibase:geoLongitude ?lon. # get the longitude
// SERVICE wikibase:label {
// bd:serviceParam wikibase:language "en".
// ?item rdfs:label ?name.
// }
// }
// ORDER BY (?name)
// `
// )
// .then(res =>
// res.map(r => {
// r.lat = +r.lat;
// r.lon = +r.lon;
// r.item = entityId(r.item);
// return r;
// })
// )
// .then(res => locations.push(...res));
// yield { progress: i++ / stateIds.length, value: locations };
// }
// return yield { value: locations };
}
Insert cell
Insert cell
Insert cell
Insert cell
import
{
queryDispatcher
,
entityId
}
from
"@lukesmurray/wikidata-sparql-helpers"
Insert cell
topojson
=
require
(
"topojson-client@3"
)
Insert cell
d3
=
require
(
"d3@6"
)
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
Fork
View
Export
intro
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
canvas
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
name
Edit
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
activeLocations
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
projectedLocations
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
projection
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
height
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
states
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
us
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
locations
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
stateIds
Edit
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
topojson
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML