don't run optimize_ticks multiple times
This commit is contained in:
parent
1e536dda4b
commit
44bd1812e0
19
src/axes.jl
19
src/axes.jl
@ -213,10 +213,12 @@ function optimal_ticks_and_labels(sp::Subplot, axis::Axis, ticks = nothing)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# return (continuous_values, discrete_values) for the ticks on this axis
|
# return (continuous_values, discrete_values) for the ticks on this axis
|
||||||
function get_ticks(sp::Subplot, axis::Axis)
|
function get_ticks(sp::Subplot, axis::Axis; update = true)
|
||||||
|
if update || !haskey(axis.plotattributes, :optimized_ticks)
|
||||||
ticks = _transform_ticks(axis[:ticks])
|
ticks = _transform_ticks(axis[:ticks])
|
||||||
ticks in (:none, nothing, false) && return nothing
|
if ticks in (:none, nothing, false)
|
||||||
|
axis.plotattributes[:optimized_ticks] = nothing
|
||||||
|
else
|
||||||
# treat :native ticks as :auto
|
# treat :native ticks as :auto
|
||||||
ticks = ticks == :native ? :auto : ticks
|
ticks = ticks == :native ? :auto : ticks
|
||||||
|
|
||||||
@ -252,9 +254,10 @@ function get_ticks(sp::Subplot, axis::Axis)
|
|||||||
else
|
else
|
||||||
error("Unknown ticks type in get_ticks: $(typeof(ticks))")
|
error("Unknown ticks type in get_ticks: $(typeof(ticks))")
|
||||||
end
|
end
|
||||||
# @show ticks dvals cv dv
|
axis.plotattributes[:optimized_ticks] = (cv, dv)
|
||||||
|
end
|
||||||
return cv, dv
|
end
|
||||||
|
axis.plotattributes[:optimized_ticks]
|
||||||
end
|
end
|
||||||
|
|
||||||
_transform_ticks(ticks) = ticks
|
_transform_ticks(ticks) = ticks
|
||||||
@ -589,7 +592,7 @@ function axis_drawing_info(sp, letter)
|
|||||||
ax, oax = sp[asym], sp[oasym]
|
ax, oax = sp[asym], sp[oasym]
|
||||||
amin, amax = axis_limits(sp, letter)
|
amin, amax = axis_limits(sp, letter)
|
||||||
oamin, oamax = axis_limits(sp, oletter)
|
oamin, oamax = axis_limits(sp, oletter)
|
||||||
ticks = get_ticks(sp, ax)
|
ticks = get_ticks(sp, ax, update = false)
|
||||||
minor_ticks = get_minor_ticks(sp, ax, ticks)
|
minor_ticks = get_minor_ticks(sp, ax, ticks)
|
||||||
|
|
||||||
# initialize the segments
|
# initialize the segments
|
||||||
@ -714,7 +717,7 @@ function axis_drawing_info_3d(sp, letter)
|
|||||||
namin, namax = axis_limits(sp, near_letter)
|
namin, namax = axis_limits(sp, near_letter)
|
||||||
famin, famax = axis_limits(sp, far_letter)
|
famin, famax = axis_limits(sp, far_letter)
|
||||||
|
|
||||||
ticks = get_ticks(sp, ax)
|
ticks = get_ticks(sp, ax, update = false)
|
||||||
minor_ticks = get_minor_ticks(sp, ax, ticks)
|
minor_ticks = get_minor_ticks(sp, ax, ticks)
|
||||||
|
|
||||||
# initialize the segments
|
# initialize the segments
|
||||||
|
|||||||
@ -215,7 +215,7 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot)
|
|||||||
a = α .+ 90
|
a = α .+ 90
|
||||||
sinf = sind.(a)
|
sinf = sind.(a)
|
||||||
cosf = cosd.(a)
|
cosf = cosd.(a)
|
||||||
rtick_values, rtick_labels = get_ticks(sp, yaxis)
|
rtick_values, rtick_labels = get_ticks(sp, yaxis, update = false)
|
||||||
|
|
||||||
#draw angular grid
|
#draw angular grid
|
||||||
if xaxis[:grid]
|
if xaxis[:grid]
|
||||||
@ -692,7 +692,7 @@ end
|
|||||||
|
|
||||||
function gr_axis_height(sp, axis)
|
function gr_axis_height(sp, axis)
|
||||||
GR.savestate()
|
GR.savestate()
|
||||||
ticks = get_ticks(sp, axis)
|
ticks = get_ticks(sp, axis, update = false)
|
||||||
gr_set_font(tickfont(axis), sp)
|
gr_set_font(tickfont(axis), sp)
|
||||||
h = (ticks in (nothing, false, :none) ? 0 : last(gr_get_ticks_size(ticks, axis[:rotation])))
|
h = (ticks in (nothing, false, :none) ? 0 : last(gr_get_ticks_size(ticks, axis[:rotation])))
|
||||||
if axis[:guide] != ""
|
if axis[:guide] != ""
|
||||||
@ -705,7 +705,7 @@ end
|
|||||||
|
|
||||||
function gr_axis_width(sp, axis)
|
function gr_axis_width(sp, axis)
|
||||||
GR.savestate()
|
GR.savestate()
|
||||||
ticks = get_ticks(sp, axis)
|
ticks = get_ticks(sp, axis, update = false)
|
||||||
gr_set_font(tickfont(axis), sp)
|
gr_set_font(tickfont(axis), sp)
|
||||||
w = (ticks in (nothing, false, :none) ? 0 : first(gr_get_ticks_size(ticks, axis[:rotation])))
|
w = (ticks in (nothing, false, :none) ? 0 : first(gr_get_ticks_size(ticks, axis[:rotation])))
|
||||||
if axis[:guide] != ""
|
if axis[:guide] != ""
|
||||||
@ -897,28 +897,21 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
leg = gr_get_legend_geometry(viewport_plotarea, sp)
|
leg = gr_get_legend_geometry(viewport_plotarea, sp)
|
||||||
gr_update_viewport_legend!(viewport_plotarea, sp, leg)
|
gr_update_viewport_legend!(viewport_plotarea, sp, leg)
|
||||||
|
|
||||||
# TODO daschw is this required here?
|
|
||||||
data_lims = xy_lims = gr_xy_axislims(sp)
|
|
||||||
|
|
||||||
# fill in the plot area background
|
# fill in the plot area background
|
||||||
gr_fill_plotarea(sp, viewport_plotarea)
|
gr_fill_plotarea(sp, viewport_plotarea)
|
||||||
|
|
||||||
# reduced from before... set some flags based on the series in this subplot
|
|
||||||
# TODO: can these be generic flags?
|
|
||||||
outside_ticks = false
|
|
||||||
cbar = GRColorbar()
|
cbar = GRColorbar()
|
||||||
|
|
||||||
draw_axes = sp[:framestyle] != :none
|
draw_axes = sp[:framestyle] != :none
|
||||||
# axes_2d = true
|
# axes_2d = true
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
st = series[:seriestype]
|
# st = series[:seriestype]
|
||||||
if st in (:heatmap, :image)
|
# if st in (:heatmap, :image)
|
||||||
x, y = heatmap_edges(series[:x], sp[:xaxis][:scale], series[:y], sp[:yaxis][:scale], size(series[:z]))
|
# x, y = heatmap_edges(series[:x], sp[:xaxis][:scale], series[:y], sp[:yaxis][:scale], size(series[:z]))
|
||||||
xy_lims = x[1], x[end], y[1], y[end]
|
# xy_lims = x[1], x[end], y[1], y[end]
|
||||||
expand_extrema!(sp[:xaxis], x)
|
# expand_extrema!(sp[:xaxis], x)
|
||||||
expand_extrema!(sp[:yaxis], y)
|
# expand_extrema!(sp[:yaxis], y)
|
||||||
data_lims = gr_xy_axislims(sp)
|
# end
|
||||||
end
|
|
||||||
|
|
||||||
gr_update_colorbar!(cbar,series)
|
gr_update_colorbar!(cbar,series)
|
||||||
end
|
end
|
||||||
@ -973,7 +966,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
if ispolar(sp)
|
if ispolar(sp)
|
||||||
gr_set_viewport_polar(viewport_plotarea)
|
gr_set_viewport_polar(viewport_plotarea)
|
||||||
else
|
else
|
||||||
xmin, xmax, ymin, ymax = data_lims
|
xmin, xmax, ymin, ymax = gr_xy_axislims(sp)
|
||||||
if xmax > xmin && ymax > ymin
|
if xmax > xmin && ymax > ymin
|
||||||
GR.setwindow(xmin, xmax, ymin, ymax)
|
GR.setwindow(xmin, xmax, ymin, ymax)
|
||||||
end
|
end
|
||||||
@ -1107,9 +1100,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
else
|
else
|
||||||
phimin, phimax = 0.0, 360.0 # nonuniform polar array is not yet supported in GR.jl
|
phimin, phimax = 0.0, 360.0 # nonuniform polar array is not yet supported in GR.jl
|
||||||
nx, ny = length(series[:x]), length(series[:y])
|
nx, ny = length(series[:x]), length(series[:y])
|
||||||
xmin, xmax, ymin, ymax = xy_lims
|
xmin, xmax, ymin, ymax = gr_xy_axislims(sp)
|
||||||
rmax = data_lims[4]
|
GR.setwindow(-ymax, ymax, -ymax, ymax)
|
||||||
GR.setwindow(-rmax, rmax, -rmax, rmax)
|
|
||||||
if ymin > 0
|
if ymin > 0
|
||||||
@warn "'ymin[1] > 0' (rmin) is not yet supported."
|
@warn "'ymin[1] > 0' (rmin) is not yet supported."
|
||||||
end
|
end
|
||||||
@ -1221,7 +1213,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
if ispolar(sp)
|
if ispolar(sp)
|
||||||
gr_set_viewport_polar(viewport_plotarea)
|
gr_set_viewport_polar(viewport_plotarea)
|
||||||
else
|
else
|
||||||
xmin, xmax, ymin, ymax = data_lims
|
xmin, xmax, ymin, ymax = gr_xy_axislims(sp)
|
||||||
if xmax > xmin && ymax > ymin
|
if xmax > xmin && ymax > ymin
|
||||||
GR.setwindow(xmin, xmax, ymin, ymax)
|
GR.setwindow(xmin, xmax, ymin, ymax)
|
||||||
end
|
end
|
||||||
@ -1467,12 +1459,12 @@ end
|
|||||||
function gr_update_viewport_ratio!(viewport_plotarea, sp)
|
function gr_update_viewport_ratio!(viewport_plotarea, sp)
|
||||||
ratio = get_aspect_ratio(sp)
|
ratio = get_aspect_ratio(sp)
|
||||||
if ratio != :none
|
if ratio != :none
|
||||||
data_lims = gr_xy_axislims(sp)
|
xmin, xmax, ymin, ymax = gr_xy_axislims(sp)
|
||||||
if ratio == :equal
|
if ratio == :equal
|
||||||
ratio = 1
|
ratio = 1
|
||||||
end
|
end
|
||||||
viewport_ratio = (viewport_plotarea[2] - viewport_plotarea[1]) / (viewport_plotarea[4] - viewport_plotarea[3])
|
viewport_ratio = (viewport_plotarea[2] - viewport_plotarea[1]) / (viewport_plotarea[4] - viewport_plotarea[3])
|
||||||
window_ratio = (data_lims[2] - data_lims[1]) / (data_lims[4] - data_lims[3]) / ratio
|
window_ratio = (xmax - xmin) / (ymax - ymin) / ratio
|
||||||
if window_ratio < viewport_ratio
|
if window_ratio < viewport_ratio
|
||||||
viewport_center = 0.5 * (viewport_plotarea[1] + viewport_plotarea[2])
|
viewport_center = 0.5 * (viewport_plotarea[1] + viewport_plotarea[2])
|
||||||
viewport_size = (viewport_plotarea[2] - viewport_plotarea[1]) * window_ratio / viewport_ratio
|
viewport_size = (viewport_plotarea[2] - viewport_plotarea[1]) * window_ratio / viewport_ratio
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user