Need to recalculate partition layout after filter in D3?

瘦欲@ 提交于 2019-12-13 04:37:31

问题


I am using the Zoomable Icicle layout example to view a folder hierarchy.

I currently use the filter function as follows:

var data = partition.nodes(root).filter(
        function (d) {
            return d.parent == null ? d.children && d.dateAccessed > formattedD : d.children && d.dateAccessed > formattedD && d.parent.dateAccessed > formattedD;
        });

This filters out whether a folder (with all its sub-folders) needs to be shown / not shown depending on whether the folder's dateAccessed is after a certain date.

I then use the example code using this data variable to draw the partitions.

rect = rect
               .data(data)
              .enter().append("rect")
              .attr("x", function (d) { console.log(!d.children); return x(d.x); })
              .attr("y", function (d) { return y(d.y); })
              .attr("width", function (d) { return x(d.dx); })
              .attr("height", function (d) { return y(d.dy); })
              .attr("fill", function (d) {
                  return (type == "Documents") ? '#9370DB' : (type == "Pictures") ? '#87CEFA' : (type == "Music") ? '#6B8E23' : (type == "Videos") ? '#F0E68C' : "#000000";
              })
              .on("click", clicked);

I need the layout to recalculate where the folders are placed, as currently it keeps the space for a filtered out folder (see the attached image). (Please excuse the dis-organisation of the folders in the image, that's how it was when it was read in.)

Many thanks.

来源:https://stackoverflow.com/questions/20752242/need-to-recalculate-partition-layout-after-filter-in-d3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!