DagreLayout.prototype.run = function()

in static/js/cytoscape-dagre.js [122:269]


      DagreLayout.prototype.run = function () {
        var options = this.options;
        var layout = this;

        var cy = options.cy; // cy is automatically populated for us in the constructor
        var eles = options.eles;

        var getVal = function getVal(ele, val) {
          return isFunction(val) ? val.apply(ele, [ele]) : val;
        };

        var bb = options.boundingBox || { x1: 0, y1: 0, w: cy.width(), h: cy.height() };
        if (bb.x2 === undefined) {
          bb.x2 = bb.x1 + bb.w;
        }
        if (bb.w === undefined) {
          bb.w = bb.x2 - bb.x1;
        }
        if (bb.y2 === undefined) {
          bb.y2 = bb.y1 + bb.h;
        }
        if (bb.h === undefined) {
          bb.h = bb.y2 - bb.y1;
        }

        var g = new dagre.graphlib.Graph({
          multigraph: true,
          compound: true
        });

        var gObj = {};
        var setGObj = function setGObj(name, val) {
          if (val != null) {
            gObj[name] = val;
          }
        };

        setGObj('nodesep', options.nodeSep);
        setGObj('edgesep', options.edgeSep);
        setGObj('ranksep', options.rankSep);
        setGObj('rankdir', options.rankDir);
        setGObj('ranker', options.ranker);

        g.setGraph(gObj);

        g.setDefaultEdgeLabel(function () {
          return {};
        });
        g.setDefaultNodeLabel(function () {
          return {};
        });

        // add nodes to dagre
        var nodes = eles.nodes();
        for (var i = 0; i < nodes.length; i++) {
          var node = nodes[i];
          var nbb = node.layoutDimensions(options);

          g.setNode(node.id(), {
            width: nbb.w,
            height: nbb.h,
            name: node.id()
          });

          // console.log( g.node(node.id()) );
        }

        // set compound parents
        for (var _i = 0; _i < nodes.length; _i++) {
          var _node = nodes[_i];

          if (_node.isChild()) {
            g.setParent(_node.id(), _node.parent().id());
          }
        }

        // add edges to dagre
        var edges = eles.edges().stdFilter(function (edge) {
          return !edge.source().isParent() && !edge.target().isParent(); // dagre can't handle edges on compound nodes
        });
        for (var _i2 = 0; _i2 < edges.length; _i2++) {
          var edge = edges[_i2];

          g.setEdge(edge.source().id(), edge.target().id(), {
            minlen: getVal(edge, options.minLen),
            weight: getVal(edge, options.edgeWeight),
            name: edge.id()
          }, edge.id());

          // console.log( g.edge(edge.source().id(), edge.target().id(), edge.id()) );
        }

        dagre.layout(g);

        var gNodeIds = g.nodes();
        for (var _i3 = 0; _i3 < gNodeIds.length; _i3++) {
          var id = gNodeIds[_i3];
          var n = g.node(id);

          cy.getElementById(id).scratch().dagre = n;
        }

        var dagreBB = void 0;

        if (options.boundingBox) {
          dagreBB = { x1: Infinity, x2: -Infinity, y1: Infinity, y2: -Infinity };
          nodes.forEach(function (node) {
            var dModel = node.scratch().dagre;

            dagreBB.x1 = Math.min(dagreBB.x1, dModel.x);
            dagreBB.x2 = Math.max(dagreBB.x2, dModel.x);

            dagreBB.y1 = Math.min(dagreBB.y1, dModel.y);
            dagreBB.y2 = Math.max(dagreBB.y2, dModel.y);
          });

          dagreBB.w = dagreBB.x2 - dagreBB.x1;
          dagreBB.h = dagreBB.y2 - dagreBB.y1;
        } else {
          dagreBB = bb;
        }

        var constrainPos = function constrainPos(p) {
          if (options.boundingBox) {
            var xPct = dagreBB.w === 0 ? 0 : (p.x - dagreBB.x1) / dagreBB.w;
            var yPct = dagreBB.h === 0 ? 0 : (p.y - dagreBB.y1) / dagreBB.h;

            return {
              x: bb.x1 + xPct * bb.w,
              y: bb.y1 + yPct * bb.h
            };
          } else {
            return p;
          }
        };

        nodes.layoutPositions(layout, options, function (ele) {
          ele = (typeof ele === 'undefined' ? 'undefined' : _typeof(ele)) === "object" ? ele : this;
          var dModel = ele.scratch().dagre;

          return constrainPos({
            x: dModel.x,
            y: dModel.y
          });
        });

        return this; // chaining
      };