blob: 79151875bdf2f4f0dd1551505a68b92eee589345 [file] [log] [blame]
Paul Greysonc090d142013-04-09 16:59:03 -07001
2
3
4(function () {
5
Paul Greyson981e8c22013-04-09 17:43:59 -07006var projection = d3.geo.mercator()
7 .center([82, 45])
8 .scale(10000)
9 .rotate([-180,0]);
Paul Greysonc090d142013-04-09 16:59:03 -070010
Paul Greyson981e8c22013-04-09 17:43:59 -070011function createMap(svg, cb) {
Paul Greysonc090d142013-04-09 16:59:03 -070012 topology = svg.append('svg:svg').attr('id', 'viewBox').attr('viewBox', '0 0 1000 1000').
13 attr('id', 'viewbox');
14
15 var map = topology.append("g").attr('id', 'map');
16
Paul Greysonc090d142013-04-09 16:59:03 -070017 var path = d3.geo.path().projection(projection);
18
19 d3.json('data/world.json', function(error, topology) {
20 map.selectAll('path')
21 .data(topojson.object(topology, topology.objects.world).geometries)
22 .enter()
23 .append('path')
24 .attr('d', path)
25
26 cb();
27 });
Paul Greyson981e8c22013-04-09 17:43:59 -070028}
Paul Greysonc090d142013-04-09 16:59:03 -070029
30
Paul Greyson981e8c22013-04-09 17:43:59 -070031var projection
32createTopologyView = function (cb) {
33 var svg = createRootSVG();
Paul Greysonc090d142013-04-09 16:59:03 -070034
Paul Greyson981e8c22013-04-09 17:43:59 -070035 createMap(svg, cb);
36}
Paul Greysonc090d142013-04-09 16:59:03 -070037
Paul Greyson981e8c22013-04-09 17:43:59 -070038function makeSwitchesModel(switches) {
39 var switchesModel = [];
40 switches.forEach(function (s) {
41 switchesModel.push({
42 dpid: s.dpid,
43 state: s.state,
44 className: 'core',
45 controller: s.controller,
46 geo: model.configuration.geo[s.dpid]
47 });
48 });
49
50 return switchesModel;
Paul Greysonc090d142013-04-09 16:59:03 -070051}
52
53drawTopology = function () {
54
Paul Greyson981e8c22013-04-09 17:43:59 -070055
56 // enter
57 function switchEnter(s) {
58 var g = d3.select(this);
59
60 g.append('svg:circle').attr('r', widths.core);
61 g.append('svg:text').text(s.geo.label).attr('transform', 'translate(' + widths.core + ' ' + widths.core + ')');
62
63 }
64
65 var coreSwitches = topology.selectAll('.core').data(makeSwitchesModel(model.coreSwitches))
66 .enter()
67 .append('svg:g')
68 .attr("id", function (d) {
69 return d.dpid;
70 })
71 .classed('core', true)
72 .attr("transform", function(d) {
73 if (d.geo) {
74 return "translate(" + projection([d.geo.lng, d.geo.lat]) + ")";
75 }
76 })
77 .each(switchEnter);
78
79
80
81 // update
82 coreSwitches
83 .each(function (data) {
84 // if there's a pending state changed and then the state changes, clear the pending class
85 var circle = d3.select(this);
86 if (data.state === 'ACTIVE' && circle.classed('inactive') ||
87 data.state === 'INACTIVE' && circle.classed('active')) {
88 circle.classed('pending', false);
89 }
90 })
91 .attr('class', function (data) {
92 if (data.state === 'ACTIVE' && data.controller) {
93 return data.className + ' active ' + controllerColorMap[data.controller];
94 } else {
95 return data.className + ' inactive ' + 'colorInactive';
96 }
97 });
98
Paul Greysonc090d142013-04-09 16:59:03 -070099}
100
101})();