B: Fix cst graph visualization
This commit is contained in:
parent
22eb2a482c
commit
6b2268a76b
|
|
@ -57,11 +57,11 @@ export function applyLayout(nodes: Node<TGNodeState>[], edges: Edge[], subLabels
|
|||
});
|
||||
}
|
||||
|
||||
export function inferEdgeType(schema: IRSForm, source: number, target: number): GraphType | null {
|
||||
export function inferEdgeType(schema: IRSForm, source: number, target: number): GraphType {
|
||||
const isDefinition = schema.graph.hasEdge(source, target);
|
||||
const isAttribution = schema.attribution_graph.hasEdge(source, target);
|
||||
if (!isDefinition && !isAttribution) {
|
||||
return null;
|
||||
return 'definition';
|
||||
} else if (isDefinition && isAttribution) {
|
||||
return 'full';
|
||||
} else if (isDefinition) {
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ export function TGFlow() {
|
|||
filteredGraph.nodes.forEach(source => {
|
||||
source.outputs.forEach(target => {
|
||||
const edgeType = inferEdgeType(schema, source.id, target);
|
||||
if (edgeType && newNodes.find(node => node.id === String(target))) {
|
||||
if (newNodes.find(node => node.id === String(target))) {
|
||||
const color = filter.graphType === 'full' ? colorGraphEdge(edgeType) : colorGraphEdge(filter.graphType);
|
||||
newEdges.push({
|
||||
id: String(edgeID),
|
||||
|
|
|
|||
|
|
@ -61,6 +61,45 @@ describe('Testing Graph editing', () => {
|
|||
expect(graph.hasEdge(2, 5)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('folding a non-existent node should not change the graph', () => {
|
||||
const graph = new Graph([
|
||||
[1, 2],
|
||||
[2, 3]
|
||||
]);
|
||||
const clone = graph.clone();
|
||||
graph.foldNode(99); // Node 99 does not exist
|
||||
expect(graph.nodes.size).toBe(clone.nodes.size);
|
||||
expect([...graph.nodes.keys()]).toEqual([...clone.nodes.keys()]);
|
||||
expect(graph.hasEdge(1, 2)).toBeTruthy();
|
||||
expect(graph.hasEdge(2, 3)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('folding a node with no inputs', () => {
|
||||
const graph = new Graph([
|
||||
[1, 2],
|
||||
[1, 3]
|
||||
]);
|
||||
graph.foldNode(1);
|
||||
expect(graph.hasNode(1)).toBeFalsy();
|
||||
expect(graph.nodes.size).toBe(2); // Nodes 2 and 3 remain
|
||||
expect(graph.hasNode(2)).toBeTruthy();
|
||||
expect(graph.hasNode(3)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('folding a node with no outputs', () => {
|
||||
const graph = new Graph([
|
||||
[1, 3],
|
||||
[2, 3]
|
||||
]);
|
||||
graph.foldNode(3);
|
||||
expect(graph.hasNode(3)).toBeFalsy();
|
||||
expect(graph.nodes.size).toBe(2); // Nodes 1 and 2 remain
|
||||
expect(graph.hasNode(1)).toBeTruthy();
|
||||
expect(graph.hasNode(2)).toBeTruthy();
|
||||
expect(graph.nodes.get(1)!.outputs.length).toBe(0);
|
||||
expect(graph.nodes.get(2)!.outputs.length).toBe(0);
|
||||
});
|
||||
|
||||
test('removing isolated nodes', () => {
|
||||
const graph = new Graph([[9, 1], [9, 2], [2, 1], [4, 3], [5, 9], [7], [8]]);
|
||||
graph.removeIsolated();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user