How to hide folders using partition layout based on available space in D3?

元气小坏坏 提交于 2019-12-25 01:32:48

问题


I am using the Zoomable Icicle layout example in D3 found here: http://bl.ocks.org/mbostock/1005873 and would like to hide some sub-folders within a folder based on certain conditions i.e. if it has not been recently modified and based on available screen space (if this is possible).

I would then like the sub-folders that meet the criteria to make up the entire space underneath their parent folders, but the parent folder should have an arrow to show that there are hidden sub-folders within that folder. See the below image for clarity.

I am new at using D3 and am not sure how to filter the data correctly to completely hide the other folders (although I need to be able to access these folders later as well).

Is there anyone that can point me in the right direction using the example code?

Many thanks.


回答1:


You need to filter the data to exclude the empty subfolders before you're passing it to the layout. The point of the layout is to compute the position and size of the elements given the data. So in order to have the non-hidden folders take up all available space, only pass those to the layout.

The Javascript array .filter() function may be of help for what you're doing.



来源:https://stackoverflow.com/questions/20790773/how-to-hide-folders-using-partition-layout-based-on-available-space-in-d3

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