Platform
Resources
Pricing
Sign in
Get started
Toph Tucker
Workspace
Fork
Public
Utilities
By
Toph Tucker
Edited
Mar 19, 2023
12 stars
Insert cell
Insert cell
sales
=
[
{
units
:
10
,
fruit
:
"fig"
}
,
{
units
:
20
,
fruit
:
"date"
}
,
{
units
:
40
,
fruit
:
"plum"
}
,
{
units
:
30
,
fruit
:
"Siberian apricot"
}
]
Insert cell
Plot
.
dot
(
sales
,
{
x
:
"units"
,
y
:
"fruit"
}
)
.
plot
(
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
length
=
measureText
(
string
,
fontSize
)
Insert cell
Insert cell
d3
.
max
(
sales
,
(
d
)
=>
measureText
(
d
.
fruit
,
10
)
)
Insert cell
Insert cell
Plot
.
dot
(
sales
,
{
x
:
"units"
,
y
:
"fruit"
}
)
.
plot
(
{
marginLeft
:
d3
.
max
(
sales
,
(
d
)
=>
measureText
(
d
.
fruit
,
10
)
)
}
)
Insert cell
Insert cell
tickLabelPadding
=
9
+
10
Insert cell
Plot
.
dot
(
sales
,
{
x
:
"units"
,
y
:
"fruit"
}
)
.
plot
(
{
marginLeft
:
d3
.
max
(
sales
,
(
d
)
=>
measureText
(
d
.
fruit
,
10
)
)
+
tickLabelPadding
}
)
Insert cell
Insert cell
2
autoMargin
=
(
data
,
accessor
)
=>
d3
.
max
(
Plot
.
valueof
(
data
,
accessor
)
,
(
d
)
=>
measureText
(
d
,
10
)
)
+
tickLabelPadding
Insert cell
Plot
.
dot
(
sales
,
{
x
:
"units"
,
y
:
"fruit"
}
)
.
plot
(
{
marginLeft
:
autoMargin
(
sales
,
"fruit"
)
}
)
Insert cell
Insert cell
measureText
=
(
str
,
fontSize
=
10
)
=>
d3
.
sum
(
str
,
(
cur
)
=>
characterWidths
[
cur
.
charCodeAt
(
0
)
]
??
avg
)
*
fontSize
Insert cell
avg
=
d3
.
mean
(
characterWidths
.
filter
(
(
d
)
=>
d
)
)
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
sales
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
string
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
fontSize
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
length
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
tickLabelPadding
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
autoMargin
Show 2 comments
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
measureText
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
avg
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
characterWidths
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML