Merge pull request #1438 from daschw/categorical-ticks

allow ticks = :all and ticks = n::Int for categorical axes
This commit is contained in:
Daniel Schwabeneder 2018-03-18 23:21:44 +01:00 committed by GitHub
commit d11c6a20bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -238,10 +238,18 @@ 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) && ticks == :auto cv, dv = if !isempty(dvals)
# discrete ticks... # discrete ticks...
axis[:continuous_values], dvals n = length(dvals)
elseif ticks == :auto rng = if ticks == :auto
Int[round(Int,i) for i in linspace(1, n, 15)]
elseif ticks == :all
1:n
elseif typeof(ticks) <: Int
Int[round(Int,i) for i in linspace(1, n, ticks)]
end
axis[:continuous_values][rng], dvals[rng]
elseif typeof(ticks) <: Symbol
if ispolar(axis.sps[1]) && axis[:letter] == :x 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))
@ -260,13 +268,7 @@ function get_ticks(axis::Axis)
end end
# @show ticks dvals cv dv # @show ticks dvals cv dv
# TODO: better/smarter cutoff values for sampling ticks return cv, dv
if length(cv) > 30 && ticks == :auto
rng = Int[round(Int,i) for i in linspace(1, length(cv), 15)]
cv[rng], dv[rng]
else
cv, dv
end
end end
_transform_ticks(ticks) = ticks _transform_ticks(ticks) = ticks