git ssb

2+

dinoworm ๐Ÿ› / ssb-graphviz



Tree: 4c04551a3e25f880780438f3d6ba6a54f100d610

Files: 4c04551a3e25f880780438f3d6ba6a54f100d610 / renderer.js

1798 bytesRaw
1const Renderer = require('ngraph.pixel')
2const avatar = require('ssb-avatar')
3const html = require('yo-yo')
4
5module.exports = createRenderer
6
7function createRenderer (graph, config, sbot) {
8 var avatarEl = html`<div class="avatar" />`
9 document.body.appendChild(avatarEl)
10
11 var display = Renderer(graph, config)
12
13 display.on('nodehover', handleNodeHover)
14
15 return display
16
17 function handleNodeHover (node) {
18 if (node === undefined) return
19
20 avatar(sbot, node.id, node.id, (err, { name, image }) => {
21 // handle this error!
22 if (err) throw err
23
24 const imgSrc = image ? `http://localhost:7777/${image}` : ''
25
26 const newAvatarEl = html`
27 <div class="avatar">
28 <img class="image" src=${imgSrc} />
29 <div class="name">${name}</div>
30 </div>
31 `
32
33 html.update(avatarEl, newAvatarEl)
34 })
35
36 display.forEachLink(linkUI => {
37 const { from, to } = linkUI
38 const friends = node.data.friends
39
40 const isFromTarget = node.id === from.id
41 const isToTarget = node.id === to.id
42
43 const isFromFriend = friends.indexOf(from.id) > -1
44 const isToFriend = friends.indexOf(to.id) > -1
45 const involvesFoaF = isFromFriend || isToTarget
46
47 var fromColor = 0x000066
48 var toColor = 0x000066
49
50 const close = 0xffffff
51 const mid = 0xa94caf
52 const far = 0x000066
53
54 if (isFromTarget) {
55 fromColor = close
56 toColor = mid
57 } else if (isToTarget) {
58 fromColor = mid
59 toColor = close
60 } else if (involvesFoaF && isFromFriend) {
61 fromColor = mid
62 toColor = far
63 } else if (involvesFoaF && isToFriend) {
64 fromColor = far
65 toColor = mid
66 }
67
68 linkUI.fromColor = fromColor
69 linkUI.toColor = toColor
70 })
71 }
72}
73

Built with git-ssb-web