-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: louvain data pollution * chore: refine
- Loading branch information
1 parent
f6a34cd
commit 305a20a
Showing
8 changed files
with
587 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import { NodeID, INode, IEdge } from "../../packages/graph/src/types"; | ||
import { ID } from '@antv/graphlib'; | ||
import { INode, IEdge } from '../../packages/graph/src/types'; | ||
/** | ||
* Convert the old version of the data format to the new version | ||
* @param data old data | ||
* @return {{nodes:INode[],edges:IEdge[]}} new data | ||
*/ | ||
export const dataTransformer = (data: { nodes: { id: NodeID, [key: string]: any }[], edges: { source: NodeID, target: NodeID, [key: string]: any }[] }): { nodes: INode[], edges: IEdge[] } => { | ||
const { nodes, edges } = data; | ||
return { | ||
nodes: nodes.map((n) => { | ||
const { id, ...rest } = n; | ||
return { id, data: rest ? rest : {} }; | ||
}), | ||
edges: edges.map((e, i) => { | ||
const { id, source, target, ...rest } = e; | ||
return { id: id ? id : `edge-${i}`, target, source, data: rest }; | ||
}), | ||
}; | ||
export const dataTransformer = (data: { | ||
nodes: { id: ID; [key: string]: any }[]; | ||
edges: { source: ID; target: ID; [key: string]: any }[]; | ||
}): { nodes: INode[]; edges: IEdge[] } => { | ||
const { nodes, edges } = data; | ||
return { | ||
nodes: nodes.map((n) => { | ||
const { id, ...rest } = n; | ||
return { id, data: rest ? rest : {} }; | ||
}), | ||
edges: edges.map((e, i) => { | ||
const { id, source, target, ...rest } = e; | ||
return { id: id ? id : `edge-${i}`, target, source, data: rest }; | ||
}), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.