Skip to content

Commit

Permalink
Merge pull request #46 from JuliaPlots/sd/fixes
Browse files Browse the repository at this point in the history
fix all the things
  • Loading branch information
SimonDanisch committed Jun 29, 2020
2 parents 1163307 + ae4c384 commit 4f09cde
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/debug/
/test/test_recordings
/test/tested_different
/test/exported
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/WGLMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/lines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 11 additions & 17 deletions src/particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions test/offline_export.jl
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 4f09cde

Please sign in to comment.