Platform
Resources
Pricing
Sign in
Contact us
Daniel Gavrilov
Workspace
Fork
Published
By
Daniel Gavrilov
Edited
Jun 3, 2020
Insert cell
Insert cell
Insert cell
Insert cell
pathLength
=
line
.
querySelector
(
"polyline"
)
.
getTotalLength
(
)
Insert cell
calculatedLength
=
d3
.
sum
(
d3
.
pairs
(
points
)
.
map
(
pair
=>
pointDist
(
...
pair
)
)
)
Insert cell
difference
=
pathLength
-
calculatedLength
Insert cell
lineSegments
=
1000
Insert cell
points
=
d3
.
range
(
lineSegments
)
.
map
(
_
=>
(
{
x
:
+
(
Math
.
random
(
)
*
200
)
.
toFixed
(
1
)
,
y
:
+
(
Math
.
random
(
)
*
200
)
.
toFixed
(
1
)
}
)
)
Insert cell
function
pointDist
(
p1
,
p2
)
{
return
Math
.
sqrt
(
Math
.
pow
(
p1
.
x
-
p2
.
x
,
2
)
+
Math
.
pow
(
p1
.
y
-
p2
.
y
,
2
)
)
}
Insert cell
d3
=
require
(
"d3@5"
)
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
line
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
pathLength
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
calculatedLength
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
difference
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
lineSegments
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
points
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
pointDist
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML