ac180123 by David LaPalomento

Plot buffered line

Add in a line to show how much content is buffered at each point during the simulation. It's pretty noisy due to the length of the simulation.
1 parent d8ca0f0a
...@@ -418,9 +418,15 @@ form label { ...@@ -418,9 +418,15 @@ form label {
418 418
419 .line { 419 .line {
420 fill: none; 420 fill: none;
421 stroke: steelblue;
422 stroke-width: 1.5px; 421 stroke-width: 1.5px;
423 } 422 }
423 .line.bandwidth {
424 stroke: steelblue;
425 }
426 .line.buffered {
427 stroke: #2ca02c;
428 opacity: 0.25;
429 }
424 430
425 .timeline { 431 .timeline {
426 color: #888; 432 color: #888;
......
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
87 var results = { 87 var results = {
88 bandwidth: [], 88 bandwidth: [],
89 playlists: [], 89 playlists: [],
90 buffered: [],
90 options: options 91 options: options
91 }, 92 },
92 bandwidths = options.bandwidths, 93 bandwidths = options.bandwidths,
...@@ -216,6 +217,11 @@ ...@@ -216,6 +217,11 @@
216 return; 217 return;
217 }, []); 218 }, []);
218 219
220 results.buffered.push({
221 time: t,
222 buffered: buffered
223 });
224
219 // simulate playback 225 // simulate playback
220 if (buffered > 0) { 226 if (buffered > 0) {
221 buffered--; 227 buffered--;
...@@ -259,6 +265,7 @@ ...@@ -259,6 +265,7 @@
259 displayTimeline = function(error, data) { 265 displayTimeline = function(error, data) {
260 var x = d3.scale.linear().range([0, width]), 266 var x = d3.scale.linear().range([0, width]),
261 y = d3.scale.linear().range([height, 0]), 267 y = d3.scale.linear().range([height, 0]),
268 y0 = d3.scale.linear().range([height, 0]),
262 269
263 timeAxis = d3.svg.axis().scale(x).orient('bottom'), 270 timeAxis = d3.svg.axis().scale(x).orient('bottom'),
264 tickFormatter = d3.format(',.0f'), 271 tickFormatter = d3.format(',.0f'),
...@@ -276,6 +283,14 @@ ...@@ -276,6 +283,14 @@
276 }) 283 })
277 .y(function(data) { 284 .y(function(data) {
278 return y(data.bandwidth); 285 return y(data.bandwidth);
286 }),
287 bufferedLine = d3.svg.line()
288 .interpolate('basis')
289 .x(function(data) {
290 return x(data.time);
291 })
292 .y(function(data) {
293 return y0(data.buffered);
279 }); 294 });
280 295
281 x.domain(d3.extent(data.bandwidth, function(data) { 296 x.domain(d3.extent(data.bandwidth, function(data) {
...@@ -284,6 +299,9 @@ ...@@ -284,6 +299,9 @@
284 y.domain([0, Math.max(d3.max(data.bandwidth, function(data) { 299 y.domain([0, Math.max(d3.max(data.bandwidth, function(data) {
285 return data.bandwidth; 300 return data.bandwidth;
286 }), d3.max(data.options.playlists))]); 301 }), d3.max(data.options.playlists))]);
302 y0.domain([0, d3.max(data.buffered, function(data) {
303 return data.buffered;
304 })]);
287 305
288 // time axis 306 // time axis
289 svg.selectAll('.axis').remove(); 307 svg.selectAll('.axis').remove();
...@@ -312,9 +330,16 @@ ...@@ -312,9 +330,16 @@
312 330
313 svg.append('text') 331 svg.append('text')
314 .attr('transform', 'translate(' + x(x.range()[1]) + ', ' + y(data.bandwidth.slice(-1)[0].bandwidth) + ')') 332 .attr('transform', 'translate(' + x(x.range()[1]) + ', ' + y(data.bandwidth.slice(-1)[0].bandwidth) + ')')
315 .attr('x', 3)
316 .attr('dy', '1.35em') 333 .attr('dy', '1.35em')
317 .text('bandwidth') 334 .text('bandwidth');
335
336 // buffered line
337 svg.selectAll('.buffered').remove();
338 svg.append('path')
339 .datum(data.buffered)
340 .attr('class', 'line buffered')
341 .attr('y', 6)
342 .attr('d', bufferedLine);
318 343
319 // segment bitrate dots 344 // segment bitrate dots
320 svg.selectAll('.segment-bitrate').remove(); 345 svg.selectAll('.segment-bitrate').remove();
......