Position labels on a node:
const scores = {
Lions: 35,
Zebras: 45,
Dolphins: 24,
Pandas: 29
}
const teams = Object.keys(scores).sort()
canvas.node(1).add({
shape: 'rect',
size: [80, 50],
labels: {
0: { remove: true },
title: {
text: 'Score Board',
color: 'white',
size: 12,
radius: 0,
angle: 0,
size: 15,
align: 'top-middle',
rotate: true,
pos: ['-x + 8', 0]
}
}
}).labels(teams).data(teams).add({
text: k => `${k}: ${scores[k]}`,
color: 'white',
size: 12,
radius: 0,
align: 'middle-right',
pos: (_, i) => [
'x - 12',
(i - (teams.length - 1) / 2) * -20
]
})
Position labels on an edge:
const scores = {
Lions: 35,
Zebras: 45,
Dolphins: 24,
Pandas: 29
}
const teams = Object.keys(scores)
const posAttrs = {
Lions: { pos: [-4, 4], align: 'bottom-right' },
Zebras: { pos: [4, 4], align: 'bottom-left' },
Dolphins: { pos: [-4, -4], align: 'top-right' },
Pandas: { pos: [4, -4], align: 'top-left' }
}
canvas.edgelayout('individual')
canvas.nodes([1, 2]).add()
canvas.edge([1, 2]).add({
length: 200
}).labels(teams).data(teams).add(k => ({
...posAttrs[k],
text: k + ': ' + scores[k],
rotate: false,
radius: 0
}))