-
-
Save mbostock/939927 to your computer and use it in GitHub Desktop.
Revisions
-
mbostock revised this gist
Feb 9, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ license: gpl-3.0 -
mbostock revised this gist
Oct 31, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ </style> <body> <script src="//d3js.org/d3.v3.min.js"></script> <script> var width = 960, -
mbostock revised this gist
Jun 11, 2015 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ </style> <body> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> <script> var width = 960, @@ -37,6 +37,8 @@ .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); d3.json("network.json", function(error, nodes) { if (error) throw error; var nodeByName = d3.map(), links = []; -
mbostock revised this gist
Jun 18, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
mbostock revised this gist
Jun 18, 2013 . 2 changed files with 93 additions and 75 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,81 +1,93 @@ <!DOCTYPE html> <meta charset="utf-8"> <style> circle { fill: #000; stroke: #fff; stroke-width: 2px; } path { fill: none; stroke: #999; stroke-width: 1.5px; } text { font: bold 10px sans-serif; } </style> <body> <script src="http://d3js.org/d3.v3.min.js"></script> <script> var width = 960, height = 500, radius = 240; var angle = d3.scale.ordinal() .rangePoints([0, 360], 1); var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height) .append("g") .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); d3.json("network.json", function(error, nodes) { var nodeByName = d3.map(), links = []; nodes.forEach(function(d) { nodeByName.set(d.name, d); }); nodes.forEach(function(source) { source.connections.forEach(function(target) { links.push({source: source, target: nodeByName.get(target)}); }); }); angle.domain(nodes.map(function(d) { return d.name; })); var link = svg.append("g") .attr("class", "links") .selectAll("path") .data(links) .enter().append("path") .attr("d", curve); var node = svg.append("g") .attr("class", "nodes") .selectAll("g") .data(nodes) .enter().append("g") .attr("transform", function(d) { return "rotate(" + angle(d.name) + ")translate(" + radius + ",0)"; }); node.append("circle") .attr("r", 5); node.append("text") .attr("dy", ".35em") .attr("x", 6) .text(function(d) { return d.name; }) .filter(function(d) { return (angle(d.name) + 90) % 360 > 180; }) // flipped .attr("x", -6) .attr("transform", "rotate(-180)") .style("text-anchor", "end"); }); function curve(link) { var a0 = angle(link.source.name) / 180 * Math.PI, a1 = angle(link.target.name) / 180 * Math.PI, x0 = Math.cos(a0) * radius, y0 = Math.sin(a0) * radius, x1 = Math.cos(a1) * radius, y1 = Math.sin(a1) * radius, dx = x0 - x1, dy = y0 - y1, l = Math.sqrt(dx * dx + dy * dy); return "M" + x0 + "," + y0 + "A" + l * 2 + "," + l * 2 + " 0 0 1 " + x1 + "," + y1; } </script> This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ [ {"name": "Bob", "connections": ["Jane", "Tom", "Sue"]}, {"name": "Jane", "connections": ["Bob", "Sue"]}, {"name": "Sue", "connections": ["Tom", "Bob", "Jane", "Tom"]}, {"name": "Tom", "connections": []} ] -
mbostock revised this gist
Apr 24, 2011 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,6 @@ path { fill: lightsteelblue; stroke: steelblue; } @@ -31,7 +30,10 @@ var w = 300, h = 300, angle = d3.scale.ordinal().domain(d3.range(0, data.length)).rangeBands([0, 2 * Math.PI]), line = d3.svg.chord() .startAngle(function(d) { return (d.startAngle + d.endAngle) / 2; }) .endAngle(function(d) { return (d.startAngle + d.endAngle) / 2; }) .radius(h / 2 - 20), angles = {}, connections = [] -
mbostock revised this gist
Apr 24, 2011 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,6 +13,7 @@ path { fill: lightsteelblue; fill-opacity: .2; stroke: steelblue; } -
mbostock revised this gist
Apr 24, 2011 . 1 changed file with 1 addition and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -30,12 +30,7 @@ var w = 300, h = 300, angle = d3.scale.ordinal().domain(d3.range(0, data.length)).rangeBands([0, 2 * Math.PI]), line = d3.svg.chord().radius(h / 2 - 20), angles = {}, connections = [] -
mbostock revised this gist
Apr 24, 2011 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -30,9 +30,12 @@ var w = 300, h = 300, angle = d3.scale.ordinal().domain(d3.range(0, data.length)).rangeBands([0, 2 * Math.PI]), line = d3.svg.chord() .source(function(d) { return d.source; }) .target(function(d) { return d.target; }) .startAngle(Number) .endAngle(Number) .radius(h / 2 - 20), angles = {}, connections = [] -
caged renamed this gist
Apr 24, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
caged created this gist
Apr 24, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,80 @@ <!DOCTYPE html> <html> <head> <script type="text/javascript" src="https://github.com/Caged/d3/raw/master/d3.js"></script> <style type="text/css"> html, body { width: 100%; height: 100%; margin: 0; padding: 0; } path { fill: lightsteelblue; stroke: steelblue; } </style> </head> <body> <script type="text/javascript"> var data = [ {name:'bob', connections: ['jane', 'tom', 'sue']}, {name:'jane', connections: ['bob', 'sue']}, {name:'sue', connections: ['tom', 'bob', 'jane', 'tom']}, {name: 'tom', connections: []} ] var w = 300, h = 300, angle = d3.scale.ordinal().domain(d3.range(0, data.length)).rangeBands([0, 2 * Math.PI]), line = d3.svg.diagonal() .source(function(d) { return { x: 0, y: 0 }}) .target(function(d) { return { x: 0, y: 0 }}) angles = {}, connections = [] data.forEach(function(d, i) { var a = angle(i) angles[d.name] = { startAngle: a, endAngle: a + angle.rangeBand() / 2 } }) data.forEach(function(p) { p.connections.forEach(function(c) { connections.push({ source: angles[p.name], target: angles[c] }) }) }) var vis = d3.select("body").append("svg:svg") .attr("width", w) .attr("height", h) .append("svg:g") .attr("transform", "translate(" + w / 2 + "," + h / 2 + ")"); vis.selectAll("path") .data(data) .enter().append("svg:path") .attr("d", d3.svg.arc() .innerRadius(h / 2 - 20) .outerRadius(h / 2 - 10) .startAngle(function(d, i) { return angles[d.name].startAngle }) .endAngle(function(d, i) { return angles[d.name].endAngle; })); vis.selectAll('path.c') .data(connections) .enter().append('svg:path') .attr('d', line) .attr('class', 'c') </script> </body> </html>