0

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.)

image

Many thanks.

sim1
  • 457
  • 1
  • 7
  • 26
  • You need to filter the original data and run the `tree layout` again to recalculate the `d.x` and `d.y`. – musically_ut Dec 24 '13 at 02:57
  • Thanks for your comment, how would i run it again? – sim1 Dec 24 '13 at 07:25
  • You need to filter `root` _before_ calling `partition.node` on it to get the correct `d.x` and `d.y`. Sorry, my initial comment was a bit misleading. – musically_ut Dec 24 '13 at 08:32
  • 1
    Thanks for clarifying...can you possibly include the line of code how to filter root? Many thanks. – sim1 Dec 24 '13 at 14:48
  • 1
    The reason I am asking, it won't let me simply say `root.filter(function(d){ return d.children;})` as there is an error saying object has no method filter. – sim1 Dec 24 '13 at 15:14

0 Answers0