gadfly layer order; fixes #63

This commit is contained in:
Thomas Breloff 2015-11-07 21:58:04 -05:00
parent b0991a0624
commit fb82da74a1

View File

@ -88,7 +88,7 @@ function getGadflyLineTheme(d::Dict)
end end
# add a line as a new layer # add a line as a new layer
function addGadflyLine!(plt::Plot, d::Dict, geoms...) function addGadflyLine!(plt::Plot, numlayers::Int, d::Dict, geoms...)
gplt = getGadflyContext(plt) gplt = getGadflyContext(plt)
gfargs = vcat(geoms..., gfargs = vcat(geoms...,
getGadflyLineTheme(d)) getGadflyLineTheme(d))
@ -120,7 +120,7 @@ function addGadflyLine!(plt::Plot, d::Dict, geoms...)
# add the layer # add the layer
x = d[d[:linetype] == :hist ? :y : :x] x = d[d[:linetype] == :hist ? :y : :x]
Gadfly.layer(gfargs...; x = x, y = d[:y], kwargs...) Gadfly.layer(gfargs...; x = x, y = d[:y], order=numlayers, kwargs...)
end end
@ -150,7 +150,7 @@ function getGadflyMarkerTheme(d::Dict, plotargs::Dict)
) )
end end
function addGadflyMarker!(plt::Plot, d::Dict, plotargs::Dict, geoms...) function addGadflyMarker!(plt::Plot, numlayers::Int, d::Dict, plotargs::Dict, geoms...)
gfargs = vcat(geoms..., gfargs = vcat(geoms...,
getGadflyMarkerTheme(d, plotargs), getGadflyMarkerTheme(d, plotargs),
getMarkerGeom(d)) getMarkerGeom(d))
@ -166,7 +166,7 @@ function addGadflyMarker!(plt::Plot, d::Dict, plotargs::Dict, geoms...)
push!(getGadflyContext(plt).scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(d[:markercolor], p)))) push!(getGadflyContext(plt).scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(d[:markercolor], p))))
end end
Gadfly.layer(gfargs...; x = d[:x], y = d[:y], kwargs...) Gadfly.layer(gfargs...; x = d[:x], y = d[:y], order=numlayers, kwargs...)
end end
@ -220,6 +220,7 @@ getGadflySmoothing(smooth::Real) = [Gadfly.Geom.smooth(method=:loess, smoothing=
function addGadflySeries!(plt::Plot, d::Dict) function addGadflySeries!(plt::Plot, d::Dict)
layers = Gadfly.Layer[] layers = Gadfly.Layer[]
gplt = getGadflyContext(plt)
# add a regression line? # add a regression line?
# TODO: make more flexible # TODO: make more flexible
@ -228,7 +229,7 @@ function addGadflySeries!(plt::Plot, d::Dict)
# lines # lines
geom = getLineGeom(d) geom = getLineGeom(d)
if geom != nothing if geom != nothing
prepend!(layers, addGadflyLine!(plt, d, geom, smooth...)) prepend!(layers, addGadflyLine!(plt, length(gplt.layers), d, geom, smooth...))
# don't add a regression for markers too # don't add a regression for markers too
smooth = Any[] smooth = Any[]
@ -244,14 +245,14 @@ function addGadflySeries!(plt::Plot, d::Dict)
# markers # markers
if d[:markershape] != :none if d[:markershape] != :none
prepend!(layers, addGadflyMarker!(plt, d, plt.plotargs, smooth...)) prepend!(layers, addGadflyMarker!(plt, length(gplt.layers), d, plt.plotargs, smooth...))
end end
lt in (:hist, :heatmap, :hexbin, :contour) || addToGadflyLegend(plt, d) lt in (:hist, :heatmap, :hexbin, :contour) || addToGadflyLegend(plt, d)
# now save the layers that apply to this series # now save the layers that apply to this series
d[:gadflylayers] = layers d[:gadflylayers] = layers
prepend!(getGadflyContext(plt).layers, layers) prepend!(gplt.layers, layers)
end end