git ssb

2+

dinoworm 🐛 / ssb-graphviz



Commit 9972d073007ebc1c4cf8c6074bc2c3e3e5e032b5

add avatar, show gradient of FoaF linkages

mix irving committed on 12/8/2016, 9:20:33 AM
Parent: f48fe05c0643f4ff42a70e4a1b4aaf3c239932ea

Files changed

index.jschanged
output.jschanged
package.jsonchanged
renderer.jschanged
index.jsView
@@ -2,9 +2,8 @@
22 const Path = require('path')
33 const fromJson = require('ngraph.fromjson')
44 const Renderer = require('./renderer')
55 const Graph = require('./graph')
6-const avatar = require('ssb-avatar')
76
87 const config = {
98 physics: {
109 springLength : 80,
@@ -28,9 +27,9 @@
2827 Graph(sbot, (err, data) => {
2928 if (err) return cb(err)
3029 const str = JSON.stringify(data)
3130 var graph = fromJson(str)
32- var display = Renderer(graph, config)
31 + var display = Renderer(graph, config, sbot)
3332
3433 cb(null, display)
3534 })
3635 }
output.jsView
@@ -10,8 +10,19 @@
1010 overflow: hidden;
1111 padding: 0;
1212 margin: 0;
1313 }
14 +
15 + #avatar {
16 + position: fixed;
17 + left: 10px;
18 + bottom: 10px;
19 + color: #fff;
20 + }
21 +
22 + #avatar img {
23 + max-height: 160px;
24 + }
1425 `)
1526
1627 Sbot((err, sbot) => {
1728 Viz(sbot, (err, viz) => {
package.jsonView
@@ -23,10 +23,12 @@
2323 },
2424 "dependencies": {
2525 "electro": "^2.0.2",
2626 "electron": "^1.4.4",
27 + "hyperscript": "^2.0.2",
2728 "insert-css": "^1.0.0",
2829 "inu": "^3.1.3",
30 + "morphdom": "^2.2.1",
2931 "ngraph.fromjson": "^0.1.8",
3032 "ngraph.pixel": "^2.2.0",
3133 "pull-stream": "^3.4.5",
3234 "run-waterfall": "^1.1.3",
renderer.jsView
@@ -1,39 +1,76 @@
11 const Renderer = require('ngraph.pixel')
2 +const h = require('hyperscript')
3 +const avatar = require('ssb-avatar')
4 +const Sbot = require('ssb-client')
5 +const morph = require('morphdom')
26
37 module.exports = createRenderer
48
5-function createRenderer (graph, config) {
9 +function createRenderer (graph, config, sbot) {
10 + var avatarEl = h('div#avatar')
11 + document.body.appendChild(avatarEl)
12 +
613 var display = Renderer(graph, config)
714
815 display.on('nodehover', handleNodeHover)
916
1017 return display
1118
1219 function handleNodeHover (node) {
1320 if (node === undefined) return
14- // avatar(sbot, node.id, node.id, (err, data) => console.log(err, data))
1521
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 +
1637 display.forEachLink(linkUI => {
1738 const { from, to } = linkUI
1839 const friends = node.data.friends
1940
20- const involvesFoaF = friends.indexOf(from.id) > -1 || friends.indexOf(to.id) > -1
2141 const isFromTarget = node.id === from.id
2242 const isToTarget = node.id === to.id
2343
44 + const isFromFriend = friends.indexOf(from.id) > -1
45 + const isToFriend = friends.indexOf(to.id) > -1
46 + const involvesFoaF = isFromFriend || isToTarget
47 +
2448 let fromColor = 0x000066
2549 let toColor = 0x000066
2650
27- if (involvesFoaF) {
28- fromColor = 0xeeeeee
29- toColor = 0xeeeeee
30- } else if (isFromTarget) {
31- fromColor = 0x00ff00
32- } else if (isToTarget) {
33- toColor = 0xff0000
51 + const close = 0xffffff
52 + const mid = 0xa94caf
53 + const far = 0x000066
54 +
55 + if (isFromTarget) {
56 + fromColor = close
57 + toColor = mid
3458 }
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 + }
3571
72 +
3673 linkUI.fromColor = fromColor
3774 linkUI.toColor = toColor
3875 })
3976

Built with git-ssb-web