git ssb

2+

dinoworm ๐Ÿ› / ssb-graphviz



Tree: 9972d073007ebc1c4cf8c6074bc2c3e3e5e032b5

Files: 9972d073007ebc1c4cf8c6074bc2c3e3e5e032b5 / renderer.js

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

Built with git-ssb-web