Speed up get_clims (#3839)
* For Shape type, cut off process * Remove fillcolor for now * Address type inference failure instead * Store value instead of re-evaluating * Works, but not ideal * Unnecessary to update here, I think * return type * Remove unnecessary default arg * Typo * Change to clims * missed one * reconfigured to free up clims property * fix * Remove debug println, add hook for updating clims after series added * restore docstring * typo * Change to _update_subplot_colorbars
This commit is contained in:
parent
1c89bd8727
commit
405bc0820b
@ -5,37 +5,35 @@ process_clims(s::Union{Symbol,Nothing,Missing}) = ignorenan_extrema
|
|||||||
# don't specialize on ::Function otherwise python functions won't work
|
# don't specialize on ::Function otherwise python functions won't work
|
||||||
process_clims(f) = f
|
process_clims(f) = f
|
||||||
|
|
||||||
function get_clims(sp::Subplot, op = process_clims(sp[:clims]))::Tuple{Float64,Float64}
|
get_clims(sp::Subplot)::Tuple{Float64, Float64} = sp[:crange]
|
||||||
|
get_clims(series::Series)::Tuple{Float64, Float64} = series[:crange]
|
||||||
|
|
||||||
|
get_clims(sp::Subplot, series::Series)::Tuple{Float64, Float64} =
|
||||||
|
series[:colorbar_entry] ?
|
||||||
|
sp[:crange] :
|
||||||
|
series[:crange]
|
||||||
|
|
||||||
|
function update_clims(sp::Subplot, op = process_clims(sp[:clims]))::Tuple{Float64, Float64}
|
||||||
|
|
||||||
zmin, zmax = Inf, -Inf
|
zmin, zmax = Inf, -Inf
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
if series[:colorbar_entry]
|
if series[:colorbar_entry]
|
||||||
zmin, zmax = _update_clims(zmin, zmax, get_clims(series, op)...)
|
zmin, zmax = _update_clims(zmin, zmax, update_clims(series, op)...)
|
||||||
|
else
|
||||||
|
update_clims(series, op)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return zmin <= zmax ? (zmin, zmax) : (NaN, NaN)
|
return sp[:crange] = zmin <= zmax ? (zmin, zmax) : (NaN, NaN)
|
||||||
end
|
|
||||||
|
|
||||||
function get_clims(
|
|
||||||
sp::Subplot,
|
|
||||||
series::Series,
|
|
||||||
op = process_clims(sp[:clims]),
|
|
||||||
)::Tuple{Float64,Float64}
|
|
||||||
zmin, zmax = if series[:colorbar_entry]
|
|
||||||
get_clims(sp, op)
|
|
||||||
else
|
|
||||||
get_clims(series, op)
|
|
||||||
end
|
|
||||||
return zmin <= zmax ? (zmin, zmax) : (NaN, NaN)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
"""
|
"""
|
||||||
get_clims(::Series, op=Plots.ignorenan_extrema)
|
update_clims(::Series, op=Plots.ignorenan_extrema)
|
||||||
|
|
||||||
Finds the limits for the colorbar by taking the "z-values" for the series and passing them into `op`,
|
Finds the limits for the colorbar by taking the "z-values" for the series and passing them into `op`,
|
||||||
which must return the tuple `(zmin, zmax)`. The default op is the extrema of the finite
|
which must return the tuple `(zmin, zmax)`. The default op is the extrema of the finite
|
||||||
values of the input.
|
values of the input. The value is stored as a series property, which is retrieved by `get_clims`.
|
||||||
"""
|
"""
|
||||||
function get_clims(series::Series, op = ignorenan_extrema)::Tuple{Float64,Float64}
|
function update_clims(series::Series, op = ignorenan_extrema)::Tuple{Float64, Float64}
|
||||||
zmin, zmax = Inf, -Inf
|
zmin, zmax = Inf, -Inf
|
||||||
z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface, :hexbin)
|
z_colored_series = (:contour, :contour3d, :heatmap, :histogram2d, :surface, :hexbin)
|
||||||
for vals in (
|
for vals in (
|
||||||
@ -50,7 +48,7 @@ function get_clims(series::Series, op = ignorenan_extrema)::Tuple{Float64,Float6
|
|||||||
zmin, zmax = _update_clims(zmin, zmax, op(vals)...)
|
zmin, zmax = _update_clims(zmin, zmax, op(vals)...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return zmin <= zmax ? (zmin, zmax) : (NaN, NaN)
|
return series[:crange] = zmin <= zmax ? (zmin, zmax) : (NaN, NaN)
|
||||||
end
|
end
|
||||||
|
|
||||||
_update_clims(zmin, zmax, emin, emax) = NaNMath.min(zmin, emin), NaNMath.max(zmax, emax)
|
_update_clims(zmin, zmax, emin, emax) = NaNMath.min(zmin, emin), NaNMath.max(zmax, emax)
|
||||||
@ -98,4 +96,5 @@ end
|
|||||||
|
|
||||||
function _update_subplot_colorbars(sp::Subplot)
|
function _update_subplot_colorbars(sp::Subplot)
|
||||||
# Dynamic callback from the pipeline if needed
|
# Dynamic callback from the pipeline if needed
|
||||||
|
update_clims(sp)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -416,4 +416,5 @@ function _add_the_series(plt, sp, plotattributes)
|
|||||||
push!(plt.series_list, series)
|
push!(plt.series_list, series)
|
||||||
push!(sp.series_list, series)
|
push!(sp.series_list, series)
|
||||||
_series_added(plt, series)
|
_series_added(plt, series)
|
||||||
|
_update_subplot_colorbars(sp)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user