blob: c22a603f90f191c52d362796b93e0241f2cfd08e [file] [log] [blame]
Paul Greyson740bdaf2013-03-18 16:10:48 -07001/*global d3*/
2
3function createTopologyView() {
4 return d3.select('#svg-container').append('svg:svg').attr('viewBox', '0 0 1000 1000').
5 append('svg:g').attr('transform', 'translate(500 500)');
6}
7
8
9
10function drawHeader(model) {
11 d3.select('#lastUpdate').text(model.timestamp);
12}
13
14function drawTopology(svg, model) {
15
16 var rings = [{
17 radius: 3,
18 width: 16,
19 switches: model.edgeSwitches
20 }, {
21 radius: 1.5,
22 width: 32,
23 switches: model.aggregationSwitches
24 }, {
25 radius: 1,
26 width: 32,
27 switches: model.coreSwitches
28 }];
29
30 function ringEnter(data, i) {
31 if (!data.switches.length) {
32 return;
33 }
34
35 var k = 360 / data.switches.length;
36
37 d3.select(this).selectAll("g")
38 .data(d3.range(data.switches.length).map(function() {
39 return data;
40 }))
41 .enter().append("svg:g")
42 .attr("class", "square")
43 .attr("transform", function(_, i) {
44 return "rotate(" + i * k + ")translate(" + data.radius*150 + ")";
45 })
46 .append("svg:rect")
47 .attr("x", -data.width / 2)
48 .attr("y", -data.width / 2)
49 .attr("width", data.width)
50 .attr("height", data.width);
51 }
52
53 var ring = svg.selectAll("g")
54 .data(rings)
55 .enter().append("svg:g")
56 .attr("class", "ring")
57 .each(ringEnter);
58}
59
60function sync(svg) {
Paul Greyson6f86d1e2013-03-18 14:40:39 -070061 updateModel(function (model) {
Paul Greyson740bdaf2013-03-18 16:10:48 -070062
63 drawHeader(model);
64 drawTopology(svg, model);
65
66 // do it again in 1s
67 setTimeout(function () {
68 sync(svg)
69 }, 1000);
Paul Greyson6f86d1e2013-03-18 14:40:39 -070070 });
71}
Paul Greyson740bdaf2013-03-18 16:10:48 -070072
73sync(createTopologyView());