Published
Edited
Feb 26, 2021
1 fork
3 stars
Insert cell
Insert cell
container = html`<div/>`
Insert cell
layout({ nodes: nodes, edges: edges }).then(({ nodes, edges }) => {
const { x, y, zoom } = trellis.boundsToViewport(
trellis.getSelectionBounds(nodes, 40),
{ width: width, height: 600 }
)

const options = {
x,
y,
zoom,
width: width,
height: 600,
onNodeDrag: ({ nodeX: x, nodeY: y, target: { id } }) => {
nodes = nodes.map((node) => node.id === id ? { ...node, x, y } : node)
render({ nodes, edges, options })
},
onNodePointerEnter: ({ target }) => {
nodes = nodes.map((node) => target.id === node.id ? {
...node,
style: {
...node.style,
stroke: [...node.style.stroke, { color: '#ccc', width: 2 }]
}
} : node)
render({ nodes, edges, options })
},
onNodePointerLeave: ({ target }) => {
nodes = nodes.map((n) => target.id === n.id ? ({ ...n, style: styleNode(n.count) }) : n)
render({ nodes, edges, options })
}
}

render({ nodes, edges, options })
})
Insert cell
render = {
const render = trellis.renderers.WebGL.Renderer({ container })
invalidation.then(() => render.delete())
return render
}
Insert cell
layout = trellis.layout.Force.Layout()
Insert cell
Insert cell
Insert cell
Insert cell
NODE_PERSON_STYLE = {
return {
color: '#7CBBF3',
labelSize: 10,
labelWordWrap: 260,
stroke: [{ color: '#FFF', width: 2 }, { color: '#90D7FB', width: 1 }],
icon: { type: 'textIcon', family: 'Material Icons', text: 'person', color: '#fff', size: 21 },
badge: [{
position: 45,
color: '#7CBBF3',
stroke: '#FFF',
icon: {
type: 'textIcon',
family: 'Helvetica',
size: 10,
color: '#FFF',
text: '8',
}
}],
}
}
Insert cell
Insert cell
styleNode = (group) => ({
color: color(group),
labelSize: 10,
labelWordWrap: 260,
stroke: [{ color: '#FFF', width: 2 }, { color: color(group), width: 1 }],
icon: { type: 'textIcon', family: 'Material Icons', text: 'person', color: '#fff', size: 21 },
badge: [{
position: 45,
color: color(group),
stroke: '#FFF',
icon: {
type: 'textIcon',
family: 'Helvetica',
size: 10,
color: '#FFF',
text: '8',
}
}],
})
Insert cell
NODE_COMPANY_STYLE = {
return {
color: '#FFAF1D',
stroke: [{ color: '#FFF', width: 4 }, { color: '#F7CA4D' }],
icon: { type: 'textIcon', family: 'Material Icons', text: 'business', color: '#fff', size: 21 },
badge: [{
position: 45,
color: '#FFAF1D',
stroke: '#FFF',
icon: {
type: 'textIcon',
family: 'Helvetica',
size: 10,
color: '#FFF',
text: '15',
}
}, {
position: 135,
color: '#E4171B',
stroke: '#FFF',
icon: {
type: 'textIcon',
family: 'Helvetica',
size: 10,
color: '#FFF',
text: '!',
}
}],
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more