blob: e18c47d9b8ca3fc1a6ec6b3c5376b1f226563961 [file] [log] [blame]
Thomas Vachuska7648d662015-03-16 11:58:30 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 ONOS GUI -- Intent Performance View Module
19 */
20(function () {
21 'use strict';
22
23 // injected refs
24 var $log, tbs, flash;
25
26 function start() {
27 //var format = d3.time.format("%m/%d/%y");
28 var format = d3.time.format("%H:%M:%S");
29 var samples = [];
30
31 var margin = {top: 20, right: 30, bottom: 30, left: 40},
32 width = 960 - margin.left - margin.right,
33 height = 500 - margin.top - margin.bottom;
34
35 var x = d3.time.scale()
36 .range([0, width]);
37
38 var y = d3.scale.linear()
39 .range([height, 0]);
40
41 var z = d3.scale.category20c();
42
43 var xAxis = d3.svg.axis()
44 .scale(x)
45 .orient("bottom")
46 .ticks(d3.time.seconds);
47
48 var yAxis = d3.svg.axis()
49 .scale(y)
50 .orient("left");
51
52 var stack = d3.layout.stack()
53 .offset("zero")
54 .values(function(d) { return d.values; })
55 .x(function(d) { return d.date; })
56 .y(function(d) { return d.value; });
57
58 var nest = d3.nest()
59 .key(function(d) { return d.key; });
60
61 var area = d3.svg.area()
62 .interpolate("cardinal")
63 .x(function(d) { return x(d.date); })
64 .y0(function(d) { return y(d.y0); })
65 .y1(function(d) { return y(d.y0 + d.y); });
66
67 var svg = d3.select("body").append("svg")
68 .attr("width", width + margin.left + margin.right)
69 .attr("height", height + margin.top + margin.bottom)
70 .append("g")
71 .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
72
73 svg.append("g")
74 .attr("class", "x axis")
75 .attr("transform", "translate(0," + height + ")")
76 .call(xAxis);
77
78 svg.append("g")
79 .attr("class", "y axis")
80 .call(yAxis);
81
82 function fetchData() {
83 d3.csv("app/view/intentPerf/data.csv", function (data) {
84 samples = data;
85 updateGraph();
86 });
87 }
88
89 function updateGraph() {
90 samples.forEach(function(d) {
91 d.date = format.parse(d.date);
92 d.value = +d.value;
93 });
94
95 var layers = stack(nest.entries(samples));
96
97 x.domain(d3.extent(samples, function(d) { return d.date; }));
98 y.domain([0, d3.max(samples, function(d) { return d.y0 + d.y; })]);
99
100 svg.selectAll(".layer")
101 .data(layers)
102 .enter().append("path")
103 .attr("class", "layer")
104 .attr("d", function(d) { return area(d.values); })
105 .style("fill", function(d, i) { return z(i); });
106
107 svg.select(".x")
108 .attr("transform", "translate(0," + height + ")")
109 .call(xAxis);
110
111 svg.select(".y")
112 .call(yAxis);
113
114 console.log('tick');
115 }
116 }
117
118 start();
119
120 // define the controller
121
122 angular.module('ovIntentPerf', ['onosUtil'])
123 .controller('OvIntentPerfCtrl',
124 ['$scope', '$log', 'ToolbarService', 'FlashService',
125
126 function ($scope, _$log_, _tbs_, _flash_) {
127 var self = this
128
129 $log = _$log_;
130 tbs = _tbs_;
131 flash = _flash_;
132
133 self.message = 'Hey there dudes!';
134 start();
135
136 // Clean up on destroyed scope
137 $scope.$on('$destroy', function () {
138 });
139
140 $log.log('OvIntentPerfCtrl has been created');
141 }]);
142}());