From f33d13518238ce660452d675020df54b6a701006 Mon Sep 17 00:00:00 2001 From: Michael Krabbe Borregaard Date: Tue, 30 Oct 2018 11:41:27 +0100 Subject: [PATCH 1/2] More completely remove deprecated backends --- src/backends.jl | 7 +- src/deprecated/backends/bokeh.jl | 208 ----- src/deprecated/backends/gadfly.jl | 744 --------------- src/deprecated/backends/gadfly_shapes.jl | 93 -- src/deprecated/backends/immerse.jl | 186 ---- src/deprecated/backends/qwt.jl | 308 ------- src/deprecated/backends/winston.jl | 272 ------ src/deprecated/color_gradients.jl | 1067 ---------------------- src/deprecated/colors.jl | 415 --------- src/deprecated/contours.jl | 63 -- src/deprecated/series_args.jl | 99 -- src/utils.jl | 2 +- test/runtests.jl | 23 - 13 files changed, 2 insertions(+), 3485 deletions(-) delete mode 100644 src/deprecated/backends/bokeh.jl delete mode 100644 src/deprecated/backends/gadfly.jl delete mode 100644 src/deprecated/backends/gadfly_shapes.jl delete mode 100644 src/deprecated/backends/immerse.jl delete mode 100644 src/deprecated/backends/qwt.jl delete mode 100644 src/deprecated/backends/winston.jl delete mode 100644 src/deprecated/color_gradients.jl delete mode 100644 src/deprecated/colors.jl delete mode 100644 src/deprecated/contours.jl delete mode 100644 src/deprecated/series_args.jl diff --git a/src/backends.jl b/src/backends.jl index 00ac483a..d64db5e4 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -217,7 +217,7 @@ const _deprecated_backends = [:qwt, :winston, :bokeh, :gadfly, :immerse] function warn_on_deprecated_backend(bsym::Symbol) if bsym in _deprecated_backends - @warn("Backend $bsym has been deprecated. It may not work as originally intended.") + @warn("Backend $bsym has been deprecated.") end end @@ -268,13 +268,8 @@ end -# @init_backend Immerse -# @init_backend Gadfly @init_backend PyPlot -# @init_backend Qwt @init_backend UnicodePlots -# @init_backend Winston -# @init_backend Bokeh @init_backend Plotly @init_backend PlotlyJS @init_backend GR diff --git a/src/deprecated/backends/bokeh.jl b/src/deprecated/backends/bokeh.jl deleted file mode 100644 index 9e906b75..00000000 --- a/src/deprecated/backends/bokeh.jl +++ /dev/null @@ -1,208 +0,0 @@ - -# https://github.com/bokeh/Bokeh.jl - - -supported_attrs(::BokehBackend) = merge_with_base_supported([ - # :annotations, - # :axis, - # :background_color, - :linecolor, - # :color_palette, - # :fillrange, - # :fillcolor, - # :fillalpha, - # :foreground_color, - :group, - # :label, - # :layout, - # :legend, - :seriescolor, :seriesalpha, - :linestyle, - :seriestype, - :linewidth, - # :linealpha, - :markershape, - :markercolor, - :markersize, - # :markeralpha, - # :markerstrokewidth, - # :markerstrokecolor, - # :markerstrokestyle, - # :n, - # :bins, - # :nc, - # :nr, - # :pos, - # :smooth, - # :show, - :size, - :title, - # :window_title, - :x, - # :xguide, - # :xlims, - # :xticks, - :y, - # :yguide, - # :ylims, - # :yrightlabel, - # :yticks, - # :xscale, - # :yscale, - # :xflip, - # :yflip, - # :z, - # :tickfont, - # :guidefont, - # :legendfont, - # :grid, - # :surface, - # :levels, - ]) -supported_types(::BokehBackend) = [:path, :scatter] -supported_styles(::BokehBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] -supported_markers(::BokehBackend) = [:none, :auto, :circle, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] -supported_scales(::BokehBackend) = [:identity, :ln] -is_subplot_supported(::BokehBackend) = false - - -# -------------------------------------------------------------------------------------- - - - -function _initialize_backend(::BokehBackend; kw...) - @eval begin - @warn("Bokeh is no longer supported... many features will likely be broken.") - import Bokeh - export Bokeh - end -end - - -const _glyphtypes = KW( - :circle => :Circle, - :rect => :Square, - :diamond => :Diamond, - :utriangle => :Triangle, - :dtriangle => :InvertedTriangle, - # :pentagon => - # :hexagon => - # :heptagon => - # :octagon => - :cross => :Cross, - :xcross => :X, - :star5 => :Asterisk, - ) - - -function bokeh_glyph_type(plotattributes::KW) - st = plotattributes[:seriestype] - mt = plotattributes[:markershape] - if st == :scatter && mt == :none - mt = :circle - end - - # if we have a marker, use that - if st == :scatter || mt != :none - return _glyphtypes[mt] - end - - # otherwise return a line - return :Line -end - -function get_stroke_vector(linestyle::Symbol) - dash = 12 - dot = 3 - gap = 2 - linestyle == :solid && return Int[] - linestyle == :dash && return Int[dash, gap] - linestyle == :dot && return Int[dot, gap] - linestyle == :dashdot && return Int[dash, gap, dot, gap] - linestyle == :dashdotdot && return Int[dash, gap, dot, gap, dot, gap] - error("unsupported linestyle: ", linestyle) -end - -# --------------------------------------------------------------------------- - -# function _create_plot(pkg::BokehBackend, plotattributes::KW) -function _create_backend_figure(plt::Plot{BokehBackend}) - # TODO: create the window/canvas/context that is the plot within the backend (call it `o`) - # TODO: initialize the plot... title, xlabel, bgcolor, etc - - datacolumns = Bokeh.BokehDataSet[] - tools = Bokeh.tools() - filename = tempname() * ".html" - title = plt.attr[:title] - w, h = plt.attr[:size] - xaxis_type = plt.attr[:xscale] == :log10 ? :log : :auto - yaxis_type = plt.attr[:yscale] == :log10 ? :log : :auto - # legend = plt.attr[:legend] ? xxxx : nothing - legend = nothing - extra_args = KW() # TODO: we'll put extra settings (xlim, etc) here - Bokeh.Plot(datacolumns, tools, filename, title, w, h, xaxis_type, yaxis_type, legend) #, extra_args) - - # Plot(bplt, pkg, 0, plotattributes, KW[]) -end - - -# function _series_added(::BokehBackend, plt::Plot, plotattributes::KW) -function _series_added(plt::Plot{BokehBackend}, series::Series) - bdata = Dict{Symbol, Vector}(:x => collect(series.plotattributes[:x]), :y => collect(series.plotattributes[:y])) - - glyph = Bokeh.Bokehjs.Glyph( - glyphtype = bokeh_glyph_type(plotattributes), - linecolor = webcolor(plotattributes[:linecolor]), # shape's stroke or line color - linewidth = plotattributes[:linewidth], # shape's stroke width or line width - fillcolor = webcolor(plotattributes[:markercolor]), - size = ceil(Int, plotattributes[:markersize] * 2.5), # magic number 2.5 to keep in same scale as other backends - dash = get_stroke_vector(plotattributes[:linestyle]) - ) - - legend = nothing # TODO - push!(plt.o.datacolumns, Bokeh.BokehDataSet(bdata, glyph, legend)) - - # push!(plt.seriesargs, plotattributes) - # plt -end - -# ---------------------------------------------------------------- - -# TODO: override this to update plot items (title, xlabel, etc) after creation -function _update_plot_object(plt::Plot{BokehBackend}, plotattributes::KW) -end - -# ---------------------------------------------------------------- - -# accessors for x/y data - -# function getxy(plt::Plot{BokehBackend}, i::Int) -# series = plt.o.datacolumns[i].data -# series[:x], series[:y] -# end -# -# function setxy!(plt::Plot{BokehBackend}, xy::Tuple{X,Y}, i::Integer) -# series = plt.o.datacolumns[i].data -# series[:x], series[:y] = xy -# plt -# end - - - -# ---------------------------------------------------------------- - - -# ---------------------------------------------------------------- - -function Base.show(io::IO, ::MIME"image/png", plt::AbstractPlot{BokehBackend}) - # TODO: write a png to io - @warn("mime png not implemented") -end - -function Base.display(::PlotsDisplay, plt::Plot{BokehBackend}) - Bokeh.showplot(plt.o) -end - -# function Base.display(::PlotsDisplay, plt::Subplot{BokehBackend}) -# # TODO: display/show the subplot -# end diff --git a/src/deprecated/backends/gadfly.jl b/src/deprecated/backends/gadfly.jl deleted file mode 100644 index 37dac678..00000000 --- a/src/deprecated/backends/gadfly.jl +++ /dev/null @@ -1,744 +0,0 @@ - -# https://github.com/dcjones/Gadfly.jl - - -supported_attrs(::GadflyBackend) = merge_with_base_supported([ - :annotations, - :background_color, :foreground_color, :color_palette, - :group, :label, :seriestype, - :seriescolor, :seriesalpha, - :linecolor, :linestyle, :linewidth, :linealpha, - :markershape, :markercolor, :markersize, :markeralpha, - :markerstrokewidth, :markerstrokecolor, :markerstrokealpha, - :fillrange, :fillcolor, :fillalpha, - :bins, :n, :nc, :nr, :layout, :smooth, - :title, :window_title, :show, :size, - :x, :xguide, :xlims, :xticks, :xscale, :xflip, - :y, :yguide, :ylims, :yticks, :yscale, :yflip, - :z, - :tickfont, :guidefont, :legendfont, - :grid, :legend, :colorbar, - :marker_z, :levels, - :xerror, :yerror, - :ribbon, :quiver, - :orientation, - ]) -supported_types(::GadflyBackend) = [ - :path, - :scatter, :hexbin, - :bar, - :contour, :shape - ] -supported_styles(::GadflyBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] -supported_markers(::GadflyBackend) = vcat(_allMarkers, Shape) -supported_scales(::GadflyBackend) = [:identity, :ln, :log2, :log10, :asinh, :sqrt] -is_subplot_supported(::GadflyBackend) = true - - -# -------------------------------------------------------------------------------------- - -function _initialize_backend(::GadflyBackend; kw...) - @eval begin - import Gadfly, Compose - export Gadfly, Compose - include(joinpath(dirname(@__FILE__), "gadfly_shapes.jl")) - end -end - -# --------------------------------------------------------------------------- - -# immutable MissingVec <: AbstractVector{Float64} end -# Base.size(v::MissingVec) = (1,) -# Base.getindex(v::MissingVec, i::Integer) = 0.0 - -function createGadflyPlotObject(plotattributes::KW) - gplt = Gadfly.Plot() - gplt.mapping = Dict() - gplt.data_source = Gadfly.DataFrames.DataFrame() - # gplt.layers = gplt.layers[1:0] - gplt.layers = [Gadfly.layer(Gadfly.Geom.point(tag=:remove), x=zeros(1), y=zeros(1));] # x=MissingVec(), y=MissingVec());] - gplt.guides = Gadfly.GuideElement[Gadfly.Guide.xlabel(plotattributes[:xguide]), - Gadfly.Guide.ylabel(plotattributes[:yguide]), - Gadfly.Guide.title(plotattributes[:title])] - gplt -end - -# --------------------------------------------------------------------------- - - -function getLineGeom(plotattributes::KW) - st = plotattributes[:seriestype] - xbins, ybins = maketuple(plotattributes[:bins]) - if st == :hexb - Gadfly.Geom.hexbin(xbincount = xbins, ybincount = ybins) - elseif st == :histogram2d - Gadfly.Geom.histogram2d(xbincount = xbins, ybincount = ybins) - elseif st == :histogram - Gadfly.Geom.histogram(bincount = xbins, - orientation = isvertical(plotattributes) ? :vertical : :horizontal, - position = plotattributes[:bar_position] == :stack ? :stack : :dodge) - elseif st == :path - Gadfly.Geom.path - elseif st in (:bar, :sticks) - Gadfly.Geom.bar - elseif st == :steppost - Gadfly.Geom.step - elseif st == :steppre - Gadfly.Geom.step(direction = :vh) - elseif st == :hline - Gadfly.Geom.hline - elseif st == :vline - Gadfly.Geom.vline - elseif st == :contour - Gadfly.Geom.contour(levels = plotattributes[:levels]) - # elseif st == :shape - # Gadfly.Geom.polygon(fill = true, preserve_order = true) - else - nothing - end -end - -function get_extra_theme_args(plotattributes::KW, k::Symbol) - # gracefully handles old Gadfly versions - extra_theme_args = KW() - try - extra_theme_args[:line_style] = Gadfly.get_stroke_vector(plotattributes[k]) - catch err - if string(err) == "UndefVarError(:get_stroke_vector)" - Base.warn_once("Gadfly.get_stroke_vector failed... do you have an old version of Gadfly?") - else - rethrow() - end - end - extra_theme_args -end - -function getGadflyLineTheme(plotattributes::KW) - st = plotattributes[:seriestype] - lc = convertColor(getColor(plotattributes[:linecolor]), plotattributes[:linealpha]) - fc = convertColor(getColor(plotattributes[:fillcolor]), plotattributes[:fillalpha]) - - Gadfly.Theme(; - default_color = (st in (:histogram,:histogram2d,:hexbin,:bar,:sticks) ? fc : lc), - line_width = (st == :sticks ? 1 : plotattributes[:linewidth]) * Gadfly.px, - # line_style = Gadfly.get_stroke_vector(plotattributes[:linestyle]), - lowlight_color = x->RGB(fc), # fill/ribbon - lowlight_opacity = alpha(fc), # fill/ribbon - bar_highlight = RGB(lc), # bars - get_extra_theme_args(plotattributes, :linestyle)... - ) -end - -# add a line as a new layer -function addGadflyLine!(plt::Plot, numlayers::Int, plotattributes::KW, geoms...) - gplt = getGadflyContext(plt) - gfargs = vcat(geoms..., getGadflyLineTheme(plotattributes)) - kwargs = KW() - st = plotattributes[:seriestype] - - # add a fill? - if plotattributes[:fillrange] != nothing && st != :contour - fillmin, fillmax = map(makevec, maketuple(plotattributes[:fillrange])) - nmin, nmax = length(fillmin), length(fillmax) - kwargs[:ymin] = Float64[min(y, fillmin[mod1(i, nmin)], fillmax[mod1(i, nmax)]) for (i,y) in enumerate(plotattributes[:y])] - kwargs[:ymax] = Float64[max(y, fillmin[mod1(i, nmin)], fillmax[mod1(i, nmax)]) for (i,y) in enumerate(plotattributes[:y])] - push!(gfargs, Gadfly.Geom.ribbon) - end - - if st in (:hline, :vline) - kwargs[st == :hline ? :yintercept : :xintercept] = plotattributes[:y] - - else - if st == :sticks - w = 0.01 * mean(diff(plotattributes[:x])) - kwargs[:xmin] = plotattributes[:x] - w - kwargs[:xmax] = plotattributes[:x] + w - elseif st == :contour - kwargs[:z] = plotattributes[:z].surf - addGadflyContColorScale(plt, plotattributes[:linecolor]) - end - - kwargs[:x] = plotattributes[st == :histogram ? :y : :x] - kwargs[:y] = plotattributes[:y] - - end - - # # add the layer - Gadfly.layer(gfargs...; order=numlayers, kwargs...) -end - - -# --------------------------------------------------------------------------- - -get_shape(sym::Symbol) = _shapes[sym] -get_shape(shape::Shape) = shape - -# extract the underlying ShapeGeometry object(s) -getMarkerGeom(shapes::AVec) = gadflyshape(map(get_shape, shapes)) -getMarkerGeom(other) = gadflyshape(get_shape(other)) - -# getMarkerGeom(shape::Shape) = gadflyshape(shape) -# getMarkerGeom(shape::Symbol) = gadflyshape(_shapes[shape]) -# getMarkerGeom(shapes::AVec) = gadflyshape(map(gadflyshape, shapes)) # map(getMarkerGeom, shapes) -function getMarkerGeom(plotattributes::KW) - if plotattributes[:seriestype] == :shape - Gadfly.Geom.polygon(fill = true, preserve_order = true) - else - getMarkerGeom(plotattributes[:markershape]) - end -end - -function getGadflyMarkerTheme(plotattributes::KW, attr::KW) - c = getColor(plotattributes[:markercolor]) - α = plotattributes[:markeralpha] - if α != nothing - c = RGBA(RGB(c), α) - end - - ms = plotattributes[:markersize] - ms = if typeof(ms) <: AVec - @warn("Gadfly doesn't support variable marker sizes... using the average: $(mean(ms))") - mean(ms) * Gadfly.px - else - ms * Gadfly.px - end - - Gadfly.Theme(; - default_color = c, - default_point_size = ms, - discrete_highlight_color = c -> RGB(getColor(plotattributes[:markerstrokecolor])), - highlight_width = plotattributes[:markerstrokewidth] * Gadfly.px, - line_width = plotattributes[:markerstrokewidth] * Gadfly.px, - # get_extra_theme_args(plotattributes, :markerstrokestyle)... - ) -end - -function addGadflyContColorScale(plt::Plot{GadflyBackend}, c) - plt.attr[:colorbar] == :none && return - if !isa(c, ColorGradient) - c = default_gradient() - end - push!(getGadflyContext(plt).scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(c, p)))) -end - -function addGadflyMarker!(plt::Plot, numlayers::Int, plotattributes::KW, attr::KW, geoms...) - gfargs = vcat(geoms..., getGadflyMarkerTheme(plotattributes, attr), getMarkerGeom(plotattributes)) - kwargs = KW() - - # handle continuous color scales for the markers - zcolor = plotattributes[:marker_z] - if zcolor != nothing && typeof(zcolor) <: AVec - kwargs[:color] = zcolor - addGadflyContColorScale(plt, plotattributes[:markercolor]) - end - - Gadfly.layer(gfargs...; x = plotattributes[:x], y = plotattributes[:y], order=numlayers, kwargs...) -end - - -# --------------------------------------------------------------------------- - -function addToGadflyLegend(plt::Plot, plotattributes::KW) - if plt.attr[:legend] != :none && plotattributes[:label] != "" - gplt = getGadflyContext(plt) - - # add the legend if needed - if all(g -> !isa(g, Gadfly.Guide.ManualColorKey), gplt.guides) - pushfirst!(gplt.guides, Gadfly.Guide.manual_color_key("", AbstractString[], Color[])) - end - - # now add the series to the legend - for guide in gplt.guides - if isa(guide, Gadfly.Guide.ManualColorKey) - # TODO: there's a BUG in gadfly if you pass in the same color more than once, - # since gadfly will call unique(colors), but doesn't also merge the rows that match - # Should ensure from this side that colors which are the same are merged together - - c = getColor(plotattributes[plotattributes[:markershape] == :none ? :linecolor : :markercolor]) - foundit = false - - # extend the label if we found this color - for i in 1:length(guide.colors) - if RGB(c) == guide.colors[i] - guide.labels[i] *= ", " * plotattributes[:label] - foundit = true - end - end - - # didn't find the color, so add a new entry into the legend - if !foundit - push!(guide.labels, plotattributes[:label]) - push!(guide.colors, c) - end - end - end - end -end - -getGadflySmoothing(smooth::Bool) = smooth ? [Gadfly.Geom.smooth(method=:lm)] : Any[] -getGadflySmoothing(smooth::Real) = [Gadfly.Geom.smooth(method=:loess, smoothing=float(smooth))] - - -function addGadflySeries!(plt::Plot, plotattributes::KW) - layers = Gadfly.Layer[] - gplt = getGadflyContext(plt) - - # add a regression line? - # TODO: make more flexible - smooth = getGadflySmoothing(plotattributes[:smooth]) - - # lines - geom = getLineGeom(plotattributes) - if geom != nothing - prepend!(layers, addGadflyLine!(plt, length(gplt.layers), plotattributes, geom, smooth...)) - smooth = Any[] # don't add a regression for markers too - end - - # special handling for ohlc and scatter - st = plotattributes[:seriestype] - # if st == :ohlc - # error("Haven't re-implemented after refactoring") - if st in (:histogram2d, :hexbin) && (isa(plotattributes[:fillcolor], ColorGradient) || isa(plotattributes[:fillcolor], ColorFunction)) - push!(gplt.scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(plotattributes[:fillcolor], p)))) - elseif st == :scatter && plotattributes[:markershape] == :none - plotattributes[:markershape] = :circle - end - - # markers - if plotattributes[:markershape] != :none || st == :shape - prepend!(layers, addGadflyMarker!(plt, length(gplt.layers), plotattributes, plt.attr, smooth...)) - end - - st in (:histogram2d, :hexbin, :contour) || addToGadflyLegend(plt, plotattributes) - - # now save the layers that apply to this series - plotattributes[:gadflylayers] = layers - prepend!(gplt.layers, layers) -end - - -# --------------------------------------------------------------------------- - -# NOTE: I'm leaving this here and commented out just in case I want to implement again... it was hacky code to create multi-colored line segments - -# # colorgroup -# z = plotattributes[:z] - -# # handle line segments of different colors -# cscheme = plotattributes[:linecolor] -# if isa(cscheme, ColorVector) -# # create a color scale, and set the color group to the index of the color -# push!(gplt.scales, Gadfly.Scale.color_discrete_manual(cscheme.v...)) - -# # this is super weird, but... oh well... for some reason this creates n separate line segments... -# # create a list of vertices that go: [x1,x2,x2,x3,x3, ... ,xi,xi, ... xn,xn] (same for y) -# # then the vector passed to the "color" keyword should be a vector: [1,1,2,2,3,3,4,4, ..., i,i, ... , n,n] -# csindices = Int[mod1(i,length(cscheme.v)) for i in 1:length(plotattributes[:y])] -# cs = collect(repeat(csindices', 2, 1))[1:end-1] -# grp = collect(repeat((1:length(plotattributes[:y]))', 2, 1))[1:end-1] -# plotattributes[:x], plotattributes[:y] = map(createSegments, (plotattributes[:x], plotattributes[:y])) -# colorgroup = [(:linecolor, cs), (:group, grp)] - - -# --------------------------------------------------------------------------- - - -function addGadflyTicksGuide(gplt, ticks, isx::Bool) - ticks == :auto && return - - # remove the ticks? - if ticks in (:none, false, nothing) - return addOrReplace(gplt.guides, isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks; label=false) - end - - ttype = ticksType(ticks) - - # just the values... put ticks here, but use standard labels - if ttype == :ticks - gtype = isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks - replaceType(gplt.guides, gtype(ticks = collect(ticks))) - - # set the ticks and the labels - # Note: this is pretty convoluted, but I think it works. We set the ticks using Gadfly.Guide, - # and then set the label function (wraps a dict lookup) through a continuous Gadfly.Scale. - elseif ttype == :ticks_and_labels - gtype = isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks - replaceType(gplt.guides, gtype(ticks = collect(ticks[1]))) - - # # TODO add xtick_label function (given tick, return label??) - # # Scale.x_discrete(; labels=nothing, levels=nothing, order=nothing) - # filterGadflyScale(gplt, isx) - # gfunc = isx ? Gadfly.Scale.x_discrete : Gadfly.Scale.y_discrete - # labelmap = Dict(zip(ticks...)) - # labelfunc = val -> labelmap[val] - # push!(gplt.scales, gfunc(levels = collect(ticks[1]), labels = labelfunc)) - - filterGadflyScale(gplt, isx) - gfunc = isx ? Gadfly.Scale.x_continuous : Gadfly.Scale.y_continuous - labelmap = Dict(zip(ticks...)) - labelfunc = val -> labelmap[val] - push!(gplt.scales, gfunc(labels = labelfunc)) - - else - error("Invalid input for $(isx ? "xticks" : "yticks"): ", ticks) - end -end - -continuousAndSameAxis(scale, isx::Bool) = isa(scale, Gadfly.Scale.ContinuousScale) && scale.vars[1] == (isx ? :x : :y) -filterGadflyScale(gplt, isx::Bool) = filter!(scale -> !continuousAndSameAxis(scale, isx), gplt.scales) - - -function getGadflyScaleFunction(plotattributes::KW, isx::Bool) - scalekey = isx ? :xscale : :yscale - hasScaleKey = haskey(plotattributes, scalekey) - if hasScaleKey - scale = plotattributes[scalekey] - scale == :ln && return isx ? Gadfly.Scale.x_log : Gadfly.Scale.y_log, hasScaleKey, log - scale == :log2 && return isx ? Gadfly.Scale.x_log2 : Gadfly.Scale.y_log2, hasScaleKey, log2 - scale == :log10 && return isx ? Gadfly.Scale.x_log10 : Gadfly.Scale.y_log10, hasScaleKey, log10 - scale == :asinh && return isx ? Gadfly.Scale.x_asinh : Gadfly.Scale.y_asinh, hasScaleKey, asinh - scale == :sqrt && return isx ? Gadfly.Scale.x_sqrt : Gadfly.Scale.y_sqrt, hasScaleKey, sqrt - end - isx ? Gadfly.Scale.x_continuous : Gadfly.Scale.y_continuous, hasScaleKey, identity -end - - -function addGadflyLimitsScale(gplt, plotattributes::KW, isx::Bool) - gfunc, hasScaleKey, func = getGadflyScaleFunction(plotattributes, isx) - - # do we want to add min/max limits for the axis? - limsym = isx ? :xlims : :ylims - limargs = Any[] - - # map :auto to nothing, otherwise add to limargs - lims = get(plotattributes, limsym, :auto) - if lims == :auto - lims = nothing - else - if limsType(lims) == :limits - push!(limargs, (:minvalue, min(lims...))) - push!(limargs, (:maxvalue, max(lims...))) - else - error("Invalid input for $(isx ? "xlims" : "ylims"): ", lims) - end - end - - # replace any current scales with this one - if hasScaleKey || !isempty(limargs) - filterGadflyScale(gplt, isx) - push!(gplt.scales, gfunc(; limargs...)) - end - - lims, func -end - -function updateGadflyAxisFlips(gplt, plotattributes::KW, xlims, ylims, xfunc, yfunc) - if isa(gplt.coord, Gadfly.Coord.Cartesian) - gplt.coord = Gadfly.Coord.cartesian( - gplt.coord.xvars, - gplt.coord.yvars; - xmin = xlims == nothing ? gplt.coord.xmin : xfunc(minimum(xlims)), - xmax = xlims == nothing ? gplt.coord.xmax : xfunc(maximum(xlims)), - ymin = ylims == nothing ? gplt.coord.ymin : yfunc(minimum(ylims)), - ymax = ylims == nothing ? gplt.coord.ymax : yfunc(maximum(ylims)), - xflip = get(plotattributes, :xflip, gplt.coord.xflip), - yflip = get(plotattributes, :yflip, gplt.coord.yflip), - fixed = gplt.coord.fixed, - aspect_ratio = gplt.coord.aspect_ratio, - raster = gplt.coord.raster - ) - else - gplt.coord = Gadfly.Coord.Cartesian( - xflip = get(plotattributes, :xflip, false), - yflip = get(plotattributes, :yflip, false) - ) - end -end - - -function findGuideAndSet(gplt, t::DataType, args...; kw...) - for (i,guide) in enumerate(gplt.guides) - if isa(guide, t) - gplt.guides[i] = t(args...; kw...) - end - end -end - -function updateGadflyGuides(plt::Plot, plotattributes::KW) - gplt = getGadflyContext(plt) - haskey(plotattributes, :title) && findGuideAndSet(gplt, Gadfly.Guide.title, string(plotattributes[:title])) - haskey(plotattributes, :xguide) && findGuideAndSet(gplt, Gadfly.Guide.xlabel, string(plotattributes[:xguide])) - haskey(plotattributes, :yguide) && findGuideAndSet(gplt, Gadfly.Guide.ylabel, string(plotattributes[:yguide])) - - xlims, xfunc = addGadflyLimitsScale(gplt, plotattributes, true) - ylims, yfunc = addGadflyLimitsScale(gplt, plotattributes, false) - - ticks = get(plotattributes, :xticks, :auto) - if ticks == :none - _remove_axis(plt, true) - else - addGadflyTicksGuide(gplt, ticks, true) - end - ticks = get(plotattributes, :yticks, :auto) - if ticks == :none - _remove_axis(plt, false) - else - addGadflyTicksGuide(gplt, ticks, false) - end - - updateGadflyAxisFlips(gplt, plotattributes, xlims, ylims, xfunc, yfunc) -end - -function updateGadflyPlotTheme(plt::Plot, plotattributes::KW) - kwargs = KW() - - # colors - insidecolor, gridcolor, textcolor, guidecolor, legendcolor = - map(s -> getColor(plotattributes[s]), ( - :background_color_inside, - :foreground_color_grid, - :foreground_color_text, - :foreground_color_guide, - :foreground_color_legend - )) - - # # hide the legend? - leg = plotattributes[plotattributes[:legend] == :none ? :colorbar : :legend] - if leg != :best - kwargs[:key_position] = leg == :inside ? :right : leg - end - - if !get(plotattributes, :grid, true) - kwargs[:grid_color] = gridcolor - end - - # fonts - tfont, gfont, lfont = plotattributes[:tickfont], plotattributes[:guidefont], plotattributes[:legendfont] - - getGadflyContext(plt).theme = Gadfly.Theme(; - background_color = insidecolor, - minor_label_color = textcolor, - minor_label_font = tfont.family, - minor_label_font_size = tfont.pointsize * Gadfly.pt, - major_label_color = guidecolor, - major_label_font = gfont.family, - major_label_font_size = gfont.pointsize * Gadfly.pt, - key_title_color = guidecolor, - key_title_font = gfont.family, - key_title_font_size = gfont.pointsize * Gadfly.pt, - key_label_color = legendcolor, - key_label_font = lfont.family, - key_label_font_size = lfont.pointsize * Gadfly.pt, - plot_padding = 1 * Gadfly.mm, - kwargs... - ) -end - -# ---------------------------------------------------------------- - - -function createGadflyAnnotationObject(x, y, val::AbstractString) - Gadfly.Guide.annotation(Compose.compose( - Compose.context(), - Compose.text(x, y, val) - )) -end - -function createGadflyAnnotationObject(x, y, txt::PlotText) - halign = (txt.font.halign == :hcenter ? Compose.hcenter : (txt.font.halign == :left ? Compose.hleft : Compose.hright)) - valign = (txt.font.valign == :vcenter ? Compose.vcenter : (txt.font.valign == :top ? Compose.vtop : Compose.vbottom)) - rotations = (txt.font.rotation == 0.0 ? [] : [Compose.Rotation(txt.font.rotation, Compose.Point(Compose.x_measure(x), Compose.y_measure(y)))]) - Gadfly.Guide.annotation(Compose.compose( - Compose.context(), - Compose.text(x, y, txt.str, halign, valign, rotations...), - Compose.font(string(txt.font.family)), - Compose.fontsize(txt.font.pointsize * Gadfly.pt), - Compose.stroke(txt.font.color), - Compose.fill(txt.font.color) - )) -end - -function _add_annotations(plt::Plot{GadflyBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} - for ann in anns - push!(plt.o.guides, createGadflyAnnotationObject(ann...)) - end -end - - -# --------------------------------------------------------------------------- - -# create a blank Gadfly.Plot object -# function _create_plot(pkg::GadflyBackend, plotattributes::KW) -# gplt = createGadflyPlotObject(plotattributes) -# Plot(gplt, pkg, 0, plotattributes, KW[]) -# end -function _create_backend_figure(plt::Plot{GadflyBackend}) - createGadflyPlotObject(plt.attr) -end - - -# plot one data series -# function _series_added(::GadflyBackend, plt::Plot, plotattributes::KW) -function _series_added(plt::Plot{GadflyBackend}, series::Series) - # first clear out the temporary layer - gplt = getGadflyContext(plt) - if gplt.layers[1].geom.tag == :remove - gplt.layers = gplt.layers[2:end] - end - - addGadflySeries!(plt, series.plotattributes) - # push!(plt.seriesargs, plotattributes) - # plt -end - - - -function _update_plot_object(plt::Plot{GadflyBackend}, plotattributes::KW) - updateGadflyGuides(plt, plotattributes) - updateGadflyPlotTheme(plt, plotattributes) -end - - -# ---------------------------------------------------------------- - -# accessors for x/y data - -# TODO: need to save all the layer indices which apply to this series -function getGadflyMappings(plt::Plot, i::Integer) - @assert i > 0 && i <= plt.n - mappings = [l.mapping for l in plt.seriesargs[i][:gadflylayers]] -end - -function getxy(plt::Plot{GadflyBackend}, i::Integer) - mapping = getGadflyMappings(plt, i)[1] - mapping[:x], mapping[:y] -end - -function setxy!(plt::Plot{GadflyBackend}, xy::Tuple{X,Y}, i::Integer) where {X,Y} - for mapping in getGadflyMappings(plt, i) - mapping[:x], mapping[:y] = xy - end - plt -end - -# ---------------------------------------------------------------- - - -# # create the underlying object (each backend will do this differently) -# function _create_subplot(subplt::Subplot{GadflyBackend}, isbefore::Bool) -# isbefore && return false # wait until after plotting to create the subplots -# subplt.o = nothing -# true -# end - - -function _remove_axis(plt::Plot{GadflyBackend}, isx::Bool) - gplt = getGadflyContext(plt) - addOrReplace(gplt.guides, isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks; label=false) - addOrReplace(gplt.guides, isx ? Gadfly.Guide.xlabel : Gadfly.Guide.ylabel, "") -end - -function _expand_limits(lims, plt::Plot{GadflyBackend}, isx::Bool) - for l in getGadflyContext(plt).layers - _expand_limits(lims, l.mapping[isx ? :x : :y]) - end -end - - -# ---------------------------------------------------------------- - - -getGadflyContext(plt::Plot{GadflyBackend}) = plt.o -# getGadflyContext(subplt::Subplot{GadflyBackend}) = buildGadflySubplotContext(subplt) - -# # create my Compose.Context grid by hstacking and vstacking the Gadfly.Plot objects -# function buildGadflySubplotContext(subplt::Subplot) -# rows = Any[] -# row = Any[] -# for (i,(r,c)) in enumerate(subplt.layout) -# -# # add the Plot object to the row -# push!(row, getGadflyContext(subplt.plts[i])) -# -# # add the row -# if c == ncols(subplt.layout, r) -# push!(rows, Gadfly.hstack(row...)) -# row = Any[] -# end -# end -# -# # stack the rows -# Gadfly.vstack(rows...) -# end - -setGadflyDisplaySize(w,h) = Compose.set_default_graphic_size(w * Compose.px, h * Compose.px) -setGadflyDisplaySize(plt::Plot) = setGadflyDisplaySize(plt.attr[:size]...) -# setGadflyDisplaySize(subplt::Subplot) = setGadflyDisplaySize(getattr(subplt, 1)[:size]...) -# ------------------------------------------------------------------------- - - -function doshow(io::IO, func, plt::AbstractPlot{P}) where P<:Union{GadflyBackend,ImmerseBackend} - gplt = getGadflyContext(plt) - setGadflyDisplaySize(plt) - Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) -end - -getGadflyWriteFunc(::MIME"image/png") = Gadfly.PNG -getGadflyWriteFunc(::MIME"image/svg+xml") = Gadfly.SVG -# getGadflyWriteFunc(::MIME"text/html") = Gadfly.SVGJS -getGadflyWriteFunc(::MIME"application/pdf") = Gadfly.PDF -getGadflyWriteFunc(::MIME"application/postscript") = Gadfly.PS -getGadflyWriteFunc(::MIME"application/x-tex") = Gadfly.PGF -getGadflyWriteFunc(m::MIME) = error("Unsupported in Gadfly/Immerse: ", m) - -for mime in (MIME"image/png", MIME"image/svg+xml", MIME"application/pdf", MIME"application/postscript", MIME"application/x-tex") - @eval function Base.show(io::IO, ::$mime, plt::AbstractPlot{P}) where P<:Union{GadflyBackend,ImmerseBackend} - func = getGadflyWriteFunc($mime()) - doshow(io, func, plt) - end -end - - - -function Base.display(::PlotsDisplay, plt::Plot{GadflyBackend}) - setGadflyDisplaySize(plt.attr[:size]...) - display(plt.o) -end - - -# function Base.display(::PlotsDisplay, subplt::Subplot{GadflyBackend}) -# setGadflyDisplaySize(getattr(subplt,1)[:size]...) -# ctx = buildGadflySubplotContext(subplt) -# -# # taken from Gadfly since I couldn't figure out how to do it directly -# -# filename = string(Gadfly.tempname(), ".html") -# output = open(filename, "w") -# -# plot_output = IOBuffer() -# Gadfly.draw(Gadfly.SVGJS(plot_output, Compose.default_graphic_width, -# Compose.default_graphic_height, false), ctx) -# plotsvg = takebuf_string(plot_output) -# -# write(output, -# """ -# -# -# -# Gadfly Plot -# -# -# -# -# -# $(plotsvg) -# -# -# """) -# close(output) -# Gadfly.open_file(filename) -# end diff --git a/src/deprecated/backends/gadfly_shapes.jl b/src/deprecated/backends/gadfly_shapes.jl deleted file mode 100644 index 1a818993..00000000 --- a/src/deprecated/backends/gadfly_shapes.jl +++ /dev/null @@ -1,93 +0,0 @@ - - -# Geometry which displays arbitrary shapes at given (x, y) positions. -# note: vertices is a list of shapes -struct ShapeGeometry <: Gadfly.GeometryElement - vertices::AbstractVector #{Tuple{Float64,Float64}} - tag::Symbol - - function ShapeGeometry(shape; tag::Symbol=Gadfly.Geom.empty_tag) - new(shape, tag) - end -end - -# TODO: add for PR -# const shape = ShapeGeometry - - -function Gadfly.element_aesthetics(::ShapeGeometry) - [:x, :y, :size, :color] -end - - -# Generate a form for a shape geometry. -# -# Args: -# geom: shape geometry. -# theme: the plot's theme. -# aes: aesthetics. -# -# Returns: -# A compose Form. -# -function Gadfly.render(geom::ShapeGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) - - # TODO: add for PR - # Gadfly.assert_aesthetics_defined("Geom.shape", aes, :x, :y) - # Gadfly.assert_aesthetics_equal_length("Geom.shape", aes, - # element_aesthetics(geom)...) - - default_aes = Gadfly.Aesthetics() - default_aes.color = Gadfly.DataFrames.PooledDataArray(RGBA{Float32}[theme.default_color]) - default_aes.size = Compose.Measure[theme.default_point_size] - aes = Gadfly.inherit(aes, default_aes) - - lw_hover_scale = 10 - lw_ratio = theme.line_width / aes.size[1] - - aes_x, aes_y = Gadfly.concretize(aes.x, aes.y) - - ctx = Compose.compose!( - Compose.context(), - make_polygon(geom, aes.x, aes.y, aes.size), - Compose.fill(aes.color), - Compose.linewidth(theme.highlight_width)) - - if aes.color_key_continuous != nothing && aes.color_key_continuous - Compose.compose!(ctx, - Compose.stroke(map(theme.continuous_highlight_color, aes.color))) - else - Compose.compose!(ctx, - Compose.stroke(map(theme.discrete_highlight_color, aes.color)), - Compose.svgclass([Gadfly.svg_color_class_from_label(Gadfly.escape_id(aes.color_label([c])[1])) - for c in aes.color])) - end - - return Compose.compose!(Compose.context(order=4), Compose.svgclass("geometry"), ctx) -end - -function gadflyshape(sv::Shape) - ShapeGeometry(Any[vertices(sv)]) -end - -function gadflyshape(sv::AVec{Shape}) - ShapeGeometry(Any[vertices(s) for s in sv]) -end - - -# create a Compose context given a ShapeGeometry and the xs/ys/sizes -function make_polygon(geom::ShapeGeometry, xs::AbstractArray, ys::AbstractArray, rs::AbstractArray) - n = max(length(xs), length(ys), length(rs)) - T = Tuple{Compose.Measure, Compose.Measure} - polys = Array(Vector{T}, n) - for i in 1:n - x = Compose.x_measure(xs[mod1(i, length(xs))]) - y = Compose.y_measure(ys[mod1(i, length(ys))]) - r = rs[mod1(i, length(rs))] - polys[i] = T[(x + r * sx, y + r * sy) for (sx,sy) in _cycle(geom.vertices, i)] - end - Gadfly.polygon(polys, geom.tag) -end - - -# --------------------------------------------------------------------------------------------- diff --git a/src/deprecated/backends/immerse.jl b/src/deprecated/backends/immerse.jl deleted file mode 100644 index 754f55de..00000000 --- a/src/deprecated/backends/immerse.jl +++ /dev/null @@ -1,186 +0,0 @@ - -# https://github.com/JuliaGraphics/Immerse.jl - -supported_attrs(::ImmerseBackend) = supported_attrs(GadflyBackend()) -supported_types(::ImmerseBackend) = supported_types(GadflyBackend()) -supported_styles(::ImmerseBackend) = supported_styles(GadflyBackend()) -supported_markers(::ImmerseBackend) = supported_markers(GadflyBackend()) -supported_scales(::ImmerseBackend) = supported_scales(GadflyBackend()) -is_subplot_supported(::ImmerseBackend) = true - -# -------------------------------------------------------------------------------------- - -function _initialize_backend(::ImmerseBackend; kw...) - @eval begin - import Immerse, Gadfly, Compose, Gtk - export Immerse, Gadfly, Compose, Gtk - include(joinpath(dirname(@__FILE__), "gadfly_shapes.jl")) - end -end - -function createImmerseFigure(plotattributes::KW) - w,h = plotattributes[:size] - figidx = Immerse.figure(; name = plotattributes[:window_title], width = w, height = h) - Immerse.Figure(figidx) -end - -# ---------------------------------------------------------------- - - -# create a blank Gadfly.Plot object -# function _create_plot(pkg::ImmerseBackend, plotattributes::KW) -# # create the underlying Gadfly.Plot object -# gplt = createGadflyPlotObject(plotattributes) -# -# # save both the Immerse.Figure and the Gadfly.Plot -# Plot((nothing,gplt), pkg, 0, plotattributes, KW[]) -# end -function _create_backend_figure(plt::Plot{ImmerseBackend}) - (nothing, createGadflyPlotObject(plt.attr)) -end - - -# # plot one data series -# function _series_added(::ImmerseBackend, plt::Plot, plotattributes::KW) -# addGadflySeries!(plt, plotattributes) -# push!(plt.seriesargs, plotattributes) -# plt -# end - -function _series_added(plt::Plot{ImmerseBackend}, series::Series) - addGadflySeries!(plt, series.plotattributes) -end - - -function _update_plot_object(plt::Plot{ImmerseBackend}, plotattributes::KW) - updateGadflyGuides(plt, plotattributes) - updateGadflyPlotTheme(plt, plotattributes) -end - - - -# ---------------------------------------------------------------- - -function _add_annotations(plt::Plot{ImmerseBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} - for ann in anns - push!(getGadflyContext(plt).guides, createGadflyAnnotationObject(ann...)) - end -end - -# ---------------------------------------------------------------- - -# accessors for x/y data - -function getxy(plt::Plot{ImmerseBackend}, i::Integer) - mapping = getGadflyMappings(plt, i)[1] - mapping[:x], mapping[:y] -end - -function setxy!(plt::Plot{ImmerseBackend}, xy::Tuple{X,Y}, i::Integer) where {X,Y} - for mapping in getGadflyMappings(plt, i) - mapping[:x], mapping[:y] = xy - end - plt -end - - -# ---------------------------------------------------------------- - - -# function _create_subplot(subplt::Subplot{ImmerseBackend}, isbefore::Bool) -# return false -# # isbefore && return false -# end -# -# function showSubplotObject(subplt::Subplot{ImmerseBackend}) -# # create the Gtk window with vertical box vsep -# plotattributes = getattr(subplt,1) -# w,h = plotattributes[:size] -# vsep = Gtk.GtkBoxLeaf(:v) -# win = Gtk.GtkWindowLeaf(vsep, plotattributes[:window_title], w, h) -# -# figindices = [] -# row = Gtk.GtkBoxLeaf(:h) -# push!(vsep, row) -# for (i,(r,c)) in enumerate(subplt.layout) -# plt = subplt.plts[i] -# -# # get the components... box is the main plot GtkBox, and canvas is the GtkCanvas where it's plotted -# box, toolbar, canvas = Immerse.createPlotGuiComponents() -# -# # add the plot's box to the row -# push!(row, box) -# -# # create the figure and store the index returned for destruction later -# figidx = Immerse.figure(canvas) -# push!(figindices, figidx) -# -# fig = Immerse.figure(figidx) -# plt.o = (fig, plt.o[2]) -# -# # add the row -# if c == ncols(subplt.layout, r) -# row = Gtk.GtkBoxLeaf(:h) -# push!(vsep, row) -# end -# -# end -# -# # destructor... clean up plots -# Gtk.on_signal_destroy((x...) -> ([Immerse.dropfig(Immerse._display,i) for i in figindices]; subplt.o = nothing), win) -# -# subplt.o = win -# true -# end - - -function _remove_axis(plt::Plot{ImmerseBackend}, isx::Bool) - gplt = getGadflyContext(plt) - addOrReplace(gplt.guides, isx ? Gadfly.Guide.xticks : Gadfly.Guide.yticks; label=false) - addOrReplace(gplt.guides, isx ? Gadfly.Guide.xlabel : Gadfly.Guide.ylabel, "") -end - -function _expand_limits(lims, plt::Plot{ImmerseBackend}, isx::Bool) - for l in getGadflyContext(plt).layers - _expand_limits(lims, l.mapping[isx ? :x : :y]) - end -end - - -# ---------------------------------------------------------------- - -getGadflyContext(plt::Plot{ImmerseBackend}) = plt.o[2] -# getGadflyContext(subplt::Subplot{ImmerseBackend}) = buildGadflySubplotContext(subplt) - - -function Base.display(::PlotsDisplay, plt::Plot{ImmerseBackend}) - - fig, gplt = plt.o - if fig == nothing - fig = createImmerseFigure(plt.attr) - Gtk.on_signal_destroy((x...) -> (Immerse.dropfig(Immerse._display, fig.figno); plt.o = (nothing,gplt)), fig.canvas) - plt.o = (fig, gplt) - end - - Immerse.figure(fig.figno; displayfig = false) - display(gplt) -end - - -# function Base.display(::PlotsDisplay, subplt::Subplot{ImmerseBackend}) -# -# # if we haven't created the window yet, do it -# if subplt.o == nothing -# showSubplotObject(subplt) -# end -# -# # display the plots by creating a fresh Immerse.Figure object from the GtkCanvas and Gadfly.Plot -# for plt in subplt.plts -# fig, gplt = plt.o -# Immerse.figure(fig.figno; displayfig = false) -# display(gplt) -# end -# -# # o is the window... show it -# showall(subplt.o) -# end diff --git a/src/deprecated/backends/qwt.jl b/src/deprecated/backends/qwt.jl deleted file mode 100644 index 0546b3db..00000000 --- a/src/deprecated/backends/qwt.jl +++ /dev/null @@ -1,308 +0,0 @@ - -# https://github.com/tbreloff/Qwt.jl - - -supported_attrs(::QwtBackend) = merge_with_base_supported([ - :annotations, - :linecolor, - :fillrange, - :fillcolor, - :label, - :legend, - :seriescolor, :seriesalpha, - :linestyle, - :linewidth, - :markershape, - :markercolor, - :markersize, - :bins, - :pos, - :title, - :window_title, - :guide, :lims, :ticks, :scale, - ]) -supported_types(::QwtBackend) = [:path, :scatter, :hexbin, :bar] -supported_markers(::QwtBackend) = [:none, :auto, :rect, :circle, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :star8, :hexagon] -supported_scales(::QwtBackend) = [:identity, :log10] -is_subplot_supported(::QwtBackend) = true - - -# -------------------------------------------------------------------------------------- - -function _initialize_backend(::QwtBackend; kw...) - @eval begin - @warn("Qwt is no longer supported... many features will likely be broken.") - import Qwt - export Qwt - end -end - -# ------------------------------- - -const _qwtAliases = KW( - :bins => :heatmap_n, - :fillrange => :fillto, - :linewidth => :width, - :markershape => :marker, - :hexbin => :heatmap, - :path => :line, - :steppost => :step, - :steppre => :stepinverted, - :star5 => :star1, - :star8 => :star2, - ) - -function fixcolors(plotattributes::KW) - for (k,v) in plotattributes - if typeof(v) <: ColorScheme - plotattributes[k] = getColor(v) - end - end -end - -function replaceQwtAliases(plotattributes, s) - if haskey(_qwtAliases, plotattributes[s]) - plotattributes[s] = _qwtAliases[plotattributes[s]] - end -end - -function adjustQwtKeywords(plt::Plot{QwtBackend}, iscreating::Bool; kw...) - plotattributes = KW(kw) - st = plotattributes[:seriestype] - if st == :scatter - plotattributes[:seriestype] = :none - if plotattributes[:markershape] == :none - plotattributes[:markershape] = :circle - end - - elseif st in (:hline, :vline) - addLineMarker(plt, plotattributes) - plotattributes[:seriestype] = :none - plotattributes[:markershape] = :circle - plotattributes[:markersize] = 1 - if st == :vline - plotattributes[:x], plotattributes[:y] = plotattributes[:y], plotattributes[:x] - end - - elseif !iscreating && st == :bar - plotattributes = barHack(; kw...) - elseif !iscreating && st == :histogram - plotattributes = barHack(; histogramHack(; kw...)...) - end - - replaceQwtAliases(plotattributes, :seriestype) - replaceQwtAliases(plotattributes, :markershape) - - for k in keys(plotattributes) - if haskey(_qwtAliases, k) - plotattributes[_qwtAliases[k]] = plotattributes[k] - end - end - - plotattributes[:x] = collect(plotattributes[:x]) - plotattributes[:y] = collect(plotattributes[:y]) - - plotattributes -end - -# function _create_plot(pkg::QwtBackend, plotattributes::KW) -function _create_backend_figure(plt::Plot{QwtBackend}) - fixcolors(plt.attr) - dumpdict(plt.attr,"\n\n!!! plot") - o = Qwt.plot(zeros(0,0); plt.attr..., show=false) - # plt = Plot(o, pkg, 0, plotattributes, KW[]) - # plt -end - -# function _series_added(::QwtBackend, plt::Plot, plotattributes::KW) -function _series_added(plt::Plot{QwtBackend}, series::Series) - plotattributes = adjustQwtKeywords(plt, false; series.plotattributes...) - fixcolors(plotattributes) - dumpdict(plotattributes,"\n\n!!! plot!") - Qwt.oplot(plt.o; plotattributes...) - # push!(plt.seriesargs, plotattributes) - # plt -end - - -# ---------------------------------------------------------------- - -function updateLimsAndTicks(plt::Plot{QwtBackend}, plotattributes::KW, isx::Bool) - lims = get(plotattributes, isx ? :xlims : :ylims, nothing) - ticks = get(plotattributes, isx ? :xticks : :yticks, nothing) - w = plt.o.widget - axisid = Qwt.QWT.QwtPlot[isx ? :xBottom : :yLeft] - - if typeof(lims) <: Union{Tuple,AVec} && length(lims) == 2 - if isx - plt.o.autoscale_x = false - else - plt.o.autoscale_y = false - end - w[:setAxisScale](axisid, lims...) - end - - if typeof(ticks) <: AbstractRange - if isx - plt.o.autoscale_x = false - else - plt.o.autoscale_y = false - end - w[:setAxisScale](axisid, float(minimum(ticks)), float(maximum(ticks)), float(step(ticks))) - elseif !(ticks in (nothing, :none, :auto)) - @warn("Only Range types are supported for Qwt xticks/yticks. typeof(ticks)=$(typeof(ticks))") - end - - # change the scale - scalesym = isx ? :xscale : :yscale - if haskey(plotattributes, scalesym) - scaletype = plotattributes[scalesym] - scaletype == :identity && w[:setAxisScaleEngine](axisid, Qwt.QWT.QwtLinearScaleEngine()) - # scaletype == :log && w[:setAxisScaleEngine](axisid, Qwt.QWT.QwtLogScaleEngine(e)) - # scaletype == :log2 && w[:setAxisScaleEngine](axisid, Qwt.QWT.QwtLogScaleEngine(2)) - scaletype == :log10 && w[:setAxisScaleEngine](axisid, Qwt.QWT.QwtLog10ScaleEngine()) - scaletype in supported_scales() || @warn("Unsupported scale type: ", scaletype) - end - -end - - -function _update_plot_object(plt::Plot{QwtBackend}, plotattributes::KW) - haskey(plotattributes, :title) && Qwt.title(plt.o, plotattributes[:title]) - haskey(plotattributes, :xguide) && Qwt.xlabel(plt.o, plotattributes[:xguide]) - haskey(plotattributes, :yguide) && Qwt.ylabel(plt.o, plotattributes[:yguide]) - updateLimsAndTicks(plt, plotattributes, true) - updateLimsAndTicks(plt, plotattributes, false) -end - -function _update_plot_pos_size(plt::AbstractPlot{QwtBackend}, plotattributes::KW) - haskey(plotattributes, :size) && Qwt.resizewidget(plt.o, plotattributes[:size]...) - haskey(plotattributes, :pos) && Qwt.movewidget(plt.o, plotattributes[:pos]...) -end - - -# ---------------------------------------------------------------- - - # curve.setPen(Qt.QPen(Qt.QColor(color), linewidth, self.getLineStyle(linestyle))) -function addLineMarker(plt::Plot{QwtBackend}, plotattributes::KW) - for yi in plotattributes[:y] - marker = Qwt.QWT.QwtPlotMarker() - ishorizontal = (plotattributes[:seriestype] == :hline) - marker[:setLineStyle](ishorizontal ? 1 : 2) - marker[ishorizontal ? :setYValue : :setXValue](yi) - qcolor = Qwt.convertRGBToQColor(getColor(plotattributes[:linecolor])) - linestyle = plt.o.widget[:getLineStyle](string(plotattributes[:linestyle])) - marker[:setLinePen](Qwt.QT.QPen(qcolor, plotattributes[:linewidth], linestyle)) - marker[:attach](plt.o.widget) - end - - # marker[:setValue](x, y) - # marker[:setLabel](Qwt.QWT.QwtText(val)) - # marker[:attach](plt.o.widget) -end - -function createQwtAnnotation(plt::Plot, x, y, val::PlotText) - marker = Qwt.QWT.QwtPlotMarker() - marker[:setValue](x, y) - qwttext = Qwt.QWT.QwtText(val.str) - qwttext[:setFont](Qwt.QT.QFont(val.font.family, val.font.pointsize)) - qwttext[:setColor](Qwt.convertRGBToQColor(getColor(val.font.color))) - marker[:setLabel](qwttext) - marker[:attach](plt.o.widget) -end - -function createQwtAnnotation(plt::Plot, x, y, val::AbstractString) - marker = Qwt.QWT.QwtPlotMarker() - marker[:setValue](x, y) - marker[:setLabel](Qwt.QWT.QwtText(val)) - marker[:attach](plt.o.widget) -end - -function _add_annotations(plt::Plot{QwtBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} - for ann in anns - createQwtAnnotation(plt, ann...) - end -end - -# ---------------------------------------------------------------- - -# accessors for x/y data - -function getxy(plt::Plot{QwtBackend}, i::Int) - series = plt.o.lines[i] - series.x, series.y -end - -function setxy!(plt::Plot{QwtBackend}, xy::Tuple{X,Y}, i::Integer) where {X,Y} - series = plt.o.lines[i] - series.x, series.y = xy - plt -end - - -# ------------------------------- - -# ------------------------------- - -# # create the underlying object (each backend will do this differently) -# function _create_subplot(subplt::Subplot{QwtBackend}, isbefore::Bool) -# isbefore && return false -# i = 0 -# rows = Any[] -# row = Any[] -# for (i,(r,c)) in enumerate(subplt.layout) -# push!(row, subplt.plts[i].o) -# if c == ncols(subplt.layout, r) -# push!(rows, Qwt.hsplitter(row...)) -# row = Any[] -# end -# end -# # for rowcnt in subplt.layout.rowcounts -# # push!(rows, Qwt.hsplitter([plt.o for plt in subplt.plts[(1:rowcnt) + i]]...)) -# # i += rowcnt -# # end -# subplt.o = Qwt.vsplitter(rows...) -# # Qwt.resizewidget(subplt.o, getattr(subplt,1)[:size]...) -# # Qwt.moveToLastScreen(subplt.o) # hack so it goes to my center monitor... sorry -# true -# end - -function _expand_limits(lims, plt::Plot{QwtBackend}, isx::Bool) - for series in plt.o.lines - _expand_limits(lims, isx ? series.x : series.y) - end -end - - -function _remove_axis(plt::Plot{QwtBackend}, isx::Bool) -end - - -# ---------------------------------------------------------------- - -function Base.show(io::IO, ::MIME"image/png", plt::Plot{QwtBackend}) - Qwt.refresh(plt.o) - Qwt.savepng(plt.o, "/tmp/dfskjdhfkh.png") - write(io, readall("/tmp/dfskjdhfkh.png")) -end - -# function Base.show(io::IO, ::MIME"image/png", subplt::Subplot{QwtBackend}) -# for plt in subplt.plts -# Qwt.refresh(plt.o) -# end -# Qwt.savepng(subplt.o, "/tmp/dfskjdhfkh.png") -# write(io, readall("/tmp/dfskjdhfkh.png")) -# end - - -function Base.display(::PlotsDisplay, plt::Plot{QwtBackend}) - Qwt.refresh(plt.o) - Qwt.showwidget(plt.o) -end - -# function Base.display(::PlotsDisplay, subplt::Subplot{QwtBackend}) -# for plt in subplt.plts -# Qwt.refresh(plt.o) -# end -# Qwt.showwidget(subplt.o) -# end diff --git a/src/deprecated/backends/winston.jl b/src/deprecated/backends/winston.jl deleted file mode 100644 index 5f292271..00000000 --- a/src/deprecated/backends/winston.jl +++ /dev/null @@ -1,272 +0,0 @@ - -# https://github.com/nolta/Winston.jl - -# credit goes to https://github.com/jverzani for contributing to the first draft of this backend implementation - -supported_attrs(::WinstonBackend) = merge_with_base_supported([ - :annotations, - :linecolor, - :fillrange, - :fillcolor, - :label, - :legend, - :seriescolor, :seriesalpha, - :linestyle, - :linewidth, - :markershape, - :markercolor, - :markersize, - :bins, - :title, - :window_title, - :guide, :lims, :scale, - ]) -supported_types(::WinstonBackend) = [:path, :scatter, :bar] -supported_styles(::WinstonBackend) = [:auto, :solid, :dash, :dot, :dashdot] -supported_markers(::WinstonBackend) = [:none, :auto, :rect, :circle, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] -supported_scales(::WinstonBackend) = [:identity, :log10] -is_subplot_supported(::WinstonBackend) = false - - -# -------------------------------------------------------------------------------------- - - -function _initialize_backend(::WinstonBackend; kw...) - @eval begin - # ENV["WINSTON_OUTPUT"] = "gtk" - @warn("Winston is no longer supported... many features will likely be broken.") - import Winston, Gtk - export Winston, Gtk - end -end - -# --------------------------------------------------------------------------- - - -## dictionaries for conversion of Plots.jl names to Winston ones. -const winston_linestyle = KW(:solid=>"solid", - :dash=>"dash", - :dot=>"dotted", - :dashdot=>"dotdashed" - ) - -const winston_marker = KW(:none=>".", - :rect => "square", - :circle=>"circle", - :diamond=>"diamond", - :utriangle=>"triangle", - :dtriangle=>"down-triangle", - :cross => "plus", - :xcross => "cross", - :star5 => "asterisk" - ) - -function _before_update(plt::Plot{WinstonBackend}) - Winston.ghf(plt.o) -end - -# --------------------------------------------------------------------------- - -function _create_backend_figure(plt::Plot{WinstonBackend}) - Winston.FramedPlot( - title = plt.attr[:title], - xlabel = plt.attr[:xguide], - ylabel = plt.attr[:yguide] - ) -end - -copy_remove(plotattributes::KW, s::Symbol) = delete!(copy(plotattributes), s) - -function addRegressionLineWinston(plotattributes::KW, wplt) - xs, ys = regressionXY(plotattributes[:x], plotattributes[:y]) - Winston.add(wplt, Winston.Curve(xs, ys, kind="dotted")) -end - -function getWinstonItems(plt::Plot) - if isa(plt.o, Winston.FramedPlot) - wplt = plt.o - window, canvas = nothing, nothing - else - window, canvas, wplt = plt.o - end - window, canvas, wplt -end - -function _series_added(plt::Plot{WinstonBackend}, series::Series) - plotattributes = series.plotattributes - window, canvas, wplt = getWinstonItems(plt) - - # until we call it normally, do the hack - if plotattributes[:seriestype] == :bar - plotattributes = barHack(;plotattributes...) - end - - - e = KW() - e[:color] = getColor(plotattributes[:linecolor]) - e[:linewidth] = plotattributes[:linewidth] - e[:kind] = winston_linestyle[plotattributes[:linestyle]] - e[:symbolkind] = winston_marker[plotattributes[:markershape]] - # markercolor # same choices as `color`, or :match will set the color to be the same as `color` - e[:symbolsize] = plotattributes[:markersize] / 5 - - # pos # (Int,Int), move the enclosing window to this position - # screen # Integer, move enclosing window to this screen number (for multiscreen desktops) - - - - ## lintype :path, :step, :stepinverted, :sticks, :dots, :none, :histogram2d, :hexbin, :histogram, :bar - if plotattributes[:seriestype] == :none - Winston.add(wplt, Winston.Points(plotattributes[:x], plotattributes[:y]; copy_remove(e, :kind)..., color=getColor(plotattributes[:markercolor]))) - - elseif plotattributes[:seriestype] == :path - x, y = plotattributes[:x], plotattributes[:y] - Winston.add(wplt, Winston.Curve(x, y; e...)) - - fillrange = plotattributes[:fillrange] - if fillrange != nothing - if isa(fillrange, AbstractVector) - y2 = fillrange - else - y2 = Float64[fillrange for yi in y] - end - Winston.add(wplt, Winston.FillBetween(x, y, x, y2, fillcolor=getColor(plotattributes[:fillcolor]))) - end - - elseif plotattributes[:seriestype] == :scatter - if plotattributes[:markershape] == :none - plotattributes[:markershape] = :circle - end - - # elseif plotattributes[:seriestype] == :step - # fn = Winston.XXX - - # elseif plotattributes[:seriestype] == :stepinverted - # fn = Winston.XXX - - elseif plotattributes[:seriestype] == :sticks - Winston.add(wplt, Winston.Stems(plotattributes[:x], plotattributes[:y]; e...)) - - # elseif plotattributes[:seriestype] == :dots - # fn = Winston.XXX - - # elseif plotattributes[:seriestype] == :histogram2d - # fn = Winston.XXX - - # elseif plotattributes[:seriestype] == :hexbin - # fn = Winston.XXX - - elseif plotattributes[:seriestype] == :histogram - hst = hist(plotattributes[:y], plotattributes[:bins]) - Winston.add(wplt, Winston.Histogram(hst...; copy_remove(e, :bins)...)) - - # elseif plotattributes[:seriestype] == :bar - # # fn = Winston.XXX - - else - error("seriestype $(plotattributes[:seriestype]) not supported by Winston.") - - end - - - # markershape - if plotattributes[:markershape] != :none - Winston.add(wplt, Winston.Points(plotattributes[:x], plotattributes[:y]; copy_remove(e, :kind)..., color=getColor(plotattributes[:markercolor]))) - end - - - # optionally add a regression line - plotattributes[:smooth] && plotattributes[:seriestype] != :histogram && addRegressionLineWinston(plotattributes, wplt) - - # push!(plt.seriesargs, plotattributes) - # plt -end - - -# ---------------------------------------------------------------- - -const _winstonNames = KW( - :xlims => :xrange, - :ylims => :yrange, - :xscale => :xlog, - :yscale => :ylog, - ) - -function _update_plot_object(plt::Plot{WinstonBackend}, plotattributes::KW) - window, canvas, wplt = getWinstonItems(plt) - for k in (:xguide, :yguide, :title, :xlims, :ylims) - if haskey(plotattributes, k) - Winston.setattr(wplt, string(get(_winstonNames, k, k)), plotattributes[k]) - end - end - - for k in (:xscale, :yscale) - if haskey(plotattributes, k) - islogscale = plotattributes[k] == :log10 - Winston.setattr(wplt, (k == :xscale ? :xlog : :ylog), islogscale) - end - end - -end - - - -# ---------------------------------------------------------------- - -function createWinstonAnnotationObject(plt::Plot{WinstonBackend}, x, y, val::AbstractString) - Winston.text(x, y, val) -end - -function _add_annotations(plt::Plot{WinstonBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} - for ann in anns - createWinstonAnnotationObject(plt, ann...) - end -end - - -# ---------------------------------------------------------------- - -# function _create_subplot(subplt::Subplot{WinstonBackend}, isbefore::Bool) -# # TODO: build the underlying Subplot object. this is where you might layout the panes within a GUI window, for example -# end - -# ---------------------------------------------------------------- - -function addWinstonLegend(plt::Plot, wplt) - if plt.attr[:legend] != :none - Winston.legend(wplt, [sd[:label] for sd in plt.seriesargs]) - end -end - -function Base.show(io::IO, ::MIME"image/png", plt::AbstractPlot{WinstonBackend}) - window, canvas, wplt = getWinstonItems(plt) - addWinstonLegend(plt, wplt) - show(io, "image/png", wplt) -end - - -function Base.display(::PlotsDisplay, plt::Plot{WinstonBackend}) - - window, canvas, wplt = getWinstonItems(plt) - - if window == nothing - if Winston.output_surface != :gtk - error("Gtk is the only supported display for Winston in Plots. Set `output_surface = gtk` in src/Winston.ini") - end - # initialize window - w,h = plt.attr[:size] - canvas = Gtk.GtkCanvasLeaf() - window = Gtk.GtkWindowLeaf(canvas, plt.attr[:window_title], w, h) - plt.o = (window, canvas, wplt) - end - - addWinstonLegend(plt, wplt) - - Winston.display(canvas, wplt) - Gtk.showall(window) -end - - -# function Base.display(::PlotsDisplay, subplt::Subplot{WinstonBackend}) -# # TODO: display/show the Subplot object -# end diff --git a/src/deprecated/color_gradients.jl b/src/deprecated/color_gradients.jl deleted file mode 100644 index 5516ac06..00000000 --- a/src/deprecated/color_gradients.jl +++ /dev/null @@ -1,1067 +0,0 @@ - -# -------------------------------------------------------------------------- -# -------------------------------------------------------------------------- -# The following gradients were taken from https://github.com/BIDS/colormap/blob/master/colormaps.py -# Here is the licensing note which accompanied this: - - # New matplotlib colormaps by Nathaniel J. Smith, Stefan van der Walt, - # and (in the case of viridis) Eric Firing. - # - # This file and the colormaps in it are released under the CC0 license / - # public domain dedication. We would appreciate credit if you use or - # redistribute these colormaps, but do not impose any legal restrictions. - # - # To the extent possible under law, the persons who associated CC0 with - # mpl-colormaps have waived all copyright and related or neighboring rights - # to mpl-colormaps. - # - # You should have received a copy of the CC0 legalcode along with this - # work. If not, see . - -function sample_evenly(v::AVec, n::Integer = length(v)) - idx = Int[round(Int, x) for x in range(1, stop=length(v), length=n)] - v[idx] -end - -# note: to use the full arrays, just take out the second param (n) from the sample_evenly calls - -register_gradient_colors(:magma, sample_evenly([ - RGB(0.001462, 0.000466, 0.013866), - RGB(0.002258, 0.001295, 0.018331), - RGB(0.003279, 0.002305, 0.023708), - RGB(0.004512, 0.003490, 0.029965), - RGB(0.005950, 0.004843, 0.037130), - RGB(0.007588, 0.006356, 0.044973), - RGB(0.009426, 0.008022, 0.052844), - RGB(0.011465, 0.009828, 0.060750), - RGB(0.013708, 0.011771, 0.068667), - RGB(0.016156, 0.013840, 0.076603), - RGB(0.018815, 0.016026, 0.084584), - RGB(0.021692, 0.018320, 0.092610), - RGB(0.024792, 0.020715, 0.100676), - RGB(0.028123, 0.023201, 0.108787), - RGB(0.031696, 0.025765, 0.116965), - RGB(0.035520, 0.028397, 0.125209), - RGB(0.039608, 0.031090, 0.133515), - RGB(0.043830, 0.033830, 0.141886), - RGB(0.048062, 0.036607, 0.150327), - RGB(0.052320, 0.039407, 0.158841), - RGB(0.056615, 0.042160, 0.167446), - RGB(0.060949, 0.044794, 0.176129), - RGB(0.065330, 0.047318, 0.184892), - RGB(0.069764, 0.049726, 0.193735), - RGB(0.074257, 0.052017, 0.202660), - RGB(0.078815, 0.054184, 0.211667), - RGB(0.083446, 0.056225, 0.220755), - RGB(0.088155, 0.058133, 0.229922), - RGB(0.092949, 0.059904, 0.239164), - RGB(0.097833, 0.061531, 0.248477), - RGB(0.102815, 0.063010, 0.257854), - RGB(0.107899, 0.064335, 0.267289), - RGB(0.113094, 0.065492, 0.276784), - RGB(0.118405, 0.066479, 0.286321), - RGB(0.123833, 0.067295, 0.295879), - RGB(0.129380, 0.067935, 0.305443), - RGB(0.135053, 0.068391, 0.315000), - RGB(0.140858, 0.068654, 0.324538), - RGB(0.146785, 0.068738, 0.334011), - RGB(0.152839, 0.068637, 0.343404), - RGB(0.159018, 0.068354, 0.352688), - RGB(0.165308, 0.067911, 0.361816), - RGB(0.171713, 0.067305, 0.370771), - RGB(0.178212, 0.066576, 0.379497), - RGB(0.184801, 0.065732, 0.387973), - RGB(0.191460, 0.064818, 0.396152), - RGB(0.198177, 0.063862, 0.404009), - RGB(0.204935, 0.062907, 0.411514), - RGB(0.211718, 0.061992, 0.418647), - RGB(0.218512, 0.061158, 0.425392), - RGB(0.225302, 0.060445, 0.431742), - RGB(0.232077, 0.059889, 0.437695), - RGB(0.238826, 0.059517, 0.443256), - RGB(0.245543, 0.059352, 0.448436), - RGB(0.252220, 0.059415, 0.453248), - RGB(0.258857, 0.059706, 0.457710), - RGB(0.265447, 0.060237, 0.461840), - RGB(0.271994, 0.060994, 0.465660), - RGB(0.278493, 0.061978, 0.469190), - RGB(0.284951, 0.063168, 0.472451), - RGB(0.291366, 0.064553, 0.475462), - RGB(0.297740, 0.066117, 0.478243), - RGB(0.304081, 0.067835, 0.480812), - RGB(0.310382, 0.069702, 0.483186), - RGB(0.316654, 0.071690, 0.485380), - RGB(0.322899, 0.073782, 0.487408), - RGB(0.329114, 0.075972, 0.489287), - RGB(0.335308, 0.078236, 0.491024), - RGB(0.341482, 0.080564, 0.492631), - RGB(0.347636, 0.082946, 0.494121), - RGB(0.353773, 0.085373, 0.495501), - RGB(0.359898, 0.087831, 0.496778), - RGB(0.366012, 0.090314, 0.497960), - RGB(0.372116, 0.092816, 0.499053), - RGB(0.378211, 0.095332, 0.500067), - RGB(0.384299, 0.097855, 0.501002), - RGB(0.390384, 0.100379, 0.501864), - RGB(0.396467, 0.102902, 0.502658), - RGB(0.402548, 0.105420, 0.503386), - RGB(0.408629, 0.107930, 0.504052), - RGB(0.414709, 0.110431, 0.504662), - RGB(0.420791, 0.112920, 0.505215), - RGB(0.426877, 0.115395, 0.505714), - RGB(0.432967, 0.117855, 0.506160), - RGB(0.439062, 0.120298, 0.506555), - RGB(0.445163, 0.122724, 0.506901), - RGB(0.451271, 0.125132, 0.507198), - RGB(0.457386, 0.127522, 0.507448), - RGB(0.463508, 0.129893, 0.507652), - RGB(0.469640, 0.132245, 0.507809), - RGB(0.475780, 0.134577, 0.507921), - RGB(0.481929, 0.136891, 0.507989), - RGB(0.488088, 0.139186, 0.508011), - RGB(0.494258, 0.141462, 0.507988), - RGB(0.500438, 0.143719, 0.507920), - RGB(0.506629, 0.145958, 0.507806), - RGB(0.512831, 0.148179, 0.507648), - RGB(0.519045, 0.150383, 0.507443), - RGB(0.525270, 0.152569, 0.507192), - RGB(0.531507, 0.154739, 0.506895), - RGB(0.537755, 0.156894, 0.506551), - RGB(0.544015, 0.159033, 0.506159), - RGB(0.550287, 0.161158, 0.505719), - RGB(0.556571, 0.163269, 0.505230), - RGB(0.562866, 0.165368, 0.504692), - RGB(0.569172, 0.167454, 0.504105), - RGB(0.575490, 0.169530, 0.503466), - RGB(0.581819, 0.171596, 0.502777), - RGB(0.588158, 0.173652, 0.502035), - RGB(0.594508, 0.175701, 0.501241), - RGB(0.600868, 0.177743, 0.500394), - RGB(0.607238, 0.179779, 0.499492), - RGB(0.613617, 0.181811, 0.498536), - RGB(0.620005, 0.183840, 0.497524), - RGB(0.626401, 0.185867, 0.496456), - RGB(0.632805, 0.187893, 0.495332), - RGB(0.639216, 0.189921, 0.494150), - RGB(0.645633, 0.191952, 0.492910), - RGB(0.652056, 0.193986, 0.491611), - RGB(0.658483, 0.196027, 0.490253), - RGB(0.664915, 0.198075, 0.488836), - RGB(0.671349, 0.200133, 0.487358), - RGB(0.677786, 0.202203, 0.485819), - RGB(0.684224, 0.204286, 0.484219), - RGB(0.690661, 0.206384, 0.482558), - RGB(0.697098, 0.208501, 0.480835), - RGB(0.703532, 0.210638, 0.479049), - RGB(0.709962, 0.212797, 0.477201), - RGB(0.716387, 0.214982, 0.475290), - RGB(0.722805, 0.217194, 0.473316), - RGB(0.729216, 0.219437, 0.471279), - RGB(0.735616, 0.221713, 0.469180), - RGB(0.742004, 0.224025, 0.467018), - RGB(0.748378, 0.226377, 0.464794), - RGB(0.754737, 0.228772, 0.462509), - RGB(0.761077, 0.231214, 0.460162), - RGB(0.767398, 0.233705, 0.457755), - RGB(0.773695, 0.236249, 0.455289), - RGB(0.779968, 0.238851, 0.452765), - RGB(0.786212, 0.241514, 0.450184), - RGB(0.792427, 0.244242, 0.447543), - RGB(0.798608, 0.247040, 0.444848), - RGB(0.804752, 0.249911, 0.442102), - RGB(0.810855, 0.252861, 0.439305), - RGB(0.816914, 0.255895, 0.436461), - RGB(0.822926, 0.259016, 0.433573), - RGB(0.828886, 0.262229, 0.430644), - RGB(0.834791, 0.265540, 0.427671), - RGB(0.840636, 0.268953, 0.424666), - RGB(0.846416, 0.272473, 0.421631), - RGB(0.852126, 0.276106, 0.418573), - RGB(0.857763, 0.279857, 0.415496), - RGB(0.863320, 0.283729, 0.412403), - RGB(0.868793, 0.287728, 0.409303), - RGB(0.874176, 0.291859, 0.406205), - RGB(0.879464, 0.296125, 0.403118), - RGB(0.884651, 0.300530, 0.400047), - RGB(0.889731, 0.305079, 0.397002), - RGB(0.894700, 0.309773, 0.393995), - RGB(0.899552, 0.314616, 0.391037), - RGB(0.904281, 0.319610, 0.388137), - RGB(0.908884, 0.324755, 0.385308), - RGB(0.913354, 0.330052, 0.382563), - RGB(0.917689, 0.335500, 0.379915), - RGB(0.921884, 0.341098, 0.377376), - RGB(0.925937, 0.346844, 0.374959), - RGB(0.929845, 0.352734, 0.372677), - RGB(0.933606, 0.358764, 0.370541), - RGB(0.937221, 0.364929, 0.368567), - RGB(0.940687, 0.371224, 0.366762), - RGB(0.944006, 0.377643, 0.365136), - RGB(0.947180, 0.384178, 0.363701), - RGB(0.950210, 0.390820, 0.362468), - RGB(0.953099, 0.397563, 0.361438), - RGB(0.955849, 0.404400, 0.360619), - RGB(0.958464, 0.411324, 0.360014), - RGB(0.960949, 0.418323, 0.359630), - RGB(0.963310, 0.425390, 0.359469), - RGB(0.965549, 0.432519, 0.359529), - RGB(0.967671, 0.439703, 0.359810), - RGB(0.969680, 0.446936, 0.360311), - RGB(0.971582, 0.454210, 0.361030), - RGB(0.973381, 0.461520, 0.361965), - RGB(0.975082, 0.468861, 0.363111), - RGB(0.976690, 0.476226, 0.364466), - RGB(0.978210, 0.483612, 0.366025), - RGB(0.979645, 0.491014, 0.367783), - RGB(0.981000, 0.498428, 0.369734), - RGB(0.982279, 0.505851, 0.371874), - RGB(0.983485, 0.513280, 0.374198), - RGB(0.984622, 0.520713, 0.376698), - RGB(0.985693, 0.528148, 0.379371), - RGB(0.986700, 0.535582, 0.382210), - RGB(0.987646, 0.543015, 0.385210), - RGB(0.988533, 0.550446, 0.388365), - RGB(0.989363, 0.557873, 0.391671), - RGB(0.990138, 0.565296, 0.395122), - RGB(0.990871, 0.572706, 0.398714), - RGB(0.991558, 0.580107, 0.402441), - RGB(0.992196, 0.587502, 0.406299), - RGB(0.992785, 0.594891, 0.410283), - RGB(0.993326, 0.602275, 0.414390), - RGB(0.993834, 0.609644, 0.418613), - RGB(0.994309, 0.616999, 0.422950), - RGB(0.994738, 0.624350, 0.427397), - RGB(0.995122, 0.631696, 0.431951), - RGB(0.995480, 0.639027, 0.436607), - RGB(0.995810, 0.646344, 0.441361), - RGB(0.996096, 0.653659, 0.446213), - RGB(0.996341, 0.660969, 0.451160), - RGB(0.996580, 0.668256, 0.456192), - RGB(0.996775, 0.675541, 0.461314), - RGB(0.996925, 0.682828, 0.466526), - RGB(0.997077, 0.690088, 0.471811), - RGB(0.997186, 0.697349, 0.477182), - RGB(0.997254, 0.704611, 0.482635), - RGB(0.997325, 0.711848, 0.488154), - RGB(0.997351, 0.719089, 0.493755), - RGB(0.997351, 0.726324, 0.499428), - RGB(0.997341, 0.733545, 0.505167), - RGB(0.997285, 0.740772, 0.510983), - RGB(0.997228, 0.747981, 0.516859), - RGB(0.997138, 0.755190, 0.522806), - RGB(0.997019, 0.762398, 0.528821), - RGB(0.996898, 0.769591, 0.534892), - RGB(0.996727, 0.776795, 0.541039), - RGB(0.996571, 0.783977, 0.547233), - RGB(0.996369, 0.791167, 0.553499), - RGB(0.996162, 0.798348, 0.559820), - RGB(0.995932, 0.805527, 0.566202), - RGB(0.995680, 0.812706, 0.572645), - RGB(0.995424, 0.819875, 0.579140), - RGB(0.995131, 0.827052, 0.585701), - RGB(0.994851, 0.834213, 0.592307), - RGB(0.994524, 0.841387, 0.598983), - RGB(0.994222, 0.848540, 0.605696), - RGB(0.993866, 0.855711, 0.612482), - RGB(0.993545, 0.862859, 0.619299), - RGB(0.993170, 0.870024, 0.626189), - RGB(0.992831, 0.877168, 0.633109), - RGB(0.992440, 0.884330, 0.640099), - RGB(0.992089, 0.891470, 0.647116), - RGB(0.991688, 0.898627, 0.654202), - RGB(0.991332, 0.905763, 0.661309), - RGB(0.990930, 0.912915, 0.668481), - RGB(0.990570, 0.920049, 0.675675), - RGB(0.990175, 0.927196, 0.682926), - RGB(0.989815, 0.934329, 0.690198), - RGB(0.989434, 0.941470, 0.697519), - RGB(0.989077, 0.948604, 0.704863), - RGB(0.988717, 0.955742, 0.712242), - RGB(0.988367, 0.962878, 0.719649), - RGB(0.988033, 0.970012, 0.727077), - RGB(0.987691, 0.977154, 0.734536), - RGB(0.987387, 0.984288, 0.742002), - RGB(0.987053, 0.991438, 0.749504) -], 30)) - -register_gradient_colors(:inferno, sample_evenly([ - RGB(0.001462, 0.000466, 0.013866), - RGB(0.002267, 0.001270, 0.018570), - RGB(0.003299, 0.002249, 0.024239), - RGB(0.004547, 0.003392, 0.030909), - RGB(0.006006, 0.004692, 0.038558), - RGB(0.007676, 0.006136, 0.046836), - RGB(0.009561, 0.007713, 0.055143), - RGB(0.011663, 0.009417, 0.063460), - RGB(0.013995, 0.011225, 0.071862), - RGB(0.016561, 0.013136, 0.080282), - RGB(0.019373, 0.015133, 0.088767), - RGB(0.022447, 0.017199, 0.097327), - RGB(0.025793, 0.019331, 0.105930), - RGB(0.029432, 0.021503, 0.114621), - RGB(0.033385, 0.023702, 0.123397), - RGB(0.037668, 0.025921, 0.132232), - RGB(0.042253, 0.028139, 0.141141), - RGB(0.046915, 0.030324, 0.150164), - RGB(0.051644, 0.032474, 0.159254), - RGB(0.056449, 0.034569, 0.168414), - RGB(0.061340, 0.036590, 0.177642), - RGB(0.066331, 0.038504, 0.186962), - RGB(0.071429, 0.040294, 0.196354), - RGB(0.076637, 0.041905, 0.205799), - RGB(0.081962, 0.043328, 0.215289), - RGB(0.087411, 0.044556, 0.224813), - RGB(0.092990, 0.045583, 0.234358), - RGB(0.098702, 0.046402, 0.243904), - RGB(0.104551, 0.047008, 0.253430), - RGB(0.110536, 0.047399, 0.262912), - RGB(0.116656, 0.047574, 0.272321), - RGB(0.122908, 0.047536, 0.281624), - RGB(0.129285, 0.047293, 0.290788), - RGB(0.135778, 0.046856, 0.299776), - RGB(0.142378, 0.046242, 0.308553), - RGB(0.149073, 0.045468, 0.317085), - RGB(0.155850, 0.044559, 0.325338), - RGB(0.162689, 0.043554, 0.333277), - RGB(0.169575, 0.042489, 0.340874), - RGB(0.176493, 0.041402, 0.348111), - RGB(0.183429, 0.040329, 0.354971), - RGB(0.190367, 0.039309, 0.361447), - RGB(0.197297, 0.038400, 0.367535), - RGB(0.204209, 0.037632, 0.373238), - RGB(0.211095, 0.037030, 0.378563), - RGB(0.217949, 0.036615, 0.383522), - RGB(0.224763, 0.036405, 0.388129), - RGB(0.231538, 0.036405, 0.392400), - RGB(0.238273, 0.036621, 0.396353), - RGB(0.244967, 0.037055, 0.400007), - RGB(0.251620, 0.037705, 0.403378), - RGB(0.258234, 0.038571, 0.406485), - RGB(0.264810, 0.039647, 0.409345), - RGB(0.271347, 0.040922, 0.411976), - RGB(0.277850, 0.042353, 0.414392), - RGB(0.284321, 0.043933, 0.416608), - RGB(0.290763, 0.045644, 0.418637), - RGB(0.297178, 0.047470, 0.420491), - RGB(0.303568, 0.049396, 0.422182), - RGB(0.309935, 0.051407, 0.423721), - RGB(0.316282, 0.053490, 0.425116), - RGB(0.322610, 0.055634, 0.426377), - RGB(0.328921, 0.057827, 0.427511), - RGB(0.335217, 0.060060, 0.428524), - RGB(0.341500, 0.062325, 0.429425), - RGB(0.347771, 0.064616, 0.430217), - RGB(0.354032, 0.066925, 0.430906), - RGB(0.360284, 0.069247, 0.431497), - RGB(0.366529, 0.071579, 0.431994), - RGB(0.372768, 0.073915, 0.432400), - RGB(0.379001, 0.076253, 0.432719), - RGB(0.385228, 0.078591, 0.432955), - RGB(0.391453, 0.080927, 0.433109), - RGB(0.397674, 0.083257, 0.433183), - RGB(0.403894, 0.085580, 0.433179), - RGB(0.410113, 0.087896, 0.433098), - RGB(0.416331, 0.090203, 0.432943), - RGB(0.422549, 0.092501, 0.432714), - RGB(0.428768, 0.094790, 0.432412), - RGB(0.434987, 0.097069, 0.432039), - RGB(0.441207, 0.099338, 0.431594), - RGB(0.447428, 0.101597, 0.431080), - RGB(0.453651, 0.103848, 0.430498), - RGB(0.459875, 0.106089, 0.429846), - RGB(0.466100, 0.108322, 0.429125), - RGB(0.472328, 0.110547, 0.428334), - RGB(0.478558, 0.112764, 0.427475), - RGB(0.484789, 0.114974, 0.426548), - RGB(0.491022, 0.117179, 0.425552), - RGB(0.497257, 0.119379, 0.424488), - RGB(0.503493, 0.121575, 0.423356), - RGB(0.509730, 0.123769, 0.422156), - RGB(0.515967, 0.125960, 0.420887), - RGB(0.522206, 0.128150, 0.419549), - RGB(0.528444, 0.130341, 0.418142), - RGB(0.534683, 0.132534, 0.416667), - RGB(0.540920, 0.134729, 0.415123), - RGB(0.547157, 0.136929, 0.413511), - RGB(0.553392, 0.139134, 0.411829), - RGB(0.559624, 0.141346, 0.410078), - RGB(0.565854, 0.143567, 0.408258), - RGB(0.572081, 0.145797, 0.406369), - RGB(0.578304, 0.148039, 0.404411), - RGB(0.584521, 0.150294, 0.402385), - RGB(0.590734, 0.152563, 0.400290), - RGB(0.596940, 0.154848, 0.398125), - RGB(0.603139, 0.157151, 0.395891), - RGB(0.609330, 0.159474, 0.393589), - RGB(0.615513, 0.161817, 0.391219), - RGB(0.621685, 0.164184, 0.388781), - RGB(0.627847, 0.166575, 0.386276), - RGB(0.633998, 0.168992, 0.383704), - RGB(0.640135, 0.171438, 0.381065), - RGB(0.646260, 0.173914, 0.378359), - RGB(0.652369, 0.176421, 0.375586), - RGB(0.658463, 0.178962, 0.372748), - RGB(0.664540, 0.181539, 0.369846), - RGB(0.670599, 0.184153, 0.366879), - RGB(0.676638, 0.186807, 0.363849), - RGB(0.682656, 0.189501, 0.360757), - RGB(0.688653, 0.192239, 0.357603), - RGB(0.694627, 0.195021, 0.354388), - RGB(0.700576, 0.197851, 0.351113), - RGB(0.706500, 0.200728, 0.347777), - RGB(0.712396, 0.203656, 0.344383), - RGB(0.718264, 0.206636, 0.340931), - RGB(0.724103, 0.209670, 0.337424), - RGB(0.729909, 0.212759, 0.333861), - RGB(0.735683, 0.215906, 0.330245), - RGB(0.741423, 0.219112, 0.326576), - RGB(0.747127, 0.222378, 0.322856), - RGB(0.752794, 0.225706, 0.319085), - RGB(0.758422, 0.229097, 0.315266), - RGB(0.764010, 0.232554, 0.311399), - RGB(0.769556, 0.236077, 0.307485), - RGB(0.775059, 0.239667, 0.303526), - RGB(0.780517, 0.243327, 0.299523), - RGB(0.785929, 0.247056, 0.295477), - RGB(0.791293, 0.250856, 0.291390), - RGB(0.796607, 0.254728, 0.287264), - RGB(0.801871, 0.258674, 0.283099), - RGB(0.807082, 0.262692, 0.278898), - RGB(0.812239, 0.266786, 0.274661), - RGB(0.817341, 0.270954, 0.270390), - RGB(0.822386, 0.275197, 0.266085), - RGB(0.827372, 0.279517, 0.261750), - RGB(0.832299, 0.283913, 0.257383), - RGB(0.837165, 0.288385, 0.252988), - RGB(0.841969, 0.292933, 0.248564), - RGB(0.846709, 0.297559, 0.244113), - RGB(0.851384, 0.302260, 0.239636), - RGB(0.855992, 0.307038, 0.235133), - RGB(0.860533, 0.311892, 0.230606), - RGB(0.865006, 0.316822, 0.226055), - RGB(0.869409, 0.321827, 0.221482), - RGB(0.873741, 0.326906, 0.216886), - RGB(0.878001, 0.332060, 0.212268), - RGB(0.882188, 0.337287, 0.207628), - RGB(0.886302, 0.342586, 0.202968), - RGB(0.890341, 0.347957, 0.198286), - RGB(0.894305, 0.353399, 0.193584), - RGB(0.898192, 0.358911, 0.188860), - RGB(0.902003, 0.364492, 0.184116), - RGB(0.905735, 0.370140, 0.179350), - RGB(0.909390, 0.375856, 0.174563), - RGB(0.912966, 0.381636, 0.169755), - RGB(0.916462, 0.387481, 0.164924), - RGB(0.919879, 0.393389, 0.160070), - RGB(0.923215, 0.399359, 0.155193), - RGB(0.926470, 0.405389, 0.150292), - RGB(0.929644, 0.411479, 0.145367), - RGB(0.932737, 0.417627, 0.140417), - RGB(0.935747, 0.423831, 0.135440), - RGB(0.938675, 0.430091, 0.130438), - RGB(0.941521, 0.436405, 0.125409), - RGB(0.944285, 0.442772, 0.120354), - RGB(0.946965, 0.449191, 0.115272), - RGB(0.949562, 0.455660, 0.110164), - RGB(0.952075, 0.462178, 0.105031), - RGB(0.954506, 0.468744, 0.099874), - RGB(0.956852, 0.475356, 0.094695), - RGB(0.959114, 0.482014, 0.089499), - RGB(0.961293, 0.488716, 0.084289), - RGB(0.963387, 0.495462, 0.079073), - RGB(0.965397, 0.502249, 0.073859), - RGB(0.967322, 0.509078, 0.068659), - RGB(0.969163, 0.515946, 0.063488), - RGB(0.970919, 0.522853, 0.058367), - RGB(0.972590, 0.529798, 0.053324), - RGB(0.974176, 0.536780, 0.048392), - RGB(0.975677, 0.543798, 0.043618), - RGB(0.977092, 0.550850, 0.039050), - RGB(0.978422, 0.557937, 0.034931), - RGB(0.979666, 0.565057, 0.031409), - RGB(0.980824, 0.572209, 0.028508), - RGB(0.981895, 0.579392, 0.026250), - RGB(0.982881, 0.586606, 0.024661), - RGB(0.983779, 0.593849, 0.023770), - RGB(0.984591, 0.601122, 0.023606), - RGB(0.985315, 0.608422, 0.024202), - RGB(0.985952, 0.615750, 0.025592), - RGB(0.986502, 0.623105, 0.027814), - RGB(0.986964, 0.630485, 0.030908), - RGB(0.987337, 0.637890, 0.034916), - RGB(0.987622, 0.645320, 0.039886), - RGB(0.987819, 0.652773, 0.045581), - RGB(0.987926, 0.660250, 0.051750), - RGB(0.987945, 0.667748, 0.058329), - RGB(0.987874, 0.675267, 0.065257), - RGB(0.987714, 0.682807, 0.072489), - RGB(0.987464, 0.690366, 0.079990), - RGB(0.987124, 0.697944, 0.087731), - RGB(0.986694, 0.705540, 0.095694), - RGB(0.986175, 0.713153, 0.103863), - RGB(0.985566, 0.720782, 0.112229), - RGB(0.984865, 0.728427, 0.120785), - RGB(0.984075, 0.736087, 0.129527), - RGB(0.983196, 0.743758, 0.138453), - RGB(0.982228, 0.751442, 0.147565), - RGB(0.981173, 0.759135, 0.156863), - RGB(0.980032, 0.766837, 0.166353), - RGB(0.978806, 0.774545, 0.176037), - RGB(0.977497, 0.782258, 0.185923), - RGB(0.976108, 0.789974, 0.196018), - RGB(0.974638, 0.797692, 0.206332), - RGB(0.973088, 0.805409, 0.216877), - RGB(0.971468, 0.813122, 0.227658), - RGB(0.969783, 0.820825, 0.238686), - RGB(0.968041, 0.828515, 0.249972), - RGB(0.966243, 0.836191, 0.261534), - RGB(0.964394, 0.843848, 0.273391), - RGB(0.962517, 0.851476, 0.285546), - RGB(0.960626, 0.859069, 0.298010), - RGB(0.958720, 0.866624, 0.310820), - RGB(0.956834, 0.874129, 0.323974), - RGB(0.954997, 0.881569, 0.337475), - RGB(0.953215, 0.888942, 0.351369), - RGB(0.951546, 0.896226, 0.365627), - RGB(0.950018, 0.903409, 0.380271), - RGB(0.948683, 0.910473, 0.395289), - RGB(0.947594, 0.917399, 0.410665), - RGB(0.946809, 0.924168, 0.426373), - RGB(0.946392, 0.930761, 0.442367), - RGB(0.946403, 0.937159, 0.458592), - RGB(0.946903, 0.943348, 0.474970), - RGB(0.947937, 0.949318, 0.491426), - RGB(0.949545, 0.955063, 0.507860), - RGB(0.951740, 0.960587, 0.524203), - RGB(0.954529, 0.965896, 0.540361), - RGB(0.957896, 0.971003, 0.556275), - RGB(0.961812, 0.975924, 0.571925), - RGB(0.966249, 0.980678, 0.587206), - RGB(0.971162, 0.985282, 0.602154), - RGB(0.976511, 0.989753, 0.616760), - RGB(0.982257, 0.994109, 0.631017), - RGB(0.988362, 0.998364, 0.644924) -], 30)) - -register_gradient_colors(:plasma, sample_evenly([ - RGB(0.050383, 0.029803, 0.527975), - RGB(0.063536, 0.028426, 0.533124), - RGB(0.075353, 0.027206, 0.538007), - RGB(0.086222, 0.026125, 0.542658), - RGB(0.096379, 0.025165, 0.547103), - RGB(0.105980, 0.024309, 0.551368), - RGB(0.115124, 0.023556, 0.555468), - RGB(0.123903, 0.022878, 0.559423), - RGB(0.132381, 0.022258, 0.563250), - RGB(0.140603, 0.021687, 0.566959), - RGB(0.148607, 0.021154, 0.570562), - RGB(0.156421, 0.020651, 0.574065), - RGB(0.164070, 0.020171, 0.577478), - RGB(0.171574, 0.019706, 0.580806), - RGB(0.178950, 0.019252, 0.584054), - RGB(0.186213, 0.018803, 0.587228), - RGB(0.193374, 0.018354, 0.590330), - RGB(0.200445, 0.017902, 0.593364), - RGB(0.207435, 0.017442, 0.596333), - RGB(0.214350, 0.016973, 0.599239), - RGB(0.221197, 0.016497, 0.602083), - RGB(0.227983, 0.016007, 0.604867), - RGB(0.234715, 0.015502, 0.607592), - RGB(0.241396, 0.014979, 0.610259), - RGB(0.248032, 0.014439, 0.612868), - RGB(0.254627, 0.013882, 0.615419), - RGB(0.261183, 0.013308, 0.617911), - RGB(0.267703, 0.012716, 0.620346), - RGB(0.274191, 0.012109, 0.622722), - RGB(0.280648, 0.011488, 0.625038), - RGB(0.287076, 0.010855, 0.627295), - RGB(0.293478, 0.010213, 0.629490), - RGB(0.299855, 0.009561, 0.631624), - RGB(0.306210, 0.008902, 0.633694), - RGB(0.312543, 0.008239, 0.635700), - RGB(0.318856, 0.007576, 0.637640), - RGB(0.325150, 0.006915, 0.639512), - RGB(0.331426, 0.006261, 0.641316), - RGB(0.337683, 0.005618, 0.643049), - RGB(0.343925, 0.004991, 0.644710), - RGB(0.350150, 0.004382, 0.646298), - RGB(0.356359, 0.003798, 0.647810), - RGB(0.362553, 0.003243, 0.649245), - RGB(0.368733, 0.002724, 0.650601), - RGB(0.374897, 0.002245, 0.651876), - RGB(0.381047, 0.001814, 0.653068), - RGB(0.387183, 0.001434, 0.654177), - RGB(0.393304, 0.001114, 0.655199), - RGB(0.399411, 0.000859, 0.656133), - RGB(0.405503, 0.000678, 0.656977), - RGB(0.411580, 0.000577, 0.657730), - RGB(0.417642, 0.000564, 0.658390), - RGB(0.423689, 0.000646, 0.658956), - RGB(0.429719, 0.000831, 0.659425), - RGB(0.435734, 0.001127, 0.659797), - RGB(0.441732, 0.001540, 0.660069), - RGB(0.447714, 0.002080, 0.660240), - RGB(0.453677, 0.002755, 0.660310), - RGB(0.459623, 0.003574, 0.660277), - RGB(0.465550, 0.004545, 0.660139), - RGB(0.471457, 0.005678, 0.659897), - RGB(0.477344, 0.006980, 0.659549), - RGB(0.483210, 0.008460, 0.659095), - RGB(0.489055, 0.010127, 0.658534), - RGB(0.494877, 0.011990, 0.657865), - RGB(0.500678, 0.014055, 0.657088), - RGB(0.506454, 0.016333, 0.656202), - RGB(0.512206, 0.018833, 0.655209), - RGB(0.517933, 0.021563, 0.654109), - RGB(0.523633, 0.024532, 0.652901), - RGB(0.529306, 0.027747, 0.651586), - RGB(0.534952, 0.031217, 0.650165), - RGB(0.540570, 0.034950, 0.648640), - RGB(0.546157, 0.038954, 0.647010), - RGB(0.551715, 0.043136, 0.645277), - RGB(0.557243, 0.047331, 0.643443), - RGB(0.562738, 0.051545, 0.641509), - RGB(0.568201, 0.055778, 0.639477), - RGB(0.573632, 0.060028, 0.637349), - RGB(0.579029, 0.064296, 0.635126), - RGB(0.584391, 0.068579, 0.632812), - RGB(0.589719, 0.072878, 0.630408), - RGB(0.595011, 0.077190, 0.627917), - RGB(0.600266, 0.081516, 0.625342), - RGB(0.605485, 0.085854, 0.622686), - RGB(0.610667, 0.090204, 0.619951), - RGB(0.615812, 0.094564, 0.617140), - RGB(0.620919, 0.098934, 0.614257), - RGB(0.625987, 0.103312, 0.611305), - RGB(0.631017, 0.107699, 0.608287), - RGB(0.636008, 0.112092, 0.605205), - RGB(0.640959, 0.116492, 0.602065), - RGB(0.645872, 0.120898, 0.598867), - RGB(0.650746, 0.125309, 0.595617), - RGB(0.655580, 0.129725, 0.592317), - RGB(0.660374, 0.134144, 0.588971), - RGB(0.665129, 0.138566, 0.585582), - RGB(0.669845, 0.142992, 0.582154), - RGB(0.674522, 0.147419, 0.578688), - RGB(0.679160, 0.151848, 0.575189), - RGB(0.683758, 0.156278, 0.571660), - RGB(0.688318, 0.160709, 0.568103), - RGB(0.692840, 0.165141, 0.564522), - RGB(0.697324, 0.169573, 0.560919), - RGB(0.701769, 0.174005, 0.557296), - RGB(0.706178, 0.178437, 0.553657), - RGB(0.710549, 0.182868, 0.550004), - RGB(0.714883, 0.187299, 0.546338), - RGB(0.719181, 0.191729, 0.542663), - RGB(0.723444, 0.196158, 0.538981), - RGB(0.727670, 0.200586, 0.535293), - RGB(0.731862, 0.205013, 0.531601), - RGB(0.736019, 0.209439, 0.527908), - RGB(0.740143, 0.213864, 0.524216), - RGB(0.744232, 0.218288, 0.520524), - RGB(0.748289, 0.222711, 0.516834), - RGB(0.752312, 0.227133, 0.513149), - RGB(0.756304, 0.231555, 0.509468), - RGB(0.760264, 0.235976, 0.505794), - RGB(0.764193, 0.240396, 0.502126), - RGB(0.768090, 0.244817, 0.498465), - RGB(0.771958, 0.249237, 0.494813), - RGB(0.775796, 0.253658, 0.491171), - RGB(0.779604, 0.258078, 0.487539), - RGB(0.783383, 0.262500, 0.483918), - RGB(0.787133, 0.266922, 0.480307), - RGB(0.790855, 0.271345, 0.476706), - RGB(0.794549, 0.275770, 0.473117), - RGB(0.798216, 0.280197, 0.469538), - RGB(0.801855, 0.284626, 0.465971), - RGB(0.805467, 0.289057, 0.462415), - RGB(0.809052, 0.293491, 0.458870), - RGB(0.812612, 0.297928, 0.455338), - RGB(0.816144, 0.302368, 0.451816), - RGB(0.819651, 0.306812, 0.448306), - RGB(0.823132, 0.311261, 0.444806), - RGB(0.826588, 0.315714, 0.441316), - RGB(0.830018, 0.320172, 0.437836), - RGB(0.833422, 0.324635, 0.434366), - RGB(0.836801, 0.329105, 0.430905), - RGB(0.840155, 0.333580, 0.427455), - RGB(0.843484, 0.338062, 0.424013), - RGB(0.846788, 0.342551, 0.420579), - RGB(0.850066, 0.347048, 0.417153), - RGB(0.853319, 0.351553, 0.413734), - RGB(0.856547, 0.356066, 0.410322), - RGB(0.859750, 0.360588, 0.406917), - RGB(0.862927, 0.365119, 0.403519), - RGB(0.866078, 0.369660, 0.400126), - RGB(0.869203, 0.374212, 0.396738), - RGB(0.872303, 0.378774, 0.393355), - RGB(0.875376, 0.383347, 0.389976), - RGB(0.878423, 0.387932, 0.386600), - RGB(0.881443, 0.392529, 0.383229), - RGB(0.884436, 0.397139, 0.379860), - RGB(0.887402, 0.401762, 0.376494), - RGB(0.890340, 0.406398, 0.373130), - RGB(0.893250, 0.411048, 0.369768), - RGB(0.896131, 0.415712, 0.366407), - RGB(0.898984, 0.420392, 0.363047), - RGB(0.901807, 0.425087, 0.359688), - RGB(0.904601, 0.429797, 0.356329), - RGB(0.907365, 0.434524, 0.352970), - RGB(0.910098, 0.439268, 0.349610), - RGB(0.912800, 0.444029, 0.346251), - RGB(0.915471, 0.448807, 0.342890), - RGB(0.918109, 0.453603, 0.339529), - RGB(0.920714, 0.458417, 0.336166), - RGB(0.923287, 0.463251, 0.332801), - RGB(0.925825, 0.468103, 0.329435), - RGB(0.928329, 0.472975, 0.326067), - RGB(0.930798, 0.477867, 0.322697), - RGB(0.933232, 0.482780, 0.319325), - RGB(0.935630, 0.487712, 0.315952), - RGB(0.937990, 0.492667, 0.312575), - RGB(0.940313, 0.497642, 0.309197), - RGB(0.942598, 0.502639, 0.305816), - RGB(0.944844, 0.507658, 0.302433), - RGB(0.947051, 0.512699, 0.299049), - RGB(0.949217, 0.517763, 0.295662), - RGB(0.951344, 0.522850, 0.292275), - RGB(0.953428, 0.527960, 0.288883), - RGB(0.955470, 0.533093, 0.285490), - RGB(0.957469, 0.538250, 0.282096), - RGB(0.959424, 0.543431, 0.278701), - RGB(0.961336, 0.548636, 0.275305), - RGB(0.963203, 0.553865, 0.271909), - RGB(0.965024, 0.559118, 0.268513), - RGB(0.966798, 0.564396, 0.265118), - RGB(0.968526, 0.569700, 0.261721), - RGB(0.970205, 0.575028, 0.258325), - RGB(0.971835, 0.580382, 0.254931), - RGB(0.973416, 0.585761, 0.251540), - RGB(0.974947, 0.591165, 0.248151), - RGB(0.976428, 0.596595, 0.244767), - RGB(0.977856, 0.602051, 0.241387), - RGB(0.979233, 0.607532, 0.238013), - RGB(0.980556, 0.613039, 0.234646), - RGB(0.981826, 0.618572, 0.231287), - RGB(0.983041, 0.624131, 0.227937), - RGB(0.984199, 0.629718, 0.224595), - RGB(0.985301, 0.635330, 0.221265), - RGB(0.986345, 0.640969, 0.217948), - RGB(0.987332, 0.646633, 0.214648), - RGB(0.988260, 0.652325, 0.211364), - RGB(0.989128, 0.658043, 0.208100), - RGB(0.989935, 0.663787, 0.204859), - RGB(0.990681, 0.669558, 0.201642), - RGB(0.991365, 0.675355, 0.198453), - RGB(0.991985, 0.681179, 0.195295), - RGB(0.992541, 0.687030, 0.192170), - RGB(0.993032, 0.692907, 0.189084), - RGB(0.993456, 0.698810, 0.186041), - RGB(0.993814, 0.704741, 0.183043), - RGB(0.994103, 0.710698, 0.180097), - RGB(0.994324, 0.716681, 0.177208), - RGB(0.994474, 0.722691, 0.174381), - RGB(0.994553, 0.728728, 0.171622), - RGB(0.994561, 0.734791, 0.168938), - RGB(0.994495, 0.740880, 0.166335), - RGB(0.994355, 0.746995, 0.163821), - RGB(0.994141, 0.753137, 0.161404), - RGB(0.993851, 0.759304, 0.159092), - RGB(0.993482, 0.765499, 0.156891), - RGB(0.993033, 0.771720, 0.154808), - RGB(0.992505, 0.777967, 0.152855), - RGB(0.991897, 0.784239, 0.151042), - RGB(0.991209, 0.790537, 0.149377), - RGB(0.990439, 0.796859, 0.147870), - RGB(0.989587, 0.803205, 0.146529), - RGB(0.988648, 0.809579, 0.145357), - RGB(0.987621, 0.815978, 0.144363), - RGB(0.986509, 0.822401, 0.143557), - RGB(0.985314, 0.828846, 0.142945), - RGB(0.984031, 0.835315, 0.142528), - RGB(0.982653, 0.841812, 0.142303), - RGB(0.981190, 0.848329, 0.142279), - RGB(0.979644, 0.854866, 0.142453), - RGB(0.977995, 0.861432, 0.142808), - RGB(0.976265, 0.868016, 0.143351), - RGB(0.974443, 0.874622, 0.144061), - RGB(0.972530, 0.881250, 0.144923), - RGB(0.970533, 0.887896, 0.145919), - RGB(0.968443, 0.894564, 0.147014), - RGB(0.966271, 0.901249, 0.148180), - RGB(0.964021, 0.907950, 0.149370), - RGB(0.961681, 0.914672, 0.150520), - RGB(0.959276, 0.921407, 0.151566), - RGB(0.956808, 0.928152, 0.152409), - RGB(0.954287, 0.934908, 0.152921), - RGB(0.951726, 0.941671, 0.152925), - RGB(0.949151, 0.948435, 0.152178), - RGB(0.946602, 0.955190, 0.150328), - RGB(0.944152, 0.961916, 0.146861), - RGB(0.941896, 0.968590, 0.140956), - RGB(0.940015, 0.975158, 0.131326) -], 30)) - -register_gradient_colors(:viridis, sample_evenly([ - RGB(0.267004, 0.004874, 0.329415), - RGB(0.268510, 0.009605, 0.335427), - RGB(0.269944, 0.014625, 0.341379), - RGB(0.271305, 0.019942, 0.347269), - RGB(0.272594, 0.025563, 0.353093), - RGB(0.273809, 0.031497, 0.358853), - RGB(0.274952, 0.037752, 0.364543), - RGB(0.276022, 0.044167, 0.370164), - RGB(0.277018, 0.050344, 0.375715), - RGB(0.277941, 0.056324, 0.381191), - RGB(0.278791, 0.062145, 0.386592), - RGB(0.279566, 0.067836, 0.391917), - RGB(0.280267, 0.073417, 0.397163), - RGB(0.280894, 0.078907, 0.402329), - RGB(0.281446, 0.084320, 0.407414), - RGB(0.281924, 0.089666, 0.412415), - RGB(0.282327, 0.094955, 0.417331), - RGB(0.282656, 0.100196, 0.422160), - RGB(0.282910, 0.105393, 0.426902), - RGB(0.283091, 0.110553, 0.431554), - RGB(0.283197, 0.115680, 0.436115), - RGB(0.283229, 0.120777, 0.440584), - RGB(0.283187, 0.125848, 0.444960), - RGB(0.283072, 0.130895, 0.449241), - RGB(0.282884, 0.135920, 0.453427), - RGB(0.282623, 0.140926, 0.457517), - RGB(0.282290, 0.145912, 0.461510), - RGB(0.281887, 0.150881, 0.465405), - RGB(0.281412, 0.155834, 0.469201), - RGB(0.280868, 0.160771, 0.472899), - RGB(0.280255, 0.165693, 0.476498), - RGB(0.279574, 0.170599, 0.479997), - RGB(0.278826, 0.175490, 0.483397), - RGB(0.278012, 0.180367, 0.486697), - RGB(0.277134, 0.185228, 0.489898), - RGB(0.276194, 0.190074, 0.493001), - RGB(0.275191, 0.194905, 0.496005), - RGB(0.274128, 0.199721, 0.498911), - RGB(0.273006, 0.204520, 0.501721), - RGB(0.271828, 0.209303, 0.504434), - RGB(0.270595, 0.214069, 0.507052), - RGB(0.269308, 0.218818, 0.509577), - RGB(0.267968, 0.223549, 0.512008), - RGB(0.266580, 0.228262, 0.514349), - RGB(0.265145, 0.232956, 0.516599), - RGB(0.263663, 0.237631, 0.518762), - RGB(0.262138, 0.242286, 0.520837), - RGB(0.260571, 0.246922, 0.522828), - RGB(0.258965, 0.251537, 0.524736), - RGB(0.257322, 0.256130, 0.526563), - RGB(0.255645, 0.260703, 0.528312), - RGB(0.253935, 0.265254, 0.529983), - RGB(0.252194, 0.269783, 0.531579), - RGB(0.250425, 0.274290, 0.533103), - RGB(0.248629, 0.278775, 0.534556), - RGB(0.246811, 0.283237, 0.535941), - RGB(0.244972, 0.287675, 0.537260), - RGB(0.243113, 0.292092, 0.538516), - RGB(0.241237, 0.296485, 0.539709), - RGB(0.239346, 0.300855, 0.540844), - RGB(0.237441, 0.305202, 0.541921), - RGB(0.235526, 0.309527, 0.542944), - RGB(0.233603, 0.313828, 0.543914), - RGB(0.231674, 0.318106, 0.544834), - RGB(0.229739, 0.322361, 0.545706), - RGB(0.227802, 0.326594, 0.546532), - RGB(0.225863, 0.330805, 0.547314), - RGB(0.223925, 0.334994, 0.548053), - RGB(0.221989, 0.339161, 0.548752), - RGB(0.220057, 0.343307, 0.549413), - RGB(0.218130, 0.347432, 0.550038), - RGB(0.216210, 0.351535, 0.550627), - RGB(0.214298, 0.355619, 0.551184), - RGB(0.212395, 0.359683, 0.551710), - RGB(0.210503, 0.363727, 0.552206), - RGB(0.208623, 0.367752, 0.552675), - RGB(0.206756, 0.371758, 0.553117), - RGB(0.204903, 0.375746, 0.553533), - RGB(0.203063, 0.379716, 0.553925), - RGB(0.201239, 0.383670, 0.554294), - RGB(0.199430, 0.387607, 0.554642), - RGB(0.197636, 0.391528, 0.554969), - RGB(0.195860, 0.395433, 0.555276), - RGB(0.194100, 0.399323, 0.555565), - RGB(0.192357, 0.403199, 0.555836), - RGB(0.190631, 0.407061, 0.556089), - RGB(0.188923, 0.410910, 0.556326), - RGB(0.187231, 0.414746, 0.556547), - RGB(0.185556, 0.418570, 0.556753), - RGB(0.183898, 0.422383, 0.556944), - RGB(0.182256, 0.426184, 0.557120), - RGB(0.180629, 0.429975, 0.557282), - RGB(0.179019, 0.433756, 0.557430), - RGB(0.177423, 0.437527, 0.557565), - RGB(0.175841, 0.441290, 0.557685), - RGB(0.174274, 0.445044, 0.557792), - RGB(0.172719, 0.448791, 0.557885), - RGB(0.171176, 0.452530, 0.557965), - RGB(0.169646, 0.456262, 0.558030), - RGB(0.168126, 0.459988, 0.558082), - RGB(0.166617, 0.463708, 0.558119), - RGB(0.165117, 0.467423, 0.558141), - RGB(0.163625, 0.471133, 0.558148), - RGB(0.162142, 0.474838, 0.558140), - RGB(0.160665, 0.478540, 0.558115), - RGB(0.159194, 0.482237, 0.558073), - RGB(0.157729, 0.485932, 0.558013), - RGB(0.156270, 0.489624, 0.557936), - RGB(0.154815, 0.493313, 0.557840), - RGB(0.153364, 0.497000, 0.557724), - RGB(0.151918, 0.500685, 0.557587), - RGB(0.150476, 0.504369, 0.557430), - RGB(0.149039, 0.508051, 0.557250), - RGB(0.147607, 0.511733, 0.557049), - RGB(0.146180, 0.515413, 0.556823), - RGB(0.144759, 0.519093, 0.556572), - RGB(0.143343, 0.522773, 0.556295), - RGB(0.141935, 0.526453, 0.555991), - RGB(0.140536, 0.530132, 0.555659), - RGB(0.139147, 0.533812, 0.555298), - RGB(0.137770, 0.537492, 0.554906), - RGB(0.136408, 0.541173, 0.554483), - RGB(0.135066, 0.544853, 0.554029), - RGB(0.133743, 0.548535, 0.553541), - RGB(0.132444, 0.552216, 0.553018), - RGB(0.131172, 0.555899, 0.552459), - RGB(0.129933, 0.559582, 0.551864), - RGB(0.128729, 0.563265, 0.551229), - RGB(0.127568, 0.566949, 0.550556), - RGB(0.126453, 0.570633, 0.549841), - RGB(0.125394, 0.574318, 0.549086), - RGB(0.124395, 0.578002, 0.548287), - RGB(0.123463, 0.581687, 0.547445), - RGB(0.122606, 0.585371, 0.546557), - RGB(0.121831, 0.589055, 0.545623), - RGB(0.121148, 0.592739, 0.544641), - RGB(0.120565, 0.596422, 0.543611), - RGB(0.120092, 0.600104, 0.542530), - RGB(0.119738, 0.603785, 0.541400), - RGB(0.119512, 0.607464, 0.540218), - RGB(0.119423, 0.611141, 0.538982), - RGB(0.119483, 0.614817, 0.537692), - RGB(0.119699, 0.618490, 0.536347), - RGB(0.120081, 0.622161, 0.534946), - RGB(0.120638, 0.625828, 0.533488), - RGB(0.121380, 0.629492, 0.531973), - RGB(0.122312, 0.633153, 0.530398), - RGB(0.123444, 0.636809, 0.528763), - RGB(0.124780, 0.640461, 0.527068), - RGB(0.126326, 0.644107, 0.525311), - RGB(0.128087, 0.647749, 0.523491), - RGB(0.130067, 0.651384, 0.521608), - RGB(0.132268, 0.655014, 0.519661), - RGB(0.134692, 0.658636, 0.517649), - RGB(0.137339, 0.662252, 0.515571), - RGB(0.140210, 0.665859, 0.513427), - RGB(0.143303, 0.669459, 0.511215), - RGB(0.146616, 0.673050, 0.508936), - RGB(0.150148, 0.676631, 0.506589), - RGB(0.153894, 0.680203, 0.504172), - RGB(0.157851, 0.683765, 0.501686), - RGB(0.162016, 0.687316, 0.499129), - RGB(0.166383, 0.690856, 0.496502), - RGB(0.170948, 0.694384, 0.493803), - RGB(0.175707, 0.697900, 0.491033), - RGB(0.180653, 0.701402, 0.488189), - RGB(0.185783, 0.704891, 0.485273), - RGB(0.191090, 0.708366, 0.482284), - RGB(0.196571, 0.711827, 0.479221), - RGB(0.202219, 0.715272, 0.476084), - RGB(0.208030, 0.718701, 0.472873), - RGB(0.214000, 0.722114, 0.469588), - RGB(0.220124, 0.725509, 0.466226), - RGB(0.226397, 0.728888, 0.462789), - RGB(0.232815, 0.732247, 0.459277), - RGB(0.239374, 0.735588, 0.455688), - RGB(0.246070, 0.738910, 0.452024), - RGB(0.252899, 0.742211, 0.448284), - RGB(0.259857, 0.745492, 0.444467), - RGB(0.266941, 0.748751, 0.440573), - RGB(0.274149, 0.751988, 0.436601), - RGB(0.281477, 0.755203, 0.432552), - RGB(0.288921, 0.758394, 0.428426), - RGB(0.296479, 0.761561, 0.424223), - RGB(0.304148, 0.764704, 0.419943), - RGB(0.311925, 0.767822, 0.415586), - RGB(0.319809, 0.770914, 0.411152), - RGB(0.327796, 0.773980, 0.406640), - RGB(0.335885, 0.777018, 0.402049), - RGB(0.344074, 0.780029, 0.397381), - RGB(0.352360, 0.783011, 0.392636), - RGB(0.360741, 0.785964, 0.387814), - RGB(0.369214, 0.788888, 0.382914), - RGB(0.377779, 0.791781, 0.377939), - RGB(0.386433, 0.794644, 0.372886), - RGB(0.395174, 0.797475, 0.367757), - RGB(0.404001, 0.800275, 0.362552), - RGB(0.412913, 0.803041, 0.357269), - RGB(0.421908, 0.805774, 0.351910), - RGB(0.430983, 0.808473, 0.346476), - RGB(0.440137, 0.811138, 0.340967), - RGB(0.449368, 0.813768, 0.335384), - RGB(0.458674, 0.816363, 0.329727), - RGB(0.468053, 0.818921, 0.323998), - RGB(0.477504, 0.821444, 0.318195), - RGB(0.487026, 0.823929, 0.312321), - RGB(0.496615, 0.826376, 0.306377), - RGB(0.506271, 0.828786, 0.300362), - RGB(0.515992, 0.831158, 0.294279), - RGB(0.525776, 0.833491, 0.288127), - RGB(0.535621, 0.835785, 0.281908), - RGB(0.545524, 0.838039, 0.275626), - RGB(0.555484, 0.840254, 0.269281), - RGB(0.565498, 0.842430, 0.262877), - RGB(0.575563, 0.844566, 0.256415), - RGB(0.585678, 0.846661, 0.249897), - RGB(0.595839, 0.848717, 0.243329), - RGB(0.606045, 0.850733, 0.236712), - RGB(0.616293, 0.852709, 0.230052), - RGB(0.626579, 0.854645, 0.223353), - RGB(0.636902, 0.856542, 0.216620), - RGB(0.647257, 0.858400, 0.209861), - RGB(0.657642, 0.860219, 0.203082), - RGB(0.668054, 0.861999, 0.196293), - RGB(0.678489, 0.863742, 0.189503), - RGB(0.688944, 0.865448, 0.182725), - RGB(0.699415, 0.867117, 0.175971), - RGB(0.709898, 0.868751, 0.169257), - RGB(0.720391, 0.870350, 0.162603), - RGB(0.730889, 0.871916, 0.156029), - RGB(0.741388, 0.873449, 0.149561), - RGB(0.751884, 0.874951, 0.143228), - RGB(0.762373, 0.876424, 0.137064), - RGB(0.772852, 0.877868, 0.131109), - RGB(0.783315, 0.879285, 0.125405), - RGB(0.793760, 0.880678, 0.120005), - RGB(0.804182, 0.882046, 0.114965), - RGB(0.814576, 0.883393, 0.110347), - RGB(0.824940, 0.884720, 0.106217), - RGB(0.835270, 0.886029, 0.102646), - RGB(0.845561, 0.887322, 0.099702), - RGB(0.855810, 0.888601, 0.097452), - RGB(0.866013, 0.889868, 0.095953), - RGB(0.876168, 0.891125, 0.095250), - RGB(0.886271, 0.892374, 0.095374), - RGB(0.896320, 0.893616, 0.096335), - RGB(0.906311, 0.894855, 0.098125), - RGB(0.916242, 0.896091, 0.100717), - RGB(0.926106, 0.897330, 0.104071), - RGB(0.935904, 0.898570, 0.108131), - RGB(0.945636, 0.899815, 0.112838), - RGB(0.955300, 0.901065, 0.118128), - RGB(0.964894, 0.902323, 0.123941), - RGB(0.974417, 0.903590, 0.130215), - RGB(0.983868, 0.904867, 0.136897), - RGB(0.993248, 0.906157, 0.143936) -], 30)) - - -# end of matplotlib colormaps -# ---------------------------------------------------------------------- -# ---------------------------------------------------------------------- diff --git a/src/deprecated/colors.jl b/src/deprecated/colors.jl deleted file mode 100644 index 5e01bdc1..00000000 --- a/src/deprecated/colors.jl +++ /dev/null @@ -1,415 +0,0 @@ - -abstract type ColorScheme end - -Base.getindex(scheme::ColorScheme, i::Integer) = getColor(scheme, i) - -export - cgrad - -cgrad() = default_gradient() - -function cgrad(arg, values = nothing; alpha = nothing, scale = :identity) - colors = ColorGradient(arg, alpha=alpha).colors - values = if values != nothing - values - elseif scale in (:log, :log10) - log10(range(1, stop=10, length=30)) - elseif scale == :log2 - log2(range(1, stop=2, length=30)) - elseif scale == :ln - log(range(1, stop=pi, length=30)) - elseif scale in (:exp, :exp10) - (exp10(range(0, stop=1, length=30)) - 1) / 9 - else - range(0, stop=1, length=length(colors)) - end - ColorGradient(colors, values) -end - -# -------------------------------------------------------------- - -getColor(scheme::ColorScheme) = getColor(scheme, 1) -getColorVector(scheme::ColorScheme) = [getColor(scheme)] - -colorscheme(scheme::ColorScheme) = scheme -colorscheme(s::AbstractString; kw...) = colorscheme(Symbol(s); kw...) -colorscheme(s::Symbol; kw...) = haskey(_gradients, s) ? ColorGradient(s; kw...) : ColorWrapper(convertColor(s); kw...) -colorscheme(s::Symbol, vals::AVec{T}; kw...) where {T<:Real} = ColorGradient(s, vals; kw...) -colorscheme(cs::AVec, vs::AVec; kw...) = ColorGradient(cs, vs; kw...) -colorscheme(cs::AVec{T}; kw...) where {T<:Colorant} = ColorGradient(cs; kw...) -colorscheme(f::Function; kw...) = ColorFunction(f; kw...) -colorscheme(v::AVec; kw...) = ColorVector(v; kw...) -colorscheme(m::AMat; kw...) = size(m,1) == 1 ? map(c->colorscheme(c; kw...), m) : [colorscheme(m[:,i]; kw...) for i in 1:size(m,2)]' -colorscheme(c::Colorant; kw...) = ColorWrapper(c; kw...) - - -# -------------------------------------------------------------- - - -convertColor(c::AbstractString) = parse(Colorant, c) -convertColor(c::Symbol) = parse(Colorant, string(c)) -convertColor(c::Colorant) = c -convertColor(cvec::AbstractVector) = map(convertColor, cvec) -convertColor(c::ColorScheme) = c -convertColor(v::Nothing) = RGBA(0,0,0,0) -convertColor(b::Bool) = b ? RGBA(0,0,0,1) : RGBA(0,0,0,0) - -function convertColor(c, α::Real) - c = convertColor(c) - RGBA(RGB(getColor(c)), α) -end -convertColor(cs::AVec, α::Real) = map(c -> convertColor(c, α), cs) -convertColor(c, α::Nothing) = convertColor(c) - -# backup... try to convert -getColor(c) = convertColor(c) - -# -------------------------------------------------------------- - -function darken(c, v=0.1) - rgba = convert(RGBA, c) - r = max(0, min(rgba.r - v, 1)) - g = max(0, min(rgba.g - v, 1)) - b = max(0, min(rgba.b - v, 1)) - RGBA(r,g,b,rgba.alpha) -end -function lighten(c, v=0.3) - darken(c, -v) -end - -# -------------------------------------------------------------- - -const _rainbowColors = [colorant"purple", colorant"blue", colorant"green", colorant"orange", colorant"red"] -const _testColors = [colorant"darkblue", colorant"blueviolet", colorant"darkcyan",colorant"green", - darken(colorant"yellow",0.3), colorant"orange", darken(colorant"red",0.2)] - -const _gradients = KW( - :blues => [colorant"lightblue", colorant"darkblue"], - :reds => [colorant"lightpink", colorant"darkred"], - :greens => [colorant"lightgreen", colorant"darkgreen"], - :redsblues => [colorant"darkred", RGB(0.8,0.85,0.8), colorant"darkblue"], - :bluesreds => [colorant"darkblue", RGB(0.8,0.85,0.8), colorant"darkred"], - :heat => [colorant"lightyellow", colorant"orange", colorant"darkred"], - :grays => [RGB(.95,.95,.95),RGB(.05,.05,.05)], - :rainbow => _rainbowColors, - :lightrainbow => map(lighten, _rainbowColors), - :darkrainbow => map(darken, _rainbowColors), - :darktest => _testColors, - :lighttest => map(c -> lighten(c, 0.3), _testColors), - ) - -function register_gradient_colors(name::Symbol, colors::AVec{C}) where C<:Colorant - _gradients[name] = colors -end - -include("color_gradients.jl") - -default_gradient() = ColorGradient(:inferno) - -# -------------------------------------------------------------- - -"Continuous gradient between values. Wraps a list of bounding colors and the values they represent." -struct ColorGradient <: ColorScheme - colors::Vector - values::Vector - - function ColorGradient(cs::AVec, vals::AVec{S} = range(0, stop=1, length=length(cs)); alpha = nothing) where S<:Real - if length(cs) == length(vals) - return new(convertColor(cs,alpha), collect(vals)) - end - - # # otherwise interpolate evenly between the minval and maxval - # minval, maxval = minimum(vals), maximum(vals) - # vs = Float64[interpolate(minval, maxval, w) for w in range(0, stop = 1, length = length(cs))] - # new(convertColor(cs,alpha), vs) - - # interpolate the colors for each value - vals = merge(range(0, stop=1, length=length(cs)), vals) - grad = ColorGradient(cs) - cs = [getColorZ(grad, z) for z in range(0, stop=1, length=length(vals))] - new(convertColor(cs, alpha), vals) - end -end - - - -Base.getindex(cs::ColorGradient, i::Integer) = getColor(cs, i) -Base.getindex(cs::ColorGradient, z::Number) = getColorZ(cs, z) - - -# create a gradient from a symbol (blues, reds, etc) and vector of boundary values -function ColorGradient(s::Symbol, vals::AVec{T} = 0:0; kw...) where T<:Real - haskey(_gradients, s) || error("Invalid gradient symbol. Choose from: ", sort(collect(keys(_gradients)))) - cs = _gradients[s] - if vals == 0:0 - vals = range(0, stop=1, length=length(cs)) - end - ColorGradient(cs, vals; kw...) -end - -# function ColorGradient{T<:Real}(cs::AVec, vals::AVec{T} = range(0, stop = 1, length = length(cs)); kw...) -# ColorGradient(map(convertColor, cs), vals; kw...) -# end - -function ColorGradient(grad::ColorGradient; alpha = nothing) - ColorGradient(convertColor(grad.colors, alpha), grad.values) -end - -# anything else just gets the default gradient -function ColorGradient(cw; alpha=nothing) - ColorGradient(default_gradient(), alpha=alpha) -end - -getColor(gradient::ColorGradient, idx::Int) = gradient.colors[mod1(idx, length(gradient.colors))] - -function getColorZ(gradient::ColorGradient, z::Real) - cs = gradient.colors - vs = gradient.values - n = length(cs) - @assert n > 0 && n == length(vs) - - # can we just return the first color? - if z <= vs[1] || n == 1 - return cs[1] - end - - # find the bounding colors and interpolate - for i in 2:n - if z <= vs[i] - return interpolate_rgb(cs[i-1], cs[i], (z - vs[i-1]) / (vs[i] - vs[i-1])) - end - end - - # if we get here, return the last color - cs[end] -end - -getColorVector(gradient::ColorGradient) = gradient.colors - -# for 0.3 -Colors.RGBA(c::Colorant) = RGBA(red(c), green(c), blue(c), alpha(c)) -Colors.RGB(c::Colorant) = RGB(red(c), green(c), blue(c)) - -function interpolate_rgb(c1::Colorant, c2::Colorant, w::Real) - rgb1 = RGBA(c1) - rgb2 = RGBA(c2) - r = interpolate(rgb1.r, rgb2.r, w) - g = interpolate(rgb1.g, rgb2.g, w) - b = interpolate(rgb1.b, rgb2.b, w) - a = interpolate(rgb1.alpha, rgb2.alpha, w) - RGBA(r, g, b, a) -end - - -function interpolate(v1::Real, v2::Real, w::Real) - (1-w) * v1 + w * v2 -end - -# -------------------------------------------------------------- - -"Wraps a function, taking an index and returning a Colorant" -struct ColorFunction <: ColorScheme - f::Function -end - -getColor(scheme::ColorFunction, idx::Int) = scheme.f(idx) - -# -------------------------------------------------------------- - -"Wraps a function, taking an z-value and returning a Colorant" -struct ColorZFunction <: ColorScheme - f::Function -end - -getColorZ(scheme::ColorZFunction, z::Real) = scheme.f(z) - -# -------------------------------------------------------------- - -"Wraps a vector of colors... may be vector of Symbol/String/Colorant" -struct ColorVector <: ColorScheme - v::Vector{Colorant} - ColorVector(v::AVec; alpha = nothing) = new(convertColor(v,alpha)) -end - -getColor(scheme::ColorVector, idx::Int) = convertColor(scheme.v[mod1(idx, length(scheme.v))]) -getColorVector(scheme::ColorVector) = scheme.v - - -# -------------------------------------------------------------- - -"Wraps a single color" -struct ColorWrapper <: ColorScheme - c::RGBA - ColorWrapper(c::Colorant; alpha = nothing) = new(convertColor(c, alpha)) -end - -ColorWrapper(s::Symbol; alpha = nothing) = ColorWrapper(convertColor(parse(Colorant, s), alpha)) - -getColor(scheme::ColorWrapper, idx::Int) = scheme.c -getColorZ(scheme::ColorWrapper, z::Real) = scheme.c -convertColor(c::ColorWrapper, α::Nothing) = c.c - -# -------------------------------------------------------------- - - -isbackgrounddark(bgcolor::Color) = Lab(bgcolor).l < 0.5 - -# move closer to lighter/darker depending on background value -function adjustAway(val, bgval, vmin=0., vmax=100.) - if bgval < 0.5 * (vmax+vmin) - tmp = max(val, bgval) - return 0.5 * (tmp + max(tmp, vmax)) - else - tmp = min(val, bgval) - return 0.5 * (tmp + min(tmp, vmin)) - end -end - -# borrowed from http://stackoverflow.com/a/1855903: -lightnessLevel(c::Colorant) = 0.299 * red(c) + 0.587 * green(c) + 0.114 * blue(c) - -isdark(c::Colorant) = lightnessLevel(c) < 0.5 -islight(c::Colorant) = !isdark(c) - -function convertHexToRGB(h::Unsigned) - mask = 0x0000FF - RGB([(x & mask) / 0xFF for x in (h >> 16, h >> 8, h)]...) -end - -# note: I found this list of hex values in a comment by Tatarize here: http://stackoverflow.com/a/12224359 -const _masterColorList = [ - 0xFFFFFF, 0x000000, 0x0000FF, 0x00FF00, 0xFF0000, 0x01FFFE, 0xFFA6FE, 0xFFDB66, 0x006401, 0x010067, - 0x95003A, 0x007DB5, 0xFF00F6, 0xFFEEE8, 0x774D00, 0x90FB92, 0x0076FF, 0xD5FF00, 0xFF937E, 0x6A826C, - 0xFF029D, 0xFE8900, 0x7A4782, 0x7E2DD2, 0x85A900, 0xFF0056, 0xA42400, 0x00AE7E, 0x683D3B, 0xBDC6FF, - 0x263400, 0xBDD393, 0x00B917, 0x9E008E, 0x001544, 0xC28C9F, 0xFF74A3, 0x01D0FF, 0x004754, 0xE56FFE, - 0x788231, 0x0E4CA1, 0x91D0CB, 0xBE9970, 0x968AE8, 0xBB8800, 0x43002C, 0xDEFF74, 0x00FFC6, 0xFFE502, - 0x620E00, 0x008F9C, 0x98FF52, 0x7544B1, 0xB500FF, 0x00FF78, 0xFF6E41, 0x005F39, 0x6B6882, 0x5FAD4E, - 0xA75740, 0xA5FFD2, 0xFFB167, 0x009BFF, 0xE85EBE - ] -const _allColors = map(convertHexToRGB, _masterColorList) -const _darkColors = filter(isdark, _allColors) -const _lightColors = filter(islight, _allColors) -const _sortedColorsForDarkBackground = vcat(_lightColors, reverse(_darkColors[2:end])) -const _sortedColorsForLightBackground = vcat(_darkColors, reverse(_lightColors[2:end])) - -const _defaultNumColors = 17 - -# -------------------------------------------------------------- - -# Methods to automatically generate gradients for color selection based on -# background color and a short list of seed colors - -# here are some magic constants that could be changed if you really want -const _lightness_darkbg = [80.0] -const _lightness_lightbg = [60.0] -const _lch_c_const = [60] - -function adjust_lch(color, l, c) - lch = convert(LCHab, color) - convert(RGB, LCHab(l, c, lch.h)) -end - -function lightness_from_background(bgcolor) - bglight = convert(LCHab, bgcolor).l - bglight < 50.0 ? _lightness_darkbg[1] : _lightness_lightbg[1] -end - -function gradient_from_list(cs) - zvalues = Plots.get_zvalues(length(cs)) - indices = sortperm(zvalues) - sorted_colors = map(RGBA, cs[indices]) - sorted_zvalues = zvalues[indices] - ColorGradient(sorted_colors, sorted_zvalues) -end - -function generate_colorgradient(bgcolor = colorant"white"; - color_bases = color_bases=[colorant"steelblue",colorant"orangered"], - lightness = lightness_from_background(bgcolor), - chroma = _lch_c_const[1], - n = _defaultNumColors) - seed_colors = vcat(bgcolor, map(c -> adjust_lch(c, lightness, chroma), color_bases)) - colors = distinguishable_colors(n, - seed_colors, - lchoices=Float64[lightness], - cchoices=Float64[chroma], - hchoices=range(0, stop=340, length=20) - )[2:end] - gradient_from_list(colors) -end - -function get_color_palette(palette, bgcolor::Union{Colorant,ColorWrapper}, numcolors::Integer) - grad = if palette == :auto - generate_colorgradient(bgcolor) - else - ColorGradient(palette) - end - zrng = get_zvalues(numcolors) - RGBA[getColorZ(grad, z) for z in zrng] -end - -function get_color_palette(palette::Vector{C}, -bgcolor::Union{Colorant,ColorWrapper}, numcolors::Integer) where C<:Colorant - palette -end - -# ---------------------------------------------------------------------------------- - - -function getpctrange(n::Int) - n > 0 || error() - n == 1 && return zeros(1) - zs = [0.0, 1.0] - for i in 3:n - sorted = sort(zs) - diffs = diff(sorted) - widestj = 0 - widest = 0.0 - for (j,d) in enumerate(diffs) - if d > widest - widest = d - widestj = j - end - end - push!(zs, sorted[widestj] + 0.5 * diffs[widestj]) - end - zs -end - -function get_zvalues(n::Int) - offsets = getpctrange(ceil(Int,n/4)+1)/4 - offsets = vcat(offsets[1], offsets[3:end]) - zvalues = Float64[] - for offset in offsets - append!(zvalues, offset + [0.0, 0.5, 0.25, 0.75]) - end - vcat(zvalues[1], 1.0, zvalues[2:n-1]) -end - -# ---------------------------------------------------------------------------------- - - -make255(x) = round(Int, 255 * x) - -function webcolor(c::Color) - @sprintf("rgb(%d, %d, %d)", [make255(f(c)) for f in [red,green,blue]]...) -end -function webcolor(c::TransparentColor) - @sprintf("rgba(%d, %d, %d, %1.3f)", [make255(f(c)) for f in [red,green,blue]]..., alpha(c)) -end -webcolor(cs::ColorScheme) = webcolor(getColor(cs)) -webcolor(c) = webcolor(convertColor(c)) -webcolor(c, α) = webcolor(convertColor(getColor(c), α)) - -# ---------------------------------------------------------------------------------- - - -# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically -function getSeriesRGBColor(c, sp::Subplot, n::Int) - - if c == :auto - c = autopick(sp[:color_palette], n) - end - - # c should now be a subtype of ColorScheme - colorscheme(c) -end diff --git a/src/deprecated/contours.jl b/src/deprecated/contours.jl deleted file mode 100644 index f9ab0954..00000000 --- a/src/deprecated/contours.jl +++ /dev/null @@ -1,63 +0,0 @@ - - -# TODO: -""" -- load Contours.jl similar to DataFrames -- method to build grid from x/y/z vectors -- method to wrap contours creation -- method to plot contours as custom shapes (TODO: create Stroke and Fill types and add markerstroke/markerfill args) - -""" - - - -# # ---------------------------------------------------------- -# # ---------------------------------------------------------- - - -# immutable Vertex -# x::Float64 -# y::Float64 -# z::Float64 -# end - -# immutable Edge -# v::Vertex -# u::Vertex -# end - -# # ---------------------------------------------------------- - -# # one rectangle's z-values and the center vertex -# # z is ordered: topleft, topright, bottomright, bottomleft -# immutable GridRect -# z::Vector{Float64} -# center::Vertex -# data::Vector{Vertex} -# end - - - -# type Grid -# xs::Vector{Float64} -# ys::Vector{Float64} -# rects::Matrix{GridRect} -# end - -# function splitDataEvenly(v::AbstractVector{Float64}, n::Int) -# vs = sort(v) - -# end - -# # the goal here is to create the vertical and horizontal partitions -# # which define the grid, so that the data is somewhat evenly split -# function bucketData(x, y, z) - -# end - - -# function buildGrid(x, y, z) -# # create -# end - - diff --git a/src/deprecated/series_args.jl b/src/deprecated/series_args.jl deleted file mode 100644 index 4dafda80..00000000 --- a/src/deprecated/series_args.jl +++ /dev/null @@ -1,99 +0,0 @@ - -# create a new "build_series_args" which converts all inputs into xs = Any[xitems], ys = Any[yitems]. -# Special handling for: no args, xmin/xmax, parametric, dataframes -# Then once inputs have been converted, build the series args, map functions, etc. -# This should cut down on boilerplate code and allow more focused dispatch on type -# note: returns meta information... mainly for use with automatic labeling from DataFrames for now - -const FuncOrFuncs = Union{Function, AVec{Function}} - -all3D(plotattributes::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image), get(plotattributes, :seriestype, :none)) - -# missing -convertToAnyVector(v::Nothing, plotattributes::KW) = Any[nothing], nothing - -# fixed number of blank series -convertToAnyVector(n::Integer, plotattributes::KW) = Any[zeros(0) for i in 1:n], nothing - -# numeric vector -convertToAnyVector(v::AVec{T}, plotattributes::KW) where {T<:Number} = Any[v], nothing - -# string vector -convertToAnyVector(v::AVec{T}, plotattributes::KW) where {T<:AbstractString} = Any[v], nothing - -function convertToAnyVector(v::AMat, plotattributes::KW) - if all3D(plotattributes) - Any[Surface(v)] - else - Any[v[:,i] for i in 1:size(v,2)] - end, nothing -end - -# function -convertToAnyVector(f::Function, plotattributes::KW) = Any[f], nothing - -# surface -convertToAnyVector(s::Surface, plotattributes::KW) = Any[s], nothing - -# # vector of OHLC -# convertToAnyVector(v::AVec{OHLC}, plotattributes::KW) = Any[v], nothing - -# dates -convertToAnyVector(dts::AVec{D}, plotattributes::KW) where {D<:Union{Date,DateTime}} = Any[dts], nothing - -# list of things (maybe other vectors, functions, or something else) -function convertToAnyVector(v::AVec, plotattributes::KW) - if all(x -> typeof(x) <: Number, v) - # all real numbers wrap the whole vector as one item - Any[convert(Vector{Float64}, v)], nothing - else - # something else... treat each element as an item - vcat(Any[convertToAnyVector(vi, plotattributes)[1] for vi in v]...), nothing - # Any[vi for vi in v], nothing - end -end - -convertToAnyVector(t::Tuple, plotattributes::KW) = Any[t], nothing - - -function convertToAnyVector(args...) - error("In convertToAnyVector, could not handle the argument types: $(map(typeof, args[1:end-1]))") -end - -# -------------------------------------------------------------------- - -# TODO: can we avoid the copy here? one error that crops up is that mapping functions over the same array -# result in that array being shared. push!, etc will add too many items to that array - -compute_x(x::Nothing, y::Nothing, z) = 1:size(z,1) -compute_x(x::Nothing, y, z) = 1:size(y,1) -compute_x(x::Function, y, z) = map(x, y) -compute_x(x, y, z) = copy(x) - -# compute_y(x::Void, y::Function, z) = error() -compute_y(x::Nothing, y::Nothing, z) = 1:size(z,2) -compute_y(x, y::Function, z) = map(y, x) -compute_y(x, y, z) = copy(y) - -compute_z(x, y, z::Function) = map(z, x, y) -compute_z(x, y, z::AbstractMatrix) = Surface(z) -compute_z(x, y, z::Nothing) = nothing -compute_z(x, y, z) = copy(z) - -nobigs(v::AVec{BigFloat}) = map(Float64, v) -nobigs(v::AVec{BigInt}) = map(Int64, v) -nobigs(v) = v - -@noinline function compute_xyz(x, y, z) - x = compute_x(x,y,z) - y = compute_y(x,y,z) - z = compute_z(x,y,z) - nobigs(x), nobigs(y), nobigs(z) -end - -# not allowed -compute_xyz(x::Nothing, y::FuncOrFuncs, z) = error("If you want to plot the function `$y`, you need to define the x values!") -compute_xyz(x::Nothing, y::Nothing, z::FuncOrFuncs) = error("If you want to plot the function `$z`, you need to define x and y values!") -compute_xyz(x::Nothing, y::Nothing, z::Nothing) = error("x/y/z are all nothing!") - -# -------------------------------------------------------------------- diff --git a/src/utils.jl b/src/utils.jl index c52ba186..f80244b1 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -737,7 +737,7 @@ function with(f::Function, args...; kw...) end # # TODO: generalize this strategy to allow args as much as possible - # # as in: with(:gadfly, :scatter, :legend, :grid) do; ...; end + # # as in: with(:gr, :scatter, :legend, :grid) do; ...; end # # TODO: can we generalize this enough to also do something similar in the plot commands?? # k = :seriestype diff --git a/test/runtests.jl b/test/runtests.jl index f98f877c..1587d1bb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -87,16 +87,6 @@ end # # @static Sys.islinux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], tol=img_tol) # end - -# @testset "Immerse" begin -# @test immerse() == Plots.ImmerseBackend() -# @test backend() == Plots.ImmerseBackend() -# -# # as long as we can plot anything without error, it should be the same as Gadfly -# image_comparison_facts(:immerse, only=[1], tol=img_tol) -# end - - # @testset "PlotlyJS" begin # @test plotlyjs() == Plots.PlotlyJSBackend() # @test backend() == Plots.PlotlyJSBackend() @@ -106,19 +96,6 @@ end # end -# @testset "Gadfly" begin -# @test gadfly() == Plots.GadflyBackend() -# @test backend() == Plots.GadflyBackend() -# -# @test typeof(plot(1:10)) == Plots.Plot{Plots.GadflyBackend} -# @test plot(Int[1,2,3], rand(3)) == not(nothing) -# @test plot(sort(rand(10)), rand(Int, 10, 3)) == not(nothing) -# @test plot!(rand(10,3), rand(10,3)) == not(nothing) -# -# image_comparison_facts(:gadfly, skip=[4,6,23,24,27], tol=img_tol) -# end - - @testset "Axes" begin From 1386435b17f76a9ac4811516ea964881d1fa91b9 Mon Sep 17 00:00:00 2001 From: Michael Krabbe Borregaard Date: Tue, 30 Oct 2018 11:08:08 +0100 Subject: [PATCH 2/2] Completely deprecate glvisualize --- NEWS.md | 2 +- src/backends.jl | 70 +- src/backends/glvisualize.jl | 1472 ----------------------------------- src/init.jl | 1 - src/output.jl | 1 - 5 files changed, 3 insertions(+), 1543 deletions(-) delete mode 100644 src/backends/glvisualize.jl diff --git a/NEWS.md b/NEWS.md index 703c2b2e..3510105e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,7 +10,7 @@ --- ## (current master) -- All new development should target Julia 1.x! +- deprecate GLVisualize ## 0.20.6 - fixes for PlotDocs.jl diff --git a/src/backends.jl b/src/backends.jl index d64db5e4..11cea85e 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -157,7 +157,7 @@ function pickDefaultBackend() # the ordering/inclusion of this package list is my semi-arbitrary guess at # which one someone will want to use if they have the package installed...accounting for # features, speed, and robustness - # for pkgstr in ("GR", "PyPlot", "PlotlyJS", "PGFPlots", "UnicodePlots", "InspectDR", "GLVisualize") + # for pkgstr in ("GR", "PyPlot", "PlotlyJS", "PGFPlots", "UnicodePlots", "InspectDR") # if pkgstr in keys(Pkg.installed()) # return backend(Symbol(lowercase(pkgstr))) # end @@ -213,7 +213,7 @@ function backend(sym::Symbol) backend() end -const _deprecated_backends = [:qwt, :winston, :bokeh, :gadfly, :immerse] +const _deprecated_backends = [:qwt, :winston, :bokeh, :gadfly, :immerse, :glvisualize] function warn_on_deprecated_backend(bsym::Symbol) if bsym in _deprecated_backends @@ -273,7 +273,6 @@ end @init_backend Plotly @init_backend PlotlyJS @init_backend GR -@init_backend GLVisualize @init_backend PGFPlots @init_backend InspectDR @init_backend HDF5 @@ -445,71 +444,6 @@ const _plotly_marker = [ ] const _plotly_scale = [:identity, :log10] -# ------------------------------------------------------------------------------ -# glvisualize - -function _initialize_backend(::GLVisualizeBackend; kw...) - @eval Main begin - import GLVisualize, GeometryTypes, Reactive, GLAbstraction, GLWindow, Contour - import GeometryTypes: Point2f0, Point3f0, Vec2f0, Vec3f0, GLNormalMesh, SimpleRectangle, Point, Vec - import FileIO, Images - export GLVisualize - import Reactive: Signal - import GLAbstraction: Style - import GLVisualize: visualize - import Plots.GL - import UnicodeFun - end -end - -const _glvisualize_attr = merge_with_base_supported([ - :annotations, - :background_color_legend, :background_color_inside, :background_color_outside, - :foreground_color_grid, :foreground_color_legend, :foreground_color_title, - :foreground_color_axis, :foreground_color_border, :foreground_color_guide, :foreground_color_text, - :label, - :linecolor, :linestyle, :linewidth, :linealpha, - :markershape, :markercolor, :markersize, :markeralpha, - :markerstrokewidth, :markerstrokecolor, :markerstrokealpha, - :fillrange, :fillcolor, :fillalpha, - :bins, :bar_width, :bar_edges, :bar_position, - :title, :title_location, - :window_title, - :guide, :lims, :ticks, :scale, :flip, :rotation, - :titlefontsize, :titlefontcolor, - :legendfontsize, :legendfontcolor, - :tickfontsize, - :guidefontsize, :guidefontcolor, - :grid, :gridalpha, :gridstyle, :gridlinewidth, - :legend, :colorbar, - :marker_z, - :line_z, - :levels, - :ribbon, :quiver, :arrow, - :orientation, - :overwrite_figure, - #:polar, - :normalize, :weights, - :contours, :aspect_ratio, - :match_dimensions, - :clims, - :inset_subplots, - :dpi, - :hover, - :framestyle, - :tick_direction, -]) -const _glvisualize_seriestype = [ - :path, :shape, :straightline, - :scatter, :hexbin, - :bar, :boxplot, - :heatmap, :image, :volume, - :contour, :contour3d, :path3d, :scatter3d, :surface, :wireframe -] -const _glvisualize_style = [:auto, :solid, :dash, :dot, :dashdot] -const _glvisualize_marker = _allMarkers -const _glvisualize_scale = [:identity, :ln, :log2, :log10] - # ------------------------------------------------------------------------------ # pgfplots diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl deleted file mode 100644 index 72f7c74e..00000000 --- a/src/backends/glvisualize.jl +++ /dev/null @@ -1,1472 +0,0 @@ -#= -TODO - * move all gl_ methods to GLPlot - * integrate GLPlot UI - * clean up corner cases - * find a cleaner way for extracting properties - * polar plots - * labes and axis - * fix units in all visuals (e.g dotted lines, marker scale, surfaces) -=# - - - -slice_arg(img::Matrix{C}, idx::Int) where {C<:Colorant} = img -is_marker_supported(::GLVisualizeBackend, shape::GLVisualize.AllPrimitives) = true -is_marker_supported(::GLVisualizeBackend, shape::Union{Vector{Matrix{C}}, Matrix{C}}) where {C<:Colorant} = true -is_marker_supported(::GLVisualizeBackend, shape::Shape) = true -GL = Plots - -# --------------------------------------------------------------------------- - -# initialize the figure/window -# function _create_backend_figure(plt::Plot{GLVisualizeBackend}) -# # init a screen -# -# GLPlot.init() -# end -const _glplot_deletes = [] - - -function get_plot_screen(list::Vector, name, result = []) - for elem in list - get_plot_screen(elem, name, result) - end - return result -end -function get_plot_screen(screen, name, result = []) - if screen.name == name - push!(result, screen) - return result - end - get_plot_screen(screen.children, name, result) -end - -function create_window(plt::Plot{GLVisualizeBackend}, visible) - name = Symbol("__Plots.jl") - # make sure we have any screen open - if isempty(GLVisualize.get_screens()) - # create a fresh, new screen - parent_screen = GLVisualize.glscreen( - "Plots", - resolution = plt[:size], - visible = visible - ) - @async GLWindow.renderloop(parent_screen) - GLVisualize.add_screen(parent_screen) - end - # now lets get ourselves a permanent Plotting screen - plot_screens = get_plot_screen(GLVisualize.current_screen(), name) - screen = if isempty(plot_screens) # no screen with `name` - parent = GLVisualize.current_screen() - screen = GLWindow.Screen( - parent, area = map(GLWindow.zeroposition, parent.area), - name = name - ) - screen - elseif length(plot_screens) == 1 - plot_screens[1] - else - # okay this is silly! Lets see if we can. There is an ID we could use - # will not be fine for more than 255 screens though -.-. - error("multiple Plot screens. Please don't use any screen with the name $name") - end - # Since we own this window, we can do deep cleansing - empty!(screen) - plt.o = screen - GLWindow.set_visibility!(screen, visible) - resize!(screen, plt[:size]...) - screen -end -# --------------------------------------------------------------------------- - -const _gl_marker_map = KW( - :rect => '■', - :star5 => '★', - :diamond => '◆', - :hexagon => '⬢', - :cross => '✚', - :xcross => '❌', - :utriangle => '▲', - :dtriangle => '▼', - :ltriangle => '◀', - :rtriangle => '▶', - :pentagon => '⬟', - :octagon => '⯄', - :star4 => '✦', - :star6 => '🟋', - :star8 => '✷', - :vline => '┃', - :hline => '━', - :+ => '+', - :x => 'x', - :circle => '●' -) - -function gl_marker(shape) - shape -end -function gl_marker(shape::Shape) - points = Point2f0[GeometryTypes.Vec{2, Float32}(p) for p in zip(shape.x, shape.y)] - bb = GeometryTypes.AABB(points) - mini, maxi = minimum(bb), maximum(bb) - w3 = maxi-mini - origin, width = Point2f0(mini[1], mini[2]), Point2f0(w3[1], w3[2]) - map!(p -> ((p - origin) ./ width) - 0.5f0, points, points) # normalize and center - GeometryTypes.GLNormalMesh(points) -end -# create a marker/shape type -function gl_marker(shape::Vector{Symbol}) - String(map(shape) do sym - get(_gl_marker_map, sym, '●') - end) -end - -function gl_marker(shape::Symbol) - if shape == :rect - GeometryTypes.HyperRectangle(Vec2f0(0), Vec2f0(1)) - elseif shape == :circle || shape == :none - GeometryTypes.HyperSphere(Point2f0(0), 1f0) - elseif haskey(_gl_marker_map, shape) - _gl_marker_map[shape] - elseif haskey(_shapes, shape) - gl_marker(_shapes[shape]) - else - error("Shape $shape not supported by GLVisualize") - end -end - -function extract_limits(sp, plotattributes, kw_args) - clims = sp[:clims] - if is_2tuple(clims) - if isfinite(clims[1]) && isfinite(clims[2]) - kw_args[:limits] = Vec2f0(clims) - end - end - nothing -end - -to_vec(::Type{T}, vec::T) where {T <: StaticArrays.StaticVector} = vec -to_vec(::Type{T}, s::Number) where {T <: StaticArrays.StaticVector} = T(s) - -to_vec(::Type{T}, vec::StaticArrays.StaticVector{3}) where {T <: StaticArrays.StaticVector{2}} = T(vec[1], vec[2]) -to_vec(::Type{T}, vec::StaticArrays.StaticVector{2}) where {T <: StaticArrays.StaticVector{3}} = T(vec[1], vec[2], 0) - -to_vec(::Type{T}, vecs::AbstractVector) where {T <: StaticArrays.StaticVector} = map(x-> to_vec(T, x), vecs) - -function extract_marker(plotattributes, kw_args) - dim = Plots.is3d(plotattributes) ? 3 : 2 - scaling = dim == 3 ? 0.003 : 2 - if haskey(plotattributes, :markershape) - shape = plotattributes[:markershape] - shape = gl_marker(shape) - if shape != :none - kw_args[:primitive] = shape - end - end - dim = isa(kw_args[:primitive], GLVisualize.Sprites) ? 2 : 3 - if haskey(plotattributes, :markersize) - msize = plotattributes[:markersize] - kw_args[:scale] = to_vec(GeometryTypes.Vec{dim, Float32}, msize .* scaling) - end - if haskey(plotattributes, :offset) - kw_args[:offset] = plotattributes[:offset] - end - # get the color - key = :markercolor - haskey(plotattributes, key) || return - c = gl_color(plotattributes[key]) - if isa(c, AbstractVector) && plotattributes[:marker_z] != nothing - extract_colornorm(plotattributes, kw_args) - kw_args[:color] = nothing - kw_args[:color_map] = c - kw_args[:intensity] = convert(Vector{Float32}, plotattributes[:marker_z]) - else - kw_args[:color] = c - end - key = :markerstrokecolor - haskey(plotattributes, key) || return - c = gl_color(plotattributes[key]) - if c != nothing - if !(isa(c, Colorant) || (isa(c, Vector) && eltype(c) <: Colorant)) - error("Stroke Color not supported: $c") - end - kw_args[:stroke_color] = c - kw_args[:stroke_width] = Float32(plotattributes[:markerstrokewidth]) - end -end - -function _extract_surface(plotattributes::Plots.Surface) - plotattributes.surf -end -function _extract_surface(plotattributes::AbstractArray) - plotattributes -end - -# TODO when to transpose?? -function extract_surface(plotattributes) - map(_extract_surface, (plotattributes[:x], plotattributes[:y], plotattributes[:z])) -end -function topoints(::Type{P}, array) where P - [P(x) for x in zip(array...)] -end -function extract_points(plotattributes) - dim = is3d(plotattributes) ? 3 : 2 - array = if plotattributes[:seriestype] == :straightline - straightline_data(plotattributes) - elseif plotattributes[:seriestype] == :shape - shape_data(plotattributes) - else - (plotattributes[:x], plotattributes[:y], plotattributes[:z])[1:dim] - end - topoints(Point{dim, Float32}, array) -end -function make_gradient(grad::Vector{C}) where C <: Colorant - grad -end -function make_gradient(grad::ColorGradient) - RGBA{Float32}[c for c in grad.colors] -end -make_gradient(c) = make_gradient(cgrad()) - -function extract_any_color(plotattributes, kw_args) - if plotattributes[:marker_z] == nothing - c = scalar_color(plotattributes, :fill) - extract_c(plotattributes, kw_args, :fill) - if isa(c, Colorant) - kw_args[:color] = c - else - kw_args[:color] = nothing - kw_args[:color_map] = make_gradient(c) - clims = plotattributes[:subplot][:clims] - if Plots.is_2tuple(clims) - if isfinite(clims[1]) && isfinite(clims[2]) - kw_args[:color_norm] = Vec2f0(clims) - end - elseif clims == :auto - kw_args[:color_norm] = Vec2f0(ignorenan_extrema(plotattributes[:y])) - end - end - else - kw_args[:color] = nothing - clims = plotattributes[:subplot][:clims] - if Plots.is_2tuple(clims) - if isfinite(clims[1]) && isfinite(clims[2]) - kw_args[:color_norm] = Vec2f0(clims) - end - elseif clims == :auto - kw_args[:color_norm] = Vec2f0(ignorenan_extrema(plotattributes[:y])) - else - error("Unsupported limits: $clims") - end - kw_args[:intensity] = convert(Vector{Float32}, plotattributes[:marker_z]) - kw_args[:color_map] = gl_color_map(plotattributes, :marker) - end -end - -function extract_stroke(plotattributes, kw_args) - extract_c(plotattributes, kw_args, :line) - if haskey(plotattributes, :linewidth) - kw_args[:thickness] = Float32(plotattributes[:linewidth] * 3) - end -end - -function extract_color(plotattributes, sym) - plotattributes[Symbol("$(sym)color")] -end - -gl_color(c::PlotUtils.ColorGradient) = c.colors -gl_color(c::Vector{T}) where {T<:Colorant} = c -gl_color(c::RGBA{Float32}) = c -gl_color(c::Colorant) = RGBA{Float32}(c) - -function gl_color(tuple::Tuple) - gl_color(tuple...) -end - -# convert to RGBA -function gl_color(c, a) - c = convertColor(c, a) - RGBA{Float32}(c) -end -function scalar_color(plotattributes, sym) - gl_color(extract_color(plotattributes, sym)) -end - -function gl_color_map(plotattributes, sym) - colors = extract_color(plotattributes, sym) - _gl_color_map(colors) -end -function _gl_color_map(colors::PlotUtils.ColorGradient) - colors.colors -end -function _gl_color_map(c) - Plots.default_gradient() -end - - - -dist(a, b) = abs(a-b) -mindist(x, a, b) = NaNMath.min(dist(a, x), dist(b, x)) - -function gappy(x, ps) - n = length(ps) - x <= first(ps) && return first(ps) - x - for j=1:(n-1) - p0 = ps[j] - p1 = ps[NaNMath.min(j+1, n)] - if p0 <= x && p1 >= x - return mindist(x, p0, p1) * (isodd(j) ? 1 : -1) - end - end - return last(ps) - x -end -function ticks(points, resolution) - Float16[gappy(x, points) for x = range(first(points), stop=last(points), length=resolution)] -end - - -function insert_pattern!(points, kw_args) - tex = GLAbstraction.Texture(ticks(points, 100), x_repeat=:repeat) - kw_args[:pattern] = tex - kw_args[:pattern_length] = Float32(last(points)) -end -function extract_linestyle(plotattributes, kw_args) - haskey(plotattributes, :linestyle) || return - ls = plotattributes[:linestyle] - lw = plotattributes[:linewidth] - kw_args[:thickness] = Float32(lw) - if ls == :dash - points = [0.0, lw, 2lw, 3lw, 4lw] - insert_pattern!(points, kw_args) - elseif ls == :dot - tick, gap = lw/2, lw/4 - points = [0.0, tick, tick+gap, 2tick+gap, 2tick+2gap] - insert_pattern!(points, kw_args) - elseif ls == :dashdot - dtick, dgap = lw, lw - ptick, pgap = lw/2, lw/4 - points = [0.0, dtick, dtick+dgap, dtick+dgap+ptick, dtick+dgap+ptick+pgap] - insert_pattern!(points, kw_args) - elseif ls == :dashdotdot - dtick, dgap = lw, lw - ptick, pgap = lw/2, lw/4 - points = [0.0, dtick, dtick+dgap, dtick+dgap+ptick, dtick+dgap+ptick+pgap, dtick+dgap+ptick+pgap+ptick, dtick+dgap+ptick+pgap+ptick+pgap] - insert_pattern!(points, kw_args) - end - extract_c(plotattributes, kw_args, :line) - nothing -end - -function hover(to_hover::Vector, to_display, window) - hover(to_hover[], to_display, window) -end - -function get_cam(x) - if isa(x, GLAbstraction.Context) - return get_cam(x.children) - elseif isa(x, Vector) - return get_cam(first(x)) - elseif isa(x, GLAbstraction.RenderObject) - return x[:preferred_camera] - end -end - - -function hover(to_hover, to_display, window) - if isa(to_hover, GLAbstraction.Context) - return hover(to_hover.children, to_display, window) - end - area = map(window.inputs[:mouseposition]) do mp - SimpleRectangle{Int}(round(Int, mp+10)..., 100, 70) - end - mh = GLWindow.mouse2id(window) - popup = GLWindow.Screen( - window, - hidden = map(mh-> !(mh.id == to_hover.id), mh), - area = area, - stroke = (2f0, RGBA(0f0, 0f0, 0f0, 0.8f0)) - ) - cam = get!(popup.cameras, :perspective) do - GLAbstraction.PerspectiveCamera( - popup.inputs, Vec3f0(3), Vec3f0(0), - keep = Signal(false), - theta = Signal(Vec3f0(0)), trans = Signal(Vec3f0(0)) - ) - end - - map(enumerate(to_display)) do id - i,d = id - robj = visualize(d) - viewit = Reactive.droprepeats(map(mh->mh.id == to_hover.id && mh.index == i, mh)) - camtype = get_cam(robj) - Reactive.preserve(map(viewit) do vi - if vi - empty!(popup) - if camtype == :perspective - cam.projectiontype.value = GLVisualize.PERSPECTIVE - else - cam.projectiontype.value = GLVisualize.ORTHOGRAPHIC - end - GLVisualize._view(robj, popup, camera = cam) - 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 + 2 * wborder) - GLAbstraction.center!(cam, bb) - end - end) - end - nothing -end - -function extract_extrema(plotattributes, kw_args) - xmin, xmax = ignorenan_extrema(plotattributes[:x]); ymin, ymax = ignorenan_extrema(plotattributes[:y]) - kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(xmin, ymin, xmax-xmin, ymax-ymin) - nothing -end - -function extract_font(font, kw_args) - kw_args[:family] = font.family - kw_args[:relative_scale] = pointsize(font) - kw_args[:color] = gl_color(font.color) -end - -function extract_colornorm(plotattributes, kw_args) - clims = plotattributes[:subplot][:clims] - if Plots.is_2tuple(clims) - if isfinite(clims[1]) && isfinite(clims[2]) - kw_args[:color_norm] = Vec2f0(clims) - end - elseif clims == :auto - z = if haskey(plotattributes, :marker_z) && plotattributes[:marker_z] != nothing - plotattributes[:marker_z] - elseif haskey(plotattributes, :line_z) && plotattributes[:line_z] != nothing - plotattributes[:line_z] - elseif isa(plotattributes[:z], Plots.Surface) - plotattributes[:z].surf - else - plotattributes[:y] - end - kw_args[:color_norm] = Vec2f0(ignorenan_extrema(z)) - kw_args[:intensity] = map(Float32, collect(z)) - end -end - -function extract_gradient(plotattributes, kw_args, sym) - key = Symbol("$(sym)color") - haskey(plotattributes, key) || return - c = make_gradient(plotattributes[key]) - kw_args[:color] = nothing - extract_colornorm(plotattributes, kw_args) - kw_args[:color_map] = c - return -end - -function extract_c(plotattributes, kw_args, sym) - key = Symbol("$(sym)color") - haskey(plotattributes, key) || return - c = gl_color(plotattributes[key]) - kw_args[:color] = nothing - kw_args[:color_map] = nothing - kw_args[:color_norm] = nothing - if ( - isa(c, AbstractVector) && - ((haskey(plotattributes, :marker_z) && plotattributes[:marker_z] != nothing) || - (haskey(plotattributes, :line_z) && plotattributes[:line_z] != nothing)) - ) - extract_colornorm(plotattributes, kw_args) - kw_args[:color_map] = c - else - kw_args[:color] = c - end - return -end - -function extract_stroke(plotattributes, kw_args, sym) - key = Symbol("$(sym)strokecolor") - haskey(plotattributes, key) || return - c = gl_color(plotattributes[key]) - if c != nothing - if !isa(c, Colorant) - error("Stroke Color not supported: $c") - end - kw_args[:stroke_color] = c - kw_args[:stroke_width] = Float32(plotattributes[Symbol("$(sym)strokewidth")]) * 2 - end - return -end - - - -function draw_grid_lines(sp, grid_segs, thickness, style, model, color) - - kw_args = Dict{Symbol, Any}( - :model => model - ) - plotattributes = Dict( - :linestyle => style, - :linewidth => Float32(thickness), - :linecolor => color - ) - Plots.extract_linestyle(plotattributes, kw_args) - GL.gl_lines(map(Point2f0, grid_segs.pts), kw_args) -end - -function align_offset(startpos, lastpos, atlas, rscale, font, align) - xscale, yscale = GLVisualize.glyph_scale!('X', rscale) - xmove = (lastpos-startpos)[1] + xscale - if isa(align, GeometryTypes.Vec) - return -Vec2f0(xmove, yscale) .* align - elseif align == :top - return -Vec2f0(xmove/2f0, yscale) - elseif align == :right - return -Vec2f0(xmove, yscale/2f0) - else - error("Align $align not known") - end -end - - -function alignment2num(x::Symbol) - (x in (:hcenter, :vcenter)) && return 0.5 - (x in (:left, :bottom)) && return 0.0 - (x in (:right, :top)) && return 1.0 - 0.0 # 0 default, or better to error? -end - -function alignment2num(font::Plots.Font) - Vec2f0(map(alignment2num, (font.halign, font.valign))) -end - -pointsize(font) = font.pointsize * 2 - -function draw_ticks( - axis, ticks, isx, isorigin, lims, m, text = "", - positions = Point2f0[], offsets=Vec2f0[] - ) - sz = pointsize(tickfont(axis)) - atlas = GLVisualize.get_texture_atlas() - font = GLVisualize.defaultfont() - - flip = axis[:flip]; mirror = axis[:mirror] - - align = if isx - mirror ? :bottom : :top - else - mirror ? :left : :right - end - axis_gap = Point2f0(isx ? 0 : sz / 2, isx ? sz / 2 : 0) - for (cv, dv) in zip(ticks...) - - x, y = cv, lims[1] - xy = if isorigin - isx ? (x, 0) : (0, x) - else - isx ? (x, y) : (y, x) - end - _pos = m * GeometryTypes.Vec4f0(xy[1], xy[2], 0, 1) - startpos = Point2f0(_pos[1], _pos[2]) - axis_gap - str = string(dv) - # need to tag a new UnicodeFun version for this... also the numbers become - # so small that it looks terrible -.- - # _str = split(string(dv), "^") - # if length(_str) == 2 - # _str[2] = UnicodeFun.to_superscript(_str[2]) - # end - # str = join(_str, "") - position = GLVisualize.calc_position(str, startpos, sz, font, atlas) - offset = GLVisualize.calc_offset(str, sz, font, atlas) - alignoff = align_offset(startpos, last(position), atlas, sz, font, align) - map!(position, position) do pos - pos .+ alignoff - end - append!(positions, position) - append!(offsets, offset) - text *= str - - end - text, positions, offsets -end - -function glvisualize_text(position, text, kw_args) - text_align = alignment2num(text.font) - startpos = Vec2f0(position) - atlas = GLVisualize.get_texture_atlas() - font = GLVisualize.defaultfont() - rscale = kw_args[:relative_scale] - - position = GLVisualize.calc_position(text.str, startpos, rscale, font, atlas) - offset = GLVisualize.calc_offset(text.str, rscale, font, atlas) - alignoff = align_offset(startpos, last(position), atlas, rscale, font, text_align) - - map!(position, position) do pos - pos .+ alignoff - end - kw_args[:position] = position - kw_args[:offset] = offset - kw_args[:scale_primitive] = true - visualize(text.str, Style(:default), kw_args) -end - -function text_model(font, pivot) - pv = GeometryTypes.Vec3f0(pivot[1], pivot[2], 0) - if font.rotation != 0.0 - rot = Float32(deg2rad(font.rotation)) - rotm = GLAbstraction.rotationmatrix_z(rot) - return GLAbstraction.translationmatrix(pv)*rotm*GLAbstraction.translationmatrix(-pv) - else - eye(GeometryTypes.Mat4f0) - end -end -function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, area) - xticks, yticks, xspine_segs, yspine_segs, xtick_segs, ytick_segs, xgrid_segs, ygrid_segs, xminorgrid_segs, yminorgrid_segs, xborder_segs, yborder_segs = Plots.axis_drawing_info(sp) - xaxis = sp[:xaxis]; yaxis = sp[:yaxis] - - xgc = Colors.color(Plots.gl_color(xaxis[:foreground_color_grid])) - ygc = Colors.color(Plots.gl_color(yaxis[:foreground_color_grid])) - axis_vis = [] - if xaxis[:grid] - grid = draw_grid_lines(sp, xgrid_segs, xaxis[:gridlinewidth], xaxis[:gridstyle], model, RGBA(xgc, xaxis[:gridalpha])) - push!(axis_vis, grid) - end - if yaxis[:grid] - grid = draw_grid_lines(sp, ygrid_segs, yaxis[:gridlinewidth], yaxis[:gridstyle], model, RGBA(ygc, yaxis[:gridalpha])) - push!(axis_vis, grid) - end - if xaxis[:minorgrid] - minorgrid = draw_minorgrid_lines(sp, xminorgrid_segs, xaxis[:minorgridlinewidth], xaxis[:minorgridstyle], model, RGBA(xgc, xaxis[:minorgridalpha])) - push!(axis_vis, minorgrid) - end - if yaxis[:minorgrid] - minorgrid = draw_minorgrid_lines(sp, yminorgrid_segs, yaxis[:minorgridlinewidth], yaxis[:minorgridstyle], model, RGBA(ygc, yaxis[:minorgridalpha])) - push!(axis_vis, minorgrid) - end - - xac = Colors.color(Plots.gl_color(xaxis[:foreground_color_axis])) - yac = Colors.color(Plots.gl_color(yaxis[:foreground_color_axis])) - if alpha(xaxis[:foreground_color_axis]) > 0 - spine = draw_grid_lines(sp, xspine_segs, 1f0, :solid, model, RGBA(xac, 1.0f0)) - push!(axis_vis, spine) - end - if alpha(yaxis[:foreground_color_axis]) > 0 - spine = draw_grid_lines(sp, yspine_segs, 1f0, :solid, model, RGBA(yac, 1.0f0)) - push!(axis_vis, spine) - end - if sp[:framestyle] in (:zerolines, :grid) - if alpha(xaxis[:foreground_color_grid]) > 0 - spine = draw_grid_lines(sp, xtick_segs, 1f0, :solid, model, RGBA(xgc, xaxis[:gridalpha])) - push!(axis_vis, spine) - end - if alpha(yaxis[:foreground_color_grid]) > 0 - spine = draw_grid_lines(sp, ytick_segs, 1f0, :solid, model, RGBA(ygc, yaxis[:gridalpha])) - push!(axis_vis, spine) - end - else - if alpha(xaxis[:foreground_color_axis]) > 0 - spine = draw_grid_lines(sp, xtick_segs, 1f0, :solid, model, RGBA(xac, 1.0f0)) - push!(axis_vis, spine) - end - if alpha(yaxis[:foreground_color_axis]) > 0 - spine = draw_grid_lines(sp, ytick_segs, 1f0, :solid, model, RGBA(yac, 1.0f0)) - push!(axis_vis, spine) - end - end - fcolor = Plots.gl_color(xaxis[:foreground_color_axis]) - - xlim = Plots.axis_limits(xaxis) - ylim = Plots.axis_limits(yaxis) - - if !(xaxis[:ticks] in (nothing, false, :none)) && !(sp[:framestyle] == :none) && xaxis[:showaxis] - ticklabels = map(model) do m - mirror = xaxis[:mirror] - t, positions, offsets = draw_ticks(xaxis, xticks, true, sp[:framestyle] == :origin, ylim, m) - end - kw_args = Dict{Symbol, Any}( - :position => map(x-> x[2], ticklabels), - :offset => map(last, ticklabels), - :color => fcolor, - :relative_scale => pointsize(tickfont(xaxis)), - :scale_primitive => false - ) - push!(axis_vis, visualize(map(first, ticklabels), Style(:default), kw_args)) - end - - if !(yaxis[:ticks] in (nothing, false, :none)) && !(sp[:framestyle] == :none) && yaxis[:showaxis] - ticklabels = map(model) do m - mirror = yaxis[:mirror] - t, positions, offsets = draw_ticks(yaxis, yticks, false, sp[:framestyle] == :origin, xlim, m) - end - kw_args = Dict{Symbol, Any}( - :position => map(x-> x[2], ticklabels), - :offset => map(last, ticklabels), - :color => fcolor, - :relative_scale => pointsize(tickfont(xaxis)), - :scale_primitive => false - ) - push!(axis_vis, visualize(map(first, ticklabels), Style(:default), kw_args)) - end - - xbc = Colors.color(Plots.gl_color(xaxis[:foreground_color_border])) - ybc = Colors.color(Plots.gl_color(yaxis[:foreground_color_border])) - intensity = sp[:framestyle] == :semi ? 0.5f0 : 1.0f0 - if sp[:framestyle] in (:box, :semi) - xborder = draw_grid_lines(sp, xborder_segs, intensity, :solid, model, RGBA(xbc, intensity)) - yborder = draw_grid_lines(sp, yborder_segs, intensity, :solid, model, RGBA(ybc, intensity)) - push!(axis_vis, xborder, yborder) - end - - area_w = GeometryTypes.widths(area) - if sp[:title] != "" - tf = titlefont(sp) - font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, tf.rotation, tf.color) - xy = Point2f0(area.w/2, area_w[2] + pointsize(tf)/2) - kw = Dict(:model => text_model(font, xy), :scale_primitive => true) - extract_font(font, kw) - t = PlotText(sp[:title], font) - push!(axis_vis, glvisualize_text(xy, t, kw)) - end - if xaxis[:guide] != "" - tf = guidefont(xaxis) - xy = Point2f0(area.w/2, - pointsize(tf)/2) - font = Plots.Font(tf.family, tf.pointsize, :hcenter, :bottom, tf.rotation, tf.color) - kw = Dict(:model => text_model(font, xy), :scale_primitive => true) - t = PlotText(xaxis[:guide], font) - extract_font(font, kw) - push!(axis_vis, glvisualize_text(xy, t, kw)) - end - - if yaxis[:guide] != "" - tf = guidefont(yaxis) - font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, 90f0, tf.color) - xy = Point2f0(-pointsize(tf)/2, area.h/2) - kw = Dict(:model => text_model(font, xy), :scale_primitive=>true) - t = PlotText(yaxis[:guide], font) - extract_font(font, kw) - push!(axis_vis, glvisualize_text(xy, t, kw)) - end - - axis_vis -end - -function gl_draw_axes_3d(sp, model) - x = Plots.axis_limits(sp[:xaxis]) - y = Plots.axis_limits(sp[:yaxis]) - z = Plots.axis_limits(sp[:zaxis]) - - min = Vec3f0(x[1], y[1], z[1]) - visualize( - GeometryTypes.AABB{Float32}(min, Vec3f0(x[2], y[2], z[2])-min), - :grid, model=model - ) -end - -function gl_bar(plotattributes, kw_args) - x, y = plotattributes[:x], plotattributes[:y] - nx, ny = length(x), length(y) - axis = plotattributes[:subplot][isvertical(plotattributes) ? :xaxis : :yaxis] - cv = [discrete_value!(axis, xi)[1] for xi=x] - x = if nx == ny - cv - elseif nx == ny + 1 - 0.5diff(cv) + cv[1:end-1] - else - error("bar recipe: x must be same length as y (centers), or one more than y (edges).\n\t\tlength(x)=$(length(x)), length(y)=$(length(y))") - end - if haskey(kw_args, :stroke_width) # stroke is inside for bars - #kw_args[:stroke_width] = -kw_args[:stroke_width] - end - # compute half-width of bars - bw = nothing - hw = if bw == nothing - ignorenan_mean(diff(x)) - else - Float64[_cycle(bw,i)*0.5 for i=1:length(x)] - end - - # make fillto a vector... default fills to 0 - fillto = plotattributes[:fillrange] - if fillto == nothing - fillto = 0 - end - # create the bar shapes by adding x/y segments - positions, scales = Array{Point2f0}(undef, ny), Array{Vec2f0}(undef, ny) - m = Reactive.value(kw_args[:model]) - sx, sy = m[1,1], m[2,2] - for i=1:ny - center = x[i] - hwi = abs(_cycle(hw,i)); yi = y[i]; fi = _cycle(fillto,i) - if Plots.isvertical(plotattributes) - sz = (hwi*sx, yi*sy) - else - sz = (yi*sx, hwi*2*sy) - end - positions[i] = (center-hwi*0.5, fi) - scales[i] = sz - end - - kw_args[:scale] = scales - kw_args[:offset] = Vec2f0(0) - visualize((GLVisualize.RECTANGLE, positions), Style(:default), kw_args) - #[] -end - -const _box_halfwidth = 0.4 - -notch_width(q2, q4, N) = 1.58 * (q4-q2)/sqrt(N) - -function gl_boxplot(plotattributes, kw_args) - kwbox = copy(kw_args) - range = 1.5; notch = false - x, y = plotattributes[:x], plotattributes[:y] - glabels = sort(collect(unique(x))) - warning = false - outliers_x, outliers_y = zeros(0), zeros(0) - - box_pos = Point2f0[] - box_scale = Vec2f0[] - outliers = Point2f0[] - t_segments = Point2f0[] - m = Reactive.value(kw_args[:model]) - sx, sy = m[1,1], m[2,2] - for (i,glabel) in enumerate(glabels) - # filter y - values = y[filter(i -> _cycle(x,i) == glabel, 1:length(y))] - # compute quantiles - q1,q2,q3,q4,q5 = quantile(values, range(0, stop=1, length=5)) - # notch - n = Plots.notch_width(q2, q4, length(values)) - # warn on inverted notches? - if notch && !warning && ( (q2>(q3-n)) || (q4<(q3+n)) ) - @warn("Boxplot's notch went outside hinges. Set notch to false.") - warning = true # Show the warning only one time - end - - # make the shape - center = Plots.discrete_value!(plotattributes[:subplot][:xaxis], glabel)[1] - hw = plotattributes[:bar_width] == nothing ? Plots._box_halfwidth*2 : _cycle(plotattributes[:bar_width], i) - l, m, r = center - hw/2, center, center + hw/2 - - # internal nodes for notches - L, R = center - 0.5 * hw, center + 0.5 * hw - # outliers - if Float64(range) != 0.0 # if the range is 0.0, the whiskers will extend to the data - limit = range*(q4-q2) - inside = Float64[] - for value in values - if (value < (q2 - limit)) || (value > (q4 + limit)) - push!(outliers, (center, value)) - else - push!(inside, value) - end - end - # change q1 and q5 to show outliers - # using maximum and minimum values inside the limits - q1, q5 = ignorenan_extrema(inside) - end - # Box - if notch - push!(t_segments, (m, q1), (l, q1), (r, q1), (m, q1), (m, q2))# lower T - push!(box_pos, (l, q2));push!(box_scale, (hw*sx, n*sy)) # lower box - push!(box_pos, (l, q4));push!(box_scale, (hw*sx, n*sy)) # upper box - push!(t_segments, (m, q5), (l, q5), (r, q5), (m, q5), (m, q4))# upper T - - else - push!(t_segments, (m, q2), (m, q1), (l, q1), (r, q1))# lower T - push!(box_pos, (l, q2)); push!(box_scale, (hw*sx, (q3-q2)*sy)) # lower box - push!(box_pos, (l, q4)); push!(box_scale, (hw*sx, (q3-q4)*sy)) # upper box - push!(t_segments, (m, q4), (m, q5), (r, q5), (l, q5))# upper T - end - end - kwbox = Dict{Symbol, Any}( - :scale => box_scale, - :model => kw_args[:model], - :offset => Vec2f0(0), - ) - extract_marker(plotattributes, kw_args) - outlier_kw = Dict( - :model => kw_args[:model], - :color => scalar_color(plotattributes, :fill), - :stroke_width => Float32(plotattributes[:markerstrokewidth]), - :stroke_color => scalar_color(plotattributes, :markerstroke), - ) - lines_kw = Dict( - :model => kw_args[:model], - :stroke_width => plotattributes[:linewidth], - :stroke_color => scalar_color(plotattributes, :fill), - ) - vis1 = GLVisualize.visualize((GLVisualize.RECTANGLE, box_pos), Style(:default), kwbox) - vis2 = GLVisualize.visualize((GLVisualize.CIRCLE, outliers), Style(:default), outlier_kw) - vis3 = GLVisualize.visualize(t_segments, Style(:linesegment), lines_kw) - [vis1, vis2, vis3] -end - - -# --------------------------------------------------------------------------- -function gl_viewport(bb, rect) - l, b, bw, bh = bb - rw, rh = rect.w, rect.h - GLVisualize.SimpleRectangle( - round(Int, rw * l), - round(Int, rh * b), - round(Int, rw * bw), - round(Int, rh * bh) - ) -end - -function to_modelmatrix(rect, subrect, rel_plotarea, sp) - xmin, xmax = Plots.axis_limits(sp[:xaxis]) - ymin, ymax = Plots.axis_limits(sp[:yaxis]) - mini, maxi = Vec3f0(xmin, ymin, 0), Vec3f0(xmax, ymax, 1) - if Plots.is3d(sp) - zmin, zmax = Plots.axis_limits(sp[:zaxis]) - mini, maxi = Vec3f0(xmin, ymin, zmin), Vec3f0(xmax, ymax, zmax) - s = Vec3f0(1) ./ (maxi-mini) - return GLAbstraction.scalematrix(s)*GLAbstraction.translationmatrix(-mini) - end - l, b, bw, bh = rel_plotarea - w, h = rect.w*bw, rect.h*bh - x, y = rect.w*l - subrect.x, rect.h*b - subrect.y - t = -mini - s = Vec3f0(w, h, 1) ./ (maxi-mini) - GLAbstraction.translationmatrix(Vec3f0(x,y,0))*GLAbstraction.scalematrix(s)*GLAbstraction.translationmatrix(t) -end - -# ---------------------------------------------------------------- - - -function scale_for_annotations!(series::Series, scaletype::Symbol = :pixels) - anns = series[:series_annotations] - if anns != nothing && anns.baseshape != nothing - # we use baseshape to overwrite the markershape attribute - # with a list of custom shapes for each - msw, msh = anns.scalefactor - offsets = Array{Vec2f0}(undef, length(anns.strs)) - series[:markersize] = map(1:length(anns.strs)) do i - str = _cycle(anns.strs, i) - # get the width and height of the string (in mm) - sw, sh = text_size(str, anns.font.pointsize) - - # how much to scale the base shape? - # note: it's a rough assumption that the shape fills the unit box [-1,-1,1,1], - # so we scale the length-2 shape by 1/2 the total length - xscale = 0.5to_pixels(sw) * 1.8 - yscale = 0.5to_pixels(sh) * 1.8 - - # we save the size of the larger direction to the markersize list, - # and then re-scale a copy of baseshape to match the w/h ratio - s = Vec2f0(xscale, yscale) - offsets[i] = -s - s - end - series[:offset] = offsets - end - return -end - - - - -function _display(plt::Plot{GLVisualizeBackend}, visible = true) - screen = create_window(plt, visible) - sw, sh = plt[:size] - sw, sh = sw*px, sh*px - - for sp in plt.subplots - _3d = Plots.is3d(sp) - # camera = :perspective - # initialize the sub-screen for this subplot - rel_bbox = Plots.bbox_to_pcts(bbox(sp), sw, sh) - sub_area = map(screen.area) do rect - Plots.gl_viewport(rel_bbox, rect) - end - c = plt[:background_color_outside] - sp_screen = GLVisualize.Screen( - screen, color = c, - area = sub_area - ) - sp.o = sp_screen - cam = get!(sp_screen.cameras, :perspective) do - inside = sp_screen.inputs[:mouseinside] - theta = _3d ? nothing : Signal(Vec3f0(0)) # surpress rotation for 2D (nothing will get usual rotation controle) - GLAbstraction.PerspectiveCamera( - sp_screen.inputs, Vec3f0(3), Vec3f0(0), - keep = inside, theta = theta - ) - end - - rel_plotarea = Plots.bbox_to_pcts(plotarea(sp), sw, sh) - model_m = map(Plots.to_modelmatrix, - screen.area, sub_area, - Signal(rel_plotarea), Signal(sp) - ) - - # loop over the series and add them to the subplot - if !_3d - axis = gl_draw_axes_2d(sp, model_m, Reactive.value(sub_area)) - GLVisualize._view(axis, sp_screen, camera=:perspective) - cam.projectiontype.value = GLVisualize.ORTHOGRAPHIC - Reactive.run_till_now() # make sure Reactive.push! arrives - GLAbstraction.center!(cam, - GeometryTypes.AABB( - Vec3f0(-20), Vec3f0((GeometryTypes.widths(sp_screen)+40f0)..., 1) - ) - ) - else - axis = gl_draw_axes_3d(sp, model_m) - GLVisualize._view(axis, sp_screen, camera=:perspective) - push!(cam.projectiontype, GLVisualize.PERSPECTIVE) - end - for series in Plots.series_list(sp) - - plotattributes = series.plotattributes - st = plotattributes[:seriestype]; kw_args = KW() # exctract kw - - kw_args[:model] = model_m # add transformation - if !_3d # 3D is treated differently, since we need boundingboxes for camera - kw_args[:boundingbox] = nothing # don't calculate bb, we dont need it - end - scale_for_annotations!(series) - if st in (:surface, :wireframe) - x, y, z = extract_surface(plotattributes) - extract_gradient(plotattributes, kw_args, :fill) - z = Plots.transpose_z(plotattributes, z, false) - if isa(x, AbstractMatrix) && isa(y, AbstractMatrix) - x, y = Plots.transpose_z(plotattributes, x, false), Plots.transpose_z(plotattributes, y, false) - end - if st == :wireframe - kw_args[:wireframe] = true - kw_args[:stroke_color] = plotattributes[:linecolor] - kw_args[:stroke_width] = Float32(plotattributes[:linewidth]/100f0) - end - vis = GL.gl_surface(x, y, z, kw_args) - elseif (st in (:path, :path3d, :straightline)) && plotattributes[:linewidth] > 0 - kw = copy(kw_args) - points = Plots.extract_points(plotattributes) - extract_linestyle(plotattributes, kw) - vis = GL.gl_lines(points, kw) - if plotattributes[:markershape] != :none - kw = copy(kw_args) - extract_stroke(plotattributes, kw) - extract_marker(plotattributes, kw) - vis2 = GL.gl_scatter(copy(points), kw) - vis = [vis; vis2] - end - if plotattributes[:fillrange] != nothing - kw = copy(kw_args) - fr = plotattributes[:fillrange] - ps = if all(x-> x >= 0, diff(plotattributes[:x])) # if is monotonic - vcat(points, Point2f0[(points[i][1], _cycle(fr, i)) for i=length(points):-1:1]) - else - points - end - extract_c(plotattributes, kw, :fill) - vis = [GL.gl_poly(ps, kw), vis] - end - elseif st in (:scatter, :scatter3d) #|| plotattributes[:markershape] != :none - extract_marker(plotattributes, kw_args) - points = extract_points(plotattributes) - vis = GL.gl_scatter(points, kw_args) - elseif st == :shape - extract_c(plotattributes, kw_args, :fill) - vis = GL.gl_shape(plotattributes, kw_args) - elseif st == :contour - x,y,z = extract_surface(plotattributes) - z = transpose_z(plotattributes, z, false) - extract_extrema(plotattributes, kw_args) - extract_gradient(plotattributes, kw_args, :fill) - kw_args[:fillrange] = plotattributes[:fillrange] - kw_args[:levels] = plotattributes[:levels] - - vis = GL.gl_contour(x,y,z, kw_args) - elseif st == :heatmap - x,y,z = extract_surface(plotattributes) - extract_gradient(plotattributes, kw_args, :fill) - extract_extrema(plotattributes, kw_args) - extract_limits(sp, plotattributes, kw_args) - vis = GL.gl_heatmap(x,y,z, kw_args) - elseif st == :bar - extract_c(plotattributes, kw_args, :fill) - extract_stroke(plotattributes, kw_args, :marker) - vis = gl_bar(plotattributes, kw_args) - elseif st == :image - extract_extrema(plotattributes, kw_args) - vis = GL.gl_image(plotattributes[:z].surf, kw_args) - elseif st == :boxplot - extract_c(plotattributes, kw_args, :fill) - vis = gl_boxplot(plotattributes, kw_args) - elseif st == :volume - volume = plotattributes[:y] - _plotattributes = copy(plotattributes) - _plotattributes[:y] = 0:1 - _plotattributes[:x] = 0:1 - kw_args = KW() - extract_gradient(_plotattributes, kw_args, :fill) - vis = visualize(volume.v, Style(:default), kw_args) - else - error("failed to display plot type $st") - end - - isa(vis, Array) && isempty(vis) && continue # nothing to see here - - GLVisualize._view(vis, sp_screen, camera=:perspective) - if haskey(plotattributes, :hover) && !(plotattributes[:hover] in (false, :none, nothing)) - hover(vis, plotattributes[:hover], sp_screen) - end - if isdefined(:GLPlot) && isdefined(Main.GLPlot, :(register_plot!)) - del_signal = Main.GLPlot.register_plot!(vis, sp_screen, create_gizmo=false) - append!(_glplot_deletes, del_signal) - end - anns = series[:series_annotations] - for (x, y, str, font) in EachAnn(anns, plotattributes[:x], plotattributes[:y]) - txt_args = Dict{Symbol, Any}(:model => eye(GLAbstraction.Mat4f0)) - x, y = Reactive.value(model_m) * GeometryTypes.Vec{4, Float32}(x, y, 0, 1) - extract_font(font, txt_args) - t = glvisualize_text(Point2f0(x, y), PlotText(str, font), txt_args) - GLVisualize._view(t, sp_screen, camera = :perspective) - end - - end - generate_legend(sp, sp_screen, model_m) - if _3d - GLAbstraction.center!(sp_screen) - end - GLAbstraction.post_empty() - yield() - end -end - -function _show(io::IO, ::MIME"image/png", plt::Plot{GLVisualizeBackend}) - _display(plt, false) - GLWindow.poll_glfw() - if Base.n_avail(Reactive._messages) > 0 - Reactive.run_till_now() - end - yield() - GLWindow.render_frame(GLWindow.rootscreen(plt.o)) - GLWindow.swapbuffers(plt.o) - buff = GLWindow.screenbuffer(plt.o) - png = map(RGB{U8}, buff) - FileIO.save(FileIO.Stream(FileIO.DataFormat{:PNG}, io), png) -end - - -function gl_image(img, kw_args) - rect = kw_args[:primitive] - kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(rect.x, rect.y, rect.w, rect.h) - visualize(img, Style(:default), kw_args) -end - -function handle_segment(lines, line_segments, points::Vector{P}, segment) where P - (isempty(segment) || length(segment) < 2) && return - if length(segment) == 2 - append!(line_segments, view(points, segment)) - elseif length(segment) == 3 - p = view(points, segment) - push!(line_segments, p[1], p[2], p[2], p[3]) - else - append!(lines, view(points, segment)) - push!(lines, P(NaN)) - end -end - -function gl_lines(points, kw_args) - result = [] - isempty(points) && return result - P = eltype(points) - lines = P[] - line_segments = P[] - last = 1 - for (i,p) in enumerate(points) - if isnan(p) || i==length(points) - _i = isnan(p) ? i-1 : i - handle_segment(lines, line_segments, points, last:_i) - last = i+1 - end - end - if !isempty(lines) - pop!(lines) # remove last NaN - push!(result, visualize(lines, Style(:lines), kw_args)) - end - if !isempty(line_segments) - push!(result, visualize(line_segments, Style(:linesegment), kw_args)) - end - return result -end - -function gl_shape(plotattributes, kw_args) - points = Plots.extract_points(plotattributes) - result = [] - for rng in iter_segments(plotattributes[:x], plotattributes[:y]) - ps = points[rng] - meshes = gl_poly(ps, kw_args) - append!(result, meshes) - end - result -end - - - -function gl_scatter(points, kw_args) - prim = get(kw_args, :primitive, GeometryTypes.Circle) - if isa(prim, GLNormalMesh) - if haskey(kw_args, :model) - p = get(kw_args, :perspective, eye(GeometryTypes.Mat4f0)) - kw_args[:scale] = GLAbstraction.const_lift(kw_args[:model], kw_args[:scale], p) do m, sc, p - s = Vec3f0(m[1,1], m[2,2], m[3,3]) - ps = Vec3f0(p[1,1], p[2,2], p[3,3]) - r = sc ./ (s .* ps) - r - end - end - else # 2D prim - kw_args[:scale] = to_vec(Vec2f0, kw_args[:scale]) - 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 - if isa(prim, String) - kw_args[:position] = points - if !isa(kw_args[:scale], Vector) # if not vector, we can assume it's relative scale - kw_args[:relative_scale] = kw_args[:scale] - delete!(kw_args, :scale) - end - return visualize(prim, Style(:default), kw_args) - end - - visualize((prim, points), Style(:default), kw_args) -end - - -function gl_poly(points, kw_args) - last(points) == first(points) && pop!(points) - polys = GeometryTypes.split_intersections(points) - result = [] - for poly in polys - mesh = GLNormalMesh(poly) # make polygon - if !isempty(GeometryTypes.faces(mesh)) # check if polygonation has any faces - push!(result, GLVisualize.visualize(mesh, Style(:default), kw_args)) - else - @warn("Couldn't draw the polygon: $points") - end - end - result -end - - - - -function gl_surface(x,y,z, kw_args) - if isa(x, AbstractRange) && isa(y, AbstractRange) - main = z - kw_args[:ranges] = (x, y) - else - if isa(x, AbstractMatrix) && isa(y, AbstractMatrix) - main = map(s->map(Float32, s), (x, y, z)) - elseif isa(x, AbstractVector) || isa(y, AbstractVector) - x = Float32[x[i] for i = 1:size(z,1), j = 1:size(z,2)] - y = Float32[y[j] for i = 1:size(z,1), j = 1:size(z,2)] - main = (x, y, map(Float32, z)) - else - error("surface: combination of types not supported: $(typeof(x)) $(typeof(y)) $(typeof(z))") - end - if get(kw_args, :wireframe, false) - points = map(Point3f0, zip(vec(x), vec(y), vec(z))) - faces = Cuint[] - idx = (i,j) -> CartesianIndices(size(z), i, j) - 1 - for i=1:size(z,1), j=1:size(z,2) - - i < size(z,1) && push!(faces, idx(i, j), idx(i+1, j)) - j < size(z,2) && push!(faces, idx(i, j), idx(i, j+1)) - - end - color = get(kw_args, :stroke_color, RGBA{Float32}(0,0,0,1)) - kw_args[:color] = color - kw_args[:thickness] = Float32(get(kw_args, :stroke_width, 1f0)) - kw_args[:indices] = faces - delete!(kw_args, :stroke_color) - delete!(kw_args, :stroke_width) - - return visualize(points, Style(:linesegment), kw_args) - end - end - return visualize(main, Style(:surface), kw_args) -end - - -function gl_contour(x, y, z, kw_args) - if kw_args[:fillrange] != nothing - - delete!(kw_args, :intensity) - I = GLVisualize.Intensity{Float32} - main = [I(z[j,i]) for i=1:size(z, 2), j=1:size(z, 1)] - return visualize(main, Style(:default), kw_args) - - else - h = kw_args[:levels] - T = eltype(z) - levels = Contour.contours(map(T, x), map(T, y), z, h) - result = Point2f0[] - zmin, zmax = get(kw_args, :limits, Vec2f0(ignorenan_extrema(z))) - cmap = get(kw_args, :color_map, get(kw_args, :color, RGBA{Float32}(0,0,0,1))) - colors = RGBA{Float32}[] - for c in levels.contours - for elem in c.lines - append!(result, elem.vertices) - push!(result, Point2f0(NaN32)) - col = GLVisualize.color_lookup(cmap, c.level, zmin, zmax) - append!(colors, fill(col, length(elem.vertices) + 1)) - end - end - kw_args[:color] = colors - kw_args[:color_map] = nothing - kw_args[:color_norm] = nothing - kw_args[:intensity] = nothing - return visualize(result, Style(:lines),kw_args) - end -end - - -function gl_heatmap(x,y,z, kw_args) - get!(kw_args, :color_norm, Vec2f0(ignorenan_extrema(z))) - get!(kw_args, :color_map, Plots.make_gradient(cgrad())) - delete!(kw_args, :intensity) - I = GLVisualize.Intensity{Float32} - heatmap = I[z[j,i] for i=1:size(z, 2), j=1:size(z, 1)] - tex = GLAbstraction.Texture(heatmap, minfilter=:nearest) - kw_args[:stroke_width] = 0f0 - kw_args[:levels] = 1f0 - visualize(tex, Style(:default), kw_args) -end - - - - -""" -Ugh, so much special casing (╯°□°)╯︵ ┻━┻ -""" -function label_scatter(plotattributes, w, ho) - kw = KW() - extract_stroke(plotattributes, kw) - extract_marker(plotattributes, kw) - kw[:scale] = Vec2f0(w/2) - kw[:offset] = Vec2f0(-w/4) - if haskey(kw, :intensity) - cmap = kw[:color_map] - norm = kw[:color_norm] - kw[:color] = GLVisualize.color_lookup(cmap, kw[:intensity][1], norm) - delete!(kw, :intensity) - delete!(kw, :color_map) - delete!(kw, :color_norm) - else - color = get(kw, :color, nothing) - kw[:color] = isa(color, Array) ? first(color) : color - end - strcolor = get(kw, :stroke_color, RGBA{Float32}(0,0,0,0)) - kw[:stroke_color] = isa(strcolor, Array) ? first(strcolor) : strcolor - p = get(kw, :primitive, GeometryTypes.Circle) - if isa(p, GLNormalMesh) - bb = GeometryTypes.AABB{Float32}(GeometryTypes.vertices(p)) - bbw = GeometryTypes.widths(bb) - if isapprox(bbw[3], 0) - bbw = Vec3f0(bbw[1], bbw[2], 1) - end - mini = minimum(bb) - m = GLAbstraction.translationmatrix(-mini) - m *= GLAbstraction.scalematrix(1 ./ bbw) - kw[:primitive] = m * p - kw[:scale] = Vec3f0(w/2) - delete!(kw, :offset) - end - if isa(p, Array) - kw[:primitive] = GeometryTypes.Circle - end - GL.gl_scatter(Point2f0[(w/2, ho)], kw) -end - - -function make_label(sp, series, i) - GL = Plots - w, gap, ho = 20f0, 5f0, 5 - result = [] - plotattributes = series.plotattributes - st = plotattributes[:seriestype] - kw_args = KW() - if (st in (:path, :path3d, :straightline)) && plotattributes[:linewidth] > 0 - points = Point2f0[(0, ho), (w, ho)] - kw = KW() - extract_linestyle(plotattributes, kw) - append!(result, GL.gl_lines(points, kw)) - if plotattributes[:markershape] != :none - push!(result, label_scatter(plotattributes, w, ho)) - end - elseif st in (:scatter, :scatter3d) #|| plotattributes[:markershape] != :none - push!(result, label_scatter(plotattributes, w, ho)) - else - extract_c(plotattributes, kw_args, :fill) - if isa(kw_args[:color], AbstractVector) - kw_args[:color] = first(kw_args[:color]) - end - push!(result, visualize( - GeometryTypes.SimpleRectangle(-w/2, ho-w/4, w/2, w/2), - Style(:default), kw_args - )) - end - labeltext = if isa(series[:label], Array) - i += 1 - series[:label][i] - else - series[:label] - end - ft = legendfont(sp) - font = Plots.Font(ft.family, ft.pointsize, :left, :bottom, 0.0, ft.color) - xy = Point2f0(w+gap, 0.0) - kw = Dict(:model => text_model(font, xy), :scale_primitive=>false) - extract_font(font, kw) - t = PlotText(labeltext, font) - push!(result, glvisualize_text(xy, t, kw)) - GLAbstraction.Context(result...), i -end - - -function generate_legend(sp, screen, model_m) - legend = GLAbstraction.Context[] - if sp[:legend] != :none - i = 0 - for series in series_list(sp) - should_add_to_legend(series) || continue - result, i = make_label(sp, series, i) - push!(legend, result) - end - if isempty(legend) - return - end - list = visualize(legend, gap=Vec3f0(0,5,0)) - bb = GLAbstraction._boundingbox(list) - wx,wy,_ = GeometryTypes.widths(bb) - xmin, _ = Plots.axis_limits(sp[:xaxis]) - _, ymax = Plots.axis_limits(sp[:yaxis]) - area = map(model_m) do m - p = m * GeometryTypes.Vec4f0(xmin, ymax, 0, 1) - h = round(Int, wy)+20 - w = round(Int, wx)+20 - x,y = round(Int, p[1])+30, round(Int, p[2]-h)-30 - GeometryTypes.SimpleRectangle(x, y, w, h) - end - sscren = GLWindow.Screen( - screen, area = area, - color = sp[:background_color_legend], - stroke = (2f0, RGBA(0.3, 0.3, 0.3, 0.9)) - ) - GLAbstraction.translate!(list, Vec3f0(10,10,0)) - GLVisualize._view(list, sscren, camera=:fixed_pixel) - end - return -end diff --git a/src/init.jl b/src/init.jl index c15975a4..95aa38d0 100644 --- a/src/init.jl +++ b/src/init.jl @@ -19,7 +19,6 @@ function __init__() pushdisplay(PlotsDisplay()) end) - @require GLVisualize = "4086de5b-f4b6-55f3-abb0-b8c73827585f" include(joinpath(@__DIR__, "backends", "glvisualize.jl")) @require HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" include(joinpath(@__DIR__, "backends", "hdf5.jl")) @require InspectDR = "d0351b0e-4b05-5898-87b3-e2a8edfddd1d" include(joinpath(@__DIR__, "backends", "inspectdr.jl")) @require PGFPlots = "3b7a836e-365b-5785-a47d-02c71176b4aa" include(joinpath(@__DIR__, "backends", "pgfplots.jl")) diff --git a/src/output.jl b/src/output.jl index df6e3b84..b3392cc5 100644 --- a/src/output.jl +++ b/src/output.jl @@ -156,7 +156,6 @@ end const _best_html_output_type = KW( :pyplot => :png, :unicodeplots => :txt, - :glvisualize => :png, :plotlyjs => :html, :plotly => :html )