-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaverageThroughputPlot_BarChart.js
More file actions
201 lines (186 loc) · 5.21 KB
/
Copy pathaverageThroughputPlot_BarChart.js
File metadata and controls
201 lines (186 loc) · 5.21 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* This code defines an object named `AverageThroughputPlot_BarChart` in JavaScript. The object
contains methods for initializing a bar chart, generating dataset, creating the chart on a canvas
element, updating the plot with new data, and removing the plot. */
"use strict";
//
// sig:
//
// is the signal that we are getting the Spectral Efficiency Plot for
//
//
//
//
var schemes = conf.schemes;
const AverageThroughputPlot_BarChart = {
dataset: [],
signal_list: [],
avgThroughput_chart: null,
init: function (
signal_list,
canvas_id,
labels,
threshold = null,
backgroundColors = null
) {
this.signal_list = signal_list;
let data = this.generate_dataset(this.signal_list);
this.dataset = data;
this.create_chart(canvas_id, labels, data, threshold, backgroundColors);
this.update_plot();
return this;
},
generate_dataset: function (signal_list) {
let dataset = [];
for (let i = 0; i < signal_list.length; i++) {
let R = signal_list[i].rate;
dataset.push(R);
}
return dataset;
},
get_total_throughput: function (signal_list) {
let rate = 0;
for (let i = 0; i < signal_list.length; i++) {
rate += signal_list[i].rate;
}
return rate;
},
create_chart: function (
canvas_id,
labels,
data,
threshold,
backgroundColors
) {
// thresholdLine plugin block
this.thresholdLine = {
id: "thresholdLine",
beforeDatasetsDraw(chart, args, options) {
const {
ctx,
chartArea: { top, right, bottom, left, width, height },
scales: { x, y },
} = chart;
ctx.save();
ctx.strokeStyle = "yellow";
ctx.setLineDash([10, 20]);
if (threshold)
ctx.strokeRect(left, y.getPixelForValue(threshold * 1e6), width, 0);
ctx.restore();
},
};
this.avgThroughput_chart = new Chart(document.getElementById(canvas_id), {
type: "bar",
data: {
labels: labels,
datasets: [
{
label: "Data Rate (bits/sec)",
barThickness: 50,
maxBarThickness: 70,
backgroundColor: function () {
if (backgroundColors) {
return backgroundColors;
}
return [
"rgb(200,56,56)",
"rgb(0,176,240)",
"rgb(36,124,76)",
"rgb(255,192,0)",
"#8e5ea2",
];
},
data: data,
},
],
},
options: {
plugins: {
legend: { display: false },
title: {
display: true,
text: "Average Data Throughput",
color: "#fff",
},
datalabels: {
anchor: "end",
align: "top",
formatter: Math.round,
font: {
weight: "bold",
},
},
},
scales: {
x: {
ticks: {
color: "#fff",
},
grid: {
color: "#666",
},
// title: {
// display: true,
// text: 'Your Title',
// color: "#fff"
// }
},
y: {
type: "logarithmic",
min: 100e3,
max: 400e6,
ticks: {
display: true,
color: "#fff",
callback: function (value) {
var val = [
100e3, 400e3, 1e6, 2e6, 4e6, 10e6, 20e6, 40e6, 100e6, 200e6,
400e6,
].includes(value)
? value
: undefined;
if (val == undefined) return undefined;
let [s, u] = scale_units(val);
return val * s + u;
},
},
grid: {
color: "#666",
},
title: {
display: true,
text: "bits / sec",
color: "#fff",
},
},
},
},
plugins: [this.thresholdLine],
});
},
update_plot: function (data_bits = null) {
if (data_bits == null) {
for (let i = 0; i < signal_list.length; i++) {
AverageThroughputPlot_BarChart.avgThroughput_chart.data.datasets[0].data[
i
] = 0;
}
AverageThroughputPlot_BarChart.avgThroughput_chart.update();
return;
}
var bits = data_bits.bits_list;
for (let i = 0; i < bits.length; i++) {
let dataRate = bits[i] / data_bits.timeElapsed;
AverageThroughputPlot_BarChart.avgThroughput_chart.data.datasets[0].data[
i
] = dataRate;
}
AverageThroughputPlot_BarChart.avgThroughput_chart.update();
},
remove_plot: function () {
if (AverageThroughputPlot_BarChart.avgThroughput_chart != null) {
AverageThroughputPlot_BarChart.avgThroughput_chart.destroy();
AverageThroughputPlot_BarChart.dataset = [];
AverageThroughputPlot_BarChart.signal_list = [];
}
},
};