git ssb

2+

dinoworm 🐛 / ssb-graphviz



Commit 4c04551a3e25f880780438f3d6ba6a54f100d610

cleanup, use yo-yo, use standard style

Michael Williams committed on 12/8/2016, 10:17:32 AM
Parent: 9972d073007ebc1c4cf8c6074bc2c3e3e5e032b5

Files changed

graph.jschanged
index.jschanged
output.jschanged
package.jsonchanged
renderer.jschanged
profile.jsdeleted
test/index.jsdeleted
graph.jsView
@@ -1,6 +1,4 @@
1-const pull = require('pull-stream')
2-const Sbot = require('ssb-client')
31 const waterfall = require('run-waterfall')
42
53 const { keys } = Object
64
@@ -9,9 +7,9 @@
97 function Graph (sbot, cb) {
108 waterfall([
119 (cb) => sbot.friends.all(cb),
1210 (friends, cb) => {
13- const filteredFriends = friends // activeFriends(friends)
11 + const filteredFriends = friends // activeFriends(friends)
1412
1513 cb(null, {
1614 nodes: buildNodes(filteredFriends),
1715 links: buildLinks(filteredFriends)
@@ -19,9 +17,9 @@
1917 }
2018 ], cb)
2119 }
2220
23-function buildNodes(friends) {
21 +function buildNodes (friends) {
2422 return keys(friends).map(id => {
2523 return {
2624 id,
2725 data: {
@@ -30,13 +28,12 @@
3028 }
3129 })
3230 }
3331
34-function buildLinks(friends) {
32 +function buildLinks (friends) {
3533 return keys(friends).reduce((sofar, friend) => {
3634 const friendOfFriends = keys(friends[friend])
3735 .filter(id => friends[friend][id] === true)
38- // .filter(id => keys(friends).indexOf(id) > -1)
3936
4037 const edges = friendOfFriends.map(friendOfFriend => {
4138 return {
4239 fromId: friend,
@@ -51,11 +48,11 @@
5148 ...sofar,
5249 ...edges
5350 ]
5451 }, [])
55-
5652 }
5753
54 +/*
5855 function activeFriends (friends) {
5956 return keys(friends)
6057 .reduce(
6158 (sofar, current) => {
@@ -66,5 +63,5 @@
6663 },
6764 {}
6865 )
6966 }
70-
67 +*/
index.jsView
@@ -1,17 +1,15 @@
1-const fs = require('fs')
2-const Path = require('path')
31 const fromJson = require('ngraph.fromjson')
42 const Renderer = require('./renderer')
53 const Graph = require('./graph')
64
75 const config = {
86 physics: {
9- springLength : 80,
10- springCoeff : 0.0001,
7 + springLength: 80,
8 + springCoeff: 0.0001,
119 gravity: -1.4,
12- theta : 0.4,
13- dragCoeff : 0.04
10 + theta: 0.4,
11 + dragCoeff: 0.04
1412 },
1513 link: (link) => {
1614 // if (link.data.hidden) return
1715 // makes linkUI element not exist ? => display.getLink doesn't work
output.jsView
@@ -1,6 +1,8 @@
11 const insertCss = require('insert-css')
22 const Sbot = require('ssb-client')
3 +const waterfall = require('run-waterfall')
4 +
35 const Viz = require('./')
46
57 insertCss(`
68 html, body {
@@ -11,22 +13,19 @@
1113 padding: 0;
1214 margin: 0;
1315 }
1416
15- #avatar {
17 + .avatar {
1618 position: fixed;
1719 left: 10px;
1820 bottom: 10px;
1921 color: #fff;
2022 }
2123
22- #avatar img {
24 + .avatar .image {
2325 max-height: 160px;
2426 }
2527 `)
26-
27-Sbot((err, sbot) => {
28- Viz(sbot, (err, viz) => {
29- if (err) throw err
30- sbot.close()
31- })
28 +
29 +waterfall([Sbot, Viz], (err) => {
30 + if (err) throw err
3231 })
package.jsonView
@@ -3,9 +3,9 @@
33 "version": "0.0.0",
44 "description": "visualize the ssb network graph",
55 "main": "index.js",
66 "scripts": {
7- "test": "tape test.js",
7 + "test": "standard",
88 "start": "electro output.js"
99 },
1010 "repository": {
1111 "type": "git",
@@ -18,22 +18,23 @@
1818 "url": "https://git.scuttlebot.io/%25hNm67sfnZFtWkD%2F%2B1qxH3UfzhXykfpKtOL1C%2FXbLANA%3D.sha256/issues"
1919 },
2020 "homepage": "https://git.scuttlebot.io/%25hNm67sfnZFtWkD%2F%2B1qxH3UfzhXykfpKtOL1C%2FXbLANA%3D.sha256#readme",
2121 "devDependencies": {
22 + "standard": "^8.6.0",
2223 "tape": "^4.5.1"
2324 },
2425 "dependencies": {
2526 "electro": "^2.0.2",
2627 "electron": "^1.4.4",
2728 "hyperscript": "^2.0.2",
2829 "insert-css": "^1.0.0",
2930 "inu": "^3.1.3",
30- "morphdom": "^2.2.1",
3131 "ngraph.fromjson": "^0.1.8",
3232 "ngraph.pixel": "^2.2.0",
3333 "pull-stream": "^3.4.5",
3434 "run-waterfall": "^1.1.3",
3535 "ssb-avatar": "^0.2.0",
3636 "ssb-client": "^4.3.0",
37- "stream-to-pull-stream": "^1.7.2"
37 + "stream-to-pull-stream": "^1.7.2",
38 + "yo-yo": "^1.3.1"
3839 }
3940 }
renderer.jsView
@@ -1,14 +1,12 @@
11 const Renderer = require('ngraph.pixel')
2-const h = require('hyperscript')
32 const avatar = require('ssb-avatar')
4-const Sbot = require('ssb-client')
5-const morph = require('morphdom')
3 +const html = require('yo-yo')
64
75 module.exports = createRenderer
86
97 function createRenderer (graph, config, sbot) {
10- var avatarEl = h('div#avatar')
8 + var avatarEl = html`<div class="avatar" />`
119 document.body.appendChild(avatarEl)
1210
1311 var display = Renderer(graph, config)
1412
@@ -18,21 +16,22 @@
1816
1917 function handleNodeHover (node) {
2018 if (node === undefined) return
2119
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}` : ''
20 + avatar(sbot, node.id, node.id, (err, { name, image }) => {
21 + // handle this error!
22 + if (err) throw err
2623
27- var newAvatarEl = h('div#avatar', [
28- h('img', { src: imgSrc }),
29- h('div', name)
30- ])
24 + const imgSrc = image ? `http://localhost:7777/${image}` : ''
3125
32- morph(avatarEl, newAvatarEl)
33- sbot.close()
34- })
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)
3534 })
3635
3736 display.forEachLink(linkUI => {
3837 const { from, to } = linkUI
@@ -44,35 +43,30 @@
4443 const isFromFriend = friends.indexOf(from.id) > -1
4544 const isToFriend = friends.indexOf(to.id) > -1
4645 const involvesFoaF = isFromFriend || isToTarget
4746
48- let fromColor = 0x000066
49- let toColor = 0x000066
47 + var fromColor = 0x000066
48 + var toColor = 0x000066
5049
5150 const close = 0xffffff
5251 const mid = 0xa94caf
5352 const far = 0x000066
5453
5554 if (isFromTarget) {
5655 fromColor = close
5756 toColor = mid
58- }
59- else if (isToTarget) {
57 + } else if (isToTarget) {
6058 fromColor = mid
6159 toColor = close
62- }
63- else if (involvesFoaF && isFromFriend) {
60 + } else if (involvesFoaF && isFromFriend) {
6461 fromColor = mid
6562 toColor = far
66- }
67- else if (involvesFoaF && isToFriend) {
63 + } else if (involvesFoaF && isToFriend) {
6864 fromColor = far
6965 toColor = mid
7066 }
7167
72-
7368 linkUI.fromColor = fromColor
7469 linkUI.toColor = toColor
7570 })
76-
7771 }
7872 }
profile.jsView
@@ -1,16 +1,0 @@
1-module.exports = profile
2-
3-module.exports = function (sbot, id, cb) {
4- pull(
5- sbot.(id, (err, profile) => {
6- if (err) return cb(err)
7- console.log('profile', profile)
8- }),
9- pull.reduce(latest, {})
10- )
11-}
12-
13-function latest (sofar, next) {
14- console.log('sofar', sofar, next)
15- return sofar
16-}
test/index.jsView
@@ -1,8 +1,0 @@
1-const test = require('tape')
2-
3-const ssbViz = require('../')
4-
5-describe('ssb-viz', function(t) {
6- t.ok(ssbViz, 'module is require-able')
7- t.end()
8-})

Built with git-ssb-web