-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdecoration_scaleBar.js.html
176 lines (138 loc) · 6.22 KB
/
decoration_scaleBar.js.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: decoration/scaleBar.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: decoration/scaleBar.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import {Decoration} from "./decoration";
/**
* Scale bar decorator
*/
class ScaleBar extends Decoration {
constructor(){
super();
this._title={
text:"",
xPadding:0,
yPadding:0,
rotation:0
};
this._length=1;
this._direction="x"
this._x=0;
this._y=0;
super.layer("axes-layer")
}
/**
* Set or get the length of the scale bar in the same units on the branches of the tree
* @param d
* @return {ScaleBar|number}
*/
length(d=null){
if(!d){
return this._length
}else{
this._length=d;
return this;
}
}
/**
* Get or set the direction of the scaleBar "x" or "y". This also determines which scale is used to convert the length
* to pixels.
* @param string
* @return {string|ScaleBar}
*/
direction(string=null){
if(!string){
return this._direction
}else{
this._direction=string;
return this;
}
}
create() {
const selection = this.figure().svgSelection.select(`.${this.layer()}`);
const group =selection
.append("g")
.attr("id", this._id)
.attr("class", "scale-bar")
.attr("transform", `translate(${this._x}, ${this._y})`)
group
.append("line")
.attr("x1",0)
.attr("y1",0)
.attr("x2",(this.direction()==="x"?this.scales().x(this._length): 0))
.attr("y2",(this.direction()==="y"?this.scales().y(this._length): 0))
.attr("stroke","black")
const pos={x:0,y:0};
if(this.direction() === "x"){
pos.x = this.scales().x(this._length)/2
}else{
pos.y=this.scales().y(this._length)/2
}
group
.append("text")
.attr("transform", `translate(${pos.x+this._title.xPadding}, ${pos.y+this._title.yPadding}) rotate(${this._title.rotation})`)
.attr("alignment-baseline", "hanging")
.style("text-anchor", "middle")
.text(this._title.text);
};
updateCycle() {
const selection = this.figure().svgSelection.select(`.${this.layer()}`);
const group =selection
.select(`g#${this._id}`)
.transition()
.attr("transform", `translate(${this._x}, ${this._y})`)
.select("line")
.attr("x1",0)
.attr("y1",0)
.attr("x2",(this.direction()==="x"?this.scales().x(this._length): 0))
.attr("y2",(this.direction()==="y"?this.scales().y(this._length): 0))
.attr("stroke","black")
const pos={x:0,y:0};
if(this.direction() === "x"){
pos.x = this.scales().x(this._length)/2
}else{
pos.y=this.scales().y(this._length)/2
}
group
.select("text")
.attr("transform", `translate(${pos.x+this._title.xPadding}, ${pos.y+this._title.yPadding}) rotate(${this._title.rotation})`)
.attr("alignment-baseline", "hanging")
.style("text-anchor", "middle")
.text(this._title.text);
};
}
/**
* Helper function that returns a new scalebar instance.
* @return {ScaleBar}
*/
export function scaleBar(){
return new ScaleBar();
}</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-bauble.html">bauble</a></li><li><a href="module-figtree.html">figtree</a></li><li><a href="module-tree.html">tree</a></li></ul><h3>Classes</h3><ul><li><a href="Axis.html">Axis</a></li><li><a href="BaubleManager.html">BaubleManager</a></li><li><a href="CircleBauble.html">CircleBauble</a></li><li><a href="Decoration.html">Decoration</a></li><li><a href="Label.html">Label</a></li><li><a href="Legend.html">Legend</a></li><li><a href="module-bauble.Bauble.html">Bauble</a></li><li><a href="module-figtree.FigTree.html">FigTree</a></li><li><a href="module-tree.Tree.html">Tree</a></li><li><a href="module-tree-Node.html">Node</a></li><li><a href="ScaleBar.html">ScaleBar</a></li></ul><h3>Global</h3><ul><li><a href="global.html#branch">branch</a></li><li><a href="global.html#branchLabel">branchLabel</a></li><li><a href="global.html#branchPathGenerator">branchPathGenerator</a></li><li><a href="global.html#circle">circle</a></li><li><a href="global.html#dateToDecimal">dateToDecimal</a></li><li><a href="global.html#decimalToDate">decimalToDate</a></li><li><a href="global.html#equalAngleLayout">equalAngleLayout</a></li><li><a href="global.html#internalNodeLabel">internalNodeLabel</a></li><li><a href="global.html#label">label</a></li><li><a href="global.html#leapYear">leapYear</a></li><li><a href="global.html#leastSquares">leastSquares</a></li><li><a href="global.html#legend">legend</a></li><li><a href="global.html#makeEdges">makeEdges</a></li><li><a href="global.html#makeVertexFromNode">makeVertexFromNode</a></li><li><a href="global.html#rectangle">rectangle</a></li><li><a href="global.html#rectangularHilightedLayout">rectangularHilightedLayout</a></li><li><a href="global.html#scaleBar">scaleBar</a></li><li><a href="global.html#tipLabel">tipLabel</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Sat Mar 21 2020 11:15:18 GMT+0000 (Greenwich Mean Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>