1<!DOCTYPE html> 2<!-- 3Copyright (c) 2015 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7 8<link rel="import" href="/tracing/base/base.html"> 9 10<script> 11'use strict'; 12 13tr.exportTo('tr.ui.tracks', function() { 14 15 /** 16 * A helper object encapsulating all parameters necessary to draw a chart 17 * series and provides conversion between world coordinates and physical 18 * pixels. 19 * 20 * All parameters (except for pixelRatio) are assumed to be in physical pixels 21 * (i.e. already pre-multiplied with pixelRatio). 22 * 23 * The diagram below explains the meaning of the resulting fields with 24 * respect to a chart track: 25 * 26 * outerTopViewY -> +--------------------/-\-------+ <- Top padding 27 * innerTopViewY -> + - - - - - - - - - -| |- - - -+ <- Axis max 28 * | .. ==\-/== | 29 * | == Series == | 30 * | ==/-\== .. | 31 * innerBottomViewY -> + - - -Point- - - - - - - - - -+ <- Axis min 32 * outerBottomViewY -> +-------\-/--------------------+ <- Bottom padding 33 * ^ ^ 34 * leftViewX rightViewX 35 * leftTimeStamp rightTimestamp 36 * 37 * Labels starting with a lower case letter are the resulting fields of the 38 * transform object. Labels starting with an upper case letter correspond 39 * to the relevant chart track concepts. 40 * 41 * @constructor 42 */ 43 function ChartTransform(displayTransform, axis, trackWidth, 44 trackHeight, topPadding, bottomPadding, pixelRatio) { 45 this.pixelRatio = pixelRatio; 46 47 // X axis. 48 this.leftViewX = 0; 49 this.rightViewX = trackWidth; 50 this.leftTimestamp = displayTransform.xViewToWorld(this.leftViewX); 51 this.rightTimestamp = displayTransform.xViewToWorld(this.rightViewX); 52 53 this.displayTransform_ = displayTransform; 54 55 // Y axis. 56 this.outerTopViewY = 0; 57 this.innerTopViewY = topPadding; 58 this.innerBottomViewY = trackHeight - bottomPadding; 59 this.outerBottomViewY = trackHeight; 60 61 this.axis_ = axis; 62 this.innerHeight_ = this.innerBottomViewY - this.innerTopViewY; 63 }; 64 65 ChartTransform.prototype = { 66 worldXToViewX: function(worldX) { 67 return this.displayTransform_.xWorldToView(worldX); 68 }, 69 70 viewXToWorldX: function(viewX) { 71 return this.displayTransform_.xViewToWorld(viewX); 72 }, 73 74 worldYToViewY: function(worldY) { 75 var innerHeightCoefficient = 1 - this.axis_.valueToUnitRange(worldY); 76 return innerHeightCoefficient * this.innerHeight_ + this.innerTopViewY; 77 } 78 }; 79 80 return { 81 ChartTransform: ChartTransform 82 }; 83}); 84</script> 85