Skip to content

Commit

Permalink
Improve altair theme processing
Browse files Browse the repository at this point in the history
- set width and height for any registered themes (if not already set)
- provide our own theme_patch to accomplish this
  • Loading branch information
dragonstyle committed Nov 16, 2023
1 parent 9b9e483 commit 113d96e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/resources/jupyter/lang/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,29 @@

try:
import altair as alt

# By default, dashboards will have container sized
# vega visualizations which allows them to flow reasonably
if 'quarto-dashboard-theme' not in alt.themes.names():
def quarto_dashboard_theme(*args, **kwargs):
return dict(width = 'container', height= 'container')
alt.themes.register('quarto-dashboard-theme', quarto_dashboard_theme)
alt.themes.enable('quarto-dashboard-theme')

theme_sentinel = '_quarto-dashboard-internal'
def make_theme(name):
nonTheme = alt.themes._plugins[name]
def patch_theme(*args, **kwargs):
existingTheme = nonTheme()
if 'height' not in existingTheme:
existingTheme['height'] = 'container'
if 'width' not in existingTheme:
existingTheme['width'] = 'container'
return existingTheme
return patch_theme

# We can only do this once per session
if theme_sentinel not in alt.themes.names():
for name in alt.themes.names():
alt.themes.register(name, make_theme(name))

# register a sentinel theme so we only do this once
alt.themes.register(theme_sentinel, make_theme('default'))
alt.themes.enable('default')

except Exception:
pass

Expand Down

0 comments on commit 113d96e

Please sign in to comment.