forked from JayP823/HLSI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththroughputPlot.js
More file actions
176 lines (144 loc) · 4.86 KB
/
Copy paththroughputPlot.js
File metadata and controls
176 lines (144 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
'use strict';
// This makes a plot that when "running" is (mostly) always changing over
// time so long as there is a change in the input signal (sig) or a change
// in an interferer signal over the time of the time length of the
// x-axis.
//
// Throughput Plot is a plot of the Integral of signal 'rate' over time
// verses time.
//
//
// ARGUMENTS:
//
// sig:
//
// is the signal that we are getting the Throughput Plot for
//
// interferers:
//
// is one or an array of signals that are interfering.
//
// If not set than the Signal.env will be used.
//
//
function ThroughputPlot(sig, interferers=[]) {
if(!Array.isArray(interferers))
interferers = [ interferers ];
if(interferers.length < 1)
Object.keys(Signal.env).forEach(function(id) {
let signal = Signal.env[id];
if(signal.id === sig.id)
// skip the signal we are getting throughput for.
return;
interferers.push(signal);
});
// Current rate in bits/second. Changes as time goes on.
var rate = sig.rate;
var width = plot.width;
var height = plot.height;
var margin = plot.margin;
// Time between plotting points:
var plot_period = 0.1; // in seconds
var interval = setInterval(update_plot, plot_period * 1000);
// length of x-axis (time) for whole plot:
var plot_time_length = 90.0; // seconds
var num_steps = plot_time_length / plot_period;
//
// historical rate plot
//
var datar = d3.range(0,num_steps).map(function(f) { return {"y":1} })
var svgr = d3.select("body")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" +
margin.left + "," + margin.top + ")");
var tscale = d3.scaleLinear().domain([-plot_period*(num_steps), 0])
.range([0, width]);
var rscale = d3.scaleLog().domain([100e3, 400e6]).range([height, 0]);
var liner = d3.line()
.x(function(d, i) { return tscale(-plot_period*(num_steps-i)); })
.y(function(d, i) { return rscale(d.y); });
svgr.append("defs").append("clipPath")
.attr("id", "clipr")
.append("rect")
.attr("width", width)
.attr("height", height);
svgr.append("rect")
.attr("width", "86.2%")
.attr("height", "81%")
.attr("fill", "black");
svgr.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(tscale));
var rtickvalues = [ 100e3, 400e3,1e6,2e6,4e6,10e6,
20e6,40e6,100e6,200e6,400e6]
svgr.append("g")
.attr("class", "y axis")
.call(d3.axisLeft(rscale)
.tickValues(rtickvalues)
.tickFormat(function(d, i) {
let [s,u] = scale_units(d);
return d*s + u;
}));
// grid lines
svgr.append("g")
.attr("class","grid")
.call(d3.axisBottom(tscale)
.tickFormat("").tickSize(height));
svgr.append("g").attr("class","grid")
.call(d3.axisLeft(rscale).tickFormat("")
.tickSize(-width).tickValues(rtickvalues));
// create x-axis axis label
svgr.append("text")
.attr("transform","translate("+(width/2)+","+
(height + 0.75*margin.bottom)+")")
.attr("dy","-0.3em")
.style("text-anchor","middle")
.attr("fill", "white")
.text("Time (seconds)");
let pre = sig.name;
if(pre.length > 0)
pre += " ";
// create y-axis label
svgr.append("text")
.attr("transform","rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x", 0 - (height/2))
.attr("dy", "1em")
.style("text-anchor","middle")
.attr("fill", "white")
.text(pre + "Data Rate (bits/second)");
// 9. Append the path, bind the data, and call the line generator
var pathr = svgr.append("path")
.attr("clip-path","url(#clipr)")
.datum(datar)
.attr("class", "stroke-med no-fill stroke-orange")
.attr("d", liner);
function reset() {
datar = d3.range(0,num_steps-1).map(function(f) { return {"y":1} });
pathr.datum(datar).attr("d", liner);
}
var count = 0;
function update_plot() {
// A rate of 0 is not something we can plot on a log scale.
// Log10(0) is minus infinity, and it makes all other values
// in the Y array invalid too.
let r = rate;
if(r < 0.1)
// The rate is not this, but it's not plotted anyway.
r = 0.1;
// update historical plot
datar.push({"y": r});
datar.shift();
pathr.datum(datar).attr("d", liner);
}
// setup initial plot
//reset();
sig.onChange('rate', function(obj, r) {
// We got a new rate in bits/second (bits/s).
rate = r;
});
}