Skip to content

Commit

Permalink
FIX: Edges appending to only one instance of Svelvet container open-…
Browse files Browse the repository at this point in the history
…source-labs#513


    Updated moveEdge function in Edge.svelte to correctly append the edge element to its respective Svelvet container based on containerId.

🔗 Linked issue

Resolves open-source-labs#513
  • Loading branch information
turizspace authored Jul 14, 2024
1 parent bd69dc3 commit c4d193e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lib/components/Edge/Edge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@
import type { CSSColorString, Direction, EdgeStyle, EndStyle, Graph } from '$lib/types';
import type { WritableEdge } from '$lib/types';
export let containerId;
let animationFrameId: number;
function moveEdge(edgeElement: SVGElement) {
function moveEdge(edgeElement: SVGElement, containerId: string) {
const parentNode = edgeElement.parentNode;
if (!parentNode) return;
// Remove the anchor from its current container
parentNode.removeChild(edgeElement);
// Add the anchor to the new container
const newContainer = document.querySelector(`.svelvet-graph-wrapper`);
const newContainer = document.querySelector(`.svelvet-graph-wrapper[data-id='${containerId}']`);
if (!newContainer) return;
newContainer.appendChild(edgeElement);
}
onDestroy(() => {
cancelAnimationFrame(animationFrameId);
});
</script>

<script lang="ts">
Expand Down Expand Up @@ -192,7 +198,7 @@
labelPoint = calculatePath(DOMPath, labelPosition);
}
}, 0);
moveEdge(edgeElement);
moveEdge(edgeElement, containerId);
});
afterUpdate(() => {
Expand Down

0 comments on commit c4d193e

Please sign in to comment.