d3.js - Change width of ellipse when zooming -


i trying create heatmap in d3js zoom , pan feature. far, pan function works should, have minor problem zoom feature.

the zoom feature should scale (stretch/squeeze) in direction of x-axis, @ moment. right now, initial view of heatmap—when load script—shows me entire dataset squeezed dots, want. problem squeezed dots stay squeezed when zoom in, leads huge gaps between them. scale dotwidth of svg ellipses (the dots) avoid this. however, not sure how implement it. below code samples script.

to more specific: if initial height , width of ellipse 1 , 3, respectively, width scale between 1 , 3, becomes circle under max zoom.

create heatmap:

var dotwidth = 1 var dotheight = 3  // heatmap ellipes svg.selectall("ellipse")     .data(dataset)     .enter()     .append("ellipse")     .attr("cx", function(d) { return xscale(d.day) + paddingleft; })     .attr("cy", function(d) { return yscale(d.hour); })     .attr("rx", dotwidth)     .attr("ry", dotheight)     .attr("fill", function(d) {         return "rgba(100, 200, 200, " + colorscale(d.toutc) + ")";     }); 

create zoom:

var zoom = d3.behavior.zoom()     .scaleextent([1, 3])     .x(xscale)     .on("zoom", zoomhandler);  function zoomhandler() {     var t = zoom.translate(),         tx = t[0],         ty = t[1];      tx = math.min(tx, 0); // tx < 0     tx = math.max(tx,  -1000); //     zoom.translate([tx, ty]);      svg.select(".x.axis").call(xaxis);     svg.selectall("ellipse")         .attr("cx", function(d) { return xscale(d.day) + paddingleft; })         .attr("cy", function(d) { return yscale(d.hour); }); } 

i think created new x , y positions ellipses didn´t change radius. circle works that:

var scalemultiplier = d3.event.scale; 

circles .attr("cx", function(d, i) { return xaxisscale(d.cx); }) .attr("cy", function(d, i) { return yaxisscale(d.cy); }) .attr("r", function(d, i) { return (d.radius * scalemultiplier); }); }


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -