Platform
Resources
Pricing
Sign in
Contact us
EBVL
Enrico Bertini's Visualization Lab
Workspace
Fork
Public
Practice Exercises
By
Dan Kerrigan
Edited
Jan 31
ISC
17 forks
Insert cell
Insert cell
Insert cell
Insert cell
<
svg
width
=
"100"
height
=
"100"
>
<
g
transform
=
"translate(50, 50)"
>
<
circle
r
=
"50"
fill
=
"steelblue"
/>
<
text
fill
=
"white"
font-size
=
"50"
dominant-baseline
=
"middle"
text-anchor
=
"middle"
>
vis
</
text
>
</
g
>
</
svg
>
Insert cell
{
}
Insert cell
Insert cell
segments
=
[
{
x1
:
5
,
y1
:
5
,
x2
:
5
,
y2
:
95
}
,
{
x1
:
45
,
y1
:
5
,
x2
:
45
,
y2
:
95
}
,
{
x1
:
5
,
y1
:
50
,
x2
:
45
,
y2
:
50
}
,
{
x1
:
55
,
y1
:
5
,
x2
:
95
,
y2
:
5
}
,
{
x1
:
55
,
y1
:
95
,
x2
:
95
,
y2
:
95
}
,
{
x1
:
75
,
y1
:
5
,
x2
:
75
,
y2
:
95
}
,
]
Insert cell
{
const
svg
=
d3
.
create
(
'svg'
)
.
attr
(
'width'
,
100
)
.
attr
(
'height'
,
100
)
;
// draw lines
return
svg
.
node
(
)
;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
widthIris
=
400
Insert cell
heightIris
=
400
Insert cell
marginIris
=
(
{
top
:
50
,
right
:
120
,
bottom
:
50
,
left
:
120
}
)
Insert cell
Insert cell
Insert cell
sepalLengthExtent
=
null
Insert cell
Insert cell
xIris
=
d3
.
scaleLinear
(
)
.
domain
(
)
.
nice
(
)
.
range
(
)
Insert cell
Insert cell
sepalWidthExtent
=
null
Insert cell
Insert cell
yIris
=
d3
.
scaleLinear
(
)
.
domain
(
)
.
nice
(
)
.
range
(
)
Insert cell
Insert cell
species
=
null
Insert cell
Insert cell
colorIris
=
d3
.
scaleOrdinal
(
)
.
domain
(
)
.
range
(
)
Insert cell
Insert cell
xAxisIris
=
null
Insert cell
yAxisIris
=
null
Insert cell
Insert cell
swatches
(
{
color
:
colorIris
}
)
Insert cell
{
const
svg
=
d3
.
create
(
'svg'
)
.
attr
(
'width'
,
widthIris
)
.
attr
(
'height'
,
heightIris
)
;
// draw the circles in circlesGroup
const
circlesGroup
=
svg
.
append
(
'g'
)
;
// create and add axes and axis labels
return
svg
.
node
(
)
;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sites
=
null
Insert cell
Insert cell
varities
=
null
Insert cell
Insert cell
varietySiteYields
=
null
Insert cell
Insert cell
maxYield
=
0
Insert cell
Insert cell
cellSize
=
60
Insert cell
marginsBarley
=
(
{
top
:
0
,
right
:
130
,
bottom
:
50
,
left
:
120
}
)
Insert cell
barleyWidth
=
varities
.
length
*
cellSize
+
marginsBarley
.
left
+
marginsBarley
.
right
Insert cell
barleyHeight
=
sites
.
length
*
cellSize
+
+
marginsBarley
.
top
+
marginsBarley
.
bottom
Insert cell
Insert cell
xBarley
=
d3
.
scalePoint
(
)
.
domain
(
)
.
range
(
)
.
padding
(
0.5
)
Insert cell
yBarley
=
d3
.
scalePoint
(
)
.
domain
(
)
.
range
(
)
.
padding
(
0.5
)
Insert cell
Insert cell
maxRadius
=
cellSize
/
2
-
2
Insert cell
Insert cell
radius
=
d3
.
scaleSqrt
(
)
.
domain
(
)
.
nice
(
)
.
range
(
)
Insert cell
Insert cell
xAxisBarley
=
null
Insert cell
yAxisBarley
=
null
Insert cell
Insert cell
{
// set up
const
svg
=
d3
.
create
(
'svg'
)
.
attr
(
'width'
,
barleyWidth
)
.
attr
(
'height'
,
barleyHeight
)
;
// draw circles
const
matrix
=
svg
.
append
(
'g'
)
;
// create one circle for each element in varietySiteYields
// set the cx, cy, r, and fill attributes for each circle
// draw the axes
// draw the size legend
svg
.
append
(
"g"
)
.
call
(
sizeLegend
)
;
return
svg
.
node
(
)
;
}
Insert cell
sizeLegend
=
g
=>
{
g
.
attr
(
"transform"
,
`translate(${
barleyWidth
-
marginsBarley
.
right
+
2
*
maxRadius
},20)`
)
.
attr
(
"font-family"
,
"sans-serif"
)
.
attr
(
"font-size"
,
12
)
;
g
.
append
(
'text'
)
.
attr
(
'font-weight'
,
'bold'
)
.
text
(
'Yield'
)
;
const
legend
=
g
.
selectAll
(
"g"
)
.
data
(
[
40
,
80
,
120
]
)
.
join
(
"g"
)
.
attr
(
"transform"
,
(
d
,
i
)
=>
`translate(0, ${
(
i
+
1
)
*
2
*
radius
(
d
)
})`
)
;
legend
.
append
(
"circle"
)
.
attr
(
"r"
,
d
=>
radius
(
d
)
)
.
attr
(
"fill"
,
"steelblue"
)
;
legend
.
append
(
"text"
)
.
attr
(
"x"
,
maxRadius
+
5
)
.
attr
(
"dominant-baseline"
,
"middle"
)
.
text
(
d
=>
d
)
;
}
Insert cell
Insert cell
Insert cell
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
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
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
segments
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
iris
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
widthIris
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
heightIris
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
marginIris
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
sepalLengthExtent
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
xIris
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
sepalWidthExtent
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
yIris
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
species
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
colorIris
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
xAxisIris
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
yAxisIris
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
barley
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sites
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
varities
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
varietySiteYields
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
maxYield
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
cellSize
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
marginsBarley
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
barleyWidth
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
barleyHeight
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
xBarley
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
yBarley
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
maxRadius
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
radius
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
xAxisBarley
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
yAxisBarley
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
sizeLegend
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
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
data
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML