Created
November 28, 2019 13:09
-
-
Save tbblack/9270721755e73d35a03b5d94ba5d2d06 to your computer and use it in GitHub Desktop.
Cytoscape.js shortest path exmaple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="cy"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cy = cytoscape({ | |
container: document.getElementById('cy'), // container to render in | |
layout: { | |
name: 'random' | |
}, | |
elements: [{ | |
group: 'nodes', | |
data: { | |
id: 'n1' | |
} | |
}, { | |
group: 'nodes', | |
data: { | |
id: 'n2' | |
} | |
}, { | |
group: 'nodes', | |
data: { | |
id: 'n3' | |
} | |
}, { | |
group: 'nodes', | |
data: { | |
id: 'n4' | |
} | |
}, { | |
data: { | |
id: 'e1', | |
source: 'n1', | |
target: 'n4' | |
} | |
}, | |
{ | |
data: { | |
id: 'e2', | |
source: 'n1', | |
target: 'n2' | |
} | |
}, { | |
data: { | |
id: 'e3', | |
source: 'n2', | |
target: 'n3' | |
} | |
}, { | |
data: { | |
id: 'e4', | |
source: 'n3', | |
target: 'n4' | |
} | |
}] | |
}); | |
var dfs = cy.elements().aStar({ | |
root: '#n1', | |
goal: '#n4', | |
directed: true | |
}) | |
dfs.path.select() | |
console.log(dfs.distance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://rawgit.com/cytoscape/cytoscape.js/master/dist/cytoscape.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cy { | |
width: 300px; | |
height: 300px; | |
display: block; | |
background: #000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment