Platform
Resources
Pricing
Sign in
Get started
Tom MacWright
hi!
Workspace
Fork
Published
By
Tom MacWright
Edited
Mar 18, 2018
Fork of
Sample notebook testing calling a function defined in one cell from another cell
2 stars
Insert cell
Insert cell
Insert cell
viewof
nodes
=
{
let
add
=
html
`<div><button>add Node</button></div>`
;
add
.
value
=
[
{
index
:
0
}
,
{
index
:
1
}
]
;
add
.
onclick
=
(
)
=>
{
add
.
value
.
push
(
{
index
:
add
.
value
.
length
}
)
;
add
.
dispatchEvent
(
new
CustomEvent
(
'input'
)
)
;
}
return
add
;
}
Insert cell
d3
.
forceSimulation
(
nodes
)
.
force
(
"charge"
,
d3
.
forceManyBody
(
)
.
strength
(
-
10
)
)
.
on
(
"tick"
,
ticked
)
Insert cell
size
=
(
{
height
:
500
,
width
:
500
}
)
Insert cell
function
ticked
(
)
{
context
.
clearRect
(
0
,
0
,
size
.
width
,
size
.
height
)
;
context
.
save
(
)
;
context
.
translate
(
size
.
width
/
2
,
size
.
height
/
2
)
;
context
.
beginPath
(
)
;
context
.
stroke
(
)
;
nodes
.
forEach
(
drawNode
)
;
context
.
fill
(
)
;
context
.
restore
(
)
;
}
Insert cell
function
drawNode
(
d
)
{
context
.
beginPath
(
)
;
context
.
moveTo
(
d
.
x
+
3
,
d
.
y
)
;
context
.
arc
(
d
.
x
,
d
.
y
,
3
,
0
,
2
*
Math
.
PI
)
;
context
.
fillStyle
=
"#aaa"
;
context
.
fill
(
)
;
context
.
stroke
(
)
;
}
Insert cell
context
=
DOM
.
context2d
(
500
,
500
)
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
Compare fork
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
nodes
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
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
ticked
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
drawNode
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
context
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML