forked from d-miller/correlation-scatter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd3.extend.js
More file actions
70 lines (55 loc) · 2.03 KB
/
d3.extend.js
File metadata and controls
70 lines (55 loc) · 2.03 KB
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
//////////////////////////////
// EXTEND D3 LIBRARY ///
//////////////////////////////
//helper function for moving elements to the front
d3.selection.prototype.moveToFront = function() {
return this.each(function(){
this.parentNode.appendChild(this);
});
};
d3.transition.prototype.moveToFront = function() {
return this.each(function(){
this.parentNode.appendChild(this);
});
};
//helper function for fluidly changing instructions
d3.selection.prototype.updateInstrucs = function() {
//next set of instructions
var instruc = this.datum().shift();
//return immediately if there's no transition
if (!instruc.trans) return this.text(instruc.text)
.style(instruc.pos)
.style(instruc.style);
//otherwise, fade out current instructions, and fade in new ones
return this.transition()
.duration(instruc.fadeOut)
.style("opacity", 0)
.transition()
.duration(instruc.fadeIn)
.text(instruc.text)
.style("opacity", 1)
.style(instruc.pos)
.style(instruc.style);
};
//updates instructions if the previous instruction was completed
//if instructions are updated, it also runs the callback function
d3.selection.prototype.checkUpdateInstrucs = function(stepID, callback) {
//next set of instructions
var next = this.datum()[0];
//if the instructions just ended, run the callback function
//and remove the instructions HTML div from the DOM
if (stepID === "end") {
if (!(typeof(callback) === "undefined")) callback();
return this.remove();
}
//if there are no instructions, then don't do anything
if (typeof(next) === "undefined") return this;
//if the previous instruction was completed, call
//callback function and update instructions
if (next.prevStep === stepID) {
if (!(typeof(callback) === "undefined")) callback();
return this.updateInstrucs();
}
//otherwise, don't do anything
return this;
}