-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tree-shaped visualization of IPFS DAG.
License: MIT Signed-off-by: Harlan T Wood <code@harlantwood.net>
- Loading branch information
1 parent
1e5b0a2
commit 6021cea
Showing
7 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
url="http://localhost:5001/ipfs/" | ||
|
||
publish: | ||
@export hash=$(shell ipfs add -r -q . | tail -n1) && \ | ||
echo $$hash >published-version && \ | ||
open $(url)$$hash/viz | ||
|
||
watch: | ||
coffee --bare --watch --compile app.coffee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
DEMO_HASH = 'QmZq1TFx4RF1LbNb9RmEMZxaXpB9UjcFTLRCT4GHzy3Kk2' | ||
|
||
app = -> | ||
hash = window.location.hash[1..] | ||
console.log hash | ||
if hash.length > 0 | ||
render hash | ||
else | ||
window.location.hash = '#'+DEMO_HASH | ||
window.location.reload() | ||
|
||
render = (hash) -> | ||
API_REFS_FORMAT = encodeURIComponent '<src> <dst> <linkname>' | ||
d3.xhr "/api/v0/refs?arg=#{hash}&recursive&format=#{API_REFS_FORMAT}", (error, xhr) -> | ||
data = xhr.responseText | ||
|
||
dict = {} | ||
|
||
refApiPattern = /"Ref": "(\S+) (\S+) (\S+)\\n"/g | ||
while match = refApiPattern.exec data | ||
[whole, src, dst, linkname] = match | ||
dict[src] ?= [] | ||
dict[src].push | ||
Hash: dst | ||
Name: linkname | ||
|
||
children = getDecendants hash, dict | ||
|
||
@root = children: children | ||
# console.log JSON.stringify @root, null, 2 | ||
|
||
@root.x0 = h / 2 | ||
@root.y0 = 0 | ||
|
||
@root.children.forEach toggleAll | ||
update @root | ||
|
||
getDecendants = (ref, dict) -> | ||
throw new Error unless ref? and dict? | ||
children = dict[ref] | ||
if children? | ||
for child in children | ||
throw new Error unless child.Hash? | ||
decendants = getDecendants child.Hash, dict | ||
child.children = decendants if decendants? | ||
children | ||
|
||
app() | ||
|
||
|
||
|
||
# Format of internal `dict`: | ||
# | ||
# { | ||
# "Qmcav25eTinMV632w9zdyXsFENDz5FCWjrMEVU7Nzy2v98": [ | ||
# { | ||
# "Name": "app.js", | ||
# "Hash": "QmZs8mitpfSZM8TaFas9WaDVF77aQvb47UEPR1g1quoQq9" | ||
# }, | ||
# { | ||
# "Name": "lib", | ||
# "Hash": "QmSXq83RU9YFnxGS7N29gBqjMXTg3qHERzrfFZxKYCGknM" | ||
# } | ||
# ], | ||
# "QmSXq83RU9YFnxGS7N29gBqjMXTg3qHERzrfFZxKYCGknM": [ | ||
# { | ||
# "Name": "d3.js", | ||
# "Hash": "QmbgWP6n7wmczy9YP79FpDRUjYhyjVKjdDHTm9SS9nadZR", | ||
# } | ||
# ] | ||
# } | ||
|
||
|
||
# Final D3 format: | ||
# | ||
# { | ||
# "Name": "", | ||
# "children": [ | ||
# { | ||
# "Hash": "QmZs8mitpfSZM8TaFas9WaDVF77aQvb47UEPR1g1quoQq9", | ||
# "Name": "app.js" | ||
# }, | ||
# { | ||
# "Hash": "QmSXq83RU9YFnxGS7N29gBqjMXTg3qHERzrfFZxKYCGknM", | ||
# "Name": "lib", | ||
# "children": [ | ||
# { | ||
# "Hash": "Qmei6UeQ3LKeKUfzKLx8SRsmxVpvvWrLmZTkKapCoQnYgf", | ||
# "Name": "d3", | ||
# "children": [ | ||
# { | ||
# "Hash": "QmbgWP6n7wmczy9YP79FpDRUjYhyjVKjdDHTm9SS9nadZR", | ||
# "Name": "d3.js" | ||
# } | ||
# ] | ||
# } | ||
# ] | ||
# } | ||
# ] | ||
# } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
A request to: | ||
|
||
http://localhost:5001/api/v0/object/get?arg=/ipfs/QmPE6xb88LKNkwptiAsKNQ2Tryd8S8r9CBs1t9fXh9cY | ||
|
||
Returns JSON like: | ||
|
||
```json | ||
{ | ||
"Links": [ | ||
{ | ||
"Name": "viz.html", | ||
"Hash": "QmfY5W7vwrD9FycZNg3zikZSpcRwPDwDJp21b3NqMM8dw5", | ||
"Size": 4743 | ||
} | ||
], | ||
"Data": "\u0008\u0001" | ||
} | ||
``` | ||
|
||
Ideal future format of recursive call to `object/links`: | ||
|
||
{ | ||
"Hash": "Qmcav25eTinMV632w9zdyXsFENDz5FCWjrMEVU7Nzy2v98", | ||
"Links": [ | ||
{ | ||
"Name": "app.js", | ||
"Hash": "QmZs8mitpfSZM8TaFas9WaDVF77aQvb47UEPR1g1quoQq9", | ||
"Size": 500 | ||
}, | ||
{ | ||
"Name": "lib", | ||
"Hash": "QmSXq83RU9YFnxGS7N29gBqjMXTg3qHERzrfFZxKYCGknM", | ||
"Size": 520503, | ||
"Links": [ | ||
{ | ||
"Name": "d3.js", | ||
"Hash": "QmbgWP6n7wmczy9YP79FpDRUjYhyjVKjdDHTm9SS9nadZR", | ||
"Size": 336528 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
QmXon5EUQxP71kFFPdp5E64kkZCNNUsPVSwuVK2WCQ5yNW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> | ||
<script type="text/javascript" src="lib/d3/d3.js"></script> | ||
<link type="text/css" rel="stylesheet" href="lib/d3/tree.css"/> | ||
</head> | ||
<body> | ||
<div id="body"> | ||
<div id="footer"> | ||
<!-- <div class="hint">click or option-click to expand or collapse</div> --> | ||
</div> | ||
</div> | ||
<script type="text/javascript" src="lib/d3/tree.js"></script> | ||
<script type="text/javascript" src="app.js"></script> | ||
</body> | ||
</html> |