Merge pull request #1445 from daschw/infinite-objects
Infinite objects (fix #1422)
This commit is contained in:
commit
bfc26fa407
@ -187,6 +187,8 @@ include("output.jl")
|
|||||||
@shorthands sticks
|
@shorthands sticks
|
||||||
@shorthands hline
|
@shorthands hline
|
||||||
@shorthands vline
|
@shorthands vline
|
||||||
|
@shorthands hspan
|
||||||
|
@shorthands vspan
|
||||||
@shorthands ohlc
|
@shorthands ohlc
|
||||||
@shorthands contour
|
@shorthands contour
|
||||||
@shorthands contourf
|
@shorthands contourf
|
||||||
|
|||||||
11
src/axes.jl
11
src/axes.jl
@ -289,8 +289,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function expand_extrema!(ex::Extrema, v::Number)
|
function expand_extrema!(ex::Extrema, v::Number)
|
||||||
ex.emin = NaNMath.min(v, ex.emin)
|
ex.emin = isfinite(v) ? min(v, ex.emin) : ex.emin
|
||||||
ex.emax = NaNMath.max(v, ex.emax)
|
ex.emax = isfinite(v) ? max(v, ex.emax) : ex.emax
|
||||||
ex
|
ex
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -305,8 +305,8 @@ expand_extrema!(axis::Axis, ::Bool) = axis[:extrema]
|
|||||||
|
|
||||||
function expand_extrema!(axis::Axis, v::Tuple{MIN,MAX}) where {MIN<:Number,MAX<:Number}
|
function expand_extrema!(axis::Axis, v::Tuple{MIN,MAX}) where {MIN<:Number,MAX<:Number}
|
||||||
ex = axis[:extrema]
|
ex = axis[:extrema]
|
||||||
ex.emin = NaNMath.min(v[1], ex.emin)
|
ex.emin = isfinite(v[1]) ? min(v[1], ex.emin) : ex.emin
|
||||||
ex.emax = NaNMath.max(v[2], ex.emax)
|
ex.emax = isfinite(v[2]) ? max(v[2], ex.emax) : ex.emax
|
||||||
ex
|
ex
|
||||||
end
|
end
|
||||||
function expand_extrema!(axis::Axis, v::AVec{N}) where N<:Number
|
function expand_extrema!(axis::Axis, v::AVec{N}) where N<:Number
|
||||||
@ -328,6 +328,9 @@ function expand_extrema!(sp::Subplot, d::KW)
|
|||||||
else
|
else
|
||||||
letter == :x ? :y : letter == :y ? :x : :z
|
letter == :x ? :y : letter == :y ? :x : :z
|
||||||
end]
|
end]
|
||||||
|
if letter != :z && d[:seriestype] == :straightline && any(series[:seriestype] != :straightline for series in series_list(sp)) && data[1] != data[2]
|
||||||
|
data = [NaN]
|
||||||
|
end
|
||||||
axis = sp[Symbol(letter, "axis")]
|
axis = sp[Symbol(letter, "axis")]
|
||||||
|
|
||||||
if isa(data, Volume)
|
if isa(data, Volume)
|
||||||
|
|||||||
@ -51,7 +51,7 @@ const _glvisualize_attr = merge_with_base_supported([
|
|||||||
:tick_direction,
|
:tick_direction,
|
||||||
])
|
])
|
||||||
const _glvisualize_seriestype = [
|
const _glvisualize_seriestype = [
|
||||||
:path, :shape,
|
:path, :shape, :straightline,
|
||||||
:scatter, :hexbin,
|
:scatter, :hexbin,
|
||||||
:bar, :boxplot,
|
:bar, :boxplot,
|
||||||
:heatmap, :image, :volume,
|
:heatmap, :image, :volume,
|
||||||
@ -287,7 +287,13 @@ function topoints(::Type{P}, array) where P
|
|||||||
end
|
end
|
||||||
function extract_points(d)
|
function extract_points(d)
|
||||||
dim = is3d(d) ? 3 : 2
|
dim = is3d(d) ? 3 : 2
|
||||||
array = (d[:x], d[:y], d[:z])[1:dim]
|
array = if d[:seriestype] == :straightline
|
||||||
|
straightline_data(d)
|
||||||
|
elseif d[:seriestype] == :shape
|
||||||
|
shape_data(d)
|
||||||
|
else
|
||||||
|
(d[:x], d[:y], d[:z])[1:dim]
|
||||||
|
end
|
||||||
topoints(Point{dim, Float32}, array)
|
topoints(Point{dim, Float32}, array)
|
||||||
end
|
end
|
||||||
function make_gradient(grad::Vector{C}) where C <: Colorant
|
function make_gradient(grad::Vector{C}) where C <: Colorant
|
||||||
@ -1102,7 +1108,7 @@ function _display(plt::Plot{GLVisualizeBackend}, visible = true)
|
|||||||
kw_args[:stroke_width] = Float32(d[:linewidth]/100f0)
|
kw_args[:stroke_width] = Float32(d[:linewidth]/100f0)
|
||||||
end
|
end
|
||||||
vis = GL.gl_surface(x, y, z, kw_args)
|
vis = GL.gl_surface(x, y, z, kw_args)
|
||||||
elseif (st in (:path, :path3d)) && d[:linewidth] > 0
|
elseif (st in (:path, :path3d, :straightline)) && d[:linewidth] > 0
|
||||||
kw = copy(kw_args)
|
kw = copy(kw_args)
|
||||||
points = Plots.extract_points(d)
|
points = Plots.extract_points(d)
|
||||||
extract_linestyle(d, kw)
|
extract_linestyle(d, kw)
|
||||||
@ -1460,7 +1466,7 @@ function make_label(sp, series, i)
|
|||||||
d = series.d
|
d = series.d
|
||||||
st = d[:seriestype]
|
st = d[:seriestype]
|
||||||
kw_args = KW()
|
kw_args = KW()
|
||||||
if (st in (:path, :path3d)) && d[:linewidth] > 0
|
if (st in (:path, :path3d, :straightline)) && d[:linewidth] > 0
|
||||||
points = Point2f0[(0, ho), (w, ho)]
|
points = Point2f0[(0, ho), (w, ho)]
|
||||||
kw = KW()
|
kw = KW()
|
||||||
extract_linestyle(d, kw)
|
extract_linestyle(d, kw)
|
||||||
|
|||||||
@ -48,7 +48,7 @@ const _gr_attr = merge_with_base_supported([
|
|||||||
:contour_labels,
|
:contour_labels,
|
||||||
])
|
])
|
||||||
const _gr_seriestype = [
|
const _gr_seriestype = [
|
||||||
:path, :scatter,
|
:path, :scatter, :straightline,
|
||||||
:heatmap, :pie, :image,
|
:heatmap, :pie, :image,
|
||||||
:contour, :path3d, :scatter3d, :surface, :wireframe,
|
:contour, :path3d, :scatter3d, :surface, :wireframe,
|
||||||
:shape
|
:shape
|
||||||
@ -1014,7 +1014,11 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
x, y = convert_to_polar(x, y, (rmin, rmax))
|
x, y = convert_to_polar(x, y, (rmin, rmax))
|
||||||
end
|
end
|
||||||
|
|
||||||
if st in (:path, :scatter)
|
if st == :straightline
|
||||||
|
x, y = straightline_data(series)
|
||||||
|
end
|
||||||
|
|
||||||
|
if st in (:path, :scatter, :straightline)
|
||||||
if length(x) > 1
|
if length(x) > 1
|
||||||
lz = series[:line_z]
|
lz = series[:line_z]
|
||||||
segments_iterator = if lz != nothing && length(lz) > 1
|
segments_iterator = if lz != nothing && length(lz) > 1
|
||||||
@ -1036,7 +1040,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# draw the line(s)
|
# draw the line(s)
|
||||||
if st == :path
|
if st in (:path, :straightline)
|
||||||
for (i, rng) in enumerate(segments_iterator)
|
for (i, rng) in enumerate(segments_iterator)
|
||||||
gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, i)) #, series[:linealpha])
|
gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, i)) #, series[:linealpha])
|
||||||
arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none
|
arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none
|
||||||
@ -1182,6 +1186,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
GR.selntran(1)
|
GR.selntran(1)
|
||||||
|
|
||||||
elseif st == :shape
|
elseif st == :shape
|
||||||
|
x, y = shape_data(series)
|
||||||
for (i,rng) in enumerate(iter_segments(x, y))
|
for (i,rng) in enumerate(iter_segments(x, y))
|
||||||
if length(rng) > 1
|
if length(rng) > 1
|
||||||
# connect to the beginning
|
# connect to the beginning
|
||||||
@ -1295,7 +1300,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
st == :shape && gr_polyline(x, y)
|
st == :shape && gr_polyline(x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
if st == :path
|
if st in (:path, :straightline)
|
||||||
GR.settransparency(gr_alpha(series[:linealpha]))
|
GR.settransparency(gr_alpha(series[:linealpha]))
|
||||||
if series[:fillrange] == nothing || series[:ribbon] != nothing
|
if series[:fillrange] == nothing || series[:ribbon] != nothing
|
||||||
GR.polyline([xpos - 0.07, xpos - 0.01], [ypos, ypos])
|
GR.polyline([xpos - 0.07, xpos - 0.01], [ypos, ypos])
|
||||||
|
|||||||
@ -97,7 +97,7 @@ const _hdf5_attr = merge_with_base_supported([
|
|||||||
:colorbar_title,
|
:colorbar_title,
|
||||||
])
|
])
|
||||||
const _hdf5_seriestype = [
|
const _hdf5_seriestype = [
|
||||||
:path, :steppre, :steppost, :shape,
|
:path, :steppre, :steppost, :shape, :straightline,
|
||||||
:scatter, :hexbin, #:histogram2d, :histogram,
|
:scatter, :hexbin, #:histogram2d, :histogram,
|
||||||
# :bar,
|
# :bar,
|
||||||
:heatmap, :pie, :image,
|
:heatmap, :pie, :image,
|
||||||
|
|||||||
@ -57,7 +57,7 @@ const _inspectdr_attr = merge_with_base_supported([
|
|||||||
])
|
])
|
||||||
const _inspectdr_style = [:auto, :solid, :dash, :dot, :dashdot]
|
const _inspectdr_style = [:auto, :solid, :dash, :dot, :dashdot]
|
||||||
const _inspectdr_seriestype = [
|
const _inspectdr_seriestype = [
|
||||||
:path, :scatter, :shape #, :steppre, :steppost
|
:path, :scatter, :shape, :straightline, #, :steppre, :steppost
|
||||||
]
|
]
|
||||||
#see: _allMarkers, _shape_keys
|
#see: _allMarkers, _shape_keys
|
||||||
const _inspectdr_marker = Symbol[
|
const _inspectdr_marker = Symbol[
|
||||||
@ -243,7 +243,11 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series)
|
|||||||
if nothing == plot; return; end
|
if nothing == plot; return; end
|
||||||
|
|
||||||
_vectorize(v) = isa(v, Vector) ? v : collect(v) #InspectDR only supports vectors
|
_vectorize(v) = isa(v, Vector) ? v : collect(v) #InspectDR only supports vectors
|
||||||
x = _vectorize(series[:x]); y = _vectorize(series[:y])
|
x, y = if st == :straightline
|
||||||
|
straightline_data(series)
|
||||||
|
else
|
||||||
|
_vectorize(series[:x]), _vectorize(series[:y])
|
||||||
|
end
|
||||||
|
|
||||||
#No support for polar grid... but can still perform polar transformation:
|
#No support for polar grid... but can still perform polar transformation:
|
||||||
if ispolar(sp)
|
if ispolar(sp)
|
||||||
@ -268,6 +272,7 @@ For st in :shape:
|
|||||||
=#
|
=#
|
||||||
|
|
||||||
if st in (:shape,)
|
if st in (:shape,)
|
||||||
|
x, y = shape_data(series)
|
||||||
nmax = 0
|
nmax = 0
|
||||||
for (i,rng) in enumerate(iter_segments(x, y))
|
for (i,rng) in enumerate(iter_segments(x, y))
|
||||||
nmax = i
|
nmax = i
|
||||||
@ -299,7 +304,7 @@ For st in :shape:
|
|||||||
color = linecolor, fillcolor = fillcolor
|
color = linecolor, fillcolor = fillcolor
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
elseif st in (:path, :scatter) #, :steppre, :steppost)
|
elseif st in (:path, :scatter, :straightline) #, :steppre, :steppost)
|
||||||
#NOTE: In Plots.jl, :scatter plots have 0-linewidths (I think).
|
#NOTE: In Plots.jl, :scatter plots have 0-linewidths (I think).
|
||||||
linewidth = series[:linewidth]
|
linewidth = series[:linewidth]
|
||||||
#More efficient & allows some support for markerstrokewidth:
|
#More efficient & allows some support for markerstrokewidth:
|
||||||
|
|||||||
@ -39,7 +39,7 @@ const _pgfplots_attr = merge_with_base_supported([
|
|||||||
:framestyle,
|
:framestyle,
|
||||||
:camera,
|
:camera,
|
||||||
])
|
])
|
||||||
const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape]
|
const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape, :straightline,]
|
||||||
const _pgfplots_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
const _pgfplots_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
||||||
const _pgfplots_marker = [:none, :auto, :circle, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :pentagon, :hline] #vcat(_allMarkers, Shape)
|
const _pgfplots_marker = [:none, :auto, :circle, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :pentagon, :hline] #vcat(_allMarkers, Shape)
|
||||||
const _pgfplots_scale = [:identity, :ln, :log2, :log10]
|
const _pgfplots_scale = [:identity, :ln, :log2, :log10]
|
||||||
@ -220,6 +220,10 @@ function pgf_series(sp::Subplot, series::Series)
|
|||||||
d[:z].surf, d[:x], d[:y]
|
d[:z].surf, d[:x], d[:y]
|
||||||
elseif is3d(st)
|
elseif is3d(st)
|
||||||
d[:x], d[:y], d[:z]
|
d[:x], d[:y], d[:z]
|
||||||
|
elseif st == :straightline
|
||||||
|
straightline_data(series)
|
||||||
|
elseif st == :shape
|
||||||
|
shape_data(series)
|
||||||
elseif d[:marker_z] != nothing
|
elseif d[:marker_z] != nothing
|
||||||
# If a marker_z is used pass it as third coordinate to a 2D plot.
|
# If a marker_z is used pass it as third coordinate to a 2D plot.
|
||||||
# See "Scatter Plots" in PGFPlots documentation
|
# See "Scatter Plots" in PGFPlots documentation
|
||||||
|
|||||||
@ -51,6 +51,7 @@ const _plotly_attr = merge_with_base_supported([
|
|||||||
const _plotly_seriestype = [
|
const _plotly_seriestype = [
|
||||||
:path, :scatter, :pie, :heatmap,
|
:path, :scatter, :pie, :heatmap,
|
||||||
:contour, :surface, :wireframe, :path3d, :scatter3d, :shape, :scattergl,
|
:contour, :surface, :wireframe, :path3d, :scatter3d, :shape, :scattergl,
|
||||||
|
:straightline
|
||||||
]
|
]
|
||||||
const _plotly_style = [:auto, :solid, :dash, :dot, :dashdot]
|
const _plotly_style = [:auto, :solid, :dash, :dot, :dashdot]
|
||||||
const _plotly_marker = [
|
const _plotly_marker = [
|
||||||
@ -522,12 +523,16 @@ function plotly_series(plt::Plot, series::Series)
|
|||||||
plotly_data(series[letter])
|
plotly_data(series[letter])
|
||||||
end), (:x, :y, :z))
|
end), (:x, :y, :z))
|
||||||
|
|
||||||
|
if st == :straightline
|
||||||
|
x, y = straightline_data(series)
|
||||||
|
end
|
||||||
|
|
||||||
d_out[:name] = series[:label]
|
d_out[:name] = series[:label]
|
||||||
|
|
||||||
isscatter = st in (:scatter, :scatter3d, :scattergl)
|
isscatter = st in (:scatter, :scatter3d, :scattergl)
|
||||||
hasmarker = isscatter || series[:markershape] != :none
|
hasmarker = isscatter || series[:markershape] != :none
|
||||||
hasline = st in (:path, :path3d)
|
hasline = st in (:path, :path3d, :straightline)
|
||||||
hasfillrange = st in (:path, :scatter, :scattergl) &&
|
hasfillrange = st in (:path, :scatter, :scattergl, :straightline) &&
|
||||||
(isa(series[:fillrange], AbstractVector) || isa(series[:fillrange], Tuple))
|
(isa(series[:fillrange], AbstractVector) || isa(series[:fillrange], Tuple))
|
||||||
|
|
||||||
d_out[:colorbar] = KW(:title => sp[:colorbar_title])
|
d_out[:colorbar] = KW(:title => sp[:colorbar_title])
|
||||||
@ -538,7 +543,7 @@ function plotly_series(plt::Plot, series::Series)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# set the "type"
|
# set the "type"
|
||||||
if st in (:path, :scatter, :scattergl)
|
if st in (:path, :scatter, :scattergl, :straightline)
|
||||||
d_out[:type] = st==:scattergl ? "scattergl" : "scatter"
|
d_out[:type] = st==:scattergl ? "scattergl" : "scatter"
|
||||||
d_out[:mode] = if hasmarker
|
d_out[:mode] = if hasmarker
|
||||||
hasline ? "lines+markers" : "markers"
|
hasline ? "lines+markers" : "markers"
|
||||||
@ -708,7 +713,7 @@ function plotly_series_shapes(plt::Plot, series::Series)
|
|||||||
base_d[:name] = series[:label]
|
base_d[:name] = series[:label]
|
||||||
# base_d[:legendgroup] = 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))
|
for (i,rng) in enumerate(iter_segments(x,y))
|
||||||
length(rng) < 2 && continue
|
length(rng) < 2 && continue
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ const _pyplot_attr = merge_with_base_supported([
|
|||||||
:contour_labels,
|
:contour_labels,
|
||||||
])
|
])
|
||||||
const _pyplot_seriestype = [
|
const _pyplot_seriestype = [
|
||||||
:path, :steppre, :steppost, :shape,
|
:path, :steppre, :steppost, :shape, :straightline,
|
||||||
:scatter, :hexbin, #:histogram2d, :histogram,
|
:scatter, :hexbin, #:histogram2d, :histogram,
|
||||||
# :bar,
|
# :bar,
|
||||||
:heatmap, :pie, :image,
|
:heatmap, :pie, :image,
|
||||||
@ -453,6 +453,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
|
|
||||||
# ax = getAxis(plt, series)
|
# ax = getAxis(plt, series)
|
||||||
x, y, z = series[:x], series[:y], series[:z]
|
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))
|
xyargs = (st in _3dTypes ? (x,y,z) : (x,y))
|
||||||
|
|
||||||
# handle zcolor and get c/cmap
|
# handle zcolor and get c/cmap
|
||||||
@ -486,7 +491,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
# for each plotting command, optionally build and add a series handle to the list
|
# for each plotting command, optionally build and add a series handle to the list
|
||||||
|
|
||||||
# line plot
|
# line plot
|
||||||
if st in (:path, :path3d, :steppre, :steppost)
|
if st in (:path, :path3d, :steppre, :steppost, :straightline)
|
||||||
if series[:linewidth] > 0
|
if series[:linewidth] > 0
|
||||||
if series[:line_z] == nothing
|
if series[:line_z] == nothing
|
||||||
handle = ax[:plot](xyargs...;
|
handle = ax[:plot](xyargs...;
|
||||||
@ -1249,7 +1254,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
|
|||||||
facecolor = py_color(_cycle(series[:fillcolor],1)),
|
facecolor = py_color(_cycle(series[:fillcolor],1)),
|
||||||
linewidth = py_dpi_scale(plt, clamp(series[:linewidth], 0, 5)),
|
linewidth = py_dpi_scale(plt, clamp(series[:linewidth], 0, 5)),
|
||||||
)
|
)
|
||||||
elseif series[:seriestype] == :path
|
elseif series[:seriestype] in (:path, :straightline)
|
||||||
PyPlot.plt[:Line2D]((0,1),(0,0),
|
PyPlot.plt[:Line2D]((0,1),(0,0),
|
||||||
color = py_color(_cycle(series[:linecolor],1)),
|
color = py_color(_cycle(series[:linecolor],1)),
|
||||||
linewidth = py_dpi_scale(plt, clamp(series[:linewidth], 0, 5)),
|
linewidth = py_dpi_scale(plt, clamp(series[:linewidth], 0, 5)),
|
||||||
|
|||||||
@ -17,7 +17,7 @@ const _unicodeplots_attr = merge_with_base_supported([
|
|||||||
:guide, :lims,
|
:guide, :lims,
|
||||||
])
|
])
|
||||||
const _unicodeplots_seriestype = [
|
const _unicodeplots_seriestype = [
|
||||||
:path, :scatter,
|
:path, :scatter, :straightline,
|
||||||
# :bar,
|
# :bar,
|
||||||
:shape,
|
:shape,
|
||||||
:histogram2d,
|
:histogram2d,
|
||||||
@ -142,7 +142,7 @@ function addUnicodeSeries!(o, d::KW, addlegend::Bool, xlim, ylim)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if st == :path
|
if st in (:path, :straightline)
|
||||||
func = UnicodePlots.lineplot!
|
func = UnicodePlots.lineplot!
|
||||||
elseif st == :scatter || d[:markershape] != :none
|
elseif st == :scatter || d[:markershape] != :none
|
||||||
func = UnicodePlots.scatterplot!
|
func = UnicodePlots.scatterplot!
|
||||||
@ -155,7 +155,13 @@ function addUnicodeSeries!(o, d::KW, addlegend::Bool, xlim, ylim)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# get the series data and label
|
# get the series data and label
|
||||||
x, y = [collect(float(d[s])) for s in (:x, :y)]
|
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
|
||||||
label = addlegend ? d[:label] : ""
|
label = addlegend ? d[:label] : ""
|
||||||
|
|
||||||
# if we happen to pass in allowed color symbols, great... otherwise let UnicodePlots decide
|
# if we happen to pass in allowed color symbols, great... otherwise let UnicodePlots decide
|
||||||
|
|||||||
@ -79,28 +79,50 @@ function hvline_limits(axis::Axis)
|
|||||||
end
|
end
|
||||||
|
|
||||||
@recipe function f(::Type{Val{:hline}}, x, y, z)
|
@recipe function f(::Type{Val{:hline}}, x, y, z)
|
||||||
xmin, xmax = hvline_limits(plotattributes[:subplot][:xaxis])
|
|
||||||
n = length(y)
|
n = length(y)
|
||||||
newx = repmat(Float64[xmin, xmax, NaN], n)
|
newx = repmat(Float64[-1, 1, NaN], n)
|
||||||
newy = vec(Float64[yi for i=1:3,yi=y])
|
newy = vec(Float64[yi for i=1:3,yi=y])
|
||||||
x := newx
|
x := newx
|
||||||
y := newy
|
y := newy
|
||||||
seriestype := :path
|
seriestype := :straightline
|
||||||
()
|
()
|
||||||
end
|
end
|
||||||
@deps hline path
|
@deps hline straightline
|
||||||
|
|
||||||
@recipe function f(::Type{Val{:vline}}, x, y, z)
|
@recipe function f(::Type{Val{:vline}}, x, y, z)
|
||||||
ymin, ymax = hvline_limits(plotattributes[:subplot][:yaxis])
|
|
||||||
n = length(y)
|
n = length(y)
|
||||||
newx = vec(Float64[yi for i=1:3,yi=y])
|
newx = vec(Float64[yi for i=1:3,yi=y])
|
||||||
newy = repmat(Float64[ymin, ymax, NaN], n)
|
newy = repmat(Float64[-1, 1, NaN], n)
|
||||||
x := newx
|
x := newx
|
||||||
y := newy
|
y := newy
|
||||||
seriestype := :path
|
seriestype := :straightline
|
||||||
()
|
()
|
||||||
end
|
end
|
||||||
@deps vline path
|
@deps vline straightline
|
||||||
|
|
||||||
|
@recipe function f(::Type{Val{:hspan}}, x, y, z)
|
||||||
|
n = div(length(y), 2)
|
||||||
|
newx = repeat([-Inf, Inf, Inf, -Inf, NaN], outer = n)
|
||||||
|
newy = vcat([[y[2i-1], y[2i-1], y[2i], y[2i], NaN] for i in 1:n]...)
|
||||||
|
linewidth --> 0
|
||||||
|
x := newx
|
||||||
|
y := newy
|
||||||
|
seriestype := :shape
|
||||||
|
()
|
||||||
|
end
|
||||||
|
@deps hspan shape
|
||||||
|
|
||||||
|
@recipe function f(::Type{Val{:vspan}}, x, y, z)
|
||||||
|
n = div(length(y), 2)
|
||||||
|
newx = vcat([[y[2i-1], y[2i-1], y[2i], y[2i], NaN] for i in 1:n]...)
|
||||||
|
newy = repeat([-Inf, Inf, Inf, -Inf, NaN], outer = n)
|
||||||
|
linewidth --> 0
|
||||||
|
x := newx
|
||||||
|
y := newy
|
||||||
|
seriestype := :shape
|
||||||
|
()
|
||||||
|
end
|
||||||
|
@deps vspan shape
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# path and scatter
|
# path and scatter
|
||||||
@ -999,15 +1021,7 @@ end
|
|||||||
# -------------------------------------------------
|
# -------------------------------------------------
|
||||||
|
|
||||||
"Adds a+bx... straight line over the current plot, without changing the axis limits"
|
"Adds a+bx... straight line over the current plot, without changing the axis limits"
|
||||||
function abline!(plt::Plot, a, b; kw...)
|
abline!(plt::Plot, a, b; kw...) = plot!(plt, [0, 1], [b, b+a]; seriestype = :straightline, kw...)
|
||||||
xl, yl = xlims(plt), ylims(plt)
|
|
||||||
x1, x2 = max(xl[1], (yl[1] - b)/a), min(xl[2], (yl[2] - b)/a)
|
|
||||||
if x2 > x1
|
|
||||||
plot!(plt, x -> b + a*x, x1, x2; kw...)
|
|
||||||
else
|
|
||||||
nothing
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
abline!(args...; kw...) = abline!(current(), args...; kw...)
|
abline!(args...; kw...) = abline!(current(), args...; kw...)
|
||||||
|
|
||||||
|
|||||||
71
src/utils.jl
71
src/utils.jl
@ -1079,3 +1079,74 @@ function convert_sci_unicode(label::AbstractString)
|
|||||||
end
|
end
|
||||||
label
|
label
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function straightline_data(series)
|
||||||
|
sp = series[:subplot]
|
||||||
|
xl, yl = isvertical(series) ? (xlims(sp), ylims(sp)) : (ylims(sp), xlims(sp))
|
||||||
|
x, y = series[:x], series[:y]
|
||||||
|
n = length(x)
|
||||||
|
if n == 2
|
||||||
|
return straightline_data(xl, yl, x, y)
|
||||||
|
else
|
||||||
|
k, r = divrem(n, 3)
|
||||||
|
if r == 0
|
||||||
|
xdata, ydata = fill(NaN, n), fill(NaN, n)
|
||||||
|
for i in 1:k
|
||||||
|
inds = (3 * i - 2):(3 * i - 1)
|
||||||
|
xdata[inds], ydata[inds] = straightline_data(xl, yl, x[inds], y[inds])
|
||||||
|
end
|
||||||
|
return xdata, ydata
|
||||||
|
else
|
||||||
|
error("Misformed data. `straightline_data` either accepts vectors of length 2 or 3k. The provided series has length $n")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function straightline_data(xl, yl, x, y)
|
||||||
|
x_vals, y_vals = if y[1] == y[2]
|
||||||
|
if x[1] == x[2]
|
||||||
|
error("Two identical points cannot be used to describe a straight line.")
|
||||||
|
else
|
||||||
|
[xl[1], xl[2]], [y[1], y[2]]
|
||||||
|
end
|
||||||
|
elseif x[1] == x[2]
|
||||||
|
[x[1], x[2]], [yl[1], yl[2]]
|
||||||
|
else
|
||||||
|
# get a and b from the line y = a * x + b through the points given by
|
||||||
|
# the coordinates x and x
|
||||||
|
b = y[1] - (y[1] - y[2]) * x[1] / (x[1] - x[2])
|
||||||
|
a = (y[1] - y[2]) / (x[1] - x[2])
|
||||||
|
# get the data values
|
||||||
|
xdata = [clamp(x[1] + (x[1] - x[2]) * (ylim - y[1]) / (y[1] - y[2]), xl...) for ylim in yl]
|
||||||
|
|
||||||
|
xdata, a .* xdata .+ b
|
||||||
|
end
|
||||||
|
# expand the data outside the axis limits, by a certain factor too improve
|
||||||
|
# plotly(js) and interactive behaviour
|
||||||
|
factor = 100
|
||||||
|
x_vals = x_vals .+ (x_vals[2] - x_vals[1]) .* factor .* [-1, 1]
|
||||||
|
y_vals = y_vals .+ (y_vals[2] - y_vals[1]) .* factor .* [-1, 1]
|
||||||
|
return x_vals, y_vals
|
||||||
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user