diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index ba8a46f9..f895df8b 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -289,6 +289,8 @@ function extract_points(d) dim = is3d(d) ? 3 : 2 array = if d[:seriestype] == :straightline straightline_data(d) + elseif d[:seriestype] == :shape + shape_data(series) else (d[:x], d[:y], d[:z])[1:dim] end diff --git a/src/backends/gr.jl b/src/backends/gr.jl index bca3362b..2ab89c5d 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1186,6 +1186,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.selntran(1) elseif st == :shape + x, y = shape_data(series) for (i,rng) in enumerate(iter_segments(x, y)) if length(rng) > 1 # connect to the beginning diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 3558040f..d0d3e285 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -272,6 +272,7 @@ For st in :shape: =# if st in (:shape,) + x, y = shape_data(series) nmax = 0 for (i,rng) in enumerate(iter_segments(x, y)) nmax = i diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 027a88a9..bda7ac16 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -222,6 +222,8 @@ function pgf_series(sp::Subplot, series::Series) d[:x], d[:y], d[:z] elseif st == :straightline straightline_data(series) + elseif st == :shape + shape_data(series) elseif d[:marker_z] != nothing # If a marker_z is used pass it as third coordinate to a 2D plot. # See "Scatter Plots" in PGFPlots documentation diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index e2207f0d..78820871 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -704,7 +704,7 @@ function plotly_series_shapes(plt::Plot, series::Series) base_d[:name] = series[:label] # base_d[:legendgroup] = series[:label] - x, y = plotly_data(series[:x]), plotly_data(series[:y]) + x, y = shape_data(series) for (i,rng) in enumerate(iter_segments(x,y)) length(rng) < 2 && continue diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 5d4d8e16..30d6a95a 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -454,6 +454,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) x, y, z = series[:x], series[:y], series[:z] if st == :straightline x, y = straightline_data(series) + elseif st == :shape + x, y = shape_data(series) end xyargs = (st in _3dTypes ? (x,y,z) : (x,y)) diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index f53435d2..8b26f6e7 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -157,6 +157,8 @@ function addUnicodeSeries!(o, d::KW, addlegend::Bool, xlim, ylim) # get the series data and label x, y = if st == :straightline straightline_data(d) + elseif st == :shape + shape_data(series) else [collect(float(d[s])) for s in (:x, :y)] end diff --git a/src/utils.jl b/src/utils.jl index d68ca24d..933ea2c6 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1121,3 +1121,25 @@ function straightline_data(xl, yl, x, y) return xdata, a .* xdata .+ b end end + +function shape_data(series) + sp = series[:subplot] + xl, yl = isvertical(series) ? (xlims(sp), ylims(sp)) : (ylims(sp), xlims(sp)) + x, y = series[:x], series[:y] + factor = 100 + for i in eachindex(x) + if x[i] == -Inf + x[i] = xl[1] - factor * (xl[2] - xl[1]) + elseif x[i] == Inf + x[i] = xl[2] + factor * (xl[2] - xl[1]) + end + end + for i in eachindex(y) + if y[i] == -Inf + y[i] = yl[1] - factor * (yl[2] - yl[1]) + elseif y[i] == Inf + y[i] = yl[2] + factor * (yl[2] - yl[1]) + end + end + return x, y +end