diff --git a/.gitignore b/.gitignore index 11c3e80ec84..cd3d0c43652 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /debug/ /test/test_recordings /test/tested_different +/test/exported diff --git a/Project.toml b/Project.toml index 7960c5a90dd..54215293f66 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" FreeTypeAbstraction = "663a7486-cb36-511b-a19d-713bb74d65c9" GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" Hyperscript = "47d2ed2b-36de-50cf-bf87-49c2cf4b8b91" +ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795" JSServe = "824d6782-a2ef-11e9-3a09-e5662e0c26f9" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" @@ -21,6 +22,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" AbstractPlotting = "0.11" Colors = "0.9, 0.10, 0.11, 0.12" FileIO = "1.1" +FreeTypeAbstraction = "0.8" GeometryBasics = "0.2.3" Hyperscript = "0.0.3" ImageTransformations = "0.7, 0.8" @@ -32,7 +34,6 @@ ShaderAbstractions = "0.2.1" StaticArrays = "0.12, 0.1" StatsMakie = "0.2" julia = "1.0" -FreeTypeAbstraction = "0.8" [extras] ElectronDisplay = "d872a56f-244b-5cc9-b574-2017b5b909a8" diff --git a/src/WGLMakie.jl b/src/WGLMakie.jl index 3574ae02768..f8893f05faf 100644 --- a/src/WGLMakie.jl +++ b/src/WGLMakie.jl @@ -15,9 +15,10 @@ using ShaderAbstractions: InstancedProgram import AbstractPlotting.FileIO using StaticArrays using GeometryBasics: decompose_uv +import ImageMagick using FreeTypeAbstraction -using AbstractPlotting: get_texture_atlas, glyph_uv_width! +using AbstractPlotting: get_texture_atlas, glyph_uv_width!, SceneSpace, Pixel using AbstractPlotting: attribute_per_char, glyph_uv_width!, layout_text using ImageTransformations @@ -431,7 +432,7 @@ function session2image(sessionlike) picture_base64 = JSServe.evaljs_value(s, js"document.querySelector('canvas').toDataURL()") picture_base64 = replace(picture_base64, "data:image/png;base64," => "") bytes = JSServe.Base64.base64decode(picture_base64) - return AbstractPlotting.ImageMagick.load_(bytes) + return ImageMagick.load_(bytes) end function AbstractPlotting.colorbuffer(screen::ThreeDisplay) diff --git a/src/lines.jl b/src/lines.jl index 1c4db985d3e..6f6afacd941 100644 --- a/src/lines.jl +++ b/src/lines.jl @@ -35,12 +35,15 @@ function create_shader(scene::Scene, plot::LineSegments) ) uniforms = Dict{Symbol, Any}() for k in (:linewidth, :color) - attribute = lift(x-> convert_attribute(x, Key{k}(), key"scatter"()), plot[k]) + attribute = lift(x-> convert_attribute(x, Key{k}(), key"lines"()), plot[k]) if isscalar(attribute) uniforms[k] = attribute uniforms[Symbol("$(k)_start")] = attribute uniforms[Symbol("$(k)_end")] = attribute else + if attribute[] isa AbstractVector{<: Number} && haskey(plot, :colorrange) + attribute = lift(array2color, attribute, plot.colormap, plot.colorrange) + end per_instance[Symbol("$(k)_start")] = Buffer(lift(x-> x[startr[]], attribute)) per_instance[Symbol("$(k)_end")] = Buffer(lift(x-> x[endr[]], attribute)) end diff --git a/src/particles.jl b/src/particles.jl index a9c0c8a5035..40192d20e61 100644 --- a/src/particles.jl +++ b/src/particles.jl @@ -20,6 +20,11 @@ function handle_color!(uniform_dict, instance_dict) end end +const IGNORE_KEYS = Set([ + :shading, :overdraw, :rotation, :distancefield, :markerspace, :fxaa, + :visible, :transformation, :alpha, :linewidth, :transparency, :marker +]) + function create_shader(scene::Scene, plot::MeshScatter) # Potentially per instance attributes per_instance_keys = (:rotations, :markersize, :color, :intensity) @@ -36,10 +41,9 @@ function create_shader(scene::Scene, plot::MeshScatter) (!haskey(per_instance, k)) && isscalar(v[]) end - uniform_dict = Dict{Symbol, Any}() for (k,v) in uniforms - k in (:shading, :overdraw, :fxaa, :visible, :transformation, :alpha, :linewidth, :transparency, :marker) && continue + k in IGNORE_KEYS && continue uniform_dict[k] = lift_convert(k, v, plot) end @@ -105,13 +109,8 @@ function scatter_shader(scene::Scene, attributes) (!haskey(per_instance, k)) && isscalar(v[]) end - ignore_keys = ( - :shading, :overdraw, :rotation, :distancefield, :fxaa, - :visible, :transformation, :alpha, :linewidth, :transparency, :marker - ) - for (k, v) in uniforms - k in ignore_keys && continue + k in IGNORE_KEYS && continue uniform_dict[k] = lift_convert(k, v, nothing) end @@ -141,15 +140,10 @@ function scatter_shader(scene::Scene, attributes) end end end - uniform_dict[:use_pixel_marker] = Observable(false) - if haskey(uniform_dict, :markersize) - msize = uniform_dict[:markersize] - if haskey(uniform_dict, :marker_offset) - moff = uniform_dict[:marker_offset] - uniform_dict[:marker_offset] = lift(x-> AbstractPlotting.number.(x), moff) - end - uniform_dict[:use_pixel_marker] = lift(x-> x isa Vec{2, <:AbstractPlotting.Pixel}, msize) - uniform_dict[:markersize] = lift(x-> AbstractPlotting.number.(x), msize) + + space = get(uniforms, :markerspace, Observable(SceneSpace)) + uniform_dict[:use_pixel_marker] = map(space) do space + space == Pixel end handle_color!(uniform_dict, per_instance) diff --git a/test/offline_export.jl b/test/offline_export.jl new file mode 100644 index 00000000000..9d379ab8a71 --- /dev/null +++ b/test/offline_export.jl @@ -0,0 +1,13 @@ +using JSServe, WGLMakie, AbstractPlotting + +function handler(session, request) + return scatter(1:4, color=1:4) +end + +dir = joinpath(@__DIR__, "exported") +isdir(dir) || mkdir(dir) +JSServe.export_standalone(handler, dir) +# Then serve it with e.g. LiveServer +using LiveServer + +LiveServer.serve(dir=dir)