Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Edges appending to only one instance of Svelvet container #513 #515

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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