import { format } from './print';
/**
* 获取节点/边/Combo 的 ID
*
* get the id of node/edge/combo
* @param data - 节点/边/Combo 的数据 | data of node/edge/combo
* @returns 节点/边/Combo 的 ID | ID of node/edge/combo
*/
export 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(format('The datum does not have available id.'));
}
/**
* 获取节点/Combo 的父节点 ID
*
* get the parent id of node/combo
* @param data - 节点/Combo 的数据 | data of node/combo
* @returns 节点/Combo 的父节点 ID | parent id of node/combo
*/
export function parentIdOf(data) {
return data.combo;
}
/**
* 获取图数据中所有节点/边/Combo 的 ID
*
* Get the IDs of all nodes/edges/combos in the graph data
* @param data - 图数据 | graph data
* @param flat - 是否扁平化返回 | Whether to return flat
* @returns - 返回元素 ID 数组 | Returns an array of element IDs
*/
export 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