Skip to content

Commit

Permalink
Fix Vega pane sizing issues (#2933)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Nov 19, 2021
1 parent 8716eb1 commit b86b65e
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion panel/models/vega.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {HTMLBox, HTMLBoxView} from "@bokehjs/models/layouts/html_box"

export class VegaPlotView extends HTMLBoxView {
model: VegaPlot
vega_view: any
_connected: string[]

connect_signals(): void {
Expand Down Expand Up @@ -68,7 +69,33 @@ export class VegaPlotView extends HTMLBoxView {
}
this.model.data['datasets'] = datasets
}
(window as any).vegaEmbed(this.el, this.model.data, {actions: false})
(window as any).vegaEmbed(this.el, this.model.data, {actions: false}).then((result: any) => {
this.vega_view = result.view
this.relayout()
if (this.vega_view._viewHeight <= 0 || this.vega_view._viewWidth <= 0) {
(window as any).dispatchEvent(new Event('resize'));
}
})
}

relayout(): void {
this.update_layout()
this.compute_layout()
if (this.root !== this)
this.invalidate_layout()
else if ((this as any)._parent != undefined) // HACK: Support ReactiveHTML
(this as any)._parent.invalidate_layout()
}

box_sizing(): any {
const sizing = super.box_sizing()
if (this.vega_view != null) {
if (sizing.height_policy === "fixed")
sizing.height = this.vega_view._viewHeight
if (sizing.width_policy === "fixed")
sizing.width = this.vega_view._viewWidth
}
return sizing
}
}

Expand Down

0 comments on commit b86b65e

Please sign in to comment.