Skip to content

Commit

Permalink
Allow setting plotly margins (#9805)
Browse files Browse the repository at this point in the history
* changes

* add changeset

---------

Co-authored-by: Ali Abid <[email protected]>
Co-authored-by: gradio-pr-bot <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent a4e70f3 commit 78e3b51
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/swift-waves-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/plot": minor
"gradio": minor
---

feat:Allow setting plotly margins
1 change: 1 addition & 0 deletions js/plot/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
{bokeh_version}
{show_actions_button}
{gradio}
{show_label}
{_selectable}
{x_lim}
on:change={() => gradio.dispatch("change")}
Expand Down
2 changes: 2 additions & 0 deletions js/plot/shared/Plot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export let value;
let _value;
export let colors: string[] = [];
export let show_label: boolean;
export let theme_mode: ThemeMode;
export let caption: string;
export let bokeh_version: string | null;
Expand Down Expand Up @@ -61,6 +62,7 @@
{value}
{colors}
{theme_mode}
{show_label}
{caption}
{bokeh_version}
{show_actions_button}
Expand Down
12 changes: 9 additions & 3 deletions js/plot/shared/plot_types/PlotlyPlot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { afterUpdate, createEventDispatcher } from "svelte";
export let value;
export let show_label: boolean;
$: plot = value?.plot;
Expand Down Expand Up @@ -34,9 +35,14 @@
plotObj.responsive = true;
plotObj.layout.autosize = true;
plotObj.layout.title
? (plotObj.layout.margin = { autoexpand: true })
: (plotObj.layout.margin = { l: 0, r: 0, b: 0, t: 0 });
if (plotObj.layout.margin == undefined) {
plotObj.layout.margin = {};
}
if (plotObj.layout.title && show_label) {
// so title does not get cut off by label
plotObj.layout.margin.t = Math.max(100, plotObj.layout.margin.t || 0);
}
plotObj.layout.margin.autoexpand = true;
Plotly.react(plot_div, plotObj.data, plotObj.layout, plotObj.config);
Plotly.Plots.resize(plot_div);
Expand Down

0 comments on commit 78e3b51

Please sign in to comment.