Infovis JIT: add click listener to edge

风流意气都作罢 提交于 2019-12-04 02:00:16

问题


I'm trying to capture a click event on an edge of a sunburst graph. I've already captured click events on nodes. This is what I'm trying:

//..sunburst example code
Events: {  
  enable: true,  
  enableForEdges: true,  
  type: 'Native',  
  onClick: function(node, eventInfo, e){  
    if (!node) return;  
    if(node.nodeFrom){  
      console.log("target is an edge");  
    }else{  
      console.log("target is a node");  
    }  
  }  

But this only captures node clicks. What's wrong? Thank you in advance.


回答1:


The problem is that 'contains' method, for the edge type 'hyperline'(which sunburst uses) is not yet implemented in the infovis library.

Contains method is used by library to know if some position specified in parameters is within the edge or not. You can not get events without contains method. So, you can either implement your own contains method for type hyperline in jit.js or you can simply change the edge type to 'line' from 'hyperline' in init method.

Edge: {
  overridable: true,
  type: 'line',  //'hyperline'
  lineWidth: 2,
  color: '#777'
} 

You will be able to capture events for edge type 'line' because contains method is defined for 'line' type.



来源:https://stackoverflow.com/questions/16547214/infovis-jit-add-click-listener-to-edge

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