github.com/mweagle/Sparta@v1.15.0/resources/describe/cytoscape.js-dagre/cytoscape-dagre.js (about) 1 (function webpackUniversalModuleDefinition(root, factory) { 2 if(typeof exports === 'object' && typeof module === 'object') 3 module.exports = factory(require("dagre")); 4 else if(typeof define === 'function' && define.amd) 5 define(["dagre"], factory); 6 else if(typeof exports === 'object') 7 exports["cytoscapeDagre"] = factory(require("dagre")); 8 else 9 root["cytoscapeDagre"] = factory(root["dagre"]); 10 })(this, function(__WEBPACK_EXTERNAL_MODULE_4__) { 11 return /******/ (function(modules) { // webpackBootstrap 12 /******/ // The module cache 13 /******/ var installedModules = {}; 14 /******/ 15 /******/ // The require function 16 /******/ function __webpack_require__(moduleId) { 17 /******/ 18 /******/ // Check if module is in cache 19 /******/ if(installedModules[moduleId]) { 20 /******/ return installedModules[moduleId].exports; 21 /******/ } 22 /******/ // Create a new module (and put it into the cache) 23 /******/ var module = installedModules[moduleId] = { 24 /******/ i: moduleId, 25 /******/ l: false, 26 /******/ exports: {} 27 /******/ }; 28 /******/ 29 /******/ // Execute the module function 30 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 31 /******/ 32 /******/ // Flag the module as loaded 33 /******/ module.l = true; 34 /******/ 35 /******/ // Return the exports of the module 36 /******/ return module.exports; 37 /******/ } 38 /******/ 39 /******/ 40 /******/ // expose the modules object (__webpack_modules__) 41 /******/ __webpack_require__.m = modules; 42 /******/ 43 /******/ // expose the module cache 44 /******/ __webpack_require__.c = installedModules; 45 /******/ 46 /******/ // identity function for calling harmony imports with the correct context 47 /******/ __webpack_require__.i = function(value) { return value; }; 48 /******/ 49 /******/ // define getter function for harmony exports 50 /******/ __webpack_require__.d = function(exports, name, getter) { 51 /******/ if(!__webpack_require__.o(exports, name)) { 52 /******/ Object.defineProperty(exports, name, { 53 /******/ configurable: false, 54 /******/ enumerable: true, 55 /******/ get: getter 56 /******/ }); 57 /******/ } 58 /******/ }; 59 /******/ 60 /******/ // getDefaultExport function for compatibility with non-harmony modules 61 /******/ __webpack_require__.n = function(module) { 62 /******/ var getter = module && module.__esModule ? 63 /******/ function getDefault() { return module['default']; } : 64 /******/ function getModuleExports() { return module; }; 65 /******/ __webpack_require__.d(getter, 'a', getter); 66 /******/ return getter; 67 /******/ }; 68 /******/ 69 /******/ // Object.prototype.hasOwnProperty.call 70 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 71 /******/ 72 /******/ // __webpack_public_path__ 73 /******/ __webpack_require__.p = ""; 74 /******/ 75 /******/ // Load entry module and return exports 76 /******/ return __webpack_require__(__webpack_require__.s = 3); 77 /******/ }) 78 /************************************************************************/ 79 /******/ ([ 80 /* 0 */ 81 /***/ (function(module, exports, __webpack_require__) { 82 83 "use strict"; 84 85 86 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; 87 88 var isFunction = function isFunction(o) { 89 return typeof o === 'function'; 90 }; 91 var defaults = __webpack_require__(2); 92 var assign = __webpack_require__(1); 93 var dagre = __webpack_require__(4); 94 95 // constructor 96 // options : object containing layout options 97 function DagreLayout(options) { 98 this.options = assign({}, defaults, options); 99 } 100 101 // runs the layout 102 DagreLayout.prototype.run = function () { 103 var options = this.options; 104 var layout = this; 105 106 var cy = options.cy; // cy is automatically populated for us in the constructor 107 var eles = options.eles; 108 109 var getVal = function getVal(ele, val) { 110 return isFunction(val) ? val.apply(ele, [ele]) : val; 111 }; 112 113 var bb = options.boundingBox || { x1: 0, y1: 0, w: cy.width(), h: cy.height() }; 114 if (bb.x2 === undefined) { 115 bb.x2 = bb.x1 + bb.w; 116 } 117 if (bb.w === undefined) { 118 bb.w = bb.x2 - bb.x1; 119 } 120 if (bb.y2 === undefined) { 121 bb.y2 = bb.y1 + bb.h; 122 } 123 if (bb.h === undefined) { 124 bb.h = bb.y2 - bb.y1; 125 } 126 127 var g = new dagre.graphlib.Graph({ 128 multigraph: true, 129 compound: true 130 }); 131 132 var gObj = {}; 133 var setGObj = function setGObj(name, val) { 134 if (val != null) { 135 gObj[name] = val; 136 } 137 }; 138 139 setGObj('nodesep', options.nodeSep); 140 setGObj('edgesep', options.edgeSep); 141 setGObj('ranksep', options.rankSep); 142 setGObj('rankdir', options.rankDir); 143 setGObj('ranker', options.ranker); 144 145 g.setGraph(gObj); 146 147 g.setDefaultEdgeLabel(function () { 148 return {}; 149 }); 150 g.setDefaultNodeLabel(function () { 151 return {}; 152 }); 153 154 // add nodes to dagre 155 var nodes = eles.nodes(); 156 for (var i = 0; i < nodes.length; i++) { 157 var node = nodes[i]; 158 var nbb = node.layoutDimensions(options); 159 160 g.setNode(node.id(), { 161 width: nbb.w, 162 height: nbb.h, 163 name: node.id() 164 }); 165 166 // console.log( g.node(node.id()) ); 167 } 168 169 // set compound parents 170 for (var _i = 0; _i < nodes.length; _i++) { 171 var _node = nodes[_i]; 172 173 if (_node.isChild()) { 174 g.setParent(_node.id(), _node.parent().id()); 175 } 176 } 177 178 // add edges to dagre 179 var edges = eles.edges().stdFilter(function (edge) { 180 return !edge.source().isParent() && !edge.target().isParent(); // dagre can't handle edges on compound nodes 181 }); 182 for (var _i2 = 0; _i2 < edges.length; _i2++) { 183 var edge = edges[_i2]; 184 185 g.setEdge(edge.source().id(), edge.target().id(), { 186 minlen: getVal(edge, options.minLen), 187 weight: getVal(edge, options.edgeWeight), 188 name: edge.id() 189 }, edge.id()); 190 191 // console.log( g.edge(edge.source().id(), edge.target().id(), edge.id()) ); 192 } 193 194 dagre.layout(g); 195 196 var gNodeIds = g.nodes(); 197 for (var _i3 = 0; _i3 < gNodeIds.length; _i3++) { 198 var id = gNodeIds[_i3]; 199 var n = g.node(id); 200 201 cy.getElementById(id).scratch().dagre = n; 202 } 203 204 var dagreBB = void 0; 205 206 if (options.boundingBox) { 207 dagreBB = { x1: Infinity, x2: -Infinity, y1: Infinity, y2: -Infinity }; 208 nodes.forEach(function (node) { 209 var dModel = node.scratch().dagre; 210 211 dagreBB.x1 = Math.min(dagreBB.x1, dModel.x); 212 dagreBB.x2 = Math.max(dagreBB.x2, dModel.x); 213 214 dagreBB.y1 = Math.min(dagreBB.y1, dModel.y); 215 dagreBB.y2 = Math.max(dagreBB.y2, dModel.y); 216 }); 217 218 dagreBB.w = dagreBB.x2 - dagreBB.x1; 219 dagreBB.h = dagreBB.y2 - dagreBB.y1; 220 } else { 221 dagreBB = bb; 222 } 223 224 var constrainPos = function constrainPos(p) { 225 if (options.boundingBox) { 226 var xPct = dagreBB.w === 0 ? 0 : (p.x - dagreBB.x1) / dagreBB.w; 227 var yPct = dagreBB.h === 0 ? 0 : (p.y - dagreBB.y1) / dagreBB.h; 228 229 return { 230 x: bb.x1 + xPct * bb.w, 231 y: bb.y1 + yPct * bb.h 232 }; 233 } else { 234 return p; 235 } 236 }; 237 238 nodes.layoutPositions(layout, options, function (ele) { 239 ele = (typeof ele === 'undefined' ? 'undefined' : _typeof(ele)) === "object" ? ele : this; 240 var dModel = ele.scratch().dagre; 241 242 return constrainPos({ 243 x: dModel.x, 244 y: dModel.y 245 }); 246 }); 247 248 return this; // chaining 249 }; 250 251 module.exports = DagreLayout; 252 253 /***/ }), 254 /* 1 */ 255 /***/ (function(module, exports, __webpack_require__) { 256 257 "use strict"; 258 259 260 // Simple, internal Object.assign() polyfill for options objects etc. 261 262 module.exports = Object.assign != null ? Object.assign.bind(Object) : function (tgt) { 263 for (var _len = arguments.length, srcs = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 264 srcs[_key - 1] = arguments[_key]; 265 } 266 267 srcs.forEach(function (src) { 268 Object.keys(src).forEach(function (k) { 269 return tgt[k] = src[k]; 270 }); 271 }); 272 273 return tgt; 274 }; 275 276 /***/ }), 277 /* 2 */ 278 /***/ (function(module, exports, __webpack_require__) { 279 280 "use strict"; 281 282 283 var defaults = { 284 // dagre algo options, uses default value on undefined 285 nodeSep: undefined, // the separation between adjacent nodes in the same rank 286 edgeSep: undefined, // the separation between adjacent edges in the same rank 287 rankSep: undefined, // the separation between adjacent nodes in the same rank 288 rankDir: undefined, // 'TB' for top to bottom flow, 'LR' for left to right, 289 ranker: undefined, // Type of algorithm to assigns a rank to each node in the input graph. 290 // Possible values: network-simplex, tight-tree or longest-path 291 minLen: function minLen(edge) { 292 return 1; 293 }, // number of ranks to keep between the source and target of the edge 294 edgeWeight: function edgeWeight(edge) { 295 return 1; 296 }, // higher weight edges are generally made shorter and straighter than lower weight edges 297 298 // general layout options 299 fit: true, // whether to fit to viewport 300 padding: 30, // fit padding 301 spacingFactor: undefined, // Applies a multiplicative factor (>0) to expand or compress the overall area that the nodes take up 302 nodeDimensionsIncludeLabels: false, // whether labels should be included in determining the space used by a node 303 animate: false, // whether to transition the node positions 304 animateFilter: function animateFilter(node, i) { 305 return true; 306 }, // whether to animate specific nodes when animation is on; non-animated nodes immediately go to their final positions 307 animationDuration: 500, // duration of animation in ms if enabled 308 animationEasing: undefined, // easing of animation if enabled 309 boundingBox: undefined, // constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h } 310 transform: function transform(node, pos) { 311 return pos; 312 }, // a function that applies a transform to the final node position 313 ready: function ready() {}, // on layoutready 314 stop: function stop() {} // on layoutstop 315 }; 316 317 module.exports = defaults; 318 319 /***/ }), 320 /* 3 */ 321 /***/ (function(module, exports, __webpack_require__) { 322 323 "use strict"; 324 325 326 var impl = __webpack_require__(0); 327 328 // registers the extension on a cytoscape lib ref 329 var register = function register(cytoscape) { 330 if (!cytoscape) { 331 return; 332 } // can't register if cytoscape unspecified 333 334 cytoscape('layout', 'dagre', impl); // register with cytoscape.js 335 }; 336 337 if (typeof cytoscape !== 'undefined') { 338 // expose to global cytoscape (i.e. window.cytoscape) 339 register(cytoscape); 340 } 341 342 module.exports = register; 343 344 /***/ }), 345 /* 4 */ 346 /***/ (function(module, exports) { 347 348 module.exports = __WEBPACK_EXTERNAL_MODULE_4__; 349 350 /***/ }) 351 /******/ ]); 352 });