How to highlight the path between two nodes in CYTOSCAPE JS

前端 未结 3 904
南方客
南方客 2020-12-19 14:45

i can create a graph using cytoscape js library . i am following the this tutorial and i implement like this.

CODE:

$(function(){ /         


        
3条回答
  •  春和景丽
    2020-12-19 15:26

    Assuming you have picked two nodes and stored them in source_node and target_node, and you want to label everything in between with class 'path_element':

    p = cy.elements().aStar({root: source_node, goal: target_node, directed: true}).path;
    if (p) {
      p.filter(function(i,x) { return x != source_node && x != target_node; })
          .addClass('path_element');
    
      p.edgesWith(p)
          .addClass('path_element');
    }
    

提交回复
热议问题