Path: blob/master/sandbox/RFinance2014/libraries/widgets/nvd3/js/fisheye.js
1433 views
(function() {1d3.fisheye = {2scale: function(scaleType) {3return d3_fisheye_scale(scaleType(), 3, 0);4},5circular: function() {6var radius = 200,7distortion = 2,8k0,9k1,10focus = [0, 0];1112function fisheye(d) {13var dx = d.x - focus[0],14dy = d.y - focus[1],15dd = Math.sqrt(dx * dx + dy * dy);16if (!dd || dd >= radius) return {x: d.x, y: d.y, z: 1};17var k = k0 * (1 - Math.exp(-dd * k1)) / dd * .75 + .25;18return {x: focus[0] + dx * k, y: focus[1] + dy * k, z: Math.min(k, 10)};19}2021function rescale() {22k0 = Math.exp(distortion);23k0 = k0 / (k0 - 1) * radius;24k1 = distortion / radius;25return fisheye;26}2728fisheye.radius = function(_) {29if (!arguments.length) return radius;30radius = +_;31return rescale();32};3334fisheye.distortion = function(_) {35if (!arguments.length) return distortion;36distortion = +_;37return rescale();38};3940fisheye.focus = function(_) {41if (!arguments.length) return focus;42focus = _;43return fisheye;44};4546return rescale();47}48};4950function d3_fisheye_scale(scale, d, a) {5152function fisheye(_) {53var x = scale(_),54left = x < a,55v,56range = d3.extent(scale.range()),57min = range[0],58max = range[1],59m = left ? a - min : max - a;60if (m == 0) m = max - min;61return (left ? -1 : 1) * m * (d + 1) / (d + (m / Math.abs(x - a))) + a;62}6364fisheye.distortion = function(_) {65if (!arguments.length) return d;66d = +_;67return fisheye;68};6970fisheye.focus = function(_) {71if (!arguments.length) return a;72a = +_;73return fisheye;74};7576fisheye.copy = function() {77return d3_fisheye_scale(scale.copy(), d, a);78};7980fisheye.nice = scale.nice;81fisheye.ticks = scale.ticks;82fisheye.tickFormat = scale.tickFormat;83return d3.rebind(fisheye, scale, "domain", "range");84}85})();868788