Skip to content

Commit

Permalink
fix: 🐛 mergeGs was trying to copy the first graph in an arr of graphs…
Browse files Browse the repository at this point in the history
…, but that arr could be empty
  • Loading branch information
SkepticMystic committed Aug 13, 2021
1 parent 0c45952 commit c3c23ea
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Graph } from "graphlib";
import { Graph } from "graphlib";
import * as graphlib from "graphlib";
import { parseTypedLink } from "juggl-api";
import {
Expand Down Expand Up @@ -450,15 +450,13 @@ export function mergeGraphs(g1: Graph, g2: Graph) {
}

export function mergeGs(...graphs: Graph[]) {
const copy = graphlib.json.read(graphlib.json.write(graphs[0]));
graphs.forEach((graph, i) => {
if (i > 0) {
graph.edges().forEach((edge) => {
copy.setEdge(edge);
});
}
const outG = new Graph();
graphs.forEach((graph) => {
graph.edges().forEach((edge) => {
outG.setEdge(edge);
});
});
return copy;
return outG;
}

export function removeUnlinkedNodes(g: Graph) {
Expand Down

0 comments on commit c3c23ea

Please sign in to comment.