From 628f1fef43470eab3352e99698159f6ce7f1ca0a Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Tue, 9 Apr 2013 15:50:44 +0200
Subject: [PATCH] reporting: @graph: keep line handles for use with legend

---
 matlab/reporting/@graph/createGraph.m | 5 +++--
 matlab/reporting/@series/getLine.m    | 8 ++++----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/matlab/reporting/@graph/createGraph.m b/matlab/reporting/@graph/createGraph.m
index e800416b4c..4a14767b8b 100644
--- a/matlab/reporting/@graph/createGraph.m
+++ b/matlab/reporting/@graph/createGraph.m
@@ -54,8 +54,9 @@ else
 end
 
 ne = o.seriesElements.numElements();
+line_handles = zeros(ne, 1);
 for i=1:ne
-    o.seriesElements(i).getLine(dd);
+    line_handles(i) = o.seriesElements(i).getLine(dd);
 end
 
 x = 1:1:dd.ndat;
@@ -98,7 +99,7 @@ set(gca,'XTick', x);
 set(gca,'XTickLabel', xlabels);
 
 if o.legend
-    lh = legend(o.seriesElements.getTexNames());
+    lh = legend(line_handles, o.seriesElements.getTexNames());
     set(lh, 'orientation', o.legend_orientation);
     set(lh, 'Location', o.legend_location);
     set(lh, 'FontSize', o.legend_font_size);
diff --git a/matlab/reporting/@series/getLine.m b/matlab/reporting/@series/getLine.m
index 61c4a5527a..f4543a85c2 100644
--- a/matlab/reporting/@series/getLine.m
+++ b/matlab/reporting/@series/getLine.m
@@ -1,5 +1,5 @@
-function o = getLine(o, xrange)
-%function o = getLine(o, xrange)
+function h = getLine(o, xrange)
+%function h = getLine(o, xrange)
 % Create the series
 %
 % INPUTS
@@ -7,7 +7,7 @@ function o = getLine(o, xrange)
 %   xrange  [dynDates]  range of x values for line
 %
 % OUTPUTS
-%   o       [series]    series object
+%   h       [handle]    handle to line
 %
 % SPECIAL REQUIREMENTS
 %   none
@@ -81,5 +81,5 @@ if ~isempty(o.graph_marker)
     opt = {opt{:}, 'MarkerFaceColor', o.graph_marker_face_color};
 end
 
-line(opt{:});
+h = line(opt{:});
 end
-- 
GitLab