reporting: add new Paragraph class

time-shift
Houtan Bastani 2014-05-23 18:09:12 +02:00
parent 43424b414f
commit 9229a35e71
14 changed files with 407 additions and 8 deletions

View File

@ -11467,6 +11467,33 @@ table. Default: @math{1e-6}
@end table
@end defmethod
@defmethod Report addParagraph balancedCols, cols, heading, indent, text
Adds a @code{Paragraph} to a @code{Section}. NB: The @code{Section} can only be
comprised of @code{Paragraphs} and must only have 1 column.
@optionshead
@table @code
@item balancedCols, @code{BOOLEAN}
Determines whether the text is spread out evenly across the columns when the
@code{Paragraph} has more than one column. Default: @code{true}
@item cols, @code{INTEGER}
The number of columns for the @code{Paragraph}. Default: @code{1}
@item heading, @code{STRING}
The heading for the Paragraph (like a section heading). The string must be
correct @LaTeX{} code. Default: @code{empty}
@item indent, @code{BOOLEAN}
Whether or not to indent the paragraph. Default: @code{true}
@item text, @code{STRING}
The paragraph itself. The string must be correct @LaTeX{} code. Default:
@code{empty}
@end table
@end defmethod
@defmethod Report addVspace hline, number
Adds a @code{Vspace} (vertical space) to a @code{Section}.
@optionshead

View File

@ -0,0 +1,32 @@
function display(o)
%function display(o)
% Display a Paragraph object
%
% INPUTS
% o [paragraph] paragraph object
%
% OUTPUTS
% none
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
display_reporting_object(o);
end

View File

@ -0,0 +1,63 @@
function o = paragraph(varargin)
%function o = paragraph(varargin)
% Instantiates a paragraph object
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
o = struct;
o.balancedCols = false;
o.cols = 1;
o.heading = '';
o.indent = true;
o.text = '';
if nargin == 1
assert(isa(varargin{1}, 'paragraph'),['With one arg to Paragraph constructor, ' ...
'you must pass a paragraph object']);
o = varargin{1};
return;
elseif nargin > 1
if round(nargin/2) ~= nargin/2
error(['@paragraph.paragraph: options must be supplied in name/value ' ...
'pairs.']);
end
optNames = fieldnames(o);
% overwrite default values
for pair = reshape(varargin, 2, [])
ind = find(strcmpi(optNames, pair{1}));
assert(isempty(ind) || length(ind) == 1);
if ~isempty(ind)
o.(optNames{ind}) = pair{2};
else
error('@paragraph.paragraph: %s is not a recognized option.', pair{1});
end
end
end
assert(islogical(o.indent), '@paragraph.paragraph: indent must be either true or false');
assert(islogical(o.balancedCols), '@paragraph.paragraph: balancedCols must be either true or false');
assert(isint(o.cols), '@paragraph.paragraph: cols must be an integer');
assert(ischar(o.text), '@paragraph.paragraph: text must be a string');
assert(ischar(o.heading), '@paragraph.paragraph: heading must be a string');
% Create paragraph object
o = class(o, 'paragraph');
end

View File

@ -0,0 +1,50 @@
function B = subsasgn(A, S, V)
% function B = subsasgn(A, S, V)
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
B = A;
if length(S) > 1
for i=1:(length(S)-1)
B = subsref(B, S(i));
end
B = subsasgn(B, S(end), V);
B = subsasgn(A, S(1:(end-1)), B);
return
end
switch S.type
case '()'
index = S.subs{:};
assert(isnumeric(index));
B.elements{index} = V;
case '{}'
index = S.subs{:};
assert(isnumeric(index));
B{index} = V;
case '.'
switch S.subs
case fieldnames(A)
B.(S.subs) = V;
otherwise
error(['@paragraph.subsasgn: field ' S.subs 'does not exist']);
end
otherwise
error('@paragraph.subsasgn: syntax error');
end
end

View File

