diff --git a/demo-compounds-collapsed.html b/demo-compounds-collapsed.html index 6b96d68..47cd77f 100644 --- a/demo-compounds-collapsed.html +++ b/demo-compounds-collapsed.html @@ -10,11 +10,15 @@ + + + - - - + + + + @@ -112,7 +116,8 @@ }); var api = cy.expandCollapse('get'); - var elements = null; + var elements = null; + var markovClusteringClickable = true; document.getElementById("collapseRecursively").addEventListener("click", function () { api.collapseRecursively(cy.$(":selected")); @@ -144,8 +149,69 @@ document.getElementById("expandAll").addEventListener("click", function () { api.expandAll(); + }); + + function applyMarkovClustering() { + var clusteringDepth = document.getElementById("clustering-depth-input").value; + if (clusteringDepth < 1) + return; + cy.startBatch(); + for (var i = 0; i < clusteringDepth; i++) { + //get clusters for this depth level + let clusters = cy.elements().markovClustering(); + + for (var j = 0; j < clusters.length; j++) { + let parentId = "p_" + i + "_" + j; + cy.add({ + group: 'nodes', + data: { + id: parentId + } + }); + clusters[j].move({ + parent: parentId + }); + } + cy.layout({ + name: "cose-bilkent", + randomize: true, + fit: true + }).run(); + api.collapseAll(); + } + cy.endBatch(); + document.getElementById("apply-markov-clustering").removeEventListener("click", applyMarkovClustering); + document.getElementById("apply-markov-clustering").style.cursor = "auto"; + markovClusteringClickable = false; + } + + document.getElementById("graphml-input").addEventListener("change", function(evt) { + //read graphML file + let files = evt.target.files; + let reader = new FileReader(); + let contents; + reader.readAsText(files[0]); + reader.onload = function(event) { + contents = event.target.result; + + cy.startBatch(); + cy.elements().remove(); + cy.graphml({layoutBy: 'cose-bilkent'}); + cy.graphml(contents); + cy.endBatch(); + + //to be able to open the same file again + document.getElementById("graphml-input").value = ""; + //avoid adding the same listener multiple times + if (!markovClusteringClickable) + document.getElementById("apply-markov-clustering").addEventListener("click", applyMarkovClustering); + document.getElementById("apply-markov-clustering").style.cursor = "pointer"; + markovClusteringClickable = true; + }; }); + document.getElementById("apply-markov-clustering").addEventListener("click", applyMarkovClustering); + }); @@ -155,7 +221,13 @@

cytoscape-expand-collapse demo

Expand all and remove / Load compouds collapsed
Collapse all / Expand all
- Collapse selected recursively / Expand selected recursively + Collapse selected recursively / Expand selected recursively
+ Import from GraphML file +
+
+ + +