Skip to content

Instantly share code, notes, and snippets.

@trtg
Created January 1, 2013 15:41
Show Gist options
  • Save trtg/4428176 to your computer and use it in GitHub Desktop.
Save trtg/4428176 to your computer and use it in GitHub Desktop.
d3 tributary fisheye plugin demo
{"description":"d3 tributary fisheye plugin demo","endpoint":"","display":"svg","public":true,"require":[{"name":"fisheye","url":"https://raw.github.com/d3/d3-plugins/master/fisheye/fisheye.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"eye.svg":{"default":true,"vim":false,"emacs":false,"fontSize":12},"fish.svg":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.5752635051573745,"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,"hidepanel":false}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
var fishD = d3.select("#fish").attr("d")
//console.log(fishD)
d3.select("#fish").style("display","none");
var eye = d3.select("#eye");
var data = _.map(d3.range(100),function(d){
return {
i: d,
x: d %10 *84,
y: parseInt(d/10)*77
}
});
var svg = d3.select("svg");
var fishies = svg.selectAll("g.fish")
var fishies = svg.selectAll("g.fish")
.data(data)
.enter()
.append("g")
.classed("fish",true);
fishies.attr("transform",function(d){
return "translate("+[d.x,d.y]+")";
});
fishies.append("path")
.attr("d",fishD)
.style({
fill:"#8709AF",
"fill-opacity":0.4,
stroke: "#125EBE",
"stroke-opacity":0.8,
"stroke-width":3
})
var fisheye = d3.fisheye.circular()
.radius(298)
.distortion(2.25994);
fisheye.focus([tributary.sw/2,tributary.sh/2]);
fishies.attr("transform",function(d){
var fe = fisheye(d);
return "translate("+[fe.x,fe.y]+")"
+"scale("+fe.z+")";
});
svg.on("mousemove",function(){
var mouse = d3.mouse(this);
eye.attr("transform","translate("+[mouse[0]-50,mouse[1]-30 ]+")");
fisheye.focus(mouse);//set center of effect
//apply effect:
fishies.attr("transform",function(d){
var fe = fisheye(d);
return "translate("+[fe.x,fe.y]+")"
+"scale("+fe.z+")";
});
//console.log(mouse);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment