generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from amosproj/hierarchical-graph-layout
Hierarchical graph layout
- Loading branch information
Showing
5 changed files
with
74 additions
and
46 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
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
44 changes: 44 additions & 0 deletions
44
frontend/src/visualization/shared-ops/convertQueryResult.ts
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { GraphData } from 'react-graph-vis'; | ||
import * as vis from 'vis-network'; | ||
import { EdgeDescriptor } from '../../shared/entities'; | ||
import { NodeResultDescriptor, QueryResult } from '../../shared/queries'; | ||
|
||
function convertNode(node: NodeResultDescriptor): vis.Node { | ||
const result: vis.Node = { | ||
id: node.id, | ||
label: node.id.toString(), | ||
// Advanced stuff, like styling nodes with different types differently... | ||
}; | ||
|
||
if (node.subsidiary) { | ||
result.color = 'yellow'; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
function convertNodes(nodes: NodeResultDescriptor[]): vis.Node[] { | ||
return nodes.map((node) => convertNode(node)); | ||
} | ||
|
||
function convertEdge(edge: EdgeDescriptor): vis.Edge { | ||
return { | ||
id: edge.id, | ||
from: edge.from, | ||
to: edge.to, | ||
// Advanced stuff, like styling edges with different types differently... | ||
}; | ||
} | ||
|
||
function convertEdges(edges: EdgeDescriptor[]): vis.Edge[] { | ||
return edges.map((edge) => convertEdge(edge)); | ||
} | ||
|
||
export default function convertQueryResult( | ||
queryResult: QueryResult | ||
): GraphData { | ||
return { | ||
nodes: convertNodes(queryResult.nodes), | ||
edges: convertEdges(queryResult.edges), | ||
}; | ||
} |