Platform
Resources
Pricing
Sign in
Get started
Ryan Murphy
Doing stuff
Workspace
Fork
Published
By
Ryan Murphy
Edited
Oct 28, 2021
1 star
Insert cell
Insert cell
Insert cell
{
const
svg
=
d3
.
create
(
"svg"
)
.
attr
(
"width"
,
width
)
.
attr
(
"height"
,
200
)
;
const
path
=
svg
.
append
(
"path"
)
.
attr
(
"d"
,
line
(
walk
)
)
.
attr
(
"stroke"
,
"black"
)
.
attr
(
"fill"
,
"none"
)
;
const
[
x
,
y
]
=
getCoordinates
(
path
.
node
(
)
,
progress
)
;
svg
.
append
(
"circle"
)
.
attr
(
"cx"
,
x
)
.
attr
(
"cy"
,
y
)
.
attr
(
"r"
,
5
)
.
attr
(
"fill"
,
"tomato"
)
;
return
svg
.
node
(
)
;
}
Insert cell
function
getCoordinates
(
path
,
progress
)
{
const
length
=
path
.
getTotalLength
(
)
;
const
distance
=
length
*
progress
;
const
point
=
path
.
getPointAtLength
(
distance
)
;
return
[
point
.
x
,
point
.
y
]
;
}
Insert cell
walk
=
{
const
data
=
[
]
;
let
v
=
2
;
for
(
let
i
=
0
;
i
<
50
;
++
i
)
{
v
+=
Math
.
random
(
)
-
0.5
;
v
=
Math
.
max
(
Math
.
min
(
v
,
4
)
,
0
)
;
data
.
push
(
[
i
,
v
]
)
;
}
return
data
;
}
Insert cell
walkX
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
49
]
)
.
range
(
[
10
,
width
-
10
]
)
Insert cell
walkY
=
d3
.
scaleLinear
(
)
.
domain
(
[
0
,
4
]
)
.
range
(
[
200
-
10
,
10
]
)
Insert cell
line
=
d3
.
line
(
)
.
curve
(
d3
.
curveBasis
)
.
x
(
(
d
)
=>
walkX
(
d
[
0
]
)
)
.
y
(
(
d
)
=>
walkY
(
d
[
1
]
)
)
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
progress
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
getCoordinates
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
walk
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
walkX
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
walkY
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
line
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML