Skip to content

Commit 2a892dc

Browse files
philippjfrCopilot
andauthored
Ensure widget stretches entire container height (#54)
* Ensure widget stretches entire container height * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 26415e4 commit 2a892dc

1 file changed

Lines changed: 84 additions & 25 deletions

File tree

src/panel_gwalker/_gwalker.js

Lines changed: 84 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,51 +71,110 @@ export function render({ model, el, view }) {
7171
model.on('msg:custom', async (e) => {
7272
let exporter
7373
if (e.action === 'compute') {
74-
events.current.set(e.id, e.result)
75-
return
74+
events.current.set(e.id, e.result)
75+
return
7676
} else if (e.action === 'add_chart') {
77-
storeRef.current.appendFromCode(e.spec)
78-
return
77+
storeRef.current.appendFromCode(e.spec)
78+
return
79+
} else if (e.action === 'remove_chart') {
80+
storeRef.current.removeFromCode(e.spec)
81+
return
7982
}
8083
if (e.mode === 'spec') {
81-
exporter = storeRef.current
84+
exporter = storeRef.current
8285
} else {
83-
exporter = graphicWalkerRef.current
86+
exporter = graphicWalkerRef.current
8487
}
8588
if (exporter === null) {
86-
return
89+
return
8790
}
8891
let value, exported
8992
if (e.scope === 'current') {
90-
if (e.mode === 'vega-lite') {
93+
if (e.mode === 'vega-lite') {
9194
exported = exporter.lastSpec
92-
} else if (e.mode === 'spec') {
95+
} else if (e.mode === 'spec') {
9396
exported = exporter.currentVis
94-
} else {
97+
} else {
9598
exported = await graphicWalkerRef.current.exportChart()
96-
}
97-
value = cleanToDict(exported)
99+
}
100+
value = cleanToDict(exported)
98101
} else if (e.scope === 'all') {
99-
value = []
100-
exported = await (e.mode === 'spec' ? exporter.exportCode() : exporter.exportChartList())
101-
for await (const chart of exported) {
102+
value = []
103+
exported = await (e.mode === 'spec' ? exporter.exportCode() : exporter.exportChartList())
104+
for await (const chart of exported) {
102105
value.push(cleanToDict(chart))
103-
}
106+
}
104107
}
105108
model.send_msg({action: 'export', data: value, id: e.id})
106109
})
107110
}, [])
108111

109-
if (renderer === 'profiler') {
110-
const resize = () => {
111-
const table = view.container.children[0].shadowRoot.querySelector('div.overflow-y-auto.h-full')
112-
if (table != null) {
113-
table.style.maxHeight = '100%'
112+
113+
useEffect(() => {
114+
const injectStyles = () => {
115+
const host = el.children[0]
116+
if (!host) return false
117+
118+
host.style.height = "100%"
119+
host.style.maxHeight = "100%"
120+
const shadow = host.shadowRoot
121+
if (!shadow) return false
122+
123+
// Avoid injecting the same style multiple times
124+
const STYLE_ID = "tabs-shadow-patch"
125+
if (shadow.getElementById(STYLE_ID)) return true
126+
127+
const styleEl = document.createElement("style")
128+
styleEl.id = STYLE_ID
129+
styleEl.textContent = `
130+
/* 1. Remove max-height constraint in the scroll container */
131+
div.relative > div.relative > div.overflow-y-auto.h-full {
132+
max-height: unset !important;
133+
}
134+
135+
/* 2. Make tabs flex properly */
136+
[role="tabpanel"] {
137+
flex-grow: 1;
138+
flex-shrink: 1;
139+
min-height: 0;
140+
}
141+
142+
[role="tabpanel"] > div.border {
143+
margin-left: 0;
144+
margin-right: 0;
145+
border: none;
146+
}
147+
148+
[role="tabpanel"] > div.border, [role="tabpanel"] > div.border > .relative {
149+
max-height: 100%;
150+
height: 100%;
151+
}
152+
`
153+
shadow.appendChild(styleEl)
154+
return true
155+
}
156+
157+
// Try immediately first
158+
if (injectStyles()) return
159+
160+
// Poll until shadow root is available
161+
const interval = setInterval(() => {
162+
if (injectStyles()) {
163+
clearInterval(interval)
164+
clearTimeout(timeout)
114165
}
166+
}, 10)
167+
168+
// Cleanup after reasonable timeout (5 seconds)
169+
const timeout = setTimeout(() => {
170+
clearInterval(interval)
171+
}, 5000)
172+
173+
return () => {
174+
clearInterval(interval)
175+
clearTimeout(timeout)
115176
}
116-
model.on('after_render', resize)
117-
model.on('after_layout', resize)
118-
}
177+
}, [refUpdated]);
119178

120179
// Data Transforms
121180
useEffect(() => {
@@ -207,7 +266,7 @@ export function render({ model, el, view }) {
207266
const interval = setInterval(() => {
208267
if (storeRef.current !== null) {
209268
setRefUpdated(true);
210-
clearInterval(interval);
269+
clearInterval(interval);
211270
}
212271
}, 10);
213272
return () => clearInterval(interval);

0 commit comments

Comments
 (0)