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
124124const instanceId = Symbol (' GraphPanelWidget' );
125125const mainDivRef = vue .ref <HTMLElement | null >(null );
126- const isVisible = vue .ref (false );
127126const margins = vue .ref <IGraphPanelMargins >({ left: - 1 , right: - 1 });
128127const theme = vueCommon .useTheme ();
129128const 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+
599610const 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