Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript Infovis Toolkit树状图中以一定深度显示标签_Javascript_Treemap_Infovis - Fatal编程技术网

在Javascript Infovis Toolkit树状图中以一定深度显示标签

在Javascript Infovis Toolkit树状图中以一定深度显示标签,javascript,treemap,infovis,Javascript,Treemap,Infovis,我正在创建一个具有4个级别(奥运会>体育>赛事>奖牌)的标签,我希望一次显示3个级别,但仅显示2/3的标签 (例如:在俯视图中,我会显示所有不同的运动项目,以及运动项目中的所有事件,但不会显示事件的标签,因为事件太多了。) 我使用下面的代码来尝试隐藏级别,但放大时不会取消隐藏 onPlaceLabel: function(domElement, node){ if (node._depth == 0) {console.dir(node);} if (node._dept

我正在创建一个具有4个级别(奥运会>体育>赛事>奖牌)的标签,我希望一次显示3个级别,但仅显示2/3的标签

(例如:在俯视图中,我会显示所有不同的运动项目,以及运动项目中的所有事件,但不会显示事件的标签,因为事件太多了。)

我使用下面的代码来尝试隐藏级别,但放大时不会取消隐藏

onPlaceLabel: function(domElement, node){
    if (node._depth == 0) {console.dir(node);}
        if (node._depth > 1) {
            domElement.style.display = 'none';
        } else {
            domElement.style.display = '';          
        }
}
当您放大/缩小时,深度似乎不会改变-它是每个节点的静态属性

我可能能够编写一个条件,根据设置为父节点的深度当前节点更改显示的深度级别。有人知道我在哪里找到的吗

谢谢

找到了! onBeforeComputer();方法在计算所有内容之前对所选节点执行操作。见以下代码:

//sets the selected node depth as the .currentParentDepth
onBeforeCompute : function(node){
    if (typeof this.currentParentDepth === "undefined") {
        this.currentParentDepth = 0;
    }
    else {
        this.currentParentDepth = node._depth; 
    }
},

onPlaceLabel: function(domElement, node){
    if (this.currentParentDepth == 0) {
        if (node._depth > 1) {
            domElement.style.display = 'none';
        } else {
            domElement.style.display = '';          
        }
    } else if (this.currentParentDepth == 1) {
        if (node._depth > 2) {
            domElement.style.display = 'none';
        } else {
            domElement.style.display = '';          
        }           
    }
}