Platform
Resources
Pricing
Sign in
Get started
Jordan Kanter
Workspace
Fork
Public
By
Jordan Kanter
Edited
Sep 16, 2023
ISC
Fork of
d3.scaleLinear
1
Insert cell
Insert cell
lin
=
d3
.
scaleLinear
(
)
Insert cell
Insert cell
Insert cell
Insert cell
run2pixels
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
42.195
]
)
// unit: km
.
range
(
[
0
,
600
]
)
// unit: pixels
Insert cell
run2pixels
(
0
)
// The start line
Insert cell
run2pixels
(
42.195
)
// The distance of a full marathon is 42.195 km; represented by 600 pixels
Insert cell
run2pixels
(
10
*
1.609344
)
// 10 miles
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
grades
=
d3
.
scaleLinear
(
)
.
rangeRound
(
[
0
,
3
]
)
Insert cell
grades
(
63
/
100
)
Insert cell
[
"D"
,
"C"
,
"B"
,
"A"
]
[
grades
(
63
/
100
)
]
Insert cell
Insert cell
children
=
d3
.
scaleLinear
(
)
.
rangeRound
(
[
0
,
46
]
)
Insert cell
children
(
90
/
100
)
Insert cell
Insert cell
Insert cell
piecewiseScale
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
100
,
200
,
300
,
400
]
)
.
range
(
[
220
,
200
,
100
,
200
,
150
]
)
// add + Math.sin(now / 1000) * 50 to one of these for animation
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
crayons
=
d3
.
scaleLinear
(
)
.
domain
(
[
-
1
,
0
,
1
]
)
.
range
(
[
"orange"
,
"white"
,
"green"
]
)
Insert cell
Insert cell
Insert cell
Insert cell
date
=
d3
.
scaleLinear
(
)
.
range
(
[
new
Date
(
"2009-01-01T00:00:00"
)
,
new
Date
(
"2009-12-31T23:59:59"
)
]
)
Insert cell
date
(
0.5
)
Insert cell
days
=
d3
.
scaleLinear
(
)
.
range
(
[
new
Date
(
"2009-01-01"
)
,
new
Date
(
"2009-12-31"
)
]
)
Insert cell
days
(
0.5
)
Insert cell
Insert cell
Insert cell
opacity
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
10
]
)
.
range
(
[
0
,
1
]
)
.
clamp
(
true
)
// try with false instead
Insert cell
opacity
(
-
1
)
// -1 is outside the domain!
Insert cell
opacity
(
15
)
// 15 is outside the domain!
Insert cell
Insert cell
opacity
.
clamp
(
)
Insert cell
Insert cell
paint
=
d3
.
scaleLinear
(
)
.
range
(
[
"yellow"
,
"red"
]
)
.
unknown
(
"#ccc"
)
Insert cell
paint
(
NaN
)
Insert cell
Insert cell
Insert cell
Insert cell
paint
.
unknown
(
)
Insert cell
Insert cell
paint
.
invert
(
"red"
)
Insert cell
Insert cell
opacity
.
clamp
(
true
)
.
invert
(
-
1
)
Insert cell
Insert cell
d3
.
scaleLinear
(
)
.
domain
(
[
-
30
,
0
,
30
]
)
.
range
(
[
1
,
0
,
1
]
)
.
clamp
(
true
)
.
invert
(
0.4
)
Insert cell
Insert cell
scaleRound
=
d3
.
scaleLinear
(
)
.
range
(
[
0
,
960
]
)
.
interpolate
(
d3
.
interpolateRound
)
Insert cell
scaleRound
(
1
/
3
)
Insert cell
Insert cell
scaleDecimal
=
d3
.
scaleLinear
(
)
.
range
(
[
0
,
960
]
)
.
interpolate
(
function
(
a
,
b
)
{
const
c
=
b
-
a
;
return
function
(
t
)
{
return
+
(
a
+
t
*
c
)
.
toFixed
(
1
)
;
}
;
}
)
Insert cell
scaleDecimal
(
2
/
7
)
Insert cell
Insert cell
scaleDecimal
.
interpolate
(
)
Insert cell
Insert cell
Insert cell
Insert cell
d3
=
require
(
"d3-scale@4"
,
"d3-array@2"
,
"d3-interpolate@3"
)
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
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
lin
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
run2pixels
Add comment
Copy import
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
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
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
rangeRound
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
grades
Add comment
Copy import
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
children
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
piecewise
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
piecewiseScale
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
crayons
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
date
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
days
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
opacity
Add comment
Copy import
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
paint
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
values
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
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
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
interpolate
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
scaleRound
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
scaleDecimal
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
identity
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
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML