Skip to content

Commit ee6f5c1

Browse files
authored
Graph Panel widget: improved graph panel resizing and visibility handling.
2 parents d1de1ba + a9512a2 commit ee6f5c1

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"url": "git+https://github.com/opencor/webapp.git"
2424
},
2525
"type": "module",
26-
"version": "0.20260325.0",
26+
"version": "0.20260325.1",
2727
"engines": {
2828
"bun": ">=1.2.0"
2929
},

src/renderer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"./style.css": "./dist/opencor.css"
4444
},
45-
"version": "0.20260325.0",
45+
"version": "0.20260325.1",
4646
"scripts": {
4747
"build": "vite build && bun scripts/generate.version.js",
4848
"build:lib": "vite build --config vite.lib.config.ts && bunx --bun vue-tsc --project tsconfig.lib.types.json",

src/renderer/src/components/widgets/GraphPanelWidget.vue

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="flex flex-row h-full" :class="isVisible ? 'visible' : 'invisible'">
2+
<div class="flex flex-row h-full">
33
<div v-if="showMarker" class="w-0.75 bg-primary" />
44
<div ref="mainDivRef" class="grow h-full" @contextmenu="onContextMenu" />
55
<ContextMenu ref="contextMenuRef" :model="contextMenuItems" />
@@ -123,7 +123,6 @@ defineExpose({
123123
124124
const instanceId = Symbol('GraphPanelWidget');
125125
const mainDivRef = vue.ref<HTMLElement | null>(null);
126-
const isVisible = vue.ref(false);
127126
const margins = vue.ref<IGraphPanelMargins>({ left: -1, right: -1 });
128127
const theme = vueCommon.useTheme();
129128
const contextMenuRef = vue.ref<InstanceType<typeof ContextMenu> | null>(null);
@@ -596,6 +595,18 @@ const compMargins = (): IGraphPanelMargins => {
596595
};
597596
};
598597
598+
const canMeasureMargins = (): boolean => {
599+
const mainDiv = mainDivRef.value;
600+
601+
if (!mainDiv) {
602+
return false;
603+
}
604+
605+
const { width, height } = mainDiv.getBoundingClientRect();
606+
607+
return width > 0 && height > 0;
608+
};
609+
599610
const updateMarginsAsync = (): void => {
600611
// Skip if we are already updating our margins.
601612
@@ -608,6 +619,14 @@ const updateMarginsAsync = (): void => {
608619
// Use requestAnimationFrame for optimal timing.
609620
610621
requestAnimationFrame(() => {
622+
// Make sure that we can measure our margins before proceeding.
623+
624+
if (!canMeasureMargins()) {
625+
updatingMargins = false;
626+
627+
return;
628+
}
629+
611630
const newMargins = compMargins();
612631
613632
// Emit an update if our margins have changed.
@@ -722,26 +741,9 @@ const updatePlot = (): void => {
722741
.then(() => {
723742
plotIsReady = true;
724743
725-
if (!isVisible.value) {
726-
// Force Plotly to recalculate the layout after the plot is rendered to ensure that it has correct dimensions.
727-
728-
return dependencies._plotlyJs.Plots.resize(mainDivRef.value);
729-
}
730-
})
731-
.then(() => {
732-
trackSize();
733-
734-
if (!isVisible.value) {
735-
// Show the component now that the plot has been properly sized.
744+
// Force Plotly to recalculate the layout after each react() call to keep the graph aligned with sibling panels.
736745
737-
vue.nextTick(() => {
738-
isVisible.value = true;
739-
});
740-
}
741-
742-
// Update our margins asynchronously after our initial render.
743-
744-
updateMarginsAsync();
746+
queueResize();
745747
});
746748
};
747749

0 commit comments

Comments
 (0)