Skip to content

Commit

Permalink
fix: Vega-chart layout broken in multi-facted charts
Browse files Browse the repository at this point in the history
Multi-facet Vega charts cannot be responsive, oh well. User must
set height/width manually.

See <https://vega.github.io/vega-lite/docs/size.html#specifying-responsive-width-and-height>

- Fixes simwrapper#133
  • Loading branch information
billyc committed Mar 16, 2022
1 parent e010ca3 commit 714b29b
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/plugins/vega-lite/VegaLite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class VegaComponent extends Vue {
private cleanConfigId = 'vega-' + Math.floor(Math.random() * 1e12)
private zippyId = 'zippy-' + Math.floor(Math.random() * 1e12)
private hasHardCodedHeight = false
public async mounted() {
this.buildFileApi()
Expand All @@ -56,16 +58,9 @@ class VegaComponent extends Vue {
this.myState.subfolder = this.subfolder
console.log(this.myState.yamlConfig)
// if (!this.yamlConfig) this.buildRouteFromUrl()
await this.getVizDetails()
this.embedChart()
// this.changeDimensions()
// window.addEventListener('resize', this.changeDimensions)
}
public beforeDestroy() {
// window.removeEventListener('resize', this.changeDimensions)
}
@Watch('globalState.isDarkMode')
Expand All @@ -79,12 +74,10 @@ class VegaComponent extends Vue {
// figure out dimensions, depending on if we are in a dashboard or not
let box = document.querySelector(`#${this.zippyId}`) as Element
let width = box.clientWidth
let height = box.clientHeight
console.log(width, height)
if (this.thumbnail) height = 125
this.vizDetails.height = height
let height = this.thumbnail ? 125 : box.clientHeight
if (!this.hasHardCodedHeight) this.vizDetails.height = height
this.embedChart()
}
Expand Down Expand Up @@ -254,9 +247,12 @@ class VegaComponent extends Vue {
}
)
// Always use responsive size -- let dashboard determine the size.
this.vizDetails.width = 'container'
this.vizDetails.height = 'container'
// Note whether user specified a height; we need to know this if the page size changes
this.hasHardCodedHeight = !!this.vizDetails.height
// Use responsive size unless user has forced a size on us
if (!this.vizDetails.width) this.vizDetails.width = 'container'
if (!this.vizDetails.height) this.vizDetails.height = 'container'
try {
await vegaEmbed(`#${this.cleanConfigId}`, this.vizDetails, embedOptions)
Expand Down

0 comments on commit 714b29b

Please sign in to comment.