[ Launch: fisheye ] 76adad68ceea66ee4be2 by enjalot
[ Launch: fisheye ] acacf2090b88622512f7 by zanarmstrong
[ Launch: test ] 4653053 by enjalot
[ Launch: test ] 4652017 by enjalot
[ Launch: test ] 4582399 by enjalot
-
-
Save enjalot/76adad68ceea66ee4be2 to your computer and use it in GitHub Desktop.
fisheye
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"fisheye","endpoint":"","display":"svg","public":true,"require":[{"name":"fisheye","url":"https://raw.githubusercontent.com/d3/d3-plugins/master/fisheye/fisheye.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"fisheye.js":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"tab":"edit","display_percent":0.7,"thumbnail":"http://i.imgur.com/Z4ghHZY.png","fullscreen":false,"ajax-caching":true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://raw.githubusercontent.com/d3/d3-plugins/master/fisheye/fisheye.js | |
(function() { | |
d3.fisheye = { | |
scale: function(scaleType) { | |
return d3_fisheye_scale(scaleType(), 3, 0); | |
}, | |
circular: function() { | |
var radius = 200, | |
distortion = 2, | |
k0, | |
k1, | |
focus = [0, 0]; | |
function fisheye(d) { | |
var dx = d.x - focus[0], | |
dy = d.y - focus[1], | |
dd = Math.sqrt(dx * dx + dy * dy); | |
if (!dd || dd >= radius) return {x: d.x, y: d.y, z: dd >= radius ? 1 : 10}; | |
var k = k0 * (1 - Math.exp(-dd * k1)) / dd * .75 + .25; | |
return {x: focus[0] + dx * k, y: focus[1] + dy * k, z: Math.min(k, 10)}; | |
} | |
function rescale() { | |
k0 = Math.exp(distortion); | |
k0 = k0 / (k0 - 1) * radius; | |
k1 = distortion / radius; | |
return fisheye; | |
} | |
fisheye.radius = function(_) { | |
if (!arguments.length) return radius; | |
radius = +_; | |
return rescale(); | |
}; | |
fisheye.distortion = function(_) { | |
if (!arguments.length) return distortion; | |
distortion = +_; | |
return rescale(); | |
}; | |
fisheye.focus = function(_) { | |
if (!arguments.length) return focus; | |
focus = _; | |
return fisheye; | |
}; | |
return rescale(); | |
} | |
}; | |
function d3_fisheye_scale(scale, d, a) { | |
function fisheye(_) { | |
var x = scale(_), | |
left = x < a, | |
range = d3.extent(scale.range()), | |
min = range[0], | |
max = range[1], | |
m = left ? a - min : max - a; | |
if (m == 0) m = max - min; | |
return (left ? -1 : 1) * m * (d + 1) / (d + (m / Math.abs(x - a))) + a; | |
} | |
fisheye.distortion = function(_) { | |
if (!arguments.length) return d; | |
d = +_; | |
return fisheye; | |
}; | |
fisheye.focus = function(_) { | |
if (!arguments.length) return a; | |
a = +_; | |
return fisheye; | |
}; | |
fisheye.copy = function() { | |
return d3_fisheye_scale(scale.copy(), d, a); | |
}; | |
fisheye.nice = scale.nice; | |
fisheye.ticks = scale.ticks; | |
fisheye.tickFormat = scale.tickFormat; | |
return d3.rebind(fisheye, scale, "domain", "range"); | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svg = d3.select("svg") | |
var list = []; | |
for (var i = 0; i <= 100; i++) { | |
list.push(i * 10); | |
} | |
svg.selectAll("circle").data(list).enter() | |
.append("circle") | |
.attr({ | |
cx: function(d){return d}, | |
cy: 200, | |
r: 4 | |
}); | |
var fisheye = d3.fisheye.circular().distortion(20).radius(300) | |
svg.on("mousemove", function(d){ | |
fisheye.focus(d3.mouse(this)); | |
d3.selectAll("circle").attr("cx", function(d){return fisheye({x: d, y: 200}).x}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment