Platform
Solutions
Resources
Pricing
Sign in
Sign up
Tim Oltman
Workspace
Fork
Published
By
Tim Oltman
Edited
Oct 9, 2020
3 forks
5 stars
2
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
showToolTip
=
(
text
,
coords
)
=>
{
d3
.
select
(
".tooltip"
)
.
text
(
text
)
.
style
(
"top"
,
coords
[
1
]
+
"px"
)
.
style
(
"left"
,
coords
[
0
]
+
"px"
)
.
style
(
"visibility"
,
"visible"
)
;
}
Insert cell
cScale
=
d3
.
scaleSqrt
(
)
.
domain
(
[
d3
.
min
(
data
,
d
=>
d
.
net_donations
)
,
0
,
d3
.
max
(
data
,
d
=>
d
.
net_donations
)
]
)
.
range
(
[
-
1
,
0
,
1
]
)
.
interpolate
(
(
a
,
b
)
=>
a
<
0
?
t
=>
d3
.
interpolateReds
(
1
-
t
)
:
t
=>
d3
.
interpolateBlues
(
t
)
)
Insert cell
height
=
{
const
[
[
x0
,
y0
]
,
[
x1
,
y1
]
]
=
d3
.
geoPath
(
projection
.
fitWidth
(
width
,
outline
)
)
.
bounds
(
outline
)
;
const
dy
=
Math
.
ceil
(
y1
-
y0
)
,
l
=
Math
.
min
(
Math
.
ceil
(
x1
-
x0
)
,
dy
)
;
projection
.
scale
(
projection
.
scale
(
)
*
(
l
-
1
)
/
l
)
.
precision
(
0.2
)
;
return
dy
;
}
Insert cell
outline
=
(
{
type
:
"Sphere"
}
)
Insert cell
projection
=
d3
.
geoNaturalEarth1
(
)
Insert cell
path
=
d3
.
geoPath
(
projection
)
Insert cell
countries
=
{
// group entities by name and year
const
entities
=
d3
.
group
(
data
,
d
=>
d
.
country
,
d
=>
d
.
year
)
;
// attach data to each country in properties
const
countries
=
topojson
.
feature
(
world
,
world
.
objects
.
countries
)
;
countries
.
features
.
forEach
(
country
=>
{
country
.
properties
.
data
=
entities
.
get
(
country
.
properties
.
name
)
;
}
)
return
countries
}
Insert cell
data
=
d3
.
csvParse
(
await
FileAttachment
(
"aiddata.csv"
)
.
text
(
)
,
d
=>
{
if
(
d
.
country
===
"United States"
)
{
d
.
country
=
"United States of America"
}
return
{
country
:
d
.
country
,
year
:
+
d
.
year
,
donations
:
+
d
.
donations
,
receipts
:
+
d
.
receipts
,
net_donations
:
+
d
.
net_donations
}
}
)
Insert cell
years
=
Array
.
from
(
new
Set
(
data
.
map
(
d
=>
d
.
year
)
.
sort
(
)
)
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
One platform
to build and deploy the best data apps
Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Try it for free
Learn more
Fork
View
Export
Edit
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
year
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
chart
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
showToolTip
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cScale
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
outline
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
path
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
countries
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
years
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
world
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
topojson
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
styles
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML