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

View File

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