Merge pull request #1543 from daschw/ticks

set fallback tick specification for axes with discrete values
This commit is contained in:
Daniel Schwabeneder 2018-06-03 16:21:54 +02:00 committed by GitHub
commit 6754b3746e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -246,19 +246,17 @@ function get_ticks(axis::Axis)
ticks = ticks == :native ? :auto : ticks ticks = ticks == :native ? :auto : ticks
dvals = axis[:discrete_values] dvals = axis[:discrete_values]
cv, dv = if !isempty(dvals) cv, dv = if typeof(ticks) <: Symbol
# discrete ticks... if !isempty(dvals)
n = length(dvals) # discrete ticks...
rng = if ticks == :auto n = length(dvals)
Int[round(Int,i) for i in linspace(1, n, 15)] rng = if ticks == :auto
elseif ticks == :all Int[round(Int,i) for i in linspace(1, n, 15)]
1:n else # if ticks == :all
elseif typeof(ticks) <: Int 1:n
Int[round(Int,i) for i in linspace(1, n, ticks)] end
end axis[:continuous_values][rng], dvals[rng]
axis[:continuous_values][rng], dvals[rng] elseif ispolar(axis.sps[1]) && axis[:letter] == :x
elseif typeof(ticks) <: Symbol
if ispolar(axis.sps[1]) && axis[:letter] == :x
#force theta axis to be full circle #force theta axis to be full circle
(collect(0:pi/4:7pi/4), string.(0:45:315)) (collect(0:pi/4:7pi/4), string.(0:45:315))
else else
@ -266,8 +264,13 @@ function get_ticks(axis::Axis)
optimal_ticks_and_labels(axis) optimal_ticks_and_labels(axis)
end end
elseif typeof(ticks) <: Union{AVec, Int} elseif typeof(ticks) <: Union{AVec, Int}
# override ticks, but get the labels if !isempty(dvals) && typeof(ticks) <: Int
optimal_ticks_and_labels(axis, ticks) rng = Int[round(Int,i) for i in linspace(1, length(dvals), ticks)]
axis[:continuous_values][rng], dvals[rng]
else
# override ticks, but get the labels
optimal_ticks_and_labels(axis, ticks)
end
elseif typeof(ticks) <: NTuple{2, Any} elseif typeof(ticks) <: NTuple{2, Any}
# assuming we're passed (ticks, labels) # assuming we're passed (ticks, labels)
ticks ticks