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):
then after doing scroll zoom or pan, note how tree still 'originally' clipped, , not being clipped outside of gray area: 
and clip path rect in dom structure: 
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
Post a Comment