@ -0,0 +1,48 @@
function A = subsref(A, S)
%function A = subsref(A, S)
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
switch S(1).type
case '.'
switch S(1).subs
case fieldnames(A)
A = A.(S(1).subs);
case methods(A)
if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:});
S = shiftS(S,1);
else
A = feval(S(1).subs, A);
end
otherwise
error(['@paragraph.subsref: unknown field or method: ' S(1).subs]);
end
case '()'
A = A.elements{S(1).subs{:}};
case '{}'
error(['@paragraph.subsref: ' S(1).type ' indexing not supported.']);
otherwise
error('@paragraph.subsref: impossible case')
end
S = shiftS(S,1);
if length(S) >= 1
A = subsref(A, S);
end
end

View File

@ -0,0 +1,70 @@
function o = write(o, fid)
%function o = write(o, fid)
% Write Paragraph object
%
% INPUTS
% o [paragraph] paragraph object
% fid [integer] file id
%
% OUTPUTS
% o [paragraph] paragraph object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(fid ~= -1);
fprintf(fid, '%% Paragraph Object\n\\multicolumn{1}{p{\\textwidth}}{%%\n');
if o.cols ~= 1
bc = '';
if o.balancedCols
bc = '*';
end
fprintf(fid, '\\begin{multicols%s}{%d}%%\n', bc, o.cols);
end
if ~isempty(o.heading)
if o.cols ~= 1
fprintf(fid, '[%s\n]\n', o.heading);
else
fprintf(fid, '%s\\newline \\newline\n', o.heading);
end
end
if o.indent
fprintf(fid, '\\hspace{4ex}');
end
fprintf(fid, '%s', o.text);
if o.cols ~= 1
fprintf(fid, '\\end{multicols%s}\n', bc);
end
fprintf(fid, '}\n%% End Paragraph Object\n\n');
end
%\multicolumn{1}{p{\textwidth}}
%{\begin{multicols}{2}
%Hello, here is some text without a meaning. This text should show what
%a printed text will look like at this place.
%\columnbreak
%If you read this text, you will get no information. Really? Is there
%no information? Is there...
%\end{multicols}}\\

View File

@ -0,0 +1,34 @@
function o = addParagraph(o, varargin)
%function o = addParagraph(o, varargin)
% Add a paragraph to the current section of the current page in the report
%
% INPUTS
% o [report] report object
% varargin arguments to @section/addGraph.m
%
% OUTPUTS
% o [report] updated report object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
o.pages{end}.sections{end} = ...
o.pages{end}.sections{end}.addParagraph(varargin{:});
end

View File

