From 0feeb0f2a97de8f9fc9c38ff86f2c4cc52480713 Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Mon, 24 Feb 2014 09:05:47 +0100
Subject: [PATCH] reporting: fix shading

---
 matlab/reports/@graph/writeGraphFile.m | 22 +++++++++++++++++-----
 tests/reporting/runDynareReport.m      |  6 ++----
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m
index 039da1ff69..a0d2273a44 100644
--- a/matlab/reports/@graph/writeGraphFile.m
+++ b/matlab/reports/@graph/writeGraphFile.m
@@ -185,11 +185,23 @@ if ~isempty(o.shade)
     assert(~isempty(x1) && ~isempty(x2), ['@graph.writeGraphFile: either ' ...
                         date2string(o.shade(1)) ' or ' date2string(o.shade(end)) ' is not in the date ' ...
                         'range of data selected.']);
-    fprintf(fid,['\\begin{pgfonlayer}{background}\n\\fill[%s!%f]\n(axis ' ...
-                 'cs:%f,\\pgfkeysvalueof{/pgfplots/ymin})\nrectangle (axis ' ...
-                 'cs:\\pgfkeysvalueof{/pgfplots/xmax},\\pgfkeysvalueof{/' ...
-                 'pgfplots/ymax});\n\\end{pgfonlayer}\n'], ...
-            o.shadeColor, o.shadeOpacity,x1);
+    if x1 == 1
+        fprintf(fid,['\\begin{pgfonlayer}{background}\n\\fill[%s!%f]\n(axis ' ...
+                     'cs:\\pgfkeysvalueof{/pgfplots/xmin},\\pgfkeysvalueof{/pgfplots/ymin})\nrectangle (axis ' ...
+                     'cs:%f,\\pgfkeysvalueof{/pgfplots/ymax});\n\\end{pgfonlayer}\n'], ...
+                o.shadeColor, o.shadeOpacity, x2);
+    elseif x2 == dd.ndat
+        fprintf(fid,['\\begin{pgfonlayer}{background}\n\\fill[%s!%f]\n(axis ' ...
+                     'cs:%f,\\pgfkeysvalueof{/pgfplots/ymin})\nrectangle (axis ' ...
+                     'cs:\\pgfkeysvalueof{/pgfplots/xmax},\\pgfkeysvalueof{/' ...
+                     'pgfplots/ymax});\n\\end{pgfonlayer}\n'], ...
+                o.shadeColor, o.shadeOpacity, x1);
+    else
+        fprintf(fid,['\\begin{pgfonlayer}{background}\n\\fill[%s!%f]\n(axis ' ...
+                     'cs:%f,\\pgfkeysvalueof{/pgfplots/ymin})\nrectangle (axis ' ...
+                     'cs:%f,\\pgfkeysvalueof{/pgfplots/ymax});\n\\end{pgfonlayer}\n'], ...
+                o.shadeColor, o.shadeOpacity, x1, x2);
+    end
 end
 
 fprintf(fid, '\\end{axis}\n\\end{tikzpicture}\n');
diff --git a/tests/reporting/runDynareReport.m b/tests/reporting/runDynareReport.m
index 684a320fdc..5a08c73d63 100644
--- a/tests/reporting/runDynareReport.m
+++ b/tests/reporting/runDynareReport.m
@@ -205,12 +205,10 @@ rep = rep.addSeries('data', dc_q{'LRPOIL_WORLD'}, ...
                     'graphLineStyle', 'dashed', ...
                     'graphLineWidth', 1.5);
 
+srange1 = prange(1):forecast_date;
 rep = rep.addGraph('title', 'Equilibrium World Real Oil Price', ...
                    'xrange', prange, ...
-                   'shade', srange, ...
-                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
-                   'xTickLabelRotation', 0);
+                   'shade', srange1);
 rep = rep.addSeries('data', db_q{'LRPOIL_BAR_WORLD'}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineWidth', 1.5);
-- 
GitLab