2012-07-28 47 views
2

我創建了4個級別(奧運>體育>活動>獎牌)的treemap with the Javascript Infovis Toolkit,我希望一次顯示三個標籤 - 但僅標籤爲2/3 。在Javascript Infovis工具包樹圖中顯示特定深度的標籤

(例如:在頂視圖中,我會展示所有不同的體育和體育內的所有事件,但沒有標籤的事件,因爲有太多的。)

我使用下面的代碼,試圖掩蓋的水平,但它不會取消隱藏他們,當我放大

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

看來,當你放大/縮小該_depth不會改變 - 這是一個靜態屬性的每個節點。

我可能能夠編寫一個條件,根據深度當前的節點設置爲父級更改深度級別以顯示深度級別。任何人都知道我會在哪找到?

謝謝!

回答

2

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