@ -41,7 +41,7 @@ if strcmpi(o.orientation, 'landscape')
fprintf(fid, ',landscape');
end
fprintf(fid, ']{geometry}\n');
fprintf(fid, '\\usepackage{pdflscape, booktabs, pgfplots, colortbl, adjustbox}\n');
fprintf(fid, '\\usepackage{pdflscape, booktabs, pgfplots, colortbl, adjustbox, multicol}\n');
fprintf(fid, '\\pgfplotsset{compat=1.5.1}');
fprintf(fid, ['\\makeatletter\n' ...
'\\def\\blfootnote{\\gdef\\@thefnmark{}\\@footnotetext}\n' ...

View File

@ -30,5 +30,9 @@ function o = addGraph(o, varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
for i=1:length(o.elements)
assert(~isa(o.elements{i}, 'paragraph'), ...
'@addGraph: A Section that contains a Paragraph cannot contain a Graph');
end
o.elements{end+1} = graph(varargin{:});
end

View File

@ -0,0 +1,42 @@
function o = addParagraph(o, varargin)
%function o = addParagraph(o, varargin)
% Add a paragraph to the Cell Array of elements in this section
%
% INPUTS
% 1 args => add empty paragraph
% 2 args => add given paragraph
% 3 args => add paragraph at index
%
% OUTPUTS
% updated page object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(o.cols == 1, ...
['@addParagraph: you can only add a paragraph to a Section that ' ...
'contains one column']);
for i=1:length(o.elements)
assert(isa(o.elements{i}, 'paragraph'), ...
['@addParagraph: you can only add a paragraph to a Section that ' ...
'contains only paragraphs']);
end
o.elements{end+1} = paragraph(varargin{:});
end

View File

@ -30,5 +30,9 @@ function o = addTable(o, varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
for i=1:length(o.elements)
assert(~isa(o.elements{i}, 'paragraph'), ...
'@addTable: A Section that contains a Paratable cannot contain a Table');
end
o.elements{end+1} = report_table(varargin{:});
end

View File

@ -29,5 +29,9 @@ function o = addVspace(o, varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
for i=1:length(o.elements)
assert(~isa(o.elements{i}, 'paragraph'), ...
'@addVspace: A Section that contains a Paragraph cannot contain a Vspace');
end
o.elements{end+1} = vspace(varargin{:});
end

View File

@ -33,6 +33,7 @@ function o = write(o, fid, pg, sec)
assert(fid ~= -1);
fprintf(fid, '%% Section Object\n');
if ~isempty(o.height)
fprintf(fid, '\\setlength\\sectionheight{%s}%%\n', o.height);
end
@ -45,9 +46,16 @@ end
fprintf(fid, '}{%%\n');
fprintf(fid, '\\begin{tabular}[t]{');
for i=1:o.cols
fprintf(fid, 'c');
if ~isa(o.elements{1}, 'paragraph')
% if one element is a paragraph, they all are
% due to check in add*.m functions
fprintf(fid, 'l');
else
fprintf(fid, 'c');
end
end
fprintf(fid, '}\n');
ne = numElements(o);
row = 1;
col = 1;
@ -61,7 +69,11 @@ for i=1:ne
return;
end
else
o.elements{i}.write(fid, pg, sec, row, col);
if isa(o.elements{i}, 'paragraph')
o.elements{i}.write(fid);
else
o.elements{i}.write(fid, pg, sec, row, col);
end
if col ~= o.cols
fprintf(fid, ' & ');
col = col + 1;

View File

@ -144,7 +144,7 @@ rep = rep.addSection();
rep = CommResidTablePage(rep, db_q, dc_q, trange, dates('2012q2'));
%% Commodities Graphs
%Page 1
%Page 24
rep = rep.addPage('title', 'Jan1 vs Jan2', ...
'titleFormat', '\large\bfseries');
rep = rep.addSection();
@ -188,11 +188,21 @@ rep = rep.addSeries('graphVline', dates('2009q2'), ...
'graphLineColor', 'red', ...
'graphLineWidth', 1.5);
% Pae 2
% Page 25
rep = rep.addPage('title', {'Jan1 vs Jan2', 'World Oil and Food Prices'}, ...
'titleFormat', {'\large\bfseries', '\large'});
rep = rep.addSection('cols', 2);
rep = rep.addSection('cols', 1);
rep = rep.addParagraph('text', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', ...
'cols', 2, ...
'heading', '\textbf{My First Paragraph Has Two Columns}');
rep = rep.addSection('cols', 1);
rep = rep.addParagraph('text', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\newline', ...
'heading', '\textbf{My Next Paragraphs Only Have One}', ...
'indent', false);
rep = rep.addParagraph('text', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\newline');
rep = rep.addSection('cols', 2);
rep = rep.addGraph('title', 'World Real Oil Price', ...
'xrange', prange, ...
@ -243,8 +253,7 @@ rep = rep.addGraph('title', 'Equilibrium World Real Food Price', ...
'xrange', prange, ...
'shade', srange, ...
'showLegend', true, ...
'xTickLabelRotation', 0, ...
'miscTikzPictureOptions', 'xscale=2.5, yscale=0.5');
'xTickLabelRotation', 0);
rep = rep.addSeries('data', db_q{'LRPFOOD_BAR_WORLD'}, ...
'graphLineColor', 'blue', ...
'graphLineWidth', 1.5, ...