git ssb

2+

dinoworm 🐛 / ssb-graphviz



Commit 41ec31f643175bf360ff1416e6448bffcccb4212

factor out building of nodes + links

mix irving committed on 12/7/2016, 8:43:20 AM
Parent: 0acc3cf490d4cdb39255ca110e2975c7c7d40768

Files changed

graph.jschanged
index.jschanged
package.jsonchanged
graph.jsView
@@ -1,33 +1,64 @@
11 const pull = require('pull-stream')
22 const Sbot = require('ssb-client')
3 +const avatar = require('ssb-avatar')
34 const waterfall = require('run-waterfall')
45
6 +const { keys } = Object
7 +
58 module.exports = Graph
69
710 function Graph (sbot, cb) {
811 waterfall([
912 (cb) => sbot.friends.all(cb),
1013 (friends, cb) => {
14 + const filteredFriends = friends // activeFriends(friends)
15 +
1116 cb(null, {
12- nodes: Object.keys(friends).map(id => ({ id })),
13- links: Object.keys(friends).reduce((sofar, friend) => {
14- const friendOfFriends = Object.keys(friends[friend])
15- .filter(id => friends[friend][id] === true)
16- const edges = friendOfFriends.map(friendOfFriend => {
17- return {
18- fromId: friend,
19- toId: friendOfFriend,
20- data: {
21- hidden: true
22- }
23- }
24- })
25- return [
26- ...sofar,
27- ...edges
28- ]
29- }, [])
17 + nodes: buildNodes(filteredFriends),
18 + links: buildLinks(filteredFriends)
3019 })
3120 }
3221 ], cb)
3322 }
23 +
24 +function buildNodes(friends) {
25 + return keys(friends).map(id => ({ id }) )
26 +}
27 +
28 +function buildLinks(friends) {
29 + return keys(friends).reduce((sofar, friend) => {
30 + const friendOfFriends = keys(friends[friend])
31 + .filter(id => friends[friend][id] === true)
32 + // .filter(id => keys(friends).indexOf(id) > -1)
33 +
34 + const edges = friendOfFriends.map(friendOfFriend => {
35 + return {
36 + fromId: friend,
37 + toId: friendOfFriend,
38 + data: {
39 + hidden: true
40 + }
41 + }
42 + })
43 +
44 + return [
45 + ...sofar,
46 + ...edges
47 + ]
48 + }, [])
49 +
50 +}
51 +
52 +function activeFriends (friends) {
53 + return keys(friends)
54 + .reduce(
55 + (sofar, current) => {
56 + if (keys(friends[current]).length < 4) return sofar
57 +
58 + sofar[current] = friends[current]
59 + return sofar
60 + },
61 + {}
62 + )
63 +}
64 +
index.jsView
@@ -35,8 +35,9 @@
3535
3636
3737 function handleNodeHover (node) {
3838 if (node === undefined) return
39 + console.log('handleNodeHover node: ', node)
3940
4041 node.links
4142 .map(link => display.getLink(link.id))
4243 .forEach(linkUI => {
package.jsonView
@@ -29,8 +29,9 @@
2929 "ngraph.fromjson": "^0.1.8",
3030 "ngraph.pixel": "^2.2.0",
3131 "pull-stream": "^3.4.5",
3232 "run-waterfall": "^1.1.3",
33 + "ssb-avatar": "^0.2.0",
3334 "ssb-client": "^4.3.0",
3435 "stream-to-pull-stream": "^1.7.2"
3536 }
3637 }

Built with git-ssb-web