Skip to content

Commit

Permalink
Merge pull request #5 from ipfs/tree-ltr
Browse files Browse the repository at this point in the history
dag visualized as a treee
  • Loading branch information
jbenet committed Aug 20, 2015
2 parents 75cacb6 + e27f6a4 commit 36d1536
Show file tree
Hide file tree
Showing 15 changed files with 10,438 additions and 0 deletions.
14 changes: 14 additions & 0 deletions webapps/tree-ltr/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

url="http://localhost:5001/ipfs/"

publish: build
@export hash=$(shell ipfs add -r -q . | tail -n1) && \
echo $$hash >>all-versions && \
echo $$hash >latest-version && \
open $(url)$$hash/viz

build: app.coffee
coffee --bare --compile $^

watch:
coffee --bare --watch --compile app.coffee
2 changes: 2 additions & 0 deletions webapps/tree-ltr/all-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
QmdQRGbijGYBe8u29Gd7LkxgC4dCVcbGALe2dQ3r1kRdzY
QmVppgFNC8TCJg3zJmSebFtZAJRSw1pS8seuYVstbzEW78
105 changes: 105 additions & 0 deletions webapps/tree-ltr/app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
DEMO_HASH = 'QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D' # example viewer directory
DEBUG = false

app = ->
hash = window.location.hash[1..]
debug 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>'
apiPath = "/api/v0/refs?arg=#{hash}&recursive&format=#{API_REFS_FORMAT}"
debug apiPath
d3.xhr apiPath, (error, xhr) ->
debug arguments
data = xhr.responseText
tree = {}

refApiPattern = /"Ref": "(\S+) (\S+) (\S+)[\\n]?"/g
while match = refApiPattern.exec data
[whole, src, dst, linkname] = match
tree[src] ?= []
tree[src].push
Hash: dst
Name: linkname

children = getDecendants hash, tree

@root = children: children
debug 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

debug = (args...) ->
if DEBUG
console.debug args...

app()



# Format of internal `tree`:
#
# {
# "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"
# }
# ]
# }
# ]
# }
# ]
# }
83 changes: 83 additions & 0 deletions webapps/tree-ltr/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions webapps/tree-ltr/doc/api.md
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
}
]
}
]
}

Binary file added webapps/tree-ltr/doc/ipfs-core.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions webapps/tree-ltr/latest-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
QmVppgFNC8TCJg3zJmSebFtZAJRSw1pS8seuYVstbzEW78
26 changes: 26 additions & 0 deletions webapps/tree-ltr/lib/d3/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2010-2015, Michael Bostock
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* The name Michael Bostock may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit 36d1536

Please sign in to comment.