Jap Evans
Jap Evans

Reputation: 1127

Is there a edge weighted spring embedded layout in cytoscape.js?

We have a requirement to show nodes and edges graph in our Angular application and we chose to do it in cytoscape over high charts/amCharts/D3. Cytoscape is faster in loading and is the only library to handle 1000s of nodes that we have. Others break or lags.

We downloaded cytoscape app and were able to see a layout 'Edge weighted spring embedded'. It shows our interconnected nodes in a overall globe-like layout.

Now I want the same in cytoscape js and looks like we only have handful of layouts in https://js.cytoscape.org/

Does this layout possible in cytoscape js? How to achieve this? (Currently using fcose layout but we really like the globe look that 'Edge weighted spring embedded layout brings.

EDIT:

Here is another example: I want to achieve this layout in cytoscape.js. What layout I should follow? Or is this something not available in js and only available in desktop App

enter image description here

Upvotes: 0

Views: 1340

Answers (2)

LCK
LCK

Reputation: 137

You can try "Euler" layout, it might give the same expected layout that you wanted. It is euler.js. I am using this layout for my own data set and is giving similar layout that you have shown above.

Upvotes: 0

Stephan T.
Stephan T.

Reputation: 6074

There are three options I think:

  • The Compound Spring Embedder layout cose
  • The Compound Spring Embedder layout by Bilkent (for an enhanced compound node placement) cose-bilkent
  • The Constraint-Based Layout cola.js

They all use some sort of force directed layout, I think you should give them a try and use the one most fitting to your needs. There are many parameters you can set for each layout, so take a closer look at them too. For example, if you set infinite to true in the cola.js layout, you will see that you can move the nodes around and see the layout force them back to or to a fitting position:

document.addEventListener("DOMContentLoaded", function() {
  var cy = (window.cy = cytoscape({
    container: document.getElementById("cy"),
    autounselectify: true,

    boxSelectionEnabled: false,
    layout: {
      name: "cola",
      infinite: true,
      fit: false
    },
    style: [{
        selector: "node",
        css: {
          "background-color": "#f92411"
        }
      },
      {
        selector: "edge",
        css: {
          "line-color": "#f92411"
        }
      }
    ],
    elements: {
      nodes: [{
          data: {
            id: "1",
            label: "P"
          }
        },
        {
          data: {
            id: "2",
            label: "sucrose phosphate phosphatase"
          }
        },
        {
          data: {
            id: "4",
            label: "sucrose 6-phosphate"
          }
        },
        {
          data: {
            id: "6",
            label: "sucrose"
          }
        },
        {
          data: {
            id: "8",
            label: "invertase"
          }
        },
        {
          data: {
            id: "10",
            label: "fructose"
          }
        },
        {
          data: {
            id: "12",
            label: "fructokinase"
          }
        },
        {
          data: {
            id: "14",
            label: "fructose 6-phosphate"
          }
        },
        {
          data: {
            id: "20",
            label: "phosphoglucose isomerase"
          }
        },
        {
          data: {
            id: "22",
            label: "glucose 6-phosphate"
          }
        },
        {
          data: {
            id: "28",
            label: "glucose"
          }
        },
        {
          data: {
            id: "30",
            label: "hexokinase"
          }
        },
        {
          data: {
            id: "33",
            label: "sucrose synthase"
          }
        },
        {
          data: {
            id: "36",
            label: "UDP - glucose"
          }
        },
        {
          data: {
            id: "38",
            label: "sucrose phosphate synthase"
          }
        },
        {
          data: {
            id: "41",
            label: "UDP"
          }
        },
        {
          data: {
            id: "44",
            label: "fructose 6-phosphate"
          }
        },
        {
          data: {
            id: "46",
            label: "ATP"
          }
        },
        {
          data: {
            id: "47",
            label: "ATP"
          }
        },
        {
          data: {
            id: "52",
            label: "ATP"
          }
        },
        {
          data: {
            id: "57",
            label: "ADP"
          }
        },
        {
          data: {
            id: "66",
            label: "PP"
          }
        },
        {
          data: {
            id: "71",
            label: "UTP"
          }
        },
        {
          data: {
            id: "76",
            label: "UDP glucose pyrophosphorylase"
          }
        },
        {
          data: {
            id: "80",
            label: "glucose 1-phosphate"
          }
        },
        {
          data: {
            id: "86",
            label: "phospho- glucomutase (cPGM)"
          }
        },
        {
          data: {
            id: "89",
            label: "G1P transporter"
          }
        },
        {
          data: {
            id: "90",
            label: "P"
          }
        },
        {
          data: {
            id: "95",
            label: "P"
          }
        },
        {
          data: {
            id: "102",
            label: "P"
          }
        },
        {
          data: {
            id: "103",
            label: "P"
          }
        },
        {
          data: {
            id: "104",
            label: "G6P transporter"
          }
        },
        {
          data: {
            id: "109",
            label: "glucose 6-phosphate"
          }
        },
        {
          data: {
            id: "115",
            label: "phospho- glucomutase (cPGM)"
          }
        },
        {
          data: {
            id: "121",
            label: "glucose 1-phosphate"
          }
        },
        {
          data: {
            id: "128",
            label: "ADPglucose pyrophosphorylase (pAGPase)"
          }
        },
        {
          data: {
            id: "130",
            label: "ADP - glucose"
          }
        },
        {
          data: {
            id: "136",
            label: "PP"
          }
        },
        {
          data: {
            id: "141",
            label: "ATP"
          }
        },
        {
          data: {
            id: "148",
            label: "inorganic diphosphatase"
          }
        },
        {
          data: {
            id: "149",
            label: "P"
          }
        },
        {
          data: {
            id: "156",
            label: "phosphate transporter"
          }
        },
        {
          data: {
            id: "158",
            label: "P"
          }
        },
        {
          data: {
            id: "164",
            label: "starch synthase (simpl.)"
          }
        },
        {
          data: {
            id: "166",
            label: "ADP"
          }
        },
        {
          data: {
            id: "172",
            label: "starch"
          }
        },
        {
          data: {
            id: "178",
            label: "ATP/ADP transporter"
          }
        },
        {
          data: {
            id: "179",
            label: "ADP"
          }
        },
        {
          data: {
            id: "184",
            label: "ADP"
          }
        },
        {
          data: {
            id: "189",
            label: "ATP"
          }
        }
      ],
      edges: [{
          data: {
            source: "2",
            target: "1"
          }
        },
        {
          data: {
            source: "4",
            target: "2"
          }
        },
        {
          data: {
            source: "2",
            target: "6"
          }
        },
        {
          data: {
            source: "6",
            target: "8"
          }
        },
        {
          data: {
            source: "8",
            target: "10"
          }
        },
        {
          data: {
            source: "12",
            target: "14"
          }
        },
        {
          data: {
            source: "14",
            target: "20"
          }
        },
        {
          data: {
            source: "20",
            target: "22"
          }
        },
        {
          data: {
            source: "8",
            target: "28"
          }
        },
        {
          data: {
            source: "28",
            target: "30"
          }
        },
        {
          data: {
            source: "30",
            target: "22"
          }
        },
        {
          data: {
            source: "6",
            target: "33"
          }
        },
        {
          data: {
            source: "33",
            target: "10"
          }
        },
        {
          data: {
            source: "33",
            target: "36"
          }
        },
        {
          data: {
            source: "36",
            target: "38"
          }
        },
        {
          data: {
            source: "38",
            target: "4"
          }
        },
        {
          data: {
            source: "38",
            target: "41"
          }
        },
        {
          data: {
            source: "41",
            target: "33"
          }
        },
        {
          data: {
            source: "44",
            target: "38"
          }
        },
        {
          data: {
            source: "52",
            target: "12"
          }
        },
        {
          data: {
            source: "12",
            target: "57"
          }
        },
        {
          data: {
            source: "46",
            target: "30"
          }
        },
        {
          data: {
            source: "30",
            target: "47"
          }
        },
        {
          data: {
            source: "71",
            target: "76"
          }
        },
        {
          data: {
            source: "76",
            target: "66"
          }
        },
        {
          data: {
            source: "76",
            target: "36"
          }
        },
        {
          data: {
            source: "80",
            target: "76"
          }
        },
        {
          data: {
            source: "22",
            target: "86"
          }
        },
        {
          data: {
            source: "86",
            target: "80"
          }
        },
        {
          data: {
            source: "95",
            target: "89"
          }
        },
        {
          data: {
            source: "89",
            target: "90"
          }
        },
        {
          data: {
            source: "102",
            target: "104"
          }
        },
        {
          data: {
            source: "80",
            target: "89"
          }
        },
        {
          data: {
            source: "104",
            target: "109"
          }
        },
        {
          data: {
            source: "115",
            target: "109"
          }
        },
        {
          data: {
            source: "121",
            target: "89"
          }
        },
        {
          data: {
            source: "121",
            target: "115"
          }
        },
        {
          data: {
            source: "121",
            target: "128"
          }
        },
        {
          data: {
            source: "128",
            target: "130"
          }
        },
        {
          data: {
            source: "141",
            target: "128"
          }
        },
        {
          data: {
            source: "128",
            target: "136"
          }
        },
        {
          data: {
            source: "136",
            target: "148"
          }
        },
        {
          data: {
            source: "148",
            target: "149"
          }
        },
        {
          data: {
            source: "149",
            target: "156"
          }
        },
        {
          data: {
            source: "156",
            target: "158"
          }
        },
        {
          data: {
            source: "130",
            target: "164"
          }
        },
        {
          data: {
            source: "164",
            target: "166"
          }
        },
        {
          data: {
            source: "178",
            target: "179"
          }
        },
        {
          data: {
            source: "184",
            target: "178"
          }
        },
        {
          data: {
            source: "178",
            target: "189"
          }
        },
        {
          data: {
            source: "141",
            target: "178"
          }
        },
        {
          data: {
            source: "104",
            target: "103"
          }
        },
        {
          data: {
            source: "10",
            target: "12"
          }
        },
        {
          data: {
            source: "164",
            target: "172"
          }
        },
        {
          data: {
            source: "22",
            target: "104"
          }
        }
      ]
    }
  }));
  cy.unbind("tapend");
  cy.bind("tapend", "node", function() {
    cy.animate({
      fit: {
        eles: cy.elements(),
        padding: 20
      },
      center: {
        eles: cy.elements()
      }
    }, {
      duration: 500
    });
  });
});
body {
  font-family: helvetica;
  font-size: 14px;
}

#cy {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 999;
}

h1 {
  opacity: 0.5;
  font-size: 1em;
}
<!DOCTYPE>

<html>

<head>
  <title>cytoscape-cola.js demo</title>

  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">

  <script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>

  <!-- for testing with local version of cytoscape.js -->
  <!--<script src="../cytoscape.js/build/cytoscape.js"></script>-->

  <script src="https://unpkg.com/webcola/WebCola/cola.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/cytoscape-cola.min.js"></script>

</head>

<body>
  <h1>cytoscape-cola demo</h1>

  <div id="cy"></div>

</body>

</html>

Upvotes: 3

Related Questions