From 4ffc28de0b61ee84b957488e10b659fa80b88913 Mon Sep 17 00:00:00 2001 From: Frankie Robertson Date: Sun, 13 Oct 2024 13:23:29 +0300 Subject: [PATCH] Make Bonito/WGLMakie offline default configurable --- src/extensions/plotting/bonito.jl | 10 +++++++--- src/extensions/plotting/bonito_connection.jl | 1 + src/extensions/plotting/wglmakie.jl | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/extensions/plotting/bonito.jl b/src/extensions/plotting/bonito.jl index 15b9a7fc..f2059e67 100644 --- a/src/extensions/plotting/bonito.jl +++ b/src/extensions/plotting/bonito.jl @@ -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() @@ -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) diff --git a/src/extensions/plotting/bonito_connection.jl b/src/extensions/plotting/bonito_connection.jl index 806fd3f8..432fc2c5 100644 --- a/src/extensions/plotting/bonito_connection.jl +++ b/src/extensions/plotting/bonito_connection.jl @@ -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 diff --git a/src/extensions/plotting/wglmakie.jl b/src/extensions/plotting/wglmakie.jl index 975a68fb..57cf5301 100644 --- a/src/extensions/plotting/wglmakie.jl +++ b/src/extensions/plotting/wglmakie.jl @@ -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() @@ -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)