Skip to content

Commit

Permalink
Reduce default plot margins on plotly graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Dec 29, 2023
1 parent d274322 commit 255a0d1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ ENV/

js/node_modules
typings/
sandbox/
Untitled*.ipynb

rsconnect-python/
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit"
},
},
"isort.args":["--profile", "black"],
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion shinywidgets/_shinywidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down

0 comments on commit 255a0d1

Please sign in to comment.