Skip to content

Commit

Permalink
gadfly layer order; fixes #63
Browse files Browse the repository at this point in the history
  • Loading branch information
tbreloff committed Nov 8, 2015
1 parent b0991a0 commit fb82da7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/backends/gadfly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function getGadflyLineTheme(d::Dict)
end

# 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)
gfargs = vcat(geoms...,
getGadflyLineTheme(d))
Expand Down Expand Up @@ -120,7 +120,7 @@ function addGadflyLine!(plt::Plot, d::Dict, geoms...)

# add the layer
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


Expand Down Expand Up @@ -150,7 +150,7 @@ function getGadflyMarkerTheme(d::Dict, plotargs::Dict)
)
end

function addGadflyMarker!(plt::Plot, d::Dict, plotargs::Dict, geoms...)
function addGadflyMarker!(plt::Plot, numlayers::Int, d::Dict, plotargs::Dict, geoms...)
gfargs = vcat(geoms...,
getGadflyMarkerTheme(d, plotargs),
getMarkerGeom(d))
Expand All @@ -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))))
end

Gadfly.layer(gfargs...; x = d[:x], y = d[:y], kwargs...)
Gadfly.layer(gfargs...; x = d[:x], y = d[:y], order=numlayers, kwargs...)
end


Expand Down Expand Up @@ -220,6 +220,7 @@ getGadflySmoothing(smooth::Real) = [Gadfly.Geom.smooth(method=:loess, smoothing=
function addGadflySeries!(plt::Plot, d::Dict)

layers = Gadfly.Layer[]
gplt = getGadflyContext(plt)

# add a regression line?
# TODO: make more flexible
Expand All @@ -228,7 +229,7 @@ function addGadflySeries!(plt::Plot, d::Dict)
# lines
geom = getLineGeom(d)
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
smooth = Any[]
Expand All @@ -244,14 +245,14 @@ function addGadflySeries!(plt::Plot, d::Dict)

# markers
if d[:markershape] != :none
prepend!(layers, addGadflyMarker!(plt, d, plt.plotargs, smooth...))
prepend!(layers, addGadflyMarker!(plt, length(gplt.layers), d, plt.plotargs, smooth...))
end

lt in (:hist, :heatmap, :hexbin, :contour) || addToGadflyLegend(plt, d)

# now save the layers that apply to this series
d[:gadflylayers] = layers
prepend!(getGadflyContext(plt).layers, layers)
prepend!(gplt.layers, layers)
end


Expand Down

0 comments on commit fb82da7

Please sign in to comment.