Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Winston.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,38 @@ function data_to_device{T<:Real}(ctx::PlotContext, x::Union(T,AbstractArray{T}),
project(ctx.geom, x, y)
end

# PlotGroup ------------------------------------------------------------------

type PlotGroup <: PlotComponent
attr::PlotAttributes
components::Vector{Any}

function PlotGroup(components)
self = new(Dict())
iniattr(self)
self.components = components
self
end
end
PlotGroup(components...) = PlotGroup(components)

function make_key(self::PlotGroup, bb::BoundingBox)
GroupPainter([make_key(pc, bb) for pc in self.components]...)
end


function limits(self::PlotGroup, window::BoundingBox)
lim = BoundingBox()
for comp in self.components
lim += limits(comp, window)
end
lim
end

function make(self::PlotGroup, context::PlotContext)
GroupPainter([make(pc, context) for pc in self.components]...)
end

# Legend ----------------------------------------------------------------------

type Legend <: PlotComponent
Expand Down
19 changes: 15 additions & 4 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,22 @@ function legend(p::FramedPlot, lab::AbstractVector, args...; kvs...)
end
# TODO: define other legend positions
plotcomp = getcomponents(p)
nitems = min(length(lab), length(plotcomp))
for c in 1:nitems
setattr(plotcomp[c], label=lab[c])
target = Array(Integer,0)
c = 0
for s in lab
while c < length(plotcomp)
c += 1
if method_exists(make_key, (typeof(plotcomp[c]), BoundingBox)) &&
typeof(make_key(plotcomp[c], BoundingBox(0,1,0,1))) <: GroupPainter
setattr(plotcomp[c], label=s)
push!(target, c)
break
end
end
end
if length(target) > 0
add(p, Legend(position..., plotcomp[target], args...; kvs...))
end
add(p, Legend(position..., plotcomp[1:nitems], args...; kvs...))
end
legend(lab::AbstractVector, args...; kvs...) = legend(_pwinston, lab, args...; kvs...)