@@ -4,7 +4,7 @@ This file is part of Checkmk (https://checkmk.com). It is subject to the terms a
44conditions defined in the file COPYING, which is part of this source code package.
55-->
66<script setup lang="ts">
7- import { type Ref , computed , onBeforeUnmount , onMounted , ref , watch } from ' vue'
7+ import { type Ref , computed , nextTick , onBeforeUnmount , onMounted , ref , watch } from ' vue'
88
99import useTimer from ' @/lib/useTimer.ts'
1010
@@ -18,7 +18,6 @@ import DashboardContentContainer from './DashboardContentContainer.vue'
1818import type { ContentProps } from ' ./types.ts'
1919
2020const props = defineProps <ContentProps >()
21- const content = props .content as GraphWidgetContent
2221const cmkToken = useInjectCmkToken ()
2322const dataEndpointUrl: Ref <string > = computed (() => {
2423 return cmkToken ? ' widget_graph_token_auth.py' : ' widget_graph.py'
@@ -31,16 +30,16 @@ const contentDiv = ref<HTMLDivElement | null>(null)
3130const parentDiv = computed (() => contentDiv .value ?.parentElement || null )
3231const isLoading = ref <boolean >(true )
3332
34- const observedElement = computed (() => {
35- if (props .isPreview && contentDiv .value ) {
33+ const resolveObservedElement = () : HTMLElement | null => {
34+ if (props .isPreview && showLegend . value && contentDiv .value ) {
3635 return (
3736 (contentDiv .value .closest (
3837 ' .db-content-container__preview-scroll-container'
3938 ) as HTMLElement ) ?? parentDiv .value
4039 )
4140 }
4241 return parentDiv .value
43- })
42+ }
4443
4544const httpVars: Ref <FilterHTTPVars > = computed (() => {
4645 if (cmkToken !== undefined ) {
@@ -93,14 +92,35 @@ const resizeObserver = new ResizeObserver((entries) => {
9392 }
9493})
9594
96- const showLegend = computed (() => content .graph_render_options ?.show_legend ?? false )
95+ const showLegend = computed (
96+ () => (props .content as GraphWidgetContent ).graph_render_options ?.show_legend ?? false
97+ )
9798const timer = useTimer (updateGraph , 60_000 )
9899
100+ let currentObservedElement: HTMLElement | null = null
101+ const reconnectResizeObserver = () => {
102+ const newElement = resolveObservedElement ()
103+ if (newElement !== currentObservedElement ) {
104+ if (currentObservedElement ) {
105+ resizeObserver .unobserve (currentObservedElement )
106+ }
107+ if (newElement ) {
108+ resizeObserver .observe (newElement )
109+ }
110+ currentObservedElement = newElement
111+ }
112+ }
113+
114+ // Reconnect the ResizeObserver after DOM updates when the scroll container appears/disappears
115+ watch ([showLegend , () => props .isPreview ], () => {
116+ void nextTick (() => {
117+ reconnectResizeObserver ()
118+ })
119+ })
120+
99121onMounted (() => {
100122 timer .start ()
101- if (observedElement .value ) {
102- resizeObserver .observe (observedElement .value )
103- }
123+ reconnectResizeObserver ()
104124})
105125
106126onBeforeUnmount (() => {
0 commit comments