UNPKG

@nodeject/ui-components

Version:

UI library for non-trivial components

43 lines (42 loc) 1.78 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.cytoscapeToSchedioTreeView = void 0; var React = require("react"); var graph_1 = require("./graph"); var cytoscapeToSchedioTreeView = function (props) { // IMPORTANT: the roots() property from cytoscape cannot be used here because it depends on nodes with no incoming edges. // We did not define edges here, so we have to find nodes that either have no parent (note that even if a node has a parent, // if the node defined in parent does not exist, it will be considered as having no parent). var cytoRoots = graph_1.toCytoscape(props.cytoGraph) .nodes() .orphans(); var loop = function (cyNode) { var childrenList = cyNode.children().map(function (c) { return loop(c); }); var nodeData = cyNode.data(); var parentNode = cyNode.parent(); var Component = props.NodeContainer; return { children: childrenList, TreeNodeComponent: React.createElement(Component, __assign({}, nodeData)), nodeKey: nodeData.id, parentKey: parentNode.data() && parentNode.data().id }; }; return cytoRoots.map(function (cyNode) { return loop(cyNode); }); }; exports.cytoscapeToSchedioTreeView = cytoscapeToSchedioTreeView;