-
Notifications
You must be signed in to change notification settings - Fork 4
Graph Panel widget: improve graph panel resizing and visibility handling #475
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
Changes from all commits
f8cc4fc
58fe006
aef6b7a
1b1b133
a8665b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||||||||
| <template> | ||||||||||||||||||||||||||
| <div class="flex flex-row h-full" :class="isVisible ? 'visible' : 'invisible'"> | ||||||||||||||||||||||||||
| <div class="flex flex-row h-full"> | ||||||||||||||||||||||||||
| <div v-if="showMarker" class="w-0.75 bg-primary" /> | ||||||||||||||||||||||||||
| <div ref="mainDivRef" class="grow h-full" @contextmenu="onContextMenu" /> | ||||||||||||||||||||||||||
| <ContextMenu ref="contextMenuRef" :model="contextMenuItems" /> | ||||||||||||||||||||||||||
|
|
@@ -123,7 +123,6 @@ defineExpose({ | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const instanceId = Symbol('GraphPanelWidget'); | ||||||||||||||||||||||||||
| const mainDivRef = vue.ref<HTMLElement | null>(null); | ||||||||||||||||||||||||||
| const isVisible = vue.ref(false); | ||||||||||||||||||||||||||
| const margins = vue.ref<IGraphPanelMargins>({ left: -1, right: -1 }); | ||||||||||||||||||||||||||
| const theme = vueCommon.useTheme(); | ||||||||||||||||||||||||||
| const contextMenuRef = vue.ref<InstanceType<typeof ContextMenu> | null>(null); | ||||||||||||||||||||||||||
|
|
@@ -596,6 +595,18 @@ const compMargins = (): IGraphPanelMargins => { | |||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const canMeasureMargins = (): boolean => { | ||||||||||||||||||||||||||
| const mainDiv = mainDivRef.value; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (!mainDiv) { | ||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const { width, height } = mainDiv.getBoundingClientRect(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return width > 0 && height > 0; | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const updateMarginsAsync = (): void => { | ||||||||||||||||||||||||||
| // Skip if we are already updating our margins. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -608,6 +619,14 @@ const updateMarginsAsync = (): void => { | |||||||||||||||||||||||||
| // Use requestAnimationFrame for optimal timing. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| requestAnimationFrame(() => { | ||||||||||||||||||||||||||
| // Make sure that we can measure our margins before proceeding. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (!canMeasureMargins()) { | ||||||||||||||||||||||||||
| updatingMargins = false; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const newMargins = compMargins(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Emit an update if our margins have changed. | ||||||||||||||||||||||||||
|
|
@@ -722,26 +741,9 @@ const updatePlot = (): void => { | |||||||||||||||||||||||||
| .then(() => { | ||||||||||||||||||||||||||
| plotIsReady = true; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (!isVisible.value) { | ||||||||||||||||||||||||||
| // Force Plotly to recalculate the layout after the plot is rendered to ensure that it has correct dimensions. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return dependencies._plotlyJs.Plots.resize(mainDivRef.value); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
| .then(() => { | ||||||||||||||||||||||||||
| trackSize(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (!isVisible.value) { | ||||||||||||||||||||||||||
| // Show the component now that the plot has been properly sized. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| vue.nextTick(() => { | ||||||||||||||||||||||||||
| isVisible.value = true; | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Update our margins asynchronously after our initial render. | ||||||||||||||||||||||||||
| // Force Plotly to recalculate the layout after each react() call to keep the graph aligned with sibling panels. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+744
to
745
|
||||||||||||||||||||||||||
| // Force Plotly to recalculate the layout after each react() call to keep the graph aligned with sibling panels. | |
| // Force Plotly to recalculate the layout after each react() call to keep the graph aligned with sibling panels. | |
| // Only resize when the main container has measurable (non-zero) dimensions to avoid unnecessary work when hidden. | |
| const mainDivEl = mainDivRef.value as HTMLElement | null; | |
| if (!mainDivEl) { | |
| return; | |
| } | |
| const rect = mainDivEl.getBoundingClientRect(); | |
| if (rect.width === 0 || rect.height === 0) { | |
| return; | |
| } |
Uh oh!
There was an error while loading. Please reload this page.