Merge pull request #478 from tbreloff/sd/dev
text rotation, move commands into module, is_marker_supported
This commit is contained in:
commit
9b0e35b4b1
@ -11,7 +11,7 @@ TODO
|
|||||||
=#
|
=#
|
||||||
|
|
||||||
const _glvisualize_attr = merge_with_base_supported([
|
const _glvisualize_attr = merge_with_base_supported([
|
||||||
#:annotations,
|
:annotations,
|
||||||
:background_color_legend, :background_color_inside, :background_color_outside,
|
:background_color_legend, :background_color_inside, :background_color_outside,
|
||||||
:foreground_color_grid, :foreground_color_legend, :foreground_color_title,
|
:foreground_color_grid, :foreground_color_legend, :foreground_color_title,
|
||||||
:foreground_color_axis, :foreground_color_border, :foreground_color_guide, :foreground_color_text,
|
:foreground_color_axis, :foreground_color_border, :foreground_color_guide, :foreground_color_text,
|
||||||
@ -51,7 +51,8 @@ const _glvisualize_seriestype = [
|
|||||||
const _glvisualize_style = [:auto, :solid, :dash, :dot, :dashdot]
|
const _glvisualize_style = [:auto, :solid, :dash, :dot, :dashdot]
|
||||||
const _glvisualize_marker = _allMarkers
|
const _glvisualize_marker = _allMarkers
|
||||||
const _glvisualize_scale = [:identity, :ln, :log2, :log10]
|
const _glvisualize_scale = [:identity, :ln, :log2, :log10]
|
||||||
is_marker_supported(::GLVisualizeBackend, shape::Shape) = true
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -64,6 +65,13 @@ function _initialize_backend(::GLVisualizeBackend; kw...)
|
|||||||
import Reactive: Signal
|
import Reactive: Signal
|
||||||
import GLAbstraction: Style
|
import GLAbstraction: Style
|
||||||
import GLVisualize: visualize
|
import GLVisualize: visualize
|
||||||
|
import Plots.GL
|
||||||
|
Plots.slice_arg(img::Images.AbstractImage, idx::Int) = img
|
||||||
|
is_marker_supported(::GLVisualizeBackend, shape::GLVisualize.AllPrimitives) = true
|
||||||
|
is_marker_supported{Img<:Images.AbstractImage}(::GLVisualizeBackend, shape::Union{Vector{Img}, Img}) = true
|
||||||
|
is_marker_supported{C<:Colorant}(::GLVisualizeBackend, shape::Union{Vector{Matrix{C}}, Matrix{C}}) = true
|
||||||
|
is_marker_supported(::GLVisualizeBackend, shape::Shape) = true
|
||||||
|
const GL = Plots
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -76,10 +84,16 @@ function add_backend(::GLVisualizeBackend)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# TODO: remove this section when the tagged versions catch up
|
# TODO: remove this section when the tagged versions catch up
|
||||||
for pkg in ["GLWindow", "GLAbstraction", "GLVisualize", "GeometryTypes", "FixedSizeArrays"]
|
for pkg in [
|
||||||
|
"GLWindow", "GLAbstraction",
|
||||||
|
"GLVisualize", "GeometryTypes", "FixedSizeArrays",
|
||||||
|
"FreeType", "GLPlot"
|
||||||
|
]
|
||||||
warn("Running Pkg.checkout(\"$pkg\"). To revert, run Pkg.free(\"$pkg\")")
|
warn("Running Pkg.checkout(\"$pkg\"). To revert, run Pkg.free(\"$pkg\")")
|
||||||
Pkg.checkout(pkg)
|
Pkg.checkout(pkg)
|
||||||
end
|
end
|
||||||
|
warn("Running Pkg.checkout(\"Reactive\", \"sd/betterstop\"). To revert, run Pkg.free(\"Reactive\")")
|
||||||
|
Pkg.checkout("Reactive", "sd/betterstop")
|
||||||
end
|
end
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -143,7 +157,7 @@ const _gl_marker_map = KW(
|
|||||||
:rect => '■',
|
:rect => '■',
|
||||||
:star5 => '★',
|
:star5 => '★',
|
||||||
:diamond => '◆',
|
:diamond => '◆',
|
||||||
#:hexagon => '⬢',
|
:hexagon => '⬢',
|
||||||
:cross => '✚',
|
:cross => '✚',
|
||||||
:xcross => '❌',
|
:xcross => '❌',
|
||||||
:utriangle => '▲',
|
:utriangle => '▲',
|
||||||
@ -159,6 +173,9 @@ const _gl_marker_map = KW(
|
|||||||
:x => 'x',
|
:x => 'x',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
function gl_marker(shape, size)
|
||||||
|
shape
|
||||||
|
end
|
||||||
function gl_marker(shape::Shape, size::FixedSizeArrays.Vec{2,Float32})
|
function gl_marker(shape::Shape, size::FixedSizeArrays.Vec{2,Float32})
|
||||||
points = Point2f0[Vec{2,Float32}(p)*10f0 for p in zip(shape.x, shape.y)]
|
points = Point2f0[Vec{2,Float32}(p)*10f0 for p in zip(shape.x, shape.y)]
|
||||||
GeometryTypes.GLNormalMesh(points)
|
GeometryTypes.GLNormalMesh(points)
|
||||||
@ -207,12 +224,23 @@ function extract_marker(d, kw_args)
|
|||||||
kw_args[:primitive] = shape
|
kw_args[:primitive] = shape
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
extract_c(d, kw_args, :marker)
|
# get the color
|
||||||
|
key = :markercolor
|
||||||
|
haskey(d, key) || return
|
||||||
|
c = gl_color(d[key])
|
||||||
|
if isa(c, AbstractVector) && d[:marker_z] != nothing
|
||||||
|
extract_colornorm(d, kw_args)
|
||||||
|
kw_args[:color] = nothing
|
||||||
|
kw_args[:color_map] = c
|
||||||
|
kw_args[:intensity] = convert(Vector{Float32}, d[:marker_z])
|
||||||
|
else
|
||||||
|
kw_args[:color] = c
|
||||||
|
end
|
||||||
key = :markerstrokecolor
|
key = :markerstrokecolor
|
||||||
haskey(d, key) || return
|
haskey(d, key) || return
|
||||||
c = gl_color(d[key])
|
c = gl_color(d[key])
|
||||||
if c != nothing
|
if c != nothing
|
||||||
if !isa(c, Colorant)
|
if !(isa(c, Colorant) || (isa(c, Vector) && eltype(c) <: Colorant))
|
||||||
error("Stroke Color not supported: $c")
|
error("Stroke Color not supported: $c")
|
||||||
end
|
end
|
||||||
kw_args[:stroke_color] = c
|
kw_args[:stroke_color] = c
|
||||||
@ -392,6 +420,11 @@ function hover(to_hover, to_display, window)
|
|||||||
area = map(window.inputs[:mouseposition]) do mp
|
area = map(window.inputs[:mouseposition]) do mp
|
||||||
SimpleRectangle{Int}(round(Int, mp+10)..., 100, 70)
|
SimpleRectangle{Int}(round(Int, mp+10)..., 100, 70)
|
||||||
end
|
end
|
||||||
|
background = visualize((GLVisualize.ROUNDED_RECTANGLE, Point2f0[0]),
|
||||||
|
color=RGBA{Float32}(0,0,0,0), scale=Vec2f0(100, 70), offset=Vec2f0(0),
|
||||||
|
stroke_color=RGBA{Float32}(0,0,0,0.4),
|
||||||
|
stroke_width=-1.0f0
|
||||||
|
)
|
||||||
mh = GLWindow.mouse2id(window)
|
mh = GLWindow.mouse2id(window)
|
||||||
popup = GLWindow.Screen(window, area=area, hidden=true)
|
popup = GLWindow.Screen(window, area=area, hidden=true)
|
||||||
cam = get!(popup.cameras, :perspective) do
|
cam = get!(popup.cameras, :perspective) do
|
||||||
@ -404,6 +437,7 @@ function hover(to_hover, to_display, window)
|
|||||||
Reactive.preserve(map(mh) do mh
|
Reactive.preserve(map(mh) do mh
|
||||||
popup.hidden = !(mh.id == to_hover.id)
|
popup.hidden = !(mh.id == to_hover.id)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
map(enumerate(to_display)) do id
|
map(enumerate(to_display)) do id
|
||||||
i,d = id
|
i,d = id
|
||||||
robj = visualize(d)
|
robj = visualize(d)
|
||||||
@ -418,7 +452,13 @@ function hover(to_hover, to_display, window)
|
|||||||
cam.projectiontype.value = GLVisualize.ORTHOGRAPHIC
|
cam.projectiontype.value = GLVisualize.ORTHOGRAPHIC
|
||||||
end
|
end
|
||||||
GLVisualize._view(robj, popup, camera=cam)
|
GLVisualize._view(robj, popup, camera=cam)
|
||||||
GLAbstraction.center!(popup, :perspective)
|
GLVisualize._view(background, popup, camera=:fixed_pixel)
|
||||||
|
bb = GLAbstraction.boundingbox(robj).value
|
||||||
|
mini = minimum(bb)
|
||||||
|
w = GeometryTypes.widths(bb)
|
||||||
|
wborder = w*0.08f0 #8 percent border
|
||||||
|
bb = GeometryTypes.AABB{Float32}(mini-wborder, w+2f0*wborder)
|
||||||
|
GLAbstraction.center!(cam, bb)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@ -509,7 +549,7 @@ function draw_grid_lines(sp, grid_segs, thickness, style, model, color)
|
|||||||
:linecolor => color
|
:linecolor => color
|
||||||
)
|
)
|
||||||
Plots.extract_linestyle(d, kw_args)
|
Plots.extract_linestyle(d, kw_args)
|
||||||
Plots.lines(map(Point2f0, grid_segs.pts), kw_args)
|
GL.gl_lines(map(Point2f0, grid_segs.pts), kw_args)
|
||||||
end
|
end
|
||||||
|
|
||||||
function align_offset(startpos, lastpos, atlas, rscale, font, align)
|
function align_offset(startpos, lastpos, atlas, rscale, font, align)
|
||||||
@ -572,30 +612,29 @@ function text(position, text, kw_args)
|
|||||||
startpos = Vec2f0(position)
|
startpos = Vec2f0(position)
|
||||||
atlas = GLVisualize.get_texture_atlas()
|
atlas = GLVisualize.get_texture_atlas()
|
||||||
font = GLVisualize.DEFAULT_FONT_FACE
|
font = GLVisualize.DEFAULT_FONT_FACE
|
||||||
rscale2 = kw_args[:relative_scale]
|
rscale = kw_args[:relative_scale]
|
||||||
m = Reactive.value(kw_args[:model])
|
m = Reactive.value(kw_args[:model])
|
||||||
xs, ys = m[1,1], m[2,2]
|
|
||||||
rscale = rscale2 ./ Vec2f0(xs, ys)
|
|
||||||
position = GLVisualize.calc_position(text.str, startpos, rscale, font, atlas)
|
position = GLVisualize.calc_position(text.str, startpos, rscale, font, atlas)
|
||||||
offset = GLVisualize.calc_offset(text.str, rscale2, font, atlas)
|
offset = GLVisualize.calc_offset(text.str, rscale, font, atlas)
|
||||||
alignoff = align_offset(startpos, last(position), atlas, rscale, font, text_align)
|
alignoff = align_offset(startpos, last(position), atlas, rscale, font, text_align)
|
||||||
map!(position) do pos
|
map!(position) do pos
|
||||||
pos .+ alignoff
|
pos .+ alignoff
|
||||||
end
|
end
|
||||||
kw_args[:position] = position
|
kw_args[:position] = position
|
||||||
kw_args[:offset] = offset
|
kw_args[:offset] = offset
|
||||||
|
kw_args[:scale_primitive] = true
|
||||||
visualize(text.str, Style(:default), kw_args)
|
visualize(text.str, Style(:default), kw_args)
|
||||||
end
|
end
|
||||||
|
|
||||||
function text_model(font)
|
function text_model(font, pivot)
|
||||||
# if font.rotation != 0.0
|
pv = GeometryTypes.Vec3f0(pivot[1], pivot[2], 0)
|
||||||
# rot = Float32(deg2rad(font.rotation))
|
if font.rotation != 0.0
|
||||||
# rotm = GLAbstraction.rotationmatrix_z(rot)
|
rot = Float32(deg2rad(font.rotation))
|
||||||
# GLAbstraction.translationmatrix(pivot)*rotm*GLAbstraction.translationmatrix(-pivot)
|
rotm = GLAbstraction.rotationmatrix_z(rot)
|
||||||
# return
|
return GLAbstraction.translationmatrix(pv)*rotm*GLAbstraction.translationmatrix(-pv)
|
||||||
# else
|
else
|
||||||
eye(GeometryTypes.Mat4f0)
|
eye(GeometryTypes.Mat4f0)
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, area)
|
function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, area)
|
||||||
xticks, yticks, spine_segs, grid_segs = Plots.axis_drawing_info(sp)
|
xticks, yticks, spine_segs, grid_segs = Plots.axis_drawing_info(sp)
|
||||||
@ -623,24 +662,25 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are
|
|||||||
:offset => offsets,
|
:offset => offsets,
|
||||||
:color => fcolor,
|
:color => fcolor,
|
||||||
:relative_scale => Vec2f0(3/sz),
|
:relative_scale => Vec2f0(3/sz),
|
||||||
:model => model
|
:model => model,
|
||||||
|
:scale_primitive => false
|
||||||
)
|
)
|
||||||
push!(axis_vis, visualize(t, Style(:default), kw_args))
|
push!(axis_vis, visualize(t, Style(:default), kw_args))
|
||||||
area_w = GeometryTypes.widths(area)
|
area_w = GeometryTypes.widths(area)
|
||||||
if sp[:title] != ""
|
if sp[:title] != ""
|
||||||
tf = sp[:titlefont]; color = gl_color(sp[:foreground_color_title])
|
tf = sp[:titlefont]; color = gl_color(sp[:foreground_color_title])
|
||||||
font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, 0.0, color)
|
font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, tf.rotation, color)
|
||||||
kw = Dict{Symbol, Any}(:model => text_model(font))
|
|
||||||
extract_font(font, kw)
|
|
||||||
xy = Point2f0(area.w/2, area_w[2])
|
xy = Point2f0(area.w/2, area_w[2])
|
||||||
|
kw = Dict(:model => text_model(font, xy), :scale_primitive=>true)
|
||||||
|
extract_font(font, kw)
|
||||||
t = PlotText(sp[:title], font)
|
t = PlotText(sp[:title], font)
|
||||||
push!(axis_vis, text(xy, t, kw))
|
push!(axis_vis, text(xy, t, kw))
|
||||||
end
|
end
|
||||||
if xaxis[:guide] != ""
|
if xaxis[:guide] != ""
|
||||||
tf = xaxis[:guidefont]; color = gl_color(xaxis[:foreground_color_guide])
|
tf = xaxis[:guidefont]; color = gl_color(xaxis[:foreground_color_guide])
|
||||||
font = Plots.Font(tf.family, tf.pointsize, :hcenter, :bottom, 0.0, color)
|
|
||||||
kw = Dict{Symbol, Any}(:model => text_model(font))
|
|
||||||
xy = Point2f0(area.w/2, 0)
|
xy = Point2f0(area.w/2, 0)
|
||||||
|
font = Plots.Font(tf.family, tf.pointsize, :hcenter, :bottom, tf.rotation, color)
|
||||||
|
kw = Dict(:model => text_model(font, xy), :scale_primitive=>true)
|
||||||
t = PlotText(xaxis[:guide], font)
|
t = PlotText(xaxis[:guide], font)
|
||||||
extract_font(font, kw)
|
extract_font(font, kw)
|
||||||
push!(axis_vis, text(xy, t, kw))
|
push!(axis_vis, text(xy, t, kw))
|
||||||
@ -648,9 +688,9 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are
|
|||||||
|
|
||||||
if yaxis[:guide] != ""
|
if yaxis[:guide] != ""
|
||||||
tf = yaxis[:guidefont]; color = gl_color(yaxis[:foreground_color_guide])
|
tf = yaxis[:guidefont]; color = gl_color(yaxis[:foreground_color_guide])
|
||||||
font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, 0.0, color)
|
font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, 90f0, color)
|
||||||
kw = Dict{Symbol, Any}(:model => text_model(font))
|
|
||||||
xy = Point2f0(0, area.h/2)
|
xy = Point2f0(0, area.h/2)
|
||||||
|
kw = Dict(:model => text_model(font, xy), :scale_primitive=>true)
|
||||||
t = PlotText(yaxis[:guide], font)
|
t = PlotText(yaxis[:guide], font)
|
||||||
extract_font(font, kw)
|
extract_font(font, kw)
|
||||||
push!(axis_vis, text(xy, t, kw))
|
push!(axis_vis, text(xy, t, kw))
|
||||||
@ -845,7 +885,6 @@ end
|
|||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
function _display(plt::Plot{GLVisualizeBackend})
|
function _display(plt::Plot{GLVisualizeBackend})
|
||||||
GL = Plots
|
|
||||||
screen = plt.o
|
screen = plt.o
|
||||||
empty_screen!(screen)
|
empty_screen!(screen)
|
||||||
sw, sh = plt[:size]
|
sw, sh = plt[:size]
|
||||||
@ -879,9 +918,10 @@ function _display(plt::Plot{GLVisualizeBackend})
|
|||||||
model_m = map(Plots.to_modelmatrix, screen.area, sub_area, Signal(rel_plotarea), Signal(sp))
|
model_m = map(Plots.to_modelmatrix, screen.area, sub_area, Signal(rel_plotarea), Signal(sp))
|
||||||
for ann in sp[:annotations]
|
for ann in sp[:annotations]
|
||||||
x, y, plot_text = ann
|
x, y, plot_text = ann
|
||||||
txt_args = Dict{Symbol, Any}(:model => model_m)
|
txt_args = Dict{Symbol, Any}(:model => eye(GeometryTypes.Mat4f0))
|
||||||
|
x, y, _1, _1 = Reactive.value(model_m) * Vec{4,Float32}(x, y, 0, 1)
|
||||||
extract_font(plot_text.font, txt_args)
|
extract_font(plot_text.font, txt_args)
|
||||||
t = GL.text(Point2f0(x, y), plot_text, txt_args)
|
t = text(Point2f0(x, y), plot_text, txt_args)
|
||||||
GLVisualize._view(t, sp_screen, camera=cam)
|
GLVisualize._view(t, sp_screen, camera=cam)
|
||||||
end
|
end
|
||||||
# loop over the series and add them to the subplot
|
# loop over the series and add them to the subplot
|
||||||
@ -892,7 +932,7 @@ function _display(plt::Plot{GLVisualizeBackend})
|
|||||||
Reactive.run_till_now() # make sure Reactive.push! arrives
|
Reactive.run_till_now() # make sure Reactive.push! arrives
|
||||||
GLAbstraction.center!(cam,
|
GLAbstraction.center!(cam,
|
||||||
GeometryTypes.AABB(
|
GeometryTypes.AABB(
|
||||||
Vec3f0(0), Vec3f0(GeometryTypes.widths(sp_screen)..., 1)
|
Vec3f0(-10), Vec3f0((GeometryTypes.widths(sp_screen)+20f0)..., 1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
@ -920,17 +960,17 @@ function _display(plt::Plot{GLVisualizeBackend})
|
|||||||
kw_args[:stroke_color] = d[:linecolor]
|
kw_args[:stroke_color] = d[:linecolor]
|
||||||
kw_args[:stroke_width] = Float32(d[:linewidth]/100f0)
|
kw_args[:stroke_width] = Float32(d[:linewidth]/100f0)
|
||||||
end
|
end
|
||||||
vis = GL.surface(x, y, z, kw_args)
|
vis = GL.gl_surface(x, y, z, kw_args)
|
||||||
elseif (st in (:path, :path3d)) && d[:linewidth] > 0
|
elseif (st in (:path, :path3d)) && d[:linewidth] > 0
|
||||||
kw = copy(kw_args)
|
kw = copy(kw_args)
|
||||||
points = Plots.extract_points(d)
|
points = Plots.extract_points(d)
|
||||||
extract_linestyle(d, kw)
|
extract_linestyle(d, kw)
|
||||||
vis = GL.lines(points, kw)
|
vis = GL.gl_lines(points, kw)
|
||||||
if d[:markershape] != :none
|
if d[:markershape] != :none
|
||||||
kw = copy(kw_args)
|
kw = copy(kw_args)
|
||||||
extract_stroke(d, kw)
|
extract_stroke(d, kw)
|
||||||
extract_marker(d, kw)
|
extract_marker(d, kw)
|
||||||
vis2 = GL.scatter(copy(points), kw)
|
vis2 = GL.gl_scatter(copy(points), kw)
|
||||||
vis = [vis; vis2]
|
vis = [vis; vis2]
|
||||||
end
|
end
|
||||||
if d[:fillrange] != nothing
|
if d[:fillrange] != nothing
|
||||||
@ -942,15 +982,15 @@ function _display(plt::Plot{GLVisualizeBackend})
|
|||||||
points
|
points
|
||||||
end
|
end
|
||||||
extract_c(d, kw, :fill)
|
extract_c(d, kw, :fill)
|
||||||
vis = [GL.poly(ps, kw), vis]
|
vis = [GL.gl_poly(ps, kw), vis]
|
||||||
end
|
end
|
||||||
elseif st in (:scatter, :scatter3d) #|| d[:markershape] != :none
|
elseif st in (:scatter, :scatter3d) #|| d[:markershape] != :none
|
||||||
extract_marker(d, kw_args)
|
extract_marker(d, kw_args)
|
||||||
points = extract_points(d)
|
points = extract_points(d)
|
||||||
vis = GL.scatter(points, kw_args)
|
vis = GL.gl_scatter(points, kw_args)
|
||||||
elseif st == :shape
|
elseif st == :shape
|
||||||
extract_c(d, kw_args, :fill)
|
extract_c(d, kw_args, :fill)
|
||||||
vis = GL.shape(d, kw_args)
|
vis = GL.gl_shape(d, kw_args)
|
||||||
elseif st == :contour
|
elseif st == :contour
|
||||||
x,y,z = extract_surface(d)
|
x,y,z = extract_surface(d)
|
||||||
z = transpose_z(d, z, false)
|
z = transpose_z(d, z, false)
|
||||||
@ -959,20 +999,20 @@ function _display(plt::Plot{GLVisualizeBackend})
|
|||||||
kw_args[:fillrange] = d[:fillrange]
|
kw_args[:fillrange] = d[:fillrange]
|
||||||
kw_args[:levels] = d[:levels]
|
kw_args[:levels] = d[:levels]
|
||||||
|
|
||||||
vis = GL.contour(x,y,z, kw_args)
|
vis = GL.gl_contour(x,y,z, kw_args)
|
||||||
elseif st == :heatmap
|
elseif st == :heatmap
|
||||||
x,y,z = extract_surface(d)
|
x,y,z = extract_surface(d)
|
||||||
extract_gradient(d, kw_args, :fill)
|
extract_gradient(d, kw_args, :fill)
|
||||||
extract_extrema(d, kw_args)
|
extract_extrema(d, kw_args)
|
||||||
extract_limits(sp, d, kw_args)
|
extract_limits(sp, d, kw_args)
|
||||||
vis = GL.heatmap(x,y,z, kw_args)
|
vis = GL.gl_heatmap(x,y,z, kw_args)
|
||||||
elseif st == :bar
|
elseif st == :bar
|
||||||
extract_c(d, kw_args, :fill)
|
extract_c(d, kw_args, :fill)
|
||||||
extract_stroke(d, kw_args, :marker)
|
extract_stroke(d, kw_args, :marker)
|
||||||
vis = gl_bar(d, kw_args)
|
vis = gl_bar(d, kw_args)
|
||||||
elseif st == :image
|
elseif st == :image
|
||||||
extract_extrema(d, kw_args)
|
extract_extrema(d, kw_args)
|
||||||
vis = GL.image(d[:z].surf, kw_args)
|
vis = GL.gl_image(d[:z].surf, kw_args)
|
||||||
elseif st == :boxplot
|
elseif st == :boxplot
|
||||||
extract_c(d, kw_args, :fill)
|
extract_c(d, kw_args, :fill)
|
||||||
vis = gl_boxplot(d, kw_args)
|
vis = gl_boxplot(d, kw_args)
|
||||||
@ -1023,7 +1063,7 @@ function _show(io::IO, ::MIME"image/png", plt::Plot{GLVisualizeBackend})
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function image(img, kw_args)
|
function gl_image(img, kw_args)
|
||||||
rect = kw_args[:primitive]
|
rect = kw_args[:primitive]
|
||||||
kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(rect.x, rect.y, rect.h, rect.w) # seems to be flipped
|
kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(rect.x, rect.y, rect.h, rect.w) # seems to be flipped
|
||||||
visualize(img, Style(:default), kw_args)
|
visualize(img, Style(:default), kw_args)
|
||||||
@ -1041,7 +1081,8 @@ function handle_segment{P}(lines, line_segments, points::Vector{P}, segment)
|
|||||||
push!(lines, P(NaN))
|
push!(lines, P(NaN))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function lines(points, kw_args)
|
|
||||||
|
function gl_lines(points, kw_args)
|
||||||
result = []
|
result = []
|
||||||
isempty(points) && return result
|
isempty(points) && return result
|
||||||
P = eltype(points)
|
P = eltype(points)
|
||||||
@ -1064,31 +1105,44 @@ function lines(points, kw_args)
|
|||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
function shape(d, kw_args)
|
function gl_shape(d, kw_args)
|
||||||
points = Plots.extract_points(d)
|
points = Plots.extract_points(d)
|
||||||
result = []
|
result = []
|
||||||
for rng in iter_segments(d[:x], d[:y])
|
for rng in iter_segments(d[:x], d[:y])
|
||||||
ps = points[rng]
|
ps = points[rng]
|
||||||
meshes = poly(ps, kw_args)
|
meshes = gl_poly(ps, kw_args)
|
||||||
append!(result, meshes)
|
append!(result, meshes)
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
tovec2(x::FixedSizeArrays.Vec{2, Float32}) = x
|
||||||
|
tovec2(x::AbstractVector) = map(tovec2, x)
|
||||||
|
tovec2(x::FixedSizeArrays.Vec) = Vec2f0(x[1], x[2])
|
||||||
|
|
||||||
function scatter(points, kw_args)
|
|
||||||
|
function gl_scatter(points, kw_args)
|
||||||
prim = get(kw_args, :primitive, GeometryTypes.Circle)
|
prim = get(kw_args, :primitive, GeometryTypes.Circle)
|
||||||
if isa(prim, GLNormalMesh)
|
if isa(prim, GLNormalMesh)
|
||||||
kw_args[:scale] = map(kw_args[:model]) do m
|
kw_args[:scale] = map(kw_args[:model]) do m
|
||||||
s = m[1,1], m[2,2], m[3,3]
|
s = m[1,1], m[2,2], m[3,3]
|
||||||
1f0./Vec3f0(s)
|
1f0./Vec3f0(s)
|
||||||
end
|
end
|
||||||
|
else # 2D prim
|
||||||
|
kw_args[:scale] = tovec2(kw_args[:scale])
|
||||||
end
|
end
|
||||||
|
if haskey(kw_args, :stroke_width)
|
||||||
|
s = Reactive.value(kw_args[:scale])
|
||||||
|
sw = kw_args[:stroke_width]
|
||||||
|
if sw*5 > cycle(Reactive.value(s), 1)[1] # restrict marker stroke to 1/10th of scale (and handle arrays of scales)
|
||||||
|
kw_args[:stroke_width] = s[1]/5f0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
kw_args[:scale_primitive] = false
|
||||||
visualize((prim, points), Style(:default), kw_args)
|
visualize((prim, points), Style(:default), kw_args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function poly(points, kw_args)
|
function gl_poly(points, kw_args)
|
||||||
last(points) == first(points) && pop!(points)
|
last(points) == first(points) && pop!(points)
|
||||||
polys = GeometryTypes.split_intersections(points)
|
polys = GeometryTypes.split_intersections(points)
|
||||||
result = []
|
result = []
|
||||||
@ -1103,7 +1157,7 @@ function poly(points, kw_args)
|
|||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
function surface(x,y,z, kw_args)
|
function gl_surface(x,y,z, kw_args)
|
||||||
if isa(x, Range) && isa(y, Range)
|
if isa(x, Range) && isa(y, Range)
|
||||||
main = z
|
main = z
|
||||||
kw_args[:ranges] = (x, y)
|
kw_args[:ranges] = (x, y)
|
||||||
@ -1139,7 +1193,7 @@ function surface(x,y,z, kw_args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function contour(x,y,z, kw_args)
|
function gl_contour(x,y,z, kw_args)
|
||||||
if kw_args[:fillrange] != nothing
|
if kw_args[:fillrange] != nothing
|
||||||
delete!(kw_args, :intensity)
|
delete!(kw_args, :intensity)
|
||||||
I = GLVisualize.Intensity{1, Float32}
|
I = GLVisualize.Intensity{1, Float32}
|
||||||
@ -1168,9 +1222,9 @@ function contour(x,y,z, kw_args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function heatmap(x,y,z, kw_args)
|
function gl_heatmap(x,y,z, kw_args)
|
||||||
get!(kw_args, :color_norm, Vec2f0(extrema(z)))
|
get!(kw_args, :color_norm, Vec2f0(extrema(z)))
|
||||||
get!(kw_args, :color_map, make_gradient(cgrad()))
|
get!(kw_args, :color_map, Plots.make_gradient(cgrad()))
|
||||||
delete!(kw_args, :intensity)
|
delete!(kw_args, :intensity)
|
||||||
I = GLVisualize.Intensity{1, Float32}
|
I = GLVisualize.Intensity{1, Float32}
|
||||||
heatmap = I[z[j,i] for i=1:size(z, 2), j=1:size(z, 1)]
|
heatmap = I[z[j,i] for i=1:size(z, 2), j=1:size(z, 1)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user