-
Notifications
You must be signed in to change notification settings - Fork 4
/
baubles_circlebauble.js.html
214 lines (183 loc) · 8.14 KB
/
baubles_circlebauble.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
213
214
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: baubles/circlebauble.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: baubles/circlebauble.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import {mergeDeep} from "../utilities";
import {Bauble} from "./bauble";
import {select} from "d3";
import uuid from "uuid"
import p from "../_privateConstants";
/**
* The CircleBauble class. Each vertex is assigned a circle in the svg.
*/
export class CircleBauble extends Bauble{
/**
* The constructor.
* @param [settings.radius=6] - the radius of the circle
*/
constructor()
{
super();
this._attrs={"r":5,"cx":0,"cy":0}
}
/**
* A function that assigns cy,cx,and r attributes to a selection. (cx and cy are set to 0 each r is the settings radius
* plus the border.
* @param selection
*/
update(selection=null) {
if(selection==null&&!this.selection){
return
}
if(selection){
this.selection=selection;
}
return selection
.selectAll(`.${this.id}`)
.data(d => [d].filter(this.filter()),d=>this.id)
.join(
enter => enter
.append("circle")
.attr("class",`node-shape ${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))
}
}),
update => update
.call(update => update.transition(d=>`u${uuid.v4()}`)
.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))
}
}),
)
);
};
//TODO move some of the these to a master class
/**
* Helper function to class the node as 'hovered' and update the radius if provided
* @param r - optional hover radius
* @return {CircleBauble}
*/
hilightOnHover(r = null) {
let oldR;
super.on("mouseenter",
(d, i,n) => {
if(r) {
if (!this._attrs.r) {
this._attrs.r = this._attrs["r"];
}
oldR=this._attrs["r"];
this.attr("r", r);
}
const parent = select(n[i]).node().parentNode;
this.update(select(parent));
select(parent).classed("hovered",true)
.raise();
if(r){
this.attr("r", oldR);
}
// move to top
});
super.on("mouseleave",
(d,i,n) => {
const parent = select(n[i]).node().parentNode;
select(parent).classed("hovered",false);
this.update(select(parent));
});
return this;
}
/**
* helper method to annotate the underlying tree node as key:true; Useful for linking interactions between figures
* that share a tree.
* @param key
* @return {CircleBauble}
*/
annotateOnHover(key){
super.on("mouseenter",
(d, i,n) => {
this.manager().figure()[p.tree].annotateNode(this.manager().figure()[p.tree].getNode(d.id),{[key]:true});
this.manager().figure()[p.tree].treeUpdateCallback();
const parent = select(n[i]).node().parentNode;
select(parent).raise();
});
super.on("mouseleave",
(d,i,n) => {
this.manager().figure()[p.tree].annotateNode(this.manager().figure()[p.tree].getNode(d.id),{[key]:false});
this.manager().figure()[p.tree].treeUpdateCallback();
});
return this;
}
/**
* Rotate a node on click
* @param recursive - optional default -false;
* @return {CircleBauble}
*/
rotateOnClick(recursive=false){
super.on("click",(d,n,i)=>{
const node = this.manager().figure()[p.tree].getNode(d.key);
this.manager().figure()[p.tree].rotate(node,recursive);
});
return this;
}
/**
* helper method to annotate the underlying tree node as key:true; Useful for linking interactions between figures
* that share a tree.
* @param key
* @return {CircleBauble}
*/
annotateOnClick(key){
super.on("click",
(d, i,n) => {
const node = this.manager().figure()[p.tree].getNode(d.id) //TODO helper getters
this.manager().figure()[p.tree].annotateNode(node,{[key]:!node.annotations[key]});
this.manager().figure()[p.tree].treeUpdateCallback();
const parent = select(n[i]).node().parentNode;
select(parent).raise();
});
return this;
}
}
/**
* helper function returns a new instance of a circle bauble.
* @return {CircleBauble}
*/
export function circle(){
return new CircleBauble();
}
</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>