-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/wglmakie-and-bonito-extensions (#171)
* added package extension for wglmakie and bonito * added a new json() case for returning binary data directly * updated Plotting support docs section
- Loading branch information
Showing
14 changed files
with
343 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module WGLGLMakieDemo | ||
using Oxygen | ||
using Oxygen: text, html | ||
using WGLMakie | ||
using WGLMakie.Makie: FigureLike | ||
using Bonito, FileIO, Colors, HTTP | ||
WGLMakie.activate!() | ||
|
||
get("/") do | ||
text("home") | ||
end | ||
|
||
get("/plot") do | ||
plt = heatmap(rand(50, 50)) | ||
html(plt) | ||
end | ||
|
||
get("/page") do | ||
app = App() do session::Session | ||
hue_slider = Slider(0:360) | ||
color_swatch = DOM.div(class="h-6 w-6 p-2 m-2 rounded shadow") | ||
onjs(session, hue_slider.value, js"""function (hue){ | ||
$(color_swatch).style.backgroundColor = "hsl(" + hue + ",60%,50%)" | ||
}""") | ||
return Row(hue_slider, color_swatch) | ||
end | ||
return html(app) | ||
end | ||
|
||
serve() | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import HTTP | ||
import .Core.Util: html # import the html function from util so we can override it | ||
import .Bonito: Page, App | ||
|
||
export html | ||
|
||
""" | ||
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) | ||
# Force inlining all data & js dependencies | ||
Page(exportable=true, offline=true) | ||
|
||
# Convert & load the figure into an IOBuffer | ||
io = IOBuffer() | ||
show(io, mime_type, content) | ||
body = take!(io) | ||
|
||
# format the response | ||
resp = HTTP.Response(status, headers, body) | ||
HTTP.setheader(resp, "Content-Type" => string(mime_type)) | ||
HTTP.setheader(resp, "Content-Length" => string(sizeof(body))) | ||
return resp | ||
end | ||
|
||
|
||
""" | ||
html(app::Bonito.App) :: HTTP.Response | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import HTTP | ||
import .Core.Util: html # import the html function from util so we can override it | ||
import .WGLMakie.Makie: FigureLike | ||
import .Bonito: Page, App | ||
|
||
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) | ||
# Force inlining all data & js dependencies | ||
Page(exportable=true, offline=true) | ||
|
||
# Convert & load the figure into an IOBuffer | ||
io = IOBuffer() | ||
show(io, mime_type, content) | ||
body = take!(io) | ||
|
||
# format the response | ||
resp = HTTP.Response(status, headers, body) | ||
HTTP.setheader(resp, "Content-Type" => string(mime_type)) | ||
HTTP.setheader(resp, "Content-Length" => string(sizeof(body))) | ||
return resp | ||
end | ||
|
||
|
||
""" | ||
html(fig::Makie.FigureLike) :: HTTP.Response | ||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module CairoMakieTests | ||
using HTTP | ||
using Test | ||
using Bonito | ||
using Oxygen; @oxidise | ||
import Oxygen: text, html | ||
using ..Constants | ||
|
||
@testset "Bonito Utils tests" begin | ||
|
||
app = App() do | ||
return DOM.div(DOM.h1("hello world"), js"""console.log('hello world')""") | ||
end | ||
|
||
response = html(app) | ||
@test response isa HTTP.Response | ||
@test response.status == 200 | ||
@test HTTP.header(response, "Content-Type") == "text/html" | ||
@test parse(Int, HTTP.header(response, "Content-Length")) >= 0 | ||
end | ||
|
||
@testset "WGLMakie server tests" begin | ||
|
||
get("/") do | ||
text("hello world") | ||
end | ||
|
||
get("/html") do | ||
html("hello world") | ||
end | ||
|
||
get("/plot/html") do | ||
app = App() do | ||
return DOM.div(DOM.h1("hello world")) | ||
end | ||
html(app) | ||
end | ||
|
||
serve(host=HOST, port=PORT, async=true, show_banner=false, access_log=nothing) | ||
|
||
# Test overloaded text() function | ||
r = HTTP.get("$localhost/") | ||
@test r.status == 200 | ||
@test HTTP.header(r, "Content-Type") == "text/plain; charset=utf-8" | ||
@test parse(Int, HTTP.header(r, "Content-Length")) >= 0 | ||
|
||
# Test overloaded html function | ||
r = HTTP.get("$localhost/html") | ||
@test r.status == 200 | ||
@test HTTP.header(r, "Content-Type") == "text/html; charset=utf-8" | ||
@test parse(Int, HTTP.header(r, "Content-Length")) >= 0 | ||
|
||
# Test for /plot/html endpoint | ||
r = HTTP.get("$localhost/plot/html") | ||
@test r.status == 200 | ||
@test HTTP.header(r, "Content-Type") == "text/html" | ||
@test parse(Int, HTTP.header(r, "Content-Length")) >= 0 | ||
terminate() | ||
end | ||
|
||
end |
Oops, something went wrong.