-
Notifications
You must be signed in to change notification settings - Fork 4
/
bauble.js.html
212 lines (175 loc) · 5.15 KB
/
bauble.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: bauble.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: bauble.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>"use strict";
/** @module bauble */
import uuid from "uuid";
/**
* The Bauble class
*
* This is a shape or Decoration at the node or edge of a tree.
*/
export class Bauble {
constructor() {
this.id=`n${uuid.v4()}`;
this._attrs ={};
this._interactions = {};
this._filter=()=>true;
}
/**
* A function that appends the element to the selection, joins the data, assigns the attributes to the svg objects
* updates and remove unneeded objects.
* @param selection
*/
update(selection) {
throw new Error("Don't call the base class method")
}
/**
* Getter or setter of bauble filter. The filter is function that will be passed the vertex or edge.It should return
* true or false
* @param f
* @return {*|Bauble}
*/
filter(f=null){
if(f===null){
return this._filter;
}else{
this._filter=f;
return this;
}
}
/**
* Get or set the bauble manager that handles these elements. this is called by the manager when the element
* is added.
* @param manager
* @return {Bauble|*}
*/
manager(manager=null){
if(manager===null){
return this._manager;
}else{
this._manager=manager;
return this;
}
}
/**
* Get or set attributes that will style the elements.
* @param string
* @param value - a string, number, or function that will be passed to d3 selection.
* @return {Bauble|*}
*/
attr(string,value=null){
if(value){
this._attrs[string] = value;
return this
}else{
return this._attrs[string]
}
}
/**
* Set a call back to be fired when the event listener is triggered.
* @param eventListener - a string that defines the event listener
* @param value - call back that will be passed d,i,n
* @return {Bauble}
*/
on(eventListener,value){
this._interactions[eventListener] = value;
return this;
}
/**
* Get or set the transition duration and ease. Defualts to the figtree instance.
* @param t - {Object} [t={tranmsissionDuration: transmissionEase:}]
* @return {Bauble|*}
*/
transitions(t=null){
if(t===null){
if(this._transitions){
return this._transitions;
}else{
return this.manager().figure().transitions();
}
}else{
this._transitions=t;
return this;
}
}
/**
* Get or set the scales used in the element defaults to the figtree instance.
* @param scales
* @return {Bauble.scales|*}
*/
scales(scales=null){
if(scales){
this._scales=scales
}else{
if(this._scales){
return this._scales;
}else{
return this.manager().figure().scales
}
}
}
/**
* sets the x position based on the scale
* @param unscaledValue - number or function that is passed the data
*/
scaledX(unscaledValue){
const n=parseFloat(unscaledValue);
if(n){
this.attr("x",d=>this.scales().x(unscaledValue))
}
else{
this.attr("x",d=>this.scales().x(unscaledValue(d)))
}
return this;
}
/**
* sets the y position based on the scale
* @param unscaledValue - number or function that is passed the data
*/
scaledY(unscaledValue){
const n=parseFloat(unscaledValue);
if(n){
this.attr("y",d=>this.scales().y(unscaledValue))
}
else{
this.attr("y",d=>this.scales().y(unscaledValue(d)))
}
return this;
}
// revealOnHover(){
//
// this.filter()
// //TODO put listener on parent only insert this element if the parent is hovered or clicked ect.
// }
}
</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></ul><h3>Classes</h3><ul><li><a href="module-bauble.Bauble.html">Bauble</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:01:56 GMT+0000 (Greenwich Mean Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>