Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / static / fusion / d3 / js / fisheye.js
1 (function() {
2   d3.fisheye = {
3     scale: function(scaleType) {
4       return d3_fisheye_scale(scaleType(), 3, 0);
5     },
6     circular: function() {
7       var radius = 200,
8           distortion = 2,
9           k0,
10           k1,
11           focus = [0, 0];
12
13       function fisheye(d) {
14         var dx = d.x - focus[0],
15             dy = d.y - focus[1],
16             dd = Math.sqrt(dx * dx + dy * dy);
17         if (!dd || dd >= radius) return {x: d.x, y: d.y, z: 1};
18         var k = k0 * (1 - Math.exp(-dd * k1)) / dd * .75 + .25;
19         return {x: focus[0] + dx * k, y: focus[1] + dy * k, z: Math.min(k, 10)};
20       }
21
22       function rescale() {
23         k0 = Math.exp(distortion);
24         k0 = k0 / (k0 - 1) * radius;
25         k1 = distortion / radius;
26         return fisheye;
27       }
28
29       fisheye.radius = function(_) {
30         if (!arguments.length) return radius;
31         radius = +_;
32         return rescale();
33       };
34
35       fisheye.distortion = function(_) {
36         if (!arguments.length) return distortion;
37         distortion = +_;
38         return rescale();
39       };
40
41       fisheye.focus = function(_) {
42         if (!arguments.length) return focus;
43         focus = _;
44         return fisheye;
45       };
46
47       return rescale();
48     }
49   };
50
51   function d3_fisheye_scale(scale, d, a) {
52
53     function fisheye(_) {
54       var x = scale(_),
55           left = x < a,
56           v,
57           range = d3.extent(scale.range()),
58           min = range[0],
59           max = range[1],
60           m = left ? a - min : max - a;
61       if (m == 0) m = max - min;
62       return (left ? -1 : 1) * m * (d + 1) / (d + (m / Math.abs(x - a))) + a;
63     }
64
65     fisheye.distortion = function(_) {
66       if (!arguments.length) return d;
67       d = +_;
68       return fisheye;
69     };
70
71     fisheye.focus = function(_) {
72       if (!arguments.length) return a;
73       a = +_;
74       return fisheye;
75     };
76
77     fisheye.copy = function() {
78       return d3_fisheye_scale(scale.copy(), d, a);
79     };
80
81     fisheye.nice = scale.nice;
82     fisheye.ticks = scale.ticks;
83     fisheye.tickFormat = scale.tickFormat;
84     return d3.rebind(fisheye, scale, "domain", "range");
85   }
86 })();