3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
8 <link rel="import" href="/base/utils.html">
13 tv.exportTo('tracing', function() {
14 function TimelineDisplayTransform(opt_that) {
24 TimelineDisplayTransform.prototype = {
26 this.scaleX = that.scaleX;
27 this.panX = that.panX;
28 this.panY = that.panY;
32 return new TimelineDisplayTransform(this);
35 equals: function(that) {
37 if (that === undefined || that === null)
39 eq &= this.panX === that.panX;
40 eq &= this.panY === that.panY;
41 eq &= this.scaleX === that.scaleX;
45 almostEquals: function(that) {
47 if (that === undefined || that === null)
49 eq &= Math.abs(this.panX - that.panX) < 0.001;
50 eq &= Math.abs(this.panY - that.panY) < 0.001;
51 eq &= Math.abs(this.scaleX - that.scaleX) < 0.001;
55 incrementPanXInViewUnits: function(xDeltaView) {
56 this.panX += this.xViewVectorToWorld(xDeltaView);
59 xPanWorldPosToViewPos: function(worldX, viewX, viewWidth) {
60 if (typeof viewX == 'string') {
61 if (viewX === 'left') {
63 } else if (viewX === 'center') {
64 viewX = viewWidth / 2;
65 } else if (viewX === 'right') {
66 viewX = viewWidth - 1;
68 throw new Error('viewX must be left|center|right or number.');
71 this.panX = (viewX / this.scaleX) - worldX;
74 xPanWorldBoundsIntoView: function(worldMin, worldMax, viewWidth) {
75 if (this.xWorldToView(worldMin) < 0)
76 this.xPanWorldPosToViewPos(worldMin, 'left', viewWidth);
77 else if (this.xWorldToView(worldMax) > viewWidth)
78 this.xPanWorldPosToViewPos(worldMax, 'right', viewWidth);
81 xSetWorldBounds: function(worldMin, worldMax, viewWidth) {
82 var worldWidth = worldMax - worldMin;
83 var scaleX = viewWidth / worldWidth;
85 this.setPanAndScale(panX, scaleX);
88 setPanAndScale: function(p, s) {
93 xWorldToView: function(x) {
94 return (x + this.panX) * this.scaleX;
97 xWorldVectorToView: function(x) {
98 return x * this.scaleX;
101 xViewToWorld: function(x) {
102 return (x / this.scaleX) - this.panX;
105 xViewVectorToWorld: function(x) {
106 return x / this.scaleX;
109 applyTransformToCanvas: function(ctx) {
110 ctx.transform(this.scaleX, 0, 0, 1, this.panX * this.scaleX, 0);
115 TimelineDisplayTransform: TimelineDisplayTransform