:straightline for all backends

This commit is contained in:
Daniel Schwabeneder 2018-03-19 16:24:23 +01:00
parent bbff66a041
commit c8cdade884
9 changed files with 44 additions and 25 deletions

View File

@ -287,13 +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)
else
(d[:x], d[:y], d[:z])[1:dim]
end
topoints(Point{dim, Float32}, array) topoints(Point{dim, Float32}, array)
end end
function extract_straightline_points(sp::Subplot, series::Series)
x, y = straightline_data(sp, series)
topoints(Point{2, Float32}, (x, y))
end
function make_gradient(grad::Vector{C}) where C <: Colorant function make_gradient(grad::Vector{C}) where C <: Colorant
grad grad
end end
@ -1108,7 +1108,7 @@ function _display(plt::Plot{GLVisualizeBackend}, visible = true)
vis = GL.gl_surface(x, y, z, kw_args) vis = GL.gl_surface(x, y, z, kw_args)
elseif (st in (:path, :path3d, :straightline)) && d[:linewidth] > 0 elseif (st in (:path, :path3d, :straightline)) && d[:linewidth] > 0
kw = copy(kw_args) kw = copy(kw_args)
points = st == :straightline ? extract_straightline_points(sp, series) : Plots.extract_points(d) points = Plots.extract_points(d)
extract_linestyle(d, kw) extract_linestyle(d, kw)
vis = GL.gl_lines(points, kw) vis = GL.gl_lines(points, kw)
if d[:markershape] != :none if d[:markershape] != :none

View File

@ -1015,7 +1015,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end end
if st == :straightline if st == :straightline
x, y = straightline_data(sp, series) x, y = straightline_data(series)
end end
if st in (:path, :scatter, :straightline) if st in (:path, :scatter, :straightline)

View File

@ -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,

View File

@ -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)
@ -299,7 +303,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:

View File

@ -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,8 @@ 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 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

View File

@ -51,6 +51,7 @@ const _plotly_attr = merge_with_base_supported([
const _plotly_seriestype = [ const _plotly_seriestype = [
:path, :scatter, :bar, :pie, :heatmap, :path, :scatter, :bar, :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 = [
@ -510,12 +511,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])
@ -526,7 +531,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"

View File

@ -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,
@ -452,6 +452,9 @@ 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)
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
@ -485,7 +488,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...;
@ -1244,7 +1247,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)),

View File

@ -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,11 @@ 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)
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

View File

@ -1080,8 +1080,9 @@ function convert_sci_unicode(label::AbstractString)
label label
end end
function straightline_data(sp::Subplot, series::Series) function straightline_data(series)
xl, yl = isvertical(series.d) ? (xlims(sp), ylims(sp)) : (ylims(sp), xlims(sp)) sp = series[:subplot]
xl, yl = isvertical(series) ? (xlims(sp), ylims(sp)) : (ylims(sp), xlims(sp))
x, y = series[:x], series[:y] x, y = series[:x], series[:y]
n = length(x) n = length(x)
if n == 2 if n == 2