Merge pull request #2740 from daschw/vline
fix infinite objects with log scale
This commit is contained in:
commit
f0f28086a9
@ -112,7 +112,7 @@ end
|
|||||||
|
|
||||||
@recipe function f(::Type{Val{:hline}}, x, y, z)
|
@recipe function f(::Type{Val{:hline}}, x, y, z)
|
||||||
n = length(y)
|
n = length(y)
|
||||||
newx = repeat(Float64[-1, 1, NaN], n)
|
newx = repeat(Float64[1, 2, NaN], n)
|
||||||
newy = vec(Float64[yi for i = 1:3, yi in y])
|
newy = vec(Float64[yi for i = 1:3, yi in y])
|
||||||
x := newx
|
x := newx
|
||||||
y := newy
|
y := newy
|
||||||
@ -124,7 +124,7 @@ end
|
|||||||
@recipe function f(::Type{Val{:vline}}, x, y, z)
|
@recipe function f(::Type{Val{:vline}}, x, y, z)
|
||||||
n = length(y)
|
n = length(y)
|
||||||
newx = vec(Float64[yi for i = 1:3, yi in y])
|
newx = vec(Float64[yi for i = 1:3, yi in y])
|
||||||
newy = repeat(Float64[-1, 1, NaN], n)
|
newy = repeat(Float64[1, 2, NaN], n)
|
||||||
x := newx
|
x := newx
|
||||||
y := newy
|
y := newy
|
||||||
seriestype := :straightline
|
seriestype := :straightline
|
||||||
|
|||||||
39
src/utils.jl
39
src/utils.jl
@ -1079,10 +1079,21 @@ end
|
|||||||
function straightline_data(series, expansion_factor = 1)
|
function straightline_data(series, expansion_factor = 1)
|
||||||
sp = series[:subplot]
|
sp = series[:subplot]
|
||||||
xl, yl = isvertical(series) ? (xlims(sp), ylims(sp)) : (ylims(sp), xlims(sp))
|
xl, yl = isvertical(series) ? (xlims(sp), ylims(sp)) : (ylims(sp), xlims(sp))
|
||||||
x, y = series[:x], series[:y]
|
|
||||||
|
# handle axes scales
|
||||||
|
xscale = sp[:xaxis][:scale]
|
||||||
|
xf = RecipesPipeline.scale_func(xscale)
|
||||||
|
xinvf = RecipesPipeline.inverse_scale_func(xscale)
|
||||||
|
yscale = sp[:yaxis][:scale]
|
||||||
|
yf = RecipesPipeline.scale_func(yscale)
|
||||||
|
yinvf = RecipesPipeline.inverse_scale_func(yscale)
|
||||||
|
|
||||||
|
xl, yl = xf.(xl), yf.(yl)
|
||||||
|
x, y = xf.(series[:x]), yf.(series[:y])
|
||||||
n = length(x)
|
n = length(x)
|
||||||
if n == 2
|
|
||||||
return straightline_data(xl, yl, x, y, expansion_factor)
|
xdata, ydata = if n == 2
|
||||||
|
straightline_data(xl, yl, x, y, expansion_factor)
|
||||||
else
|
else
|
||||||
k, r = divrem(n, 3)
|
k, r = divrem(n, 3)
|
||||||
if r == 0
|
if r == 0
|
||||||
@ -1091,11 +1102,13 @@ function straightline_data(series, expansion_factor = 1)
|
|||||||
inds = (3 * i - 2):(3 * i - 1)
|
inds = (3 * i - 2):(3 * i - 1)
|
||||||
xdata[inds], ydata[inds] = straightline_data(xl, yl, x[inds], y[inds], expansion_factor)
|
xdata[inds], ydata[inds] = straightline_data(xl, yl, x[inds], y[inds], expansion_factor)
|
||||||
end
|
end
|
||||||
return xdata, ydata
|
xdata, ydata
|
||||||
else
|
else
|
||||||
error("Misformed data. `straightline_data` either accepts vectors of length 2 or 3k. The provided series has length $n")
|
error("Misformed data. `straightline_data` either accepts vectors of length 2 or 3k. The provided series has length $n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return xinvf.(xdata), yinvf.(ydata)
|
||||||
end
|
end
|
||||||
|
|
||||||
function straightline_data(xl, yl, x, y, expansion_factor = 1)
|
function straightline_data(xl, yl, x, y, expansion_factor = 1)
|
||||||
@ -1127,20 +1140,28 @@ end
|
|||||||
function shape_data(series, expansion_factor = 1)
|
function shape_data(series, expansion_factor = 1)
|
||||||
sp = series[:subplot]
|
sp = series[:subplot]
|
||||||
xl, yl = isvertical(series) ? (xlims(sp), ylims(sp)) : (ylims(sp), xlims(sp))
|
xl, yl = isvertical(series) ? (xlims(sp), ylims(sp)) : (ylims(sp), xlims(sp))
|
||||||
|
|
||||||
|
# handle axes scales
|
||||||
|
xscale = sp[:xaxis][:scale]
|
||||||
|
xf = RecipesPipeline.scale_func(xscale)
|
||||||
|
xinvf = RecipesPipeline.inverse_scale_func(xscale)
|
||||||
|
yscale = sp[:yaxis][:scale]
|
||||||
|
yf = RecipesPipeline.scale_func(yscale)
|
||||||
|
yinvf = RecipesPipeline.inverse_scale_func(yscale)
|
||||||
|
|
||||||
x, y = copy(series[:x]), copy(series[:y])
|
x, y = copy(series[:x]), copy(series[:y])
|
||||||
factor = 100
|
|
||||||
for i in eachindex(x)
|
for i in eachindex(x)
|
||||||
if x[i] == -Inf
|
if x[i] == -Inf
|
||||||
x[i] = xl[1] - expansion_factor * (xl[2] - xl[1])
|
x[i] = xinvf(xf(xl[1]) - expansion_factor * (xf(xl[2]) - xf(xl[1])))
|
||||||
elseif x[i] == Inf
|
elseif x[i] == Inf
|
||||||
x[i] = xl[2] + expansion_factor * (xl[2] - xl[1])
|
x[i] = xinvf(xf(xl[2]) + expansion_factor * (xf(xl[2]) - xf(xl[1])))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i in eachindex(y)
|
for i in eachindex(y)
|
||||||
if y[i] == -Inf
|
if y[i] == -Inf
|
||||||
y[i] = yl[1] - expansion_factor * (yl[2] - yl[1])
|
y[i] = yinvf(yf(yl[1]) - expansion_factor * (yf(yl[2]) - yf(yl[1])))
|
||||||
elseif y[i] == Inf
|
elseif y[i] == Inf
|
||||||
y[i] = yl[2] + expansion_factor * (yl[2] - yl[1])
|
y[i] = yinvf(yf(yl[2]) + expansion_factor * (yf(yl[2]) - yf(yl[1])))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return x, y
|
return x, y
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user