From 255a0d15d74828c28999cdce3fe9a0b5c2795016 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 29 Dec 2023 12:27:00 -0600 Subject: [PATCH] Reduce default plot margins on plotly graphs --- .gitignore | 1 - .vscode/settings.json | 2 +- CHANGELOG.md | 1 + shinywidgets/_shinywidgets.py | 7 ++++++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index aa18da0..27652a7 100644 --- a/.gitignore +++ b/.gitignore @@ -108,7 +108,6 @@ ENV/ js/node_modules typings/ -sandbox/ Untitled*.ipynb rsconnect-python/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 039b746..119b731 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,7 +10,7 @@ "editor.formatOnSave": true, "editor.tabSize": 4, "editor.codeActionsOnSave": { - "source.organizeImports": true + "source.organizeImports": "explicit" }, }, "isort.args":["--profile", "black"], diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e30c19..b81ec2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [UNRELEASED] +* Reduce default plot margins on plotly graphs. ## [0.2.4] - 2023-11-20 diff --git a/shinywidgets/_shinywidgets.py b/shinywidgets/_shinywidgets.py index 6b69235..39d2b3f 100644 --- a/shinywidgets/_shinywidgets.py +++ b/shinywidgets/_shinywidgets.py @@ -327,6 +327,12 @@ def set_layout_defaults(widget: Widget) -> Tuple[Widget, bool]: if isinstance(layout, PlotlyLayout): if layout.height is not None: fill = False + # Default margins are also way too big + layout.template.layout.margin = dict(l=16, t=32, r=16, b=16) + # Unfortunately, plotly doesn't want to respect the top margin template, + # so change that 60px default to 32px + if layout.margin["t"] == 60: + layout.margin["t"] = 32 widget.layout = layout @@ -348,7 +354,6 @@ def set_layout_defaults(widget: Widget) -> Tuple[Widget, bool]: else: widget.chart = widget.chart.properties(width="container", height="container") # type: ignore - return (widget, fill) # similar to base::system.file()