Skip to content

Commit

Permalink
feat: improve dataValidation function
Browse files Browse the repository at this point in the history
  • Loading branch information
Blakko committed Jun 12, 2024
1 parent d0726a3 commit 042adeb
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/core/src/util/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ export const dataValidation = (data?: GraphData | TreeGraphData): boolean => {
}

// 3. 边的 source 和 target 必须存在于节点 或 Combo中
const nodeIds = ((nodes as NodeConfig[]) || []).map(node => node.id);
const comboIds = (combos as ComboConfig[])?.map(combo => combo.id);
const ids = [...nodeIds, ...comboIds];
const nonEdges = ((edges as EdgeConfig[]) || []).find(
edge => !ids.includes(edge.source) || !ids.includes(edge.target),
);
const ids = new Set<string>();
if (nodes && (nodes as NodeConfig[]).length) {
for (var i = 0; i < (nodes as NodeConfig[]).length; i++) {
ids.add(nodes[i].id);
}
}
if ((combos as ComboConfig[]).length) {
for (var i = 0; i < (combos as ComboConfig[]).length; i++) {
ids.add(combos[i].id);
}
}
const nonEdges = ((edges as EdgeConfig[]) || []).find(function (edge) {
return !ids.has(edge.source) || !ids.has(edge.target);
});
if (nonEdges) {
console.warn(
`G6 Warning Tips: The source %c${nonEdges.source}%c or the target %c${nonEdges.target}%c of the edge do not exist in the nodes or combos.`,
Expand Down

0 comments on commit 042adeb

Please sign in to comment.