Platform
Resources
Pricing
Sign in
Get started
Anders
Workspace
Fork
Published
HEIG-visdom-2020
By
Anders
Edited
Apr 8, 2021
Insert cell
Insert cell
Insert cell
svg
`
<svg viewBox="0 0 ${
size
.
svg
.
width
} ${
size
.
svg
.
height
}">
<g transform="translate(${
size
.
svg
.
width
/
2
}, 50)">
${
drawLinks
(
root
.
links
(
)
)
}
${
drawNodes
(
root
.
descendants
(
)
)
}
</g>
</svg>
`
Insert cell
Insert cell
size
=
(
{
svg
:
{
width
,
height
:
width
/
5
}
,
node
:
{
width
:
200
,
height
:
50
}
,
}
)
Insert cell
Insert cell
root
=
d3
.
hierarchy
(
data
)
Insert cell
Insert cell
treeGenerator
=
d3
.
tree
(
)
.
nodeSize
(
[
size
.
node
.
width
,
size
.
node
.
height
]
)
Insert cell
Insert cell
tree
=
treeGenerator
(
root
)
Insert cell
Insert cell
drawNodes
=
nodes
=>
svg
`
<g text-anchor="middle">
${
nodes
.
map
(
d
=>
svg
`
<g transform="translate(${
d
.
x
}, ${
d
.
y
})">
<text fill="white" stroke="white" stroke-width="10">${
d
.
data
.
name
}</text>
<text>${
d
.
data
.
name
}</text>
</g>
`
)
}
</g>
`
Insert cell
Insert cell
linkGenerator
=
d3
.
linkVertical
(
)
.
x
(
d
=>
d
.
x
)
.
y
(
d
=>
d
.
y
)
Insert cell
Insert cell
drawLinks
=
links
=>
svg
`
<g>
${
links
.
map
(
d
=>
svg
`
<path d="${
linkGenerator
(
d
)
}" fill="none" stroke="lightgray" />
`
)
}
</g>
`
Insert cell
d3
=
require
(
"d3@6"
)
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
data
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
size
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
root
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
treeGenerator
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
tree
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
drawNodes
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
linkGenerator
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
drawLinks
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