From 580ac8a9d1c638e06c6c0689d3155acdd77fa628 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 29 May 2020 09:42:44 +0200 Subject: [PATCH] fix infinite objects with log scale --- src/recipes.jl | 6 +++--- src/utils.jl | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/recipes.jl b/src/recipes.jl index e7bdb7ac..d2a0542f 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -112,7 +112,7 @@ end @recipe function f(::Type{Val{:hline}}, x, y, z) 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]) x := newx y := newy @@ -124,7 +124,7 @@ end @recipe function f(::Type{Val{:vline}}, x, y, z) n = length(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 y := newy seriestype := :straightline @@ -1028,7 +1028,7 @@ end function error_style!(plotattributes::AKW) plotattributes[:seriestype] = :path - plotattributes[:markercolor] = plotattributes[:markerstrokecolor] + plotattributes[:markercolor] = plotattributes[:markerstrokecolor] plotattributes[:linewidth] = plotattributes[:markerstrokewidth] plotattributes[:label] = "" end diff --git a/src/utils.jl b/src/utils.jl index 895d1ce3..c288b8a3 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1079,10 +1079,21 @@ end function straightline_data(series, expansion_factor = 1) sp = series[:subplot] 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) - 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 k, r = divrem(n, 3) if r == 0 @@ -1091,11 +1102,13 @@ function straightline_data(series, expansion_factor = 1) inds = (3 * i - 2):(3 * i - 1) xdata[inds], ydata[inds] = straightline_data(xl, yl, x[inds], y[inds], expansion_factor) end - return xdata, ydata + xdata, ydata else error("Misformed data. `straightline_data` either accepts vectors of length 2 or 3k. The provided series has length $n") end end + + return xinvf.(xdata), yinvf.(ydata) end function straightline_data(xl, yl, x, y, expansion_factor = 1) @@ -1127,20 +1140,28 @@ end function shape_data(series, expansion_factor = 1) sp = series[:subplot] 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]) - factor = 100 for i in eachindex(x) 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 - 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 for i in eachindex(y) 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 - 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 return x, y