From 6bbae11b6626968c706b9e5ed337a5af4bca39f5 Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Tue, 11 Feb 2014 16:37:15 +0100
Subject: [PATCH] reporting: new option xTickLabelRotation

---
 doc/dynare.texi                        |  5 ++++-
 matlab/reports/@graph/graph.m          |  2 ++
 matlab/reports/@graph/writeGraphFile.m |  5 +++--
 tests/reporting/CountryGraphPage.m     | 31 ++++++++++++++++----------
 tests/reporting/runDynareReport.m      | 31 ++++++++++++++++----------
 5 files changed, 47 insertions(+), 27 deletions(-)

diff --git a/doc/dynare.texi b/doc/dynare.texi
index 45397e298a..ea91a4eb7e 100644
--- a/doc/dynare.texi
+++ b/doc/dynare.texi
@@ -10704,7 +10704,7 @@ command. Default: @code{`!'}
 @end table
 @end defmethod
 
-@defmethod Report addGraph data, figname, figDirName, graphSize, height, showGrid, showLegend, showLegendBox, legendLocation, legendOrientation, legendFontSize, seriesToUse, shade, shadeColor, shadeOpacity, title, width, xlabel, ylabel, xrange, xTicks, xTickLabels, yrange, showZeroline
+@defmethod Report addGraph data, figname, figDirName, graphSize, height, showGrid, showLegend, showLegendBox, legendLocation, legendOrientation, legendFontSize, seriesToUse, shade, shadeColor, shadeOpacity, title, width, xlabel, ylabel, xrange, xTicks, xTickLabels, xTickLabelRotation, yrange, showZeroline
 Adds a @code{Graph} to a @code{Section}.
 @optionshead
 @table @code
@@ -10794,6 +10794,9 @@ begin at @math{1}. Default: set by Matlab/Octave.
 The labels to be mapped to the ticks provided by
 @ref{xTicks}. Default: the dates of the @code{dseries}
 
+@item xTickLabelRotation, @code{DOUBLE}
+The amount to rotate the x tick labels by. Default: @code{45}
+
 @item yrange, @code{NUMERICAL_VECTOR}
 The boundary on the y-axis to display in the graph, represented as a
 @code{NUMERICAL_VECTOR} of size @math{2}, with the first entry less
diff --git a/matlab/reports/@graph/graph.m b/matlab/reports/@graph/graph.m
index 48c3cbe951..541a34368c 100644
--- a/matlab/reports/@graph/graph.m
+++ b/matlab/reports/@graph/graph.m
@@ -63,6 +63,7 @@ o.showZeroline = false;
 o.graphSize = [];
 o.xTicks = [];
 o.xTickLabels = {};
+o.xTickLabelRotation = 45;
 
 o.width = 6;
 o.height = 4.5;
@@ -109,6 +110,7 @@ assert(isfloat(o.shadeOpacity) && length(o.shadeOpacity)==1 && ...
        '@graph.graph: o.shadeOpacity must be a real in [0 1]');
 assert(isfloat(o.width), '@graph.graph: o.width must be a real number');
 assert(isfloat(o.height), '@graph.height: o.width must be a real number');
+assert(isfloat(o.xTickLabelRotation), '@graph.graph: o.xTickLabelRotation must be a real number');
 
 valid_legend_locations = ...
     {'North', 'South', 'East', 'West', ...
diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m
index c8a3d9cf03..5eeadd31e7 100644
--- a/matlab/reports/@graph/writeGraphFile.m
+++ b/matlab/reports/@graph/writeGraphFile.m
@@ -86,14 +86,15 @@ for i = 1:length(x)
         fprintf(fid,',');
     end
 end
-fprintf(fid, '},\nx tick label style={rotate=45,anchor=east},\n');
+fprintf(fid, '},\nx tick label style={rotate=%f},\n',o.xTickLabelRotation);
 fprintf(fid, ['width=%fin,\n'...
               'height=%fin,\n'...
               'scale only axis,\n'...
               'xmin=1,\n'...
               'xmax=%d,\n'...
               'ymin=%d,\n'...
-              'ymax=%d,\n'], o.width, o.height, dd.ndat, ymin, ymax);
+              'ymax=%d,\n'...
+              'axis lines=box,\n'], o.width, o.height, dd.ndat, ymin, ymax);
 
 if o.showGrid
     fprintf(fid, 'xmajorgrids=true,\nymajorgrids=true,\n');
diff --git a/tests/reporting/CountryGraphPage.m b/tests/reporting/CountryGraphPage.m
index 1c5cc56dc9..3734e8c876 100644
--- a/tests/reporting/CountryGraphPage.m
+++ b/tests/reporting/CountryGraphPage.m
@@ -16,14 +16,16 @@ function rep = CountryGraphPage(rep, countryAbbr, db_q, dc_q, prange, srange)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+startpoint = strings(prange(1));
 shaded = strings(srange(1));
 endpoint = strings(prange(end));
 rep = rep.addGraph('title', 'Interest Rate', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showZeroline', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 rep = rep.addSeries('data', db_q{['RS_' countryAbbr]}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineStyle', 'dashed', ...
@@ -36,8 +38,9 @@ rep = rep.addGraph('title', 'Output Gap', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showZeroline', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 rep = rep.addSeries('data', db_q{['Y_' countryAbbr]}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineStyle', 'dashed', ...
@@ -50,8 +53,9 @@ rep = rep.addGraph('title', 'Headline Inflation (y/y)', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showZeroline', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 rep = rep.addSeries('data', db_q{['PCH_PIE4_' countryAbbr]}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineStyle', 'dashed', ...
@@ -64,8 +68,9 @@ rep = rep.addGraph('title', 'Headline Inflation (q/q)', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showZeroline', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 rep = rep.addSeries('data', db_q{['PCH_PIE_' countryAbbr]}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineStyle', 'dashed', ...
@@ -78,8 +83,9 @@ rep = rep.addGraph('title', 'GDP Growth (q/q)', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showZeroline', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 rep = rep.addSeries('data', db_q{['PCH_GROWTH_' countryAbbr]}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineStyle', 'dashed', ...
@@ -92,8 +98,9 @@ rep = rep.addGraph('title', 'Core Inflation (y/y)', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showZeroline', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 rep = rep.addSeries('data', db_q{['PCH_PIEX4_' countryAbbr]}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineStyle', 'dashed', ...
diff --git a/tests/reporting/runDynareReport.m b/tests/reporting/runDynareReport.m
index d337ebdacd..ff338c5bf5 100644
--- a/tests/reporting/runDynareReport.m
+++ b/tests/reporting/runDynareReport.m
@@ -23,6 +23,7 @@ prange = dates('2007q1'):dates('2013q4');
 forecast_date = dates('2012q2');
 srange = forecast_date:prange(end);
 
+startpoint = strings(prange(1));
 shaded = strings(srange(1));
 endpoint = strings(prange(end));
 
@@ -151,8 +152,9 @@ rep = rep.addGraph('title', 'World Real Oil Price Index', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showLegend', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 db_q = db_q.tex_rename('LRPOIL_WORLD', 'Oil Price');
 rep = rep.addSeries('data', db_q{'LRPOIL_WORLD'}, ...
                     'graphLineColor', 'blue', ...
@@ -168,8 +170,9 @@ rep = rep.addGraph('title', 'World Real Food Price Index', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showLegend', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 db_q = db_q.tex_rename('LRPFOOD_WORLD', 'Food Price');
 rep = rep.addSeries('data', db_q{'LRPFOOD_WORLD'}, ...
                     'graphLineColor', 'blue', ...
@@ -190,8 +193,9 @@ rep = rep.addGraph('title', 'World Real Oil Price', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showLegend', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 rep = rep.addSeries('data', db_q{'LRPOIL_WORLD'}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineWidth', 1.5);
@@ -204,8 +208,9 @@ rep = rep.addGraph('title', 'Equilibrium World Real Oil Price', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showLegend', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 rep = rep.addSeries('data', db_q{'LRPOIL_BAR_WORLD'}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineWidth', 1.5);
@@ -218,8 +223,9 @@ rep = rep.addGraph('title', 'World Real Food Price', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showLegend', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 rep = rep.addSeries('data', db_q{'LRPFOOD_WORLD'}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineWidth', 1.5);
@@ -232,8 +238,9 @@ rep = rep.addGraph('title', 'Equilibrium World Real Food Price', ...
                    'xrange', prange, ...
                    'shade', srange, ...
                    'showLegend', true, ...
-                   'xTicks', [5,10,15,find(srange(1)==prange),length(prange)], ...
-                   'xTickLabels',{'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}});
+                   'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
+                   'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
+                   'xTickLabelRotation', 0);
 rep = rep.addSeries('data', db_q{'LRPFOOD_BAR_WORLD'}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineWidth', 1.5);
-- 
GitLab