Created
August 23, 2011 17:41
-
-
Save engleek/1165962 to your computer and use it in GitHub Desktop.
Server Viz demo
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 characters
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> | |
| <html> | |
| <head> | |
| <meta http-equiv="Content-type" content="text/html; charset=utf-8"> | |
| <title></title> | |
| <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.29.1"> | |
| </script> | |
| <script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js?1.29.1"> | |
| </script> | |
| <script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?1.29.1"> | |
| </script> | |
| <style type="text/css"> | |
| path.link { | |
| fill: none; | |
| stroke: #666; | |
| stroke-width: 1.5px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <script type="text/javascript"> | |
| var w = 700, | |
| h = 700, | |
| server_address = "192.168.0.124"; | |
| var nodes = []; | |
| var links = []; | |
| var vis = d3.select('body') | |
| .append('svg:svg') | |
| .attr('width', w) | |
| .attr('height', h); | |
| var recvArc = d3.svg.arc() | |
| .startAngle(0) | |
| .endAngle(function(d) { return (1 / (1 - d.ups / d.req)) * 2 * Math.PI; }) | |
| .innerRadius(15) | |
| .outerRadius(20); | |
| sentArc = d3.svg.arc() | |
| .startAngle(function(d) { return (1 / (1 - d.ups / d.req)) * 2 * Math.PI; }) | |
| .endAngle(function(d) { return Math.PI * 2; }) | |
| .innerRadius(15) | |
| .outerRadius(20); | |
| force = d3.layout.force() | |
| .charge(-300) | |
| .distance(60) | |
| .nodes(nodes) | |
| .links(links) | |
| .size([w, h]); | |
| force.on('tick', function(e) { | |
| var nodes = root.selectAll('g.node'); | |
| nodes.attr('transform', function(d) { | |
| return 'translate(' + d.x + ',' + d.y + ')'; | |
| }) | |
| var link = root.selectAll("line.link").data(links) | |
| link.attr("x1", function(d) { return d.source.x; }) | |
| .attr("y1", function(d) { return d.source.y; }) | |
| .attr("x2", function(d) { return d.target.x; }) | |
| .attr("y2", function(d) { return d.target.y; }); | |
| }); | |
| var link = root.selectAll("line.link").data(links); | |
| link.enter().append("svg:line") | |
| .attr("class", "link") | |
| .attr("x1", function(d) { | |
| return d.source.x; | |
| }) | |
| .attr("y1", function(d) { | |
| return d.source.y; | |
| }) | |
| .attr("x2", function(d) { | |
| return d.target.x; | |
| }) | |
| .attr("y2", function(d) { | |
| return d.target.y; | |
| }) | |
| .style('stroke', 'silver'); | |
| var node = root.selectAll('g.node').data(nodes); | |
| var nodeEnter = node.enter().append('svg:g') | |
| .attr('class', 'node') | |
| .style('fill', 'white') | |
| .call(force.drag); | |
| nodeEnter.insert('svg:path') | |
| .attr('d', recvArc) | |
| .style('stroke', '#d62728') | |
| .style('stroke-width', 5); | |
| nodeEnter.insert('svg:path') | |
| .attr('d', sentArc) | |
| .style('stroke', '#2ca02c') | |
| .style('stroke-width', 5); | |
| nodeEnter.insert('svg:title') | |
| .text(function(d) { | |
| return d.name; | |
| }); | |
| force.start(); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment