begin GR cleanup

This commit is contained in:
Thomas Breloff 2016-05-24 15:22:16 -04:00
parent 300babd6b1
commit 5699f3c6bc
2 changed files with 782 additions and 770 deletions

View File

@ -34,7 +34,7 @@ supportedArgs(::GRBackend) = [
:overwrite_figure, :overwrite_figure,
:polar, :polar,
:aspect_ratio :aspect_ratio
] ]
supportedAxes(::GRBackend) = _allAxes supportedAxes(::GRBackend) = _allAxes
supportedTypes(::GRBackend) = [ supportedTypes(::GRBackend) = [
:none, :line, :path, :steppre, :steppost, :none, :line, :path, :steppre, :steppost,
@ -42,7 +42,7 @@ supportedTypes(::GRBackend) = [
:bar, :sticks, :bar, :sticks,
:hline, :vline, :heatmap, :pie, :image, #:ohlc, :hline, :vline, :heatmap, :pie, :image, #:ohlc,
:contour, :path3d, :scatter3d, :surface, :wireframe :contour, :path3d, :scatter3d, :surface, :wireframe
] ]
supportedStyles(::GRBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] supportedStyles(::GRBackend) = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
supportedMarkers(::GRBackend) = vcat(_allMarkers, Shape) supportedMarkers(::GRBackend) = vcat(_allMarkers, Shape)
supportedScales(::GRBackend) = [:identity, :log10] supportedScales(::GRBackend) = [:identity, :log10]
@ -61,22 +61,58 @@ function _initialize_backend(::GRBackend; kw...)
end end
const gr_linetype = KW( const gr_linetype = KW(
:auto => 1, :solid => 1, :dash => 2, :dot => 3, :dashdot => 4, :auto => 1,
:dashdotdot => -1 ) :solid => 1,
:dash => 2,
:dot => 3,
:dashdot => 4,
:dashdotdot => -1
)
const gr_markertype = KW( const gr_markertype = KW(
:auto => 1, :none => -1, :ellipse => -1, :rect => -7, :diamond => -13, :auto => 1,
:utriangle => -3, :dtriangle => -5, :pentagon => -21, :hexagon => -22, :none => -1,
:heptagon => -23, :octagon => -24, :cross => 2, :xcross => 5, :ellipse => -1,
:star4 => -25, :star5 => -26, :star6 => -27, :star7 => -28, :star8 => -29, :rect => -7,
:vline => -30, :hline => -31 ) :diamond => -13,
:utriangle => -3,
:dtriangle => -5,
:pentagon => -21,
:hexagon => -22,
:heptagon => -23,
:octagon => -24,
:cross => 2,
:xcross => 5,
:star4 => -25,
:star5 => -26,
:star6 => -27,
:star7 => -28,
:star8 => -29,
:vline => -30,
:hline => -31
)
const gr_halign = KW(:left => 1, :hcenter => 2, :right => 3) const gr_halign = KW(
const gr_valign = KW(:top => 1, :vcenter => 3, :bottom => 5) :left => 1,
:hcenter => 2,
:right => 3
)
const gr_valign = KW(
:top => 1,
:vcenter => 3,
:bottom => 5
)
const gr_font_family = Dict( const gr_font_family = Dict(
"times" => 1, "helvetica" => 5, "courier" => 9, "bookman" => 14, "times" => 1,
"newcenturyschlbk" => 18, "avantgarde" => 22, "palatino" => 26) "helvetica" => 5,
"courier" => 9,
"bookman" => 14,
"newcenturyschlbk" => 18,
"avantgarde" => 22,
"palatino" => 26
)
function gr_getcolorind(v) function gr_getcolorind(v)
c = getColor(v) c = getColor(v)
@ -84,7 +120,6 @@ function gr_getcolorind(v)
end end
function gr_getaxisind(p) function gr_getaxisind(p)
# axis = get(p, :axis, :none)
axis = :left axis = :left
if axis in [:none, :left] if axis in [:none, :left]
return 1 return 1
@ -123,6 +158,7 @@ function gr_polymarker(p, x, y)
end end
end end
# TODO: simplify
function gr_polyline(x, y) function gr_polyline(x, y)
if NaN in x || NaN in y if NaN in x || NaN in y
i = 1 i = 1
@ -261,8 +297,6 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
end end
if st == :bar if st == :bar
x, y = 1:length(p[:y]), p[:y] x, y = 1:length(p[:y]), p[:y]
# elseif st == :ohlc
# x, y = 1:size(p[:y], 1), p[:y]
elseif st in [:hist, :density] elseif st in [:hist, :density]
x, y = Base.hist(p[:y], p[:bins]) x, y = Base.hist(p[:y], p[:bins])
elseif st in [:hist2d, :hexbin] elseif st in [:hist2d, :hexbin]
@ -295,15 +329,8 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
if !(st in [:pie, :polar]) if !(st in [:pie, :polar])
xmin = min(minimum(x), xmin) xmin = min(minimum(x), xmin)
xmax = max(maximum(x), xmax) xmax = max(maximum(x), xmax)
# if st == :ohlc
# for val in y
# ymin = min(val.open, val.high, val.low, val.close, ymin)
# ymax = max(val.open, val.high, val.low, val.close, ymax)
# end
# else
ymin = min(minimum(y), ymin) ymin = min(minimum(y), ymin)
ymax = max(maximum(y), ymax) ymax = max(maximum(y), ymax)
# end
if p[:xerror] != nothing || p[:yerror] != nothing if p[:xerror] != nothing || p[:yerror] != nothing
dx = xmax - xmin dx = xmax - xmin
xmin -= 0.02 * dx xmin -= 0.02 * dx
@ -460,7 +487,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
GR.savestate() GR.savestate()
xmin, xmax, ymin, ymax = extrema[gr_getaxisind(p),:] xmin, xmax, ymin, ymax = extrema[gr_getaxisind(p),:]
GR.setwindow(xmin, xmax, ymin, ymax) GR.setwindow(xmin, xmax, ymin, ymax)
if st in [:path, :line, :steppre, :steppost, :sticks, :hline, :vline, :polar] # :ohlc, :polar] if st in [:path, :line, :steppre, :steppost, :sticks, :hline, :vline, :polar]
GR.setlinetype(gr_linetype[p[:linestyle]]) GR.setlinetype(gr_linetype[p[:linestyle]])
GR.setlinewidth(p[:linewidth]) GR.setlinewidth(p[:linewidth])
GR.setlinecolorind(gr_getcolorind(p[:linecolor])) GR.setlinecolorind(gr_getcolorind(p[:linecolor]))
@ -570,8 +597,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
counts = round(Int32, 1000 + 255 * H / maximum(H)) counts = round(Int32, 1000 + 255 * H / maximum(H))
n, m = size(counts) n, m = size(counts)
GR.cellarray(xmin, xmax, ymin, ymax, n, m, counts) GR.cellarray(xmin, xmax, ymin, ymax, n, m, counts)
GR.setviewport(viewport[2] + 0.02, viewport[2] + 0.05, GR.setviewport(viewport[2] + 0.02, viewport[2] + 0.05, viewport[3], viewport[4])
viewport[3], viewport[4])
zmin, zmax = gr_getzlims(d, 0, maximum(counts), false) zmin, zmax = gr_getzlims(d, 0, maximum(counts), false)
GR.setspace(zmin, zmax, 0, 90) GR.setspace(zmin, zmax, 0, 90)
diag = sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2) diag = sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2)
@ -589,8 +615,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
h = linspace(zmin, zmax, p[:levels]) h = linspace(zmin, zmax, p[:levels])
end end
GR.contour(x, y, h, reshape(z, length(x) * length(y)), 1000) GR.contour(x, y, h, reshape(z, length(x) * length(y)), 1000)
GR.setviewport(viewport[2] + 0.02, viewport[2] + 0.05, GR.setviewport(viewport[2] + 0.02, viewport[2] + 0.05, viewport[3], viewport[4])
viewport[3], viewport[4])
l = round(Int32, 1000 + (h - minimum(h)) / (maximum(h) - minimum(h)) * 255) l = round(Int32, 1000 + (h - minimum(h)) / (maximum(h) - minimum(h)) * 255)
GR.setwindow(xmin, xmax, zmin, zmax) GR.setwindow(xmin, xmax, zmin, zmax)
GR.cellarray(xmin, xmax, zmax, zmin, 1, length(l), l) GR.cellarray(xmin, xmax, zmax, zmin, 1, length(l), l)
@ -627,8 +652,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize) GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize)
GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize) GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize)
if cmap if cmap
GR.setviewport(viewport[2] + 0.07, viewport[2] + 0.1, GR.setviewport(viewport[2] + 0.07, viewport[2] + 0.1, viewport[3], viewport[4])
viewport[3], viewport[4])
GR.colormap() GR.colormap()
end end
elseif st == :heatmap elseif st == :heatmap
@ -638,8 +662,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
z = reshape(z, length(x) * length(y)) z = reshape(z, length(x) * length(y))
GR.surface(x, y, z, GR.OPTION_COLORED_MESH) GR.surface(x, y, z, GR.OPTION_COLORED_MESH)
if cmap if cmap
GR.setviewport(viewport[2] + 0.02, viewport[2] + 0.05, GR.setviewport(viewport[2] + 0.02, viewport[2] + 0.05, viewport[3], viewport[4])
viewport[3], viewport[4])
GR.colormap() GR.colormap()
GR.setviewport(viewport[1], viewport[2], viewport[3], viewport[4]) GR.setviewport(viewport[1], viewport[2], viewport[3], viewport[4])
end end
@ -675,15 +698,6 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
GR.setcharheight(charheight) GR.setcharheight(charheight)
GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize) GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize)
GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize) GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize)
# elseif st == :ohlc
# y = p[:y]
# n = size(y, 1)
# ticksize = 0.5 * (xmax - xmin) / n
# for i in 1:n
# GR.polyline([i-ticksize, i], [y[i].open, y[i].open])
# GR.polyline([i, i], [y[i].low, y[i].high])
# GR.polyline([i, i+ticksize], [y[i].close, y[i].close])
# end
elseif st == :pie elseif st == :pie
GR.selntran(0) GR.selntran(0)
GR.setfillintstyle(GR.INTSTYLE_SOLID) GR.setfillintstyle(GR.INTSTYLE_SOLID)
@ -831,7 +845,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
GR.restorestate() GR.restorestate()
end end
if haskey(d, :anns) if haskey(d, :annotations)
GR.savestate() GR.savestate()
for ann in d[:anns] for ann in d[:anns]
x, y, val = ann x, y, val = ann
@ -878,40 +892,40 @@ end
# plt # plt
# end # end
function _add_annotations{X,Y,V}(plt::Plot{GRBackend}, anns::AVec{@compat(Tuple{X,Y,V})}) # function _add_annotations{X,Y,V}(plt::Plot{GRBackend}, anns::AVec{@compat(Tuple{X,Y,V})})
if haskey(plt.attr, :anns) # if haskey(plt.attr, :anns)
append!(plt.attr[:anns], anns) # append!(plt.attr[:anns], anns)
else # else
plt.attr[:anns] = anns # plt.attr[:anns] = anns
end # end
end # end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# function _before_update_plot(plt::Plot{GRBackend}) # function _before_update_plot(plt::Plot{GRBackend})
# end # end
function _update_plot(plt::Plot{GRBackend}, d::KW) # function _update_plot(plt::Plot{GRBackend}, d::KW)
for k in (:title, :xguide, :yguide) # for k in (:title, :xguide, :yguide)
haskey(d, k) && (plt.attr[k] = d[k]) # haskey(d, k) && (plt.attr[k] = d[k])
end # end
end # end
# function _update_plot_pos_size(plt::AbstractPlot{GRBackend}, d::KW) # function _update_plot_pos_size(plt::AbstractPlot{GRBackend}, d::KW)
# end # end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function getxy(plt::Plot{GRBackend}, i::Int) # function getxy(plt::Plot{GRBackend}, i::Int)
d = plt.seriesargs[i] # d = plt.seriesargs[i]
d[:x], d[:y] # d[:x], d[:y]
end # end
#
function setxy!{X,Y}(plt::Plot{GRBackend}, xy::Tuple{X,Y}, i::Integer) # function setxy!{X,Y}(plt::Plot{GRBackend}, xy::Tuple{X,Y}, i::Integer)
d = plt.seriesargs[i] # d = plt.seriesargs[i]
d[:x], d[:y] = xy # d[:x], d[:y] = xy
plt # plt
end # end
# ---------------------------------------------------------------- # ----------------------------------------------------------------

View File

@ -5,8 +5,6 @@ Colors
Reexport Reexport
Measures Measures
FactCheck FactCheck
Cairo
Gadfly
Images Images
PyPlot PyPlot
@osx QuartzImageIO @osx QuartzImageIO