From e64d1e095227295f1ba64524d5f13e8a23510fbf Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Tue, 11 Feb 2014 13:21:23 +0100
Subject: [PATCH] reporting: add custom height/width to graphs

---
 doc/dynare.texi                        | 8 +++++++-
 matlab/reports/@graph/graph.m          | 6 ++++++
 matlab/reports/@graph/writeGraphFile.m | 6 +++---
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/doc/dynare.texi b/doc/dynare.texi
index f0adb5d8a..8ffb78d6d 100644
--- a/doc/dynare.texi
+++ b/doc/dynare.texi
@@ -10718,7 +10718,7 @@ command. Default: @code{`!'}
 @end table
 @end defmethod
 
-@defmethod Report addGraph data, figname, figDirName, graphSize, showGrid, showLegend, showLegendBox, legendLocation, legendOrientation, legendFontSize, seriesToUse, shade, shadeColor, shadeOpacity, title, 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, yrange, showZeroline
 Adds a @code{Graph} to a @code{Section}.
 @optionshead
 @table @code
@@ -10741,6 +10741,9 @@ the array passed to the @code{`Position'} option of Matlab's
 @code{figure} command, passed as a vector of size @math{2}. Default:
 Matlab sets width and height
 
+@item height, @code{DOUBLE}
+The height of the graph, in inches. Default: @code{4.5}
+
 @item showGrid, @code{BOOLEAN}
 Whether or not to display the minor grid on the graph. Default:
 @code{true}
@@ -10782,6 +10785,9 @@ The opacity of the shaded area, must be in @math{[0,1]}. Default: @code{.2}
 @item title, @code{STRING}
 Title for the graph. Default: @code{none}
 
+@item width, @code{DOUBLE}
+The width of the graph, in inches. Default: @code{6.0}
+
 @item xlabel, @code{STRING}
 The x-axis label. Default: @code{none}
 
diff --git a/matlab/reports/@graph/graph.m b/matlab/reports/@graph/graph.m
index e2dd102a5..48c3cbe95 100644
--- a/matlab/reports/@graph/graph.m
+++ b/matlab/reports/@graph/graph.m
@@ -64,6 +64,9 @@ o.graphSize = [];
 o.xTicks = [];
 o.xTickLabels = {};
 
+o.width = 6;
+o.height = 4.5;
+
 if nargin == 1
     assert(isa(varargin{1}, 'graph'),['@graph.graph: with one arg you ' ...
                         'must pass a graph object']);
@@ -104,6 +107,9 @@ assert(ischar(o.shadeColor), '@graph.graph: shadeColor must be a string');
 assert(isfloat(o.shadeOpacity) && length(o.shadeOpacity)==1 && ...
        o.shadeOpacity >= 0 && 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');
+
 valid_legend_locations = ...
     {'North', 'South', 'East', 'West', ...
      'NorthEast', 'SouthEast', 'NorthWest', 'SouthWest', ...
diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m
index 6d5dfb4ec..c8a3d9cf0 100644
--- a/matlab/reports/@graph/writeGraphFile.m
+++ b/matlab/reports/@graph/writeGraphFile.m
@@ -87,13 +87,13 @@ for i = 1:length(x)
     end
 end
 fprintf(fid, '},\nx tick label style={rotate=45,anchor=east},\n');
-fprintf(fid, ['width=6.0in,\n'...
-              'height=4.5in,\n'...
+fprintf(fid, ['width=%fin,\n'...
+              'height=%fin,\n'...
               'scale only axis,\n'...
               'xmin=1,\n'...
               'xmax=%d,\n'...
               'ymin=%d,\n'...
-              'ymax=%d,\n'], dd.ndat, ymin, ymax);
+              'ymax=%d,\n'], o.width, o.height, dd.ndat, ymin, ymax);
 
 if o.showGrid
     fprintf(fid, 'xmajorgrids=true,\nymajorgrids=true,\n');
-- 
GitLab