Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/sandbox/RFinance2014/libraries/widgets/nvd3/js/hive.js
1433 views
1
d3.hive = {};
2
3
d3.hive.link = function() {
4
var source = function(d) { return d.source; },
5
target = function(d) { return d.target; },
6
angle = function(d) { return d.angle; },
7
startRadius = function(d) { return d.radius; },
8
endRadius = startRadius,
9
arcOffset = -Math.PI / 2;
10
11
function link(d, i) {
12
var s = node(source, this, d, i),
13
t = node(target, this, d, i),
14
x;
15
if (t.a < s.a) x = t, t = s, s = x;
16
if (t.a - s.a > Math.PI) s.a += 2 * Math.PI;
17
var a1 = s.a + (t.a - s.a) / 3,
18
a2 = t.a - (t.a - s.a) / 3;
19
return s.r0 - s.r1 || t.r0 - t.r1
20
? "M" + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0
21
+ "L" + Math.cos(s.a) * s.r1 + "," + Math.sin(s.a) * s.r1
22
+ "C" + Math.cos(a1) * s.r1 + "," + Math.sin(a1) * s.r1
23
+ " " + Math.cos(a2) * t.r1 + "," + Math.sin(a2) * t.r1
24
+ " " + Math.cos(t.a) * t.r1 + "," + Math.sin(t.a) * t.r1
25
+ "L" + Math.cos(t.a) * t.r0 + "," + Math.sin(t.a) * t.r0
26
+ "C" + Math.cos(a2) * t.r0 + "," + Math.sin(a2) * t.r0
27
+ " " + Math.cos(a1) * s.r0 + "," + Math.sin(a1) * s.r0
28
+ " " + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0
29
: "M" + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0
30
+ "C" + Math.cos(a1) * s.r1 + "," + Math.sin(a1) * s.r1
31
+ " " + Math.cos(a2) * t.r1 + "," + Math.sin(a2) * t.r1
32
+ " " + Math.cos(t.a) * t.r1 + "," + Math.sin(t.a) * t.r1;
33
}
34
35
function node(method, thiz, d, i) {
36
var node = method.call(thiz, d, i),
37
a = +(typeof angle === "function" ? angle.call(thiz, node, i) : angle) + arcOffset,
38
r0 = +(typeof startRadius === "function" ? startRadius.call(thiz, node, i) : startRadius),
39
r1 = (startRadius === endRadius ? r0 : +(typeof endRadius === "function" ? endRadius.call(thiz, node, i) : endRadius));
40
return {r0: r0, r1: r1, a: a};
41
}
42
43
link.source = function(_) {
44
if (!arguments.length) return source;
45
source = _;
46
return link;
47
};
48
49
link.target = function(_) {
50
if (!arguments.length) return target;
51
target = _;
52
return link;
53
};
54
55
link.angle = function(_) {
56
if (!arguments.length) return angle;
57
angle = _;
58
return link;
59
};
60
61
link.radius = function(_) {
62
if (!arguments.length) return startRadius;
63
startRadius = endRadius = _;
64
return link;
65
};
66
67
link.startRadius = function(_) {
68
if (!arguments.length) return startRadius;
69
startRadius = _;
70
return link;
71
};
72
73
link.endRadius = function(_) {
74
if (!arguments.length) return endRadius;
75
endRadius = _;
76
return link;
77
};
78
79
return link;
80
};
81
82