-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlabel.js.html
164 lines (136 loc) · 4.64 KB
/
label.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: label.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: label.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import {select} from "d3";
import {Bauble} from "./bauble";
/**
* Bauble class for labels
*/
export class Label extends Bauble{
constructor() {
super();
this._text=()=>"";
this._scaleX=false;
this._scaleY=false;
return this;
}
update(selection){
return selection
.selectAll(`.${this.id}`)
.data(d => [d].filter(this.filter()),d=>`label-${this.id}`)
.join(
enter => enter
.append("text")
.attr("class",`label ${this.id}`)
.attrs(this._attrs)
.each((d,i,n)=>{
const element = select(n[i]);
for( const [key,func] of Object.entries(this._interactions)){
element.on(key,(d,i,n)=>func(d,i,n))
}
})
.text(d=>this._text(d)),
update => update
.call(update => update.transition()
.duration(this.transitions().transitionDuration)
.ease(this.transitions().transitionEase)
.attrs(this._attrs)
.each((d,i,n)=>{
const element = select(n[i]);
for( const [key,func] of Object.entries(this._interactions)){
element.on(key,(d,i,n)=>func(d,i,n))
}
})
.text(d=>this._text(d))
)
);
};
text(f){
if(f==null){
return this._text;
}else{
if(f instanceof String||typeof f==="string"){
this._text = ()=>f;
}else{
this._text=f;
}
return this;
}
}
}
//((this.scales.x(e.v1.x+this.xScaleOffset) - this.scales.x(e.v0.x+this.xScaleOffset)) / 2))
/**
* Helper function for making labels. Sets position and alignment based on
* vertex or edge object.
* @param text - text to be displayed
* @return {*}
*/
export function label(text){
return new Label()
.attr("x",d=>d.textLabel.x)
.attr("y",d=> d.textLabel.y)
.attr("alignment-baseline",d=>d.textLabel.alignmentBaseline)
.attr("text-anchor",d=>d.textLabel.textAnchor)
.text(text)
}
/**
* Helper function filters label to just work on tips
* @param text - string or function for assigning label (will be passed vertex or edge)
* @return {*}
*/
export function tipLabel(text){
return label(text)
.filter(d=>d.degree===1);
}
/**
* Helper function filters label to just work on internal nodes
* @param text
* @return {*}
*/
export function internalNodeLabel(text){
return label(text)
.filter(d=>d.degree>1);
}
/**
* Helper function that puts label in the middle of a curveStepBefore branch
* @param text
* @return {Bauble|*|null|undefined}
*/
export function branchLabel(text){
return label(text)
.scaledX(d=>(d.v1.x-d.v0.x)/2);
// const setX = obj => d=>{
// // console.log((obj.scales().x(d.v1.x)-obj.scales().x(d.v0.x)/2));
// return (obj.scales().x(d.v1.x)-obj.scales().x(d.v0.x))/2
// };
// return l.attr("x",setX(l))
}</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Label.html">Label</a></li></ul><h3>Global</h3><ul><li><a href="global.html#branchLabel">branchLabel</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#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 Wed Mar 18 2020 15:02:23 GMT+0000 (Greenwich Mean Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>