From 679fba0e8c6cb6cdc9f7b594a1a62c21dfaeb163 Mon Sep 17 00:00:00 2001 From: Helios Date: Sat, 24 Jan 2015 02:02:38 +0100 Subject: [PATCH 1/4] Added BoxPainter class (was missing for FillComponent legends) --- src/paint.jl | 13 +++++++++++++ src/renderer.jl | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/paint.jl b/src/paint.jl index 686d0eb..06c879e 100644 --- a/src/paint.jl +++ b/src/paint.jl @@ -273,6 +273,19 @@ function paint(self::PolygonPainter, context::PaintContext) polygon(context.device, self.points) end +immutable BoxPainter <: AbstractPainter + p::Point + q::Point +end + +function boundingbox(self::BoxPainter, context::PaintContext) + return BoundingBox(self.p, self.q) +end + +function paint(self::BoxPainter, context::PaintContext) + rectangle(context.device, BoundingBox(self.p, self.q)) +end + immutable ImagePainter <: AbstractPainter img bbox diff --git a/src/renderer.jl b/src/renderer.jl index ba65565..bbf80d8 100644 --- a/src/renderer.jl +++ b/src/renderer.jl @@ -256,6 +256,11 @@ function polygon(self::CairoRenderer, points::Vector) fill(self.ctx) end +function rectangle(self::CairoRenderer, bbox::BoundingBox) + rectangle(self.ctx, bbox) + fill(self.ctx) + end + function layout_text(self::CairoRenderer, str::String) set_latex(self.ctx, str, get(self,:fontsize)) end From 0442469191158680bc2108ac3bb03f5ab8cd82bc Mon Sep 17 00:00:00 2001 From: Helios Date: Sun, 1 Feb 2015 14:26:14 +0100 Subject: [PATCH 2/4] Revert "Added BoxPainter class (was missing for FillComponent legends)" This reverts commit 679fba0e8c6cb6cdc9f7b594a1a62c21dfaeb163. --- src/paint.jl | 13 ------------- src/renderer.jl | 5 ----- 2 files changed, 18 deletions(-) diff --git a/src/paint.jl b/src/paint.jl index 06c879e..686d0eb 100644 --- a/src/paint.jl +++ b/src/paint.jl @@ -273,19 +273,6 @@ function paint(self::PolygonPainter, context::PaintContext) polygon(context.device, self.points) end -immutable BoxPainter <: AbstractPainter - p::Point - q::Point -end - -function boundingbox(self::BoxPainter, context::PaintContext) - return BoundingBox(self.p, self.q) -end - -function paint(self::BoxPainter, context::PaintContext) - rectangle(context.device, BoundingBox(self.p, self.q)) -end - immutable ImagePainter <: AbstractPainter img bbox diff --git a/src/renderer.jl b/src/renderer.jl index bbf80d8..ba65565 100644 --- a/src/renderer.jl +++ b/src/renderer.jl @@ -256,11 +256,6 @@ function polygon(self::CairoRenderer, points::Vector) fill(self.ctx) end -function rectangle(self::CairoRenderer, bbox::BoundingBox) - rectangle(self.ctx, bbox) - fill(self.ctx) - end - function layout_text(self::CairoRenderer, str::String) set_latex(self.ctx, str, get(self,:fontsize)) end From 460daafb948a2697515c18fcba7dd9d98042c4b4 Mon Sep 17 00:00:00 2001 From: Helios Date: Sun, 1 Feb 2015 17:11:38 +0100 Subject: [PATCH 3/4] Fixed legend to skip components without key definition --- src/plot.jl | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index 505a08a..0545f54 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -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...) From ae28a40e6e4ed72c86fefed065370191968a52f6 Mon Sep 17 00:00:00 2001 From: Helios Date: Mon, 2 Feb 2015 23:39:22 +0100 Subject: [PATCH 4/4] Added PlotGroup type (not exported) --- src/Winston.jl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Winston.jl b/src/Winston.jl index b9b8816..8748f47 100644 --- a/src/Winston.jl +++ b/src/Winston.jl @@ -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