Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1068)

Unified Diff: content/browser/resources/media/new/number_graph.js

Issue 18889006: Removed old media-internals page and rewrote it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved all 'new' media internals files into its own folder for a smooth transition. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/resources/media/new/number_graph.js
diff --git a/content/browser/resources/media/new/number_graph.js b/content/browser/resources/media/new/number_graph.js
new file mode 100644
index 0000000000000000000000000000000000000000..e747f1961494fd2ada7bee280b6aeea8b813bf47
--- /dev/null
+++ b/content/browser/resources/media/new/number_graph.js
@@ -0,0 +1,111 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+var NumberGraph = (function () {
+ "use strict";
+
+ function NumberGraph(title) {
+
+ this.element = document.createElement('canvas');
+ this.context = this.element.getContext('2d');
+
+ this.barWidth = 1;
+
+ this.previousDataValues = [];
+
+ // Indexed by the position from the left
+ this.recording = [];
+ this.hoverAt = 0;
+ }
+
+ NumberGraph.prototype.setSize = function (width, height) {
+ this.element.width = width;
+ this.element.height = height;
+ this.width = width;
+ this.height = height;
+
+ this.maxPoints = this.width / this.barWidth;
+
+ this.setup();
+ };
+
+ NumberGraph.prototype.setup = function () {
+ this.element.onmousedown = function (event) {
+ this.hoverAt = event.offsetX;
+ this.drawWith(this.previousDataValues);
+ }.bind(this);
+ };
+
+ NumberGraph.prototype.getRelativePos = function (min, max, value) {
+ var totalDist = Math.abs(max - min);
+ var posFromBottom = Math.abs(value - min);
+ var posPercent = posFromBottom / totalDist;
+ return Math.floor(posPercent * this.height);
+ };
+
+ NumberGraph.prototype.drawWith = function (dataValues_passed) {
+ this.previousDataValues = dataValues_passed.slice(0);
+ // Reverse it so we can traverse from newest to oldest
+ var dataValues = dataValues_passed.slice(0).reverse();
+ this.recording = [];
+
+ this.context.fillStyle = "white";
+ this.context.fillRect(0, 0, this.width, this.height);
+ // We only want values that are greater than 20 milliseconds apart
+ var using = [];
+ var last = {time: -1000};
+ var i = 0;
+ var len = dataValues.length;
+
+ // We only want the last |maxPoints| values.
+ for (i = 0; i < Math.min(this.maxPoints, dataValues.length); i++) {
+ var val = dataValues[i];
+ if (Math.abs(val.time - last.time) >= 20) {
+ using.unshift(val);
+ last = val;
+ this.recording.unshift(val);
+ }
+ }
+
+ var usingValues = using.map(function (t) {
+ return t.value;
+ });
+ var maximum = Math.max.apply(null, usingValues);
+ var minimum = Math.min.apply(null, usingValues);
+ var placeZero = this.height - this.getRelativePos(minimum, maximum, 0);
+
+
+ this.context.fillStyle = "rgb(70, 70, 130)";
+ var posw = 0;
+
+ using.forEach(function (v) {
+ var position = this.getRelativePos(minimum, maximum, v.value);
+ this.context.fillRect(posw, placeZero, this.barWidth,
+ this.height - (position + placeZero));
+ posw += this.barWidth;
+ }, this);
+
+ // Draw the horizontal '0' bar
+ this.context.fillStyle = "rgb(90, 90, 90)";
+ this.context.fillRect(0, placeZero - 1, this.width, 2);
+
+ // Draw the mouse bar
+ this.context.fillStyle = "red";
+ this.context.fillRect(this.hoverAt, 0, 1, this.height);
+
+ var normalizedPosition = Math.floor(this.hoverAt / this.barWidth);
+ var dataAtCursor = this.recording[normalizedPosition];
+ if (dataAtCursor) {
+ this.context.fillText(dataAtCursor.value.toFixed(4), 20, 20);
+ this.context.fillText(goog.time.millisToString(dataAtCursor.time),
+ 20, 40);
+ }
+ if (usingValues.length >= this.maxPoints) {
+ this.hoverAt -= this.barWidth;
+ }
+ };
+
+ return NumberGraph;
+}());
« no previous file with comments | « content/browser/resources/media/new/media_internals.js ('k') | content/browser/resources/media/new/player_info.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698