step recipes

This commit is contained in:
Thomas Breloff 2016-06-06 18:19:46 -04:00
parent 56f398fb55
commit 8d8ac10429
2 changed files with 75 additions and 29 deletions

View File

@ -39,7 +39,7 @@ supportedArgs(::GRBackend) = [
] ]
supportedAxes(::GRBackend) = _allAxes supportedAxes(::GRBackend) = _allAxes
supportedTypes(::GRBackend) = [ supportedTypes(::GRBackend) = [
:path, :steppre, :steppost, :path, #:steppre, :steppost,
:scatter, :scatter,
#:histogram2d, :hexbin, #:histogram2d, :hexbin,
:sticks, :sticks,
@ -657,6 +657,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
majorx = 5 majorx = 5
xtick = GR.tick(xmin, xmax) / majorx xtick = GR.tick(xmin, xmax) / majorx
else else
# log axis
# xtick = majorx = 1 # xtick = majorx = 1
xtick = 2 # scientific notation xtick = 2 # scientific notation
majorx = 2 # no minor grid lines majorx = 2 # no minor grid lines
@ -666,6 +667,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
majory = 5 majory = 5
ytick = GR.tick(ymin, ymax) / majory ytick = GR.tick(ymin, ymax) / majory
else else
# log axis
# ytick = majory = 1 # ytick = majory = 1
ytick = 2 # scientific notation ytick = 2 # scientific notation
majory = 2 # no minor grid lines majory = 2 # no minor grid lines
@ -776,7 +778,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
GR.savestate() GR.savestate()
xmin, xmax, ymin, ymax = extrema[gr_getaxisind(d),:] xmin, xmax, ymin, ymax = extrema[gr_getaxisind(d),:]
GR.setwindow(xmin, xmax, ymin, ymax) GR.setwindow(xmin, xmax, ymin, ymax)
if st in [:path, :steppre, :steppost, :sticks, :polar] if st in [:path, :sticks, :polar]
GR.setlinetype(gr_linetype[d[:linestyle]]) GR.setlinetype(gr_linetype[d[:linestyle]])
GR.setlinewidth(d[:linewidth]) GR.setlinewidth(d[:linewidth])
GR.setlinecolorind(gr_getcolorind(d[:linecolor])) GR.setlinecolorind(gr_getcolorind(d[:linecolor]))
@ -844,27 +846,27 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# end # end
# # legend[idx] = true # # legend[idx] = true
# TODO: use recipe # # TODO: use recipe
elseif st in [:steppre, :steppost] # elseif st in [:steppre, :steppost]
n = length(d[:x]) # n = length(d[:x])
x = zeros(2*n + 1) # x = zeros(2*n + 1)
y = zeros(2*n + 1) # y = zeros(2*n + 1)
x[1], y[1] = d[:x][1], d[:y][1] # x[1], y[1] = d[:x][1], d[:y][1]
j = 2 # j = 2
for i = 2:n # for i = 2:n
if st == :steppre # if st == :steppre
x[j], x[j+1] = d[:x][i-1], d[:x][i] # x[j], x[j+1] = d[:x][i-1], d[:x][i]
y[j], y[j+1] = d[:y][i], d[:y][i] # y[j], y[j+1] = d[:y][i], d[:y][i]
else # else
x[j], x[j+1] = d[:x][i], d[:x][i] # x[j], x[j+1] = d[:x][i], d[:x][i]
y[j], y[j+1] = d[:y][i-1], d[:y][i] # y[j], y[j+1] = d[:y][i-1], d[:y][i]
end # end
j += 2 # j += 2
end # end
if n > 1 # if n > 1
gr_polyline(x, y) # gr_polyline(x, y)
end # end
# legend[idx] = true # # legend[idx] = true
# TODO: use recipe # TODO: use recipe
elseif st == :sticks elseif st == :sticks
@ -1186,7 +1188,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
d = series.d d = series.d
st = d[:seriestype] st = d[:seriestype]
GR.setlinewidth(d[:linewidth]) GR.setlinewidth(d[:linewidth])
if d[:seriestype] in [:path, :line, :steppre, :steppost, :sticks] if d[:seriestype] in [:path, :sticks]
GR.setlinecolorind(gr_getcolorind(d[:linecolor])) GR.setlinecolorind(gr_getcolorind(d[:linecolor]))
GR.setlinetype(gr_linetype[d[:linestyle]]) GR.setlinetype(gr_linetype[d[:linestyle]])
GR.polyline([xpos - 0.07, xpos - 0.01], [ypos, ypos]) GR.polyline([xpos - 0.07, xpos - 0.01], [ypos, ypos])
@ -1194,7 +1196,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
if d[:seriestype] == :scatter || d[:markershape] != :none if d[:seriestype] == :scatter || d[:markershape] != :none
GR.setmarkercolorind(gr_getcolorind(d[:markercolor])) GR.setmarkercolorind(gr_getcolorind(d[:markercolor]))
gr_setmarkershape(d) gr_setmarkershape(d)
if d[:seriestype] in [:path, :line, :steppre, :steppost, :sticks] if d[:seriestype] in [:path, :sticks]
gr_polymarker(d, [xpos - 0.06, xpos - 0.02], [ypos, ypos]) gr_polymarker(d, [xpos - 0.06, xpos - 0.02], [ypos, ypos])
else else
gr_polymarker(d, [xpos - 0.06, xpos - 0.04, xpos - 0.02], [ypos, ypos, ypos]) gr_polymarker(d, [xpos - 0.06, xpos - 0.04, xpos - 0.02], [ypos, ypos, ypos])

View File

@ -179,11 +179,55 @@ end
() ()
end end
# ---------------------------------------------------------------------------
# steps
# # create a path from steps function make_steps(x, y, st)
# @recipe function f(::Type{Val{:steppre}}, x, y, z) n = length(x)
# newx, newy = zeros(2n-1), zeros(2n-1)
# end for i=1:n
idx = 2i-1
newx[idx] = x[i]
newy[idx] = y[i]
if i > 1
newx[idx-1] = x[st == :steppre ? i-1 : i]
newy[idx-1] = y[st == :steppre ? i : i-1]
end
end
newx, newy
end
# create a path from steps
@recipe function f(::Type{Val{:steppre}}, x, y, z)
d[:x], d[:y] = make_steps(x, y, :steppre)
seriestype := :path
if d[:markershape] != :none
@series begin
seriestype := :scatter
x := x
y := y
()
end
markershape := :none
end
()
end
# create a path from steps
@recipe function f(::Type{Val{:steppost}}, x, y, z)
d[:x], d[:y] = make_steps(x, y, :steppost)
seriestype := :path
if d[:markershape] != :none
@series begin
seriestype := :scatter
x := x
y := y
()
end
markershape := :none
end
()
end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------