Skip to content

Commit

Permalink
Handle resize event
Browse files Browse the repository at this point in the history
  • Loading branch information
katharinawuensche committed Jul 18, 2024
1 parent e764b24 commit fd8964b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions components/family-tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AnchorLocations,
type AnchorSpec,
BlankEndpoint,
type BrowserJsPlumbInstance,
FlowchartConnector,
newInstance,
ready,
Expand Down Expand Up @@ -50,9 +51,16 @@ const partners = computed(() => {
props.relations.filter((r) => r.name === "hat Ehe mit").map((r) => r.to),
);
});
const instance = ref<BrowserJsPlumbInstance>();
// Add resize handler to monitor container width and adapt chart
function resizeHandler() {
console.log("Resize");
instance.value?.repaintEverything();
}
onMounted(() => {
ready(() => {
const instance = newInstance({
instance.value = newInstance({
container: familyTreeContainer.value,
});
const containers = [
Expand Down Expand Up @@ -103,7 +111,7 @@ onMounted(() => {
];
containers.forEach((container) => {
[...(container.ref.value?.children ?? [])].forEach((child, idx) => {
instance.connect({
instance.value?.connect({
source: meContainer.value,
target: child,
connector: {
Expand All @@ -125,7 +133,7 @@ onMounted(() => {
childContainerChildren
.filter((child) => child.getBoundingClientRect().top === minHeight)
.forEach((child) => {
instance.connect({
instance.value?.connect({
source: meContainer.value,
target: child,
connector: {
Expand All @@ -142,8 +150,13 @@ onMounted(() => {
],
});
});
window.addEventListener("resize", resizeHandler);
});
});
onBeforeUnmount(() => {
window.removeEventListener("resize", resizeHandler);
});
</script>

<template>
Expand Down

0 comments on commit fd8964b

Please sign in to comment.