Skip to content

Commit

Permalink
Make Bonito/WGLMakie offline default configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
frankier committed Oct 13, 2024
1 parent f4486f5 commit a7fde5d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/extensions/plotting/bonito.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import .Bonito: Page, App

export html


const BONITO_OFFLINE::Ref{Bool} = Ref(true)


"""
Converts a Figure object to the designated MIME type and wraps it inside an HTTP response.
"""
function response(content::App, mime_type::MIME, status::Int, headers::Vector)
function response(content::App, mime_type::MIME, status::Int, headers::Vector, offline=BONITO_OFFLINE[])
# Force inlining all data & js dependencies
Page(exportable=true, offline=true)
Page(exportable=true, offline=offline)

# Convert & load the figure into an IOBuffer
io = IOBuffer()
Expand All @@ -29,4 +33,4 @@ end
Convert a Bonito.App to HTML and wrap it inside an HTTP response.
"""
html(app::App, status=200, headers=[]) :: HTTP.Response = response(app, HTML, status, headers)
html(app::App, status=200, headers=[], offline=BONITO_OFFLINE[]) :: HTTP.Response = response(app, HTML, status, headers, offline)
1 change: 1 addition & 0 deletions src/extensions/plotting/bonito_connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function setup_bonito_connection(
setup_register_connection=setup_all,
route_base="/bonito-websocket/"
)
BONITO_OFFLINE[] = false
context.ext[:bonito_connection] = BonitoConnectionContext()
handler = mk_bonito_websocket_handler(context)
if setup_route
Expand Down
6 changes: 3 additions & 3 deletions src/extensions/plotting/wglmakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export html
"""
Converts a Figure object to the designated MIME type and wraps it inside an HTTP response.
"""
function response(content::FigureLike, mime_type::MIME, status::Int, headers::Vector)
function response(content::FigureLike, mime_type::MIME, status::Int, headers::Vector, offline=BONITO_OFFLINE[])
# Force inlining all data & js dependencies
Page(exportable=true, offline=true)
Page(exportable=true, offline=offline)

# Convert & load the figure into an IOBuffer
io = IOBuffer()
Expand All @@ -30,5 +30,5 @@ end
Convert a Makie figure to HTML and wrap it inside an HTTP response.
"""
html(fig::FigureLike, status=200, headers=[]) :: HTTP.Response = response(fig, HTML, status, headers)
html(fig::FigureLike, status=200, headers=[], offline=BONITO_OFFLINE[]) :: HTTP.Response = response(fig, HTML, status, headers, offline)

0 comments on commit a7fde5d

Please sign in to comment.