From 17eef46da2541981beb89047ca912cd83d23154e Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 28 Oct 2019 18:50:02 +0100 Subject: [PATCH] separate clims for colorbar_entry=false series for GR --- src/backends/gr.jl | 28 ++++------------------------ src/utils.jl | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 503172d5..84c9b24a 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -260,19 +260,6 @@ function gr_fill_viewport(vp::AVec{Float64}, c) GR.restorestate() end - -normalize_zvals(args...) = nothing -function normalize_zvals(zv::AVec, clims::NTuple{2, <:Real}) - vmin, vmax = ignorenan_extrema(zv) - isfinite(clims[1]) && (vmin = clims[1]) - isfinite(clims[2]) && (vmax = clims[2]) - if vmin == vmax - zeros(length(zv)) - else - clamp.((zv .- vmin) ./ (vmax .- vmin), 0, 1) - end -end - # --------------------------------------------------------- # draw ONE Shape @@ -920,8 +907,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # reduced from before... set some flags based on the series in this subplot # TODO: can these be generic flags? outside_ticks = false - # calculate the colorbar limits once for a subplot - clims = get_clims(sp) cbar = GRColorbar() draw_axes = sp[:framestyle] != :none @@ -995,14 +980,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.setlinewidth(sp.plt[:thickness_scaling]) if is3d(sp) - # TODO do we really need a different clims computation here from the one - # computed above using get_clims(sp)? - zmin, zmax = gr_lims(sp, zaxis, true) - clims3d = sp[:clims] - if is_2tuple(clims3d) - isfinite(clims3d[1]) && (zmin = clims3d[1]) - isfinite(clims3d[2]) && (zmax = clims3d[2]) - end GR.setspace(zmin, zmax, round.(Int, sp[:camera])...) xtick = GR.tick(xmin, xmax) / 2 ytick = GR.tick(ymin, ymax) / 2 @@ -1234,6 +1211,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) x, y, z = series[:x], series[:y], series[:z] frng = series[:fillrange] + clims = get_clims(sp, series) + # add custom frame shapes to markershape? series_annotations_shapes!(series) # ------------------------------------------------------- @@ -1470,7 +1449,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end # draw the colorbar - hascolorbar(sp) && gr_draw_colorbar(cbar, sp, clims) + hascolorbar(sp) && gr_draw_colorbar(cbar, sp, get_clims(sp)) # add the legend if sp[:legend] != :none @@ -1498,6 +1477,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_set_font(legendfont(sp)) end for series in series_list(sp) + clims = get_clims(sp, series) should_add_to_legend(series) || continue st = series[:seriestype] lc = get_linecolor(series, clims) diff --git a/src/utils.jl b/src/utils.jl index 48eb1126..0c2b4b80 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -523,16 +523,9 @@ zlims(sp_idx::Int = 1) = zlims(current(), sp_idx) function get_clims(sp::Subplot) zmin, zmax = Inf, -Inf - z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface) for series in series_list(sp) if series[:colorbar_entry] - for vals in (series[:seriestype] in z_colored_series ? series[:z] : nothing, series[:line_z], series[:marker_z], series[:fill_z]) - if (typeof(vals) <: AbstractSurface) && (eltype(vals.surf) <: Union{Missing, Real}) - zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals.surf)...) - elseif (vals !== nothing) && (eltype(vals) <: Union{Missing, Real}) - zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals)...) - end - end + zmin, zmax = _update_clims(zmin, zmax, get_clims(series)...) end end clims = sp[:clims] @@ -543,6 +536,33 @@ function get_clims(sp::Subplot) return zmin < zmax ? (zmin, zmax) : (-0.1, 0.1) end +function get_clims(sp::Subplot, series::Series) + zmin, zmax = if series[:colorbar_entry] + get_clims(sp) + else + get_clims(series) + end + clims = sp[:clims] + if is_2tuple(clims) + isfinite(clims[1]) && (zmin = clims[1]) + isfinite(clims[2]) && (zmax = clims[2]) + end + return zmin < zmax ? (zmin, zmax) : (-0.1, 0.1) +end + +function get_clims(series::Series) + zmin, zmax = Inf, -Inf + z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface) + for vals in (series[:seriestype] in z_colored_series ? series[:z] : nothing, series[:line_z], series[:marker_z], series[:fill_z]) + if (typeof(vals) <: AbstractSurface) && (eltype(vals.surf) <: Union{Missing, Real}) + zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals.surf)...) + elseif (vals !== nothing) && (eltype(vals) <: Union{Missing, Real}) + zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals)...) + end + end + return zmin < zmax ? (zmin, zmax) : (-0.1, 0.1) +end + _update_clims(zmin, zmax, emin, emax) = min(zmin, emin), max(zmax, emax) @enum ColorbarStyle cbar_gradient cbar_fill cbar_lines