Skip to content
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

feat: support automatic resizing of altair/vega-lite figures #833

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def on_click(datum):
)
.configure_view(step=13, strokeWidth=0)
.configure_axis(domain=False)
.properties(width="container")
)
with solara.Card("Annual Weather Heatmap for Seattle, WA"):
solara.AltairChart(chart, on_click=on_click)
Expand Down
18 changes: 18 additions & 0 deletions solara/widgets/vue/vegalite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ module.exports = {
mounted() {
this.do_plot_debounced();
},
destroyed() {
if (this.observer) {
this.observer.disconnect();
}
},
watch: {
spec() {
this.do_plot_debounced();
Expand All @@ -29,7 +34,15 @@ module.exports = {
(async () => {
const spec = {
...this.spec,
"renderer": "svg",
};
if (spec.width === "container") {
this.$refs.plotElement.classList.add("width-container")
this.observer = new ResizeObserver(() => {
view.resize();
});
this.observer.observe(this.$refs.plotElement);
}
const { view } = await vegaEmbed(this.$refs.plotElement, spec);
// events https://github.com/vega/vega-view#event-handling
if (this.listen_to_click) {
Expand Down Expand Up @@ -110,3 +123,8 @@ module.exports = {
},
}
</script>
<style id="vega-embed-container-width">
.width-container.vega-embed {
width: 100%;
}
</style>
Loading