git ssb

2+

dinoworm ๐Ÿ› / ssb-graphviz



Tree: 4c04551a3e25f880780438f3d6ba6a54f100d610

Files: 4c04551a3e25f880780438f3d6ba6a54f100d610 / graph.js

1242 bytesRaw
1const waterfall = require('run-waterfall')
2
3const { keys } = Object
4
5module.exports = Graph
6
7function Graph (sbot, cb) {
8 waterfall([
9 (cb) => sbot.friends.all(cb),
10 (friends, cb) => {
11 const filteredFriends = friends // activeFriends(friends)
12
13 cb(null, {
14 nodes: buildNodes(filteredFriends),
15 links: buildLinks(filteredFriends)
16 })
17 }
18 ], cb)
19}
20
21function buildNodes (friends) {
22 return keys(friends).map(id => {
23 return {
24 id,
25 data: {
26 friends: keys(friends[id])
27 }
28 }
29 })
30}
31
32function buildLinks (friends) {
33 return keys(friends).reduce((sofar, friend) => {
34 const friendOfFriends = keys(friends[friend])
35 .filter(id => friends[friend][id] === true)
36
37 const edges = friendOfFriends.map(friendOfFriend => {
38 return {
39 fromId: friend,
40 toId: friendOfFriend,
41 data: {
42 hidden: true
43 }
44 }
45 })
46
47 return [
48 ...sofar,
49 ...edges
50 ]
51 }, [])
52}
53
54/*
55function activeFriends (friends) {
56 return keys(friends)
57 .reduce(
58 (sofar, current) => {
59 if (keys(friends[current]).length < 4) return sofar
60
61 sofar[current] = friends[current]
62 return sofar
63 },
64 {}
65 )
66}
67*/
68

Built with git-ssb-web