Skip to content

Instantly share code, notes, and snippets.

@jbenet
Forked from mbostock/.block
Last active May 25, 2016 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jbenet/c51cd7eb730d18e5cdc2 to your computer and use it in GitHub Desktop.
Save jbenet/c51cd7eb730d18e5cdc2 to your computer and use it in GitHub Desktop.

go-ipfs imports

Mouseover any of the nodes in this network to see the incoming links (dependants) in green and the outgoing links (dependencies) in red.

How to do for your package?

go get github.com/jbenet/graphpkg
graphpkg -format=d3json <pkgname> > imports.json

Then (this part to be automated):

Thanks to:

[{"name":"reflect","size":1000,"imports":["math","runtime","strconv","sync","unsafe"]}
,{"name":"crypto/x509/pkix","size":1000,"imports":["encoding/asn1","math/big","time"]}
,{"name":"unicode/utf8","size":1000}
,{"name":"encoding/asn1","size":1000,"imports":["bytes","errors","fmt","io","math/big","reflect","strconv","strings","time","unicode/utf8"]}
,{"name":"fmt","size":1000,"imports":["errors","io","math","os","reflect","strconv","sync","unicode/utf8"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore","size":1000,"imports":["errors","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid","log","path","strings"]}
,{"name":"github.com/jbenet/go-ipfs/crypto/internal/pb","size":1000,"imports":["github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto","math"]}
,{"name":"crypto/elliptic","size":1000,"imports":["io","math/big","sync"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.crypto/sha3","size":1000,"imports":["encoding/binary","hash"]}
,{"name":"sync/atomic","size":1000,"imports":["unsafe"]}
,{"name":"path/filepath","size":1000,"imports":["bytes","errors","os","runtime","sort","strings","unicode/utf8"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net","size":1000,"imports":["bytes","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/h2so5/utp","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr","net","strings"]}
,{"name":"strings","size":1000,"imports":["errors","io","unicode","unicode/utf8"]}
,{"name":"crypto/x509","size":1000,"imports":["C","bytes","crypto","crypto/aes","crypto/cipher","crypto/des","crypto/dsa","crypto/ecdsa","crypto/elliptic","crypto/md5","crypto/rsa","crypto/sha1","crypto/sha256","crypto/sha512","crypto/x509/pkix","encoding/asn1","encoding/hex","encoding/pem","errors","fmt","io","math/big","net","os/exec","runtime","strconv","strings","sync","time","unicode/utf8","unsafe"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream","size":1000,"imports":["errors","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/docker/spdystream","io","math/rand","net","net/http","sync","time","unsafe"]}
,{"name":"github.com/jbenet/go-ipfs/net/conn","size":1000,"imports":["fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/io","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio/mpool","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net","github.com/jbenet/go-ipfs/crypto","github.com/jbenet/go-ipfs/crypto/secio","github.com/jbenet/go-ipfs/net/handshake","github.com/jbenet/go-ipfs/net/handshake/pb","github.com/jbenet/go-ipfs/peer","github.com/jbenet/go-ipfs/util","github.com/jbenet/go-ipfs/util/debugerror","github.com/jbenet/go-ipfs/util/eventlog","io","net","strings","time"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58","size":1000,"imports":["math/big","strings"]}
,{"name":"crypto/sha1","size":1000,"imports":["crypto","hash"]}
,{"name":"crypto/subtle","size":1000}
,{"name":"math/big","size":1000,"imports":["encoding/binary","errors","fmt","io","math","math/rand","strings","sync"]}
,{"name":"sort","size":1000}
,{"name":"hash","size":1000,"imports":["io"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio/mpool","size":1000,"imports":["fmt","sync"]}
,{"name":"github.com/jbenet/go-ipfs/crypto/spipe/internal/pb","size":1000,"imports":["github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto","math"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/docker/spdystream","size":1000,"imports":["container/heap","errors","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/spdy","io","log","net","net/http","os","sync","time"]}
,{"name":"github.com/jbenet/go-ipfs/crypto/secio","size":1000,"imports":["bytes","crypto/aes","crypto/cipher","crypto/hmac","crypto/rand","crypto/sha1","crypto/sha256","crypto/sha512","errors","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.crypto/blowfish","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio/mpool","github.com/jbenet/go-ipfs/crypto","github.com/jbenet/go-ipfs/crypto/spipe/internal/pb","github.com/jbenet/go-ipfs/peer","github.com/jbenet/go-ipfs/util","github.com/jbenet/go-ipfs/util/eventlog","hash","io","strings"]}
,{"name":"net/url","size":1000,"imports":["bytes","errors","sort","strconv","strings"]}
,{"name":"bytes","size":1000,"imports":["errors","io","unicode","unicode/utf8"]}
,{"name":"github.com/jbenet/go-ipfs/net/swarm","size":1000,"imports":["errors","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream","github.com/jbenet/go-ipfs/net/conn","github.com/jbenet/go-ipfs/peer","github.com/jbenet/go-ipfs/util/eventlog","github.com/jbenet/go-ipfs/util/eventlog/loggables","github.com/jbenet/go-ipfs/util/multierr"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio","size":1000,"imports":["encoding/binary","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio/mpool","io","sync"]}
,{"name":"errors","size":1000}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto","size":1000,"imports":["bufio","bytes","encoding/json","errors","fmt","io","log","math","os","reflect","sort","strconv","strings","sync","unicode/utf8","unsafe"]}
,{"name":"crypto/sha512","size":1000,"imports":["crypto","hash"]}
,{"name":"github.com/jbenet/go-ipfs/net/handshake/pb","size":1000,"imports":["encoding/json","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto","math"]}
,{"name":"unicode/utf16","size":1000}
,{"name":"io","size":1000,"imports":["errors","sync"]}
,{"name":"crypto/aes","size":1000,"imports":["crypto/cipher","strconv"]}
,{"name":"compress/zlib","size":1000,"imports":["bufio","compress/flate","errors","fmt","hash","hash/adler32","io"]}
,{"name":"bufio","size":1000,"imports":["bytes","errors","io","unicode/utf8"]}
,{"name":"github.com/jbenet/go-ipfs/config","size":1000,"imports":["crypto","crypto/x509","encoding/base64","encoding/json","errors","fmt","github.com/jbenet/go-ipfs/util","github.com/jbenet/go-ipfs/util/debugerror","io","os","path/filepath","strconv","strings","time"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto","size":1000,"imports":["bufio","bytes","encoding/json","errors","fmt","io","log","math","os","reflect","sort","strconv","strings","sync","unicode/utf8","unsafe"]}
,{"name":"github.com/jbenet/go-ipfs/util","size":1000,"imports":["encoding/json","errors","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-logging","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir","io","math/rand","os","path/filepath","runtime/debug","strings","sync","time"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir","size":1000,"imports":["bytes","errors","os","os/exec","runtime","strings"]}
,{"name":"encoding/binary","size":1000,"imports":["errors","io","math","reflect"]}
,{"name":"crypto/des","size":1000,"imports":["crypto/cipher","encoding/binary","strconv"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid","size":1000,"imports":["bytes","crypto/md5","crypto/rand","crypto/sha1","encoding/binary","fmt","hash","io","net","os","strings","sync","time"]}
,{"name":"github.com/jbenet/go-ipfs/net/handshake","size":1000,"imports":["errors","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver","github.com/jbenet/go-ipfs/config","github.com/jbenet/go-ipfs/net/handshake/pb","github.com/jbenet/go-ipfs/util"]}
,{"name":"net/textproto","size":1000,"imports":["bufio","bytes","fmt","io","io/ioutil","net","strconv","strings","sync"]}
,{"name":"C","size":1000}
,{"name":"crypto/rc4","size":1000,"imports":["strconv"]}
,{"name":"math","size":1000,"imports":["unsafe"]}
,{"name":"io/ioutil","size":1000,"imports":["bytes","io","os","path/filepath","sort","strconv","sync","time"]}
,{"name":"github.com/jbenet/go-ipfs/util/eventlog/loggables","size":1000,"imports":["github.com/jbenet/go-ipfs/util/eventlog","net"]}
,{"name":"runtime/debug","size":1000,"imports":["bytes","fmt","io/ioutil","os","runtime","sort","time"]}
,{"name":"log/syslog","size":1000,"imports":["errors","fmt","log","net","os","strings","sync","time"]}
,{"name":"crypto/cipher","size":1000,"imports":["crypto/subtle","errors","io","runtime","unsafe"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2","size":1000,"imports":["fmt","io","io/ioutil","os","path/filepath","sort","strings","sync","time"]}
,{"name":"container/heap","size":1000,"imports":["sort"]}
,{"name":"crypto/sha256","size":1000,"imports":["crypto","hash"]}
,{"name":"crypto","size":1000,"imports":["hash","strconv"]}
,{"name":"compress/gzip","size":1000,"imports":["bufio","compress/flate","errors","fmt","hash","hash/crc32","io","time"]}
,{"name":"encoding/base64","size":1000,"imports":["bytes","io","strconv","strings"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash","size":1000,"imports":["crypto/sha1","crypto/sha256","crypto/sha512","encoding/hex","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.crypto/sha3","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"]}
,{"name":"os","size":1000,"imports":["errors","io","runtime","sync","sync/atomic","syscall","time"]}
,{"name":"os/exec","size":1000,"imports":["bytes","errors","io","os","path/filepath","runtime","strconv","strings","sync","syscall"]}
,{"name":"log","size":1000,"imports":["fmt","io","os","runtime","sync","time"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.crypto/blowfish","size":1000,"imports":["strconv"]}
,{"name":"crypto/dsa","size":1000,"imports":["errors","io","math/big"]}
,{"name":"encoding/hex","size":1000,"imports":["bytes","errors","fmt","io"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/io","size":1000,"imports":["encoding/binary","errors","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto","io"]}
,{"name":"github.com/jbenet/go-ipfs/util/debugerror","size":1000,"imports":["errors","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/facebookgo/stackerr","github.com/jbenet/go-ipfs/util"]}
,{"name":"crypto/rsa","size":1000,"imports":["bytes","crypto","crypto/rand","crypto/subtle","errors","hash","io","math/big"]}
,{"name":"crypto/ecdsa","size":1000,"imports":["crypto/elliptic","io","math/big"]}
,{"name":"runtime","size":1000,"imports":["unsafe"]}
,{"name":"encoding/pem","size":1000,"imports":["bytes","encoding/base64","io","sort"]}
,{"name":"github.com/jbenet/go-ipfs/util/multierr","size":1000,"imports":["fmt"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/maybebtc/logrus","size":1000,"imports":["bytes","encoding/json","fmt","io","log","os","sort","strings","sync","syscall","time","unsafe"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/facebookgo/stack","size":1000,"imports":["bytes","fmt","os","path/filepath","runtime","strings"]}
,{"name":"github.com/jbenet/go-ipfs/crypto","size":1000,"imports":["bytes","crypto","crypto/elliptic","crypto/hmac","crypto/rand","crypto/rsa","crypto/sha1","crypto/sha256","crypto/sha512","crypto/x509","encoding/base64","errors","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto","github.com/jbenet/go-ipfs/crypto/internal/pb","github.com/jbenet/go-ipfs/util","hash"]}
,{"name":"syscall","size":1000,"imports":["errors","runtime","sync","unsafe"]}
,{"name":"encoding/json","size":1000,"imports":["bytes","encoding","encoding/base64","errors","fmt","io","math","reflect","runtime","sort","strconv","strings","sync","unicode","unicode/utf16","unicode/utf8"]}
,{"name":"compress/flate","size":1000,"imports":["bufio","fmt","io","math","sort","strconv"]}
,{"name":"crypto/hmac","size":1000,"imports":["crypto/subtle","hash"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup","size":1000,"imports":["github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context","sync"]}
,{"name":"unsafe","size":1000}
,{"name":"unicode","size":1000}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/spdy","size":1000,"imports":["bytes","compress/zlib","encoding/binary","io","net/http","strings"]}
,{"name":"net/http","size":1000,"imports":["bufio","bytes","compress/gzip","crypto/tls","encoding/base64","encoding/binary","errors","fmt","io","io/ioutil","log","mime","mime/multipart","net","net/textproto","net/url","os","path","path/filepath","runtime","sort","strconv","strings","sync","sync/atomic","time"]}
,{"name":"hash/adler32","size":1000,"imports":["hash"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr","size":1000,"imports":["bytes","encoding/binary","fmt","net","strconv","strings"]}
,{"name":"crypto/md5","size":1000,"imports":["crypto","hash","runtime","unsafe"]}
,{"name":"github.com/jbenet/go-ipfs/net","size":1000,"imports":["errors","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr","github.com/jbenet/go-ipfs/net/conn","github.com/jbenet/go-ipfs/net/swarm","github.com/jbenet/go-ipfs/peer","github.com/jbenet/go-ipfs/util/eventlog","github.com/jbenet/go-ipfs/util/eventlog/loggables","io","sync"]}
,{"name":"encoding","size":1000}
,{"name":"time","size":1000,"imports":["errors","runtime","sync","syscall"]}
,{"name":"container/list","size":1000}
,{"name":"crypto/rand","size":1000,"imports":["bufio","crypto/aes","crypto/cipher","errors","io","math/big","os","runtime","sync","time"]}
,{"name":"sync","size":1000,"imports":["runtime","sync/atomic","unsafe"]}
,{"name":"regexp/syntax","size":1000,"imports":["bytes","sort","strconv","strings","unicode","unicode/utf8"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver","size":1000,"imports":["bytes","errors","fmt","sort","strconv","strings"]}
,{"name":"crypto/tls","size":1000,"imports":["bytes","container/list","crypto","crypto/aes","crypto/cipher","crypto/des","crypto/ecdsa","crypto/elliptic","crypto/hmac","crypto/md5","crypto/rand","crypto/rc4","crypto/rsa","crypto/sha1","crypto/sha256","crypto/subtle","crypto/x509","encoding/asn1","encoding/pem","errors","fmt","hash","io","io/ioutil","math/big","net","strconv","strings","sync","time"]}
,{"name":"net","size":1000,"imports":["C","errors","io","math/rand","os","runtime","sort","sync","sync/atomic","syscall","time","unsafe"]}
,{"name":"regexp","size":1000,"imports":["bytes","io","regexp/syntax","sort","strconv","strings","sync","unicode","unicode/utf8"]}
,{"name":"github.com/jbenet/go-ipfs/peer","size":1000,"imports":["encoding/hex","errors","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash","github.com/jbenet/go-ipfs/crypto","github.com/jbenet/go-ipfs/util","sync","time"]}
,{"name":"math/rand","size":1000,"imports":["math","sync"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-logging","size":1000,"imports":["bytes","errors","fmt","io","log","log/syslog","os","path","path/filepath","regexp","runtime","strings","sync","sync/atomic","time","unsafe"]}
,{"name":"hash/crc32","size":1000,"imports":["hash","sync"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context","size":1000,"imports":["errors","fmt","sync","time"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/h2so5/utp","size":1000,"imports":["bytes","encoding/binary","errors","fmt","io","log","math","math/rand","net","os","strconv","sync","syscall","time"]}
,{"name":"path","size":1000,"imports":["errors","strings","unicode/utf8"]}
,{"name":"mime","size":1000,"imports":["bufio","bytes","errors","fmt","os","sort","strings","sync","unicode"]}
,{"name":"strconv","size":1000,"imports":["errors","math","unicode/utf8"]}
,{"name":"github.com/jbenet/go-ipfs/util/eventlog","size":1000,"imports":["encoding/json","errors","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid","github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-logging","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/maybebtc/logrus","github.com/jbenet/go-ipfs/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2","github.com/jbenet/go-ipfs/util","io","os","reflect","time"]}
,{"name":"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/facebookgo/stackerr","size":1000,"imports":["errors","fmt","github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/facebookgo/stack"]}
,{"name":"mime/multipart","size":1000,"imports":["bufio","bytes","crypto/rand","errors","fmt","io","io/ioutil","mime","net/textproto","os","strings"]}
]
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node {
font: 300 11px "Helvetica Neue", Helvetica, Arial, sans-serif;
fill: #bbb;
}
.node:hover {
fill: #000;
}
.link {
stroke: steelblue;
stroke-opacity: .4;
fill: none;
pointer-events: none;
}
.node:hover,
.node--source,
.node--target {
font-weight: 700;
}
.node--source {
fill: #2ca02c;
}
.node--target {
fill: #d62728;
}
.link--source,
.link--target {
stroke-opacity: 1;
stroke-width: 2px;
}
.link--source {
stroke: #d62728;
}
.link--target {
stroke: #2ca02c;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var diameter = 960,
radius = diameter / 2,
innerRadius = radius - 120;
var cluster = d3.layout.cluster()
.size([360, innerRadius])
.sort(null)
.value(function(d) { return d.size; });
var bundle = d3.layout.bundle();
var line = d3.svg.line.radial()
.interpolate("bundle")
.tension(.85)
.radius(function(d) { return d.y; })
.angle(function(d) { return d.x / 180 * Math.PI; });
var svg = d3.select("body").append("svg")
.attr("width", diameter)
.attr("height", diameter)
.append("g")
.attr("transform", "translate(" + radius + "," + radius + ")");
var link = svg.append("g").selectAll(".link"),
node = svg.append("g").selectAll(".node");
d3.json("imports.json", function(error, classes) {
var nodes = cluster.nodes(packageHierarchy(classes)),
links = packageImports(nodes);
link = link
.data(bundle(links))
.enter().append("path")
.each(function(d) { d.source = d[0], d.target = d[d.length - 1]; })
.attr("class", "link")
.attr("d", line);
node = node
.data(nodes.filter(function(n) { return !n.children; }))
.enter().append("text")
.attr("class", "node")
.attr("dy", ".31em")
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + (d.y + 8) + ",0)" + (d.x < 180 ? "" : "rotate(180)"); })
.style("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
.text(function(d) { return d.key; })
.on("mouseover", mouseovered)
.on("mouseout", mouseouted);
});
function mouseovered(d) {
node
.each(function(n) { n.target = n.source = false; });
link
.classed("link--target", function(l) { if (l.target === d) return l.source.source = true; })
.classed("link--source", function(l) { if (l.source === d) return l.target.target = true; })
.filter(function(l) { return l.target === d || l.source === d; })
.each(function() { this.parentNode.appendChild(this); });
node
.classed("node--target", function(n) { return n.target; })
.classed("node--source", function(n) { return n.source; });
}
function mouseouted(d) {
link
.classed("link--target", false)
.classed("link--source", false);
node
.classed("node--target", false)
.classed("node--source", false);
}
d3.select(self.frameElement).style("height", diameter + "px");
// Lazily construct the package hierarchy from class names.
function packageHierarchy(classes) {
var map = {};
function find(name, data) {
var node = map[name], i;
if (!node) {
node = map[name] = data || {name: name, children: []};
if (name.length) {
node.parent = find(name.substring(0, i = name.lastIndexOf(".")));
node.parent.children.push(node);
node.key = name.substring(i + 1);
}
}
return node;
}
classes.forEach(function(d) {
find(d.name, d);
});
return map[""];
}
// Return a list of imports for the given array of nodes.
function packageImports(nodes) {
var map = {},
imports = [];
// Compute a map from name to node.
nodes.forEach(function(d) {
map[d.name] = d;
});
// For each import, construct a link from the source to target node.
nodes.forEach(function(d) {
if (d.imports) d.imports.forEach(function(i) {
imports.push({source: map[d.name], target: map[i]});
});
});
return imports;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment