Platform
Solutions
Resources
Pricing
Sign in
Sign up
Tiffany France
Workspace
Fork
Public
By
Tiffany France
Edited
Apr 14, 2021
1
Insert cell
md
`# Mineral Bubbles`
Insert cell
chart
=
{
const
svg
=
d3
.
create
(
'svg'
)
.
attr
(
'viewBox'
,
[
0
,
0
,
width
,
height
]
)
;
buildCircles
(
svg
,
topData
,
topY
)
;
buildCircles
(
svg
,
bottomData
,
bottomY
)
;
return
svg
.
node
(
)
;
}
Insert cell
function
buildCircles
(
svg
,
data
,
y
)
{
let
x
=
deltaX
/
2
;
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
svg
.
append
(
'g'
)
.
selectAll
(
'circle'
)
.
data
(
data
[
i
]
)
.
join
(
'circle'
)
.
attr
(
'cx'
,
x
)
.
attr
(
'cy'
,
d
=>
y
(
d
[
'Happiness Score'
]
)
)
.
attr
(
'r'
,
3
)
.
style
(
'opacity'
,
0.1
)
.
attr
(
'fill'
,
'white'
)
x
+=
deltaX
;
}
}
Insert cell
deltaX
=
(
width
-
margin
.
left
-
margin
.
right
)
/
data
.
length
;
Insert cell
bottomY
=
d3
.
scaleLinear
(
)
.
domain
(
d3
.
extent
(
bottomData
.
flat
(
)
,
d
=>
d
[
'Happiness Score'
]
)
)
.
range
(
[
height
-
margin
.
bottom
,
(
height
/
2
)
+
halfMiddleSize
]
)
;
Insert cell
topY
=
d3
.
scaleLinear
(
)
.
domain
(
d3
.
extent
(
topData
.
flat
(
)
,
d
=>
d
[
'Happiness Score'
]
)
)
.
range
(
[
(
height
/
2
)
-
halfMiddleSize
,
margin
.
top
]
)
;
Insert cell
bottomData
=
data
.
map
(
d
=>
d
.
filter
(
d2
=>
d2
[
'Happiness Score'
]
<
5
)
)
Insert cell
topData
=
data
.
map
(
d
=>
d
.
filter
(
d2
=>
d2
[
'Happiness Score'
]
>=
5
)
)
Insert cell
data
=
await
FileAttachment
(
"alice-in-wonderland-hedonometer.json"
)
.
json
(
)
Insert cell
halfMiddleSize
=
(
height
*
middlePercent
)
/
2
Insert cell
middlePercent
=
0.1
Insert cell
height
=
600
Insert cell
margin
=
(
{
top
:
10
,
right
:
10
,
bottom
:
10
,
left
:
10
}
)
Insert cell
Insert cell
d3
=
require
(
'd3@6'
)
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
chart
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
buildCircles
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
deltaX
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
bottomY
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
topY
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
bottomData
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
topData
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
halfMiddleSize
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
middlePercent
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
margin
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
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML