【问题标题】:Showing labels at a certain depth in a Javascript Infovis Toolkit Treemap在 Javascript Infovis Toolkit Treemap 中显示特定深度的标签
【发布时间】:2012-07-28 12:33:45
【问题描述】:

我正在创建一个具有 4 个级别(奥运会 > 体育 > 赛事 > 奖牌)的 treemap with the Javascript Infovis Toolkit,并且我希望一次显示三个 - 但只显示 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 = '';          
        }
}

当您放大/缩小时,_depth 似乎没有改变——它是每个节点的静态属性。

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

谢谢!

【问题讨论】:

    标签: javascript treemap infovis


    【解决方案1】:

    想通了! 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 = '';          
            }           
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-05-07
      • 2011-02-28
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      • 2012-03-27
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多