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