@antv/g6
Version:
A Graph Visualization Framework in JavaScript
47 lines • 1.63 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.idOf = idOf;
exports.parentIdOf = parentIdOf;
exports.idsOf = idsOf;
const print_1 = require("./print");
/**
* <zh/> 获取节点/边/Combo 的 ID
*
* <en/> get the id of node/edge/combo
* @param data - <zh/> 节点/边/Combo 的数据 | <en/> data of node/edge/combo
* @returns <zh/> 节点/边/Combo 的 ID | <en/> ID of node/edge/combo
*/
function idOf(data) {
if (data.id !== undefined)
return data.id;
if (data.source !== undefined && data.target !== undefined)
return `${data.source}-${data.target}`;
throw new Error((0, print_1.format)('The datum does not have available id.'));
}
/**
* <zh/> 获取节点/Combo 的父节点 ID
*
* <en/> get the parent id of node/combo
* @param data - <zh/> 节点/Combo 的数据 | <en/> data of node/combo
* @returns <zh/> 节点/Combo 的父节点 ID | <en/> parent id of node/combo
*/
function parentIdOf(data) {
return data.combo;
}
/**
* <zh/> 获取图数据中所有节点/边/Combo 的 ID
*
* <en/> Get the IDs of all nodes/edges/combos in the graph data
* @param data - <zh/> 图数据 | <en/> graph data
* @param flat - <zh/> 是否扁平化返回 | <en/> Whether to return flat
* @returns - <zh/> 返回元素 ID 数组 | <en/> Returns an array of element IDs
*/
function idsOf(data, flat) {
const ids = {
nodes: (data.nodes || []).map(idOf),
edges: (data.edges || []).map(idOf),
combos: (data.combos || []).map(idOf),
};
return flat ? Object.values(ids).flat() : ids;
}
//# sourceMappingURL=id.js.map
;