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

Unified Diff: dashboard/ui/endure_js/coordinates.js

Issue 12094074: Support Chrome Endure graphs in perf dashboard. (Closed) Base URL: https://git.chromium.org/git/chromium/tools/perf.git@master
Patch Set: updated Created 7 years, 11 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: dashboard/ui/endure_js/coordinates.js
diff --git a/dashboard/ui/endure_js/coordinates.js b/dashboard/ui/endure_js/coordinates.js
new file mode 100644
index 0000000000000000000000000000000000000000..a1e4219a0c9af34810229a12b397f0df25cd224b
--- /dev/null
+++ b/dashboard/ui/endure_js/coordinates.js
@@ -0,0 +1,212 @@
+/*
+ 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.
+*/
+
+/**
+ * @fileoverview Class and functions to handle positioning of plot data points.
+ */
+
+/**
+ * Class that handles plot data positioning.
+ * @constructor
+ *
alias of yukishiino 2013/01/31 10:57:11 Usually people don't separate annotations (@constr
Dai Mikurube (NOT FULLTIME) 2013/02/01 06:14:13 WDYT, Dennis?
dennis_jeffrey 2013/02/05 02:48:28 I'm ok with making this change if it's closer to w
Dai Mikurube (NOT FULLTIME) 2013/02/05 06:31:49 Removed empty lines from all annotations in this f
+ * @param {Array} plotData Data that will be plotted. It is an array of lines,
alias of yukishiino 2013/01/31 10:57:11 {Array.<Array.<Array.<number>>>>} or better use @
Dai Mikurube (NOT FULLTIME) 2013/02/01 06:14:13 Temporarily changed it to {Array.<Array.<Array.<nu
+ * where each line is an array of points, and each point is a length-2 array
+ * representing an (x, y) pair.
+ */
+function Coordinates(plotData) {
+ this.plotData = plotData;
+
+ height = window.innerHeight - 16;
+ width = window.innerWidth - 16;
+
+ this.widthMax = width;
+ this.heightMax = Math.min(400, height - 85);
+
+ this.processValues_('x');
+ this.processValues_('y');
+}
+
+/**
+ * Determines the min/max x or y values in the plot, accounting for some extra
+ * buffer space.
+ *
+ * @param {string} type The type of value to process, either 'x' or 'y'.
+ */
+Coordinates.prototype.processValues_ = function (type) {
+ var merged = [];
+ for (var i = 0; i < this.plotData.length; i++)
+ for (var j = 0; j < this.plotData[i].length; j++) {
+ if (type == 'x')
+ merged.push(parseFloat(this.plotData[i][j][0])); // Index 0 is x value.
+ else
+ merged.push(parseFloat(this.plotData[i][j][1])); // Index 1 is y value.
+ }
+
+ min = merged[0];
+ max = merged[0];
+ for (var i = 1; i < merged.length; ++i) {
+ if (isNaN(min) || merged[i] < min)
+ min = merged[i];
+ if (isNaN(max) || merged[i] > max)
+ max = merged[i];
+ }
+
+ var bufferSpace = 0.02 * (max - min);
+
+ if (type == 'x') {
+ this.xBufferSpace_ = bufferSpace;
+ this.xMinValue_ = min;
+ this.xMaxValue_ = max;
+ } else {
+ this.yBufferSpace_ = bufferSpace;
+ this.yMinValue_ = min;
+ this.yMaxValue_ = max;
+ }
+};
+
+/**
+ * Difference between horizontal upper and lower limit values.
+ *
+ * @return {number} The x value range.
+ */
+Coordinates.prototype.xValueRange = function() {
+ return this.xUpperLimitValue() - this.xLowerLimitValue();
+};
+
+/**
+ * Difference between vertical upper and lower limit values.
+ *
+ * @return {number} The y value range.
+ */
+Coordinates.prototype.yValueRange = function() {
+ return this.yUpperLimitValue() - this.yLowerLimitValue();
+};
+
+/**
+ * Converts horizontal data value to pixel value on canvas.
+ *
+ * @param {number} value The x data value.
+ * @return {number} The corresponding x pixel value on the canvas.
+ */
+Coordinates.prototype.xPixel = function(value) {
+ return this.widthMax *
+ ((value - this.xLowerLimitValue()) / this.xValueRange());
+};
+
+/**
+ * Converts vertical data value to pixel value on canvas.
+ *
+ * @param {number} value The y data value.
+ * @return {number} The corresponding y pixel value on the canvas.
+ */
+Coordinates.prototype.yPixel = function(value) {
+ if (this.yValueRange() == 0) {
+ // Completely horizontal lines should be centered horizontally.
+ return this.heightMax / 2;
+ } else {
+ return this.heightMax -
+ (this.heightMax *
+ (value - this.yLowerLimitValue()) / this.yValueRange());
+ }
+};
+
+/**
+ * Converts x point on canvas to data value it represents.
+ *
+ * @param {number} position The x pixel value on the canvas.
+ * @return {number} The corresponding x data value.
+ */
+Coordinates.prototype.xValue = function(position) {
+ return this.xLowerLimitValue() +
+ (position / this.widthMax * this.xValueRange());
+};
+
+/**
+ * Converts y point on canvas to data value it represents.
+ *
+ * @param {number} position The y pixel value on the canvas.
+ * @return {number} The corresponding y data value.
+ */
+Coordinates.prototype.yValue = function(position) {
+ var ratio = this.heightMax / (this.heightMax - position);
+ return this.yLowerLimitValue() + (this.yValueRange() / ratio);
+};
+
+/**
+ * Returns the minimum x value of all the data points.
+ *
+ * @return {number} The minimum x value of all the data points.
+ */
+Coordinates.prototype.xMinValue = function() {
+ return this.xMinValue_;
+};
+
+/**
+ * Returns the maximum x value of all the data points.
+ *
+ * @return {number} The maximum x value of all the data points.
+ */
+Coordinates.prototype.xMaxValue = function() {
+ return this.xMaxValue_;
+};
+
+/**
+ * Returns the minimum y value of all the data points.
+ *
+ * @return {number} The minimum y value of all the data points.
+ */
+Coordinates.prototype.yMinValue = function() {
+ return this.yMinValue_;
+};
+
+/**
+ * Returns the maximum y value of all the data points.
+ *
+ * @return {number} The maximum y value of all the data points.
+ */
+Coordinates.prototype.yMaxValue = function() {
+ return this.yMaxValue_;
+};
+
+/**
+ * Returns the x value at the lower limit of the bounding box of the canvas.
+ *
+ * @return {number} The x value at the lower limit of the bounding box of
+ * the canvas.
+ */
+Coordinates.prototype.xLowerLimitValue = function() {
+ return this.xMinValue_ - this.xBufferSpace_;
+};
+
+/**
+ * Returns the x value at the upper limit of the bounding box of the canvas.
+ *
+ * @return {number} The x value at the upper limit of the bounding box of
+ * the canvas.
+ */
+Coordinates.prototype.xUpperLimitValue = function() {
+ return this.xMaxValue_ + this.xBufferSpace_;
+};
+
+/**
+ * Returns the y value at the lower limit of the bounding box of the canvas.
+ *
+ * @return {number} The y value at the lower limit of the bounding box of
+ * the canvas.
+ */
+Coordinates.prototype.yLowerLimitValue = function() {
+ return this.yMinValue_ - this.yBufferSpace_;
+};
+
+/**
+ * Returns the y value at the upper limit of the bounding box of the canvas.
+ *
+ * @return {number} The y value at the upper limit of the bounding box of
+ * the canvas.
+ */
+Coordinates.prototype.yUpperLimitValue = function() {
+ return this.yMaxValue_ + this.yBufferSpace_;
+};

Powered by Google App Engine
This is Rietveld 408576698