javascript - d3 v4: Clip path not updating after pan and zoom -


i have rect holding clip path, i'm applying group (holding tree). have zoom function bound rect transforms group, works fine. i've applied clip path group, , when first renders looks should. however, after panning or zooming, drawn tree extends beyond bounds of clip path while maintaining previously-clipped appearance.

var svg = d3.select(this.$.chart); var svg2 = svg.select("svg"); var main = svg2.append("g")     .attr("class","main")     .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var treecontainer = svg2.append('g')     .attr("transform", "translate(" + margin2.left + "," + margin2.top + ")") var treebaserect = treecontainer.append("rect") // rectangle holds clip path , zoom actions tree.     .attr("width", width + margin2.right)     .attr("height", height2)     .style("fill", "#eee")     .style("pointer-events", "all")     .call(d3.zoom().scaleextent([0.1, 3]).on("zoom", function () {         svggroup.attr("transform", d3.event.transform)     })); treecontainer.append('defs').append("clippath")     .attr("id", "clip")   .append("rect")     .attr("width", width + margin2.right)     .attr("height", height2); var svggroup = treecontainer.append("g")     .attr("clip-path","url(#clip)"); 

here's screenshots. first 1 shows initial render, fine (the clip area darker grey rectangle):

enter image description here

then after doing scroll zoom or pan, note how tree still 'originally' clipped, , not being clipped outside of gray area: enter image description here

and clip path rect in dom structure: enter image description here

you can tell clip rect still it's meant be, tree ignoring it. no idea why.

apparently hadn't added enough groups. easy solution add append("g") svggroup creating, last line looking this:

var svggroup = treecontainer.append("g")                 .attr("clip-path","url(#clip)")                 .append("g"); 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -