You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.3 KiB
60 lines
2.3 KiB
"use strict";
|
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
var t = {};
|
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
t[p] = s[p];
|
|
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
t[p[i]] = s[p[i]];
|
|
}
|
|
return t;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.toGraphlibData = toGraphlibData;
|
|
exports.toG6Data = toG6Data;
|
|
exports.createTreeStructure = createTreeStructure;
|
|
const constants_1 = require("../constants");
|
|
const id_1 = require("./id");
|
|
const is_1 = require("./is");
|
|
/**
|
|
* <zh/> 将 NodeData、EdgeData、ComboData 转换为 graphlib 的数据结构
|
|
*
|
|
* <en/> Transform NodeData, EdgeData, ComboData to graphlib data structure
|
|
* @param data - <zh/> 节点、边、combo 数据 | <en/> node, combo data
|
|
* @returns <zh/> graphlib 数据 | <en/> graphlib data
|
|
*/
|
|
function toGraphlibData(data) {
|
|
const { id = (0, id_1.idOf)(data), style, data: customData } = data, rest = __rest(data, ["id", "style", "data"]);
|
|
const _data = Object.assign(Object.assign({}, data), { style: Object.assign({}, style), data: Object.assign({}, customData) });
|
|
if ((0, is_1.isEdgeData)(data))
|
|
return Object.assign({ id, data: _data }, rest);
|
|
return { id, data: _data };
|
|
}
|
|
/**
|
|
* <zh/> 将 Node、Edge、Combo 转换为 G6 的数据结构
|
|
*
|
|
* <en/> Transform Node, Edge, Combo to G6 data structure
|
|
* @param data - <zh/> graphlib 节点、边、Combo 数据 | <en/> graphlib node, edge, combo data
|
|
* @returns <zh/> G6 数据 | <en/> G6 data
|
|
*/
|
|
function toG6Data(data) {
|
|
return data.data;
|
|
}
|
|
/**
|
|
* <zh/> 创建树形结构
|
|
*
|
|
* <en/> Create tree structure
|
|
* @param model - <zh/> 数据模型 | <en/> data model
|
|
*/
|
|
function createTreeStructure(model) {
|
|
if (model.hasTreeStructure(constants_1.TREE_KEY))
|
|
return;
|
|
model.attachTreeStructure(constants_1.TREE_KEY);
|
|
const edges = model.getAllEdges();
|
|
for (const edge of edges) {
|
|
const { source, target } = edge;
|
|
model.setParent(target, source, constants_1.TREE_KEY);
|
|
}
|
|
}
|
|
//# sourceMappingURL=graphlib.js.map
|