Commit 0219301e authored by Houtan Bastani's avatar Houtan Bastani
Browse files

reporting (WIP)

parent a64ec3b1
function spaces=addIndentation(spaces) function m = getDatesCellStringArray(dd)
% Return new level of indentation for latex output %function m = getDatesCellStringArray(dd)
% Returns a cell array of strings containing the dates
% %
% INPUTS % INPUTS
% spaces - char, current level of indentation % dd - dynDates object
% %
% OUTPUTS % OUTPUTS
% spaces - char, new level of indentation % m - cell array of strings
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
...@@ -27,5 +28,26 @@ function spaces=addIndentation(spaces) ...@@ -27,5 +28,26 @@ function spaces=addIndentation(spaces)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
spaces = [spaces ' ']; dateSep = '';
switch dd.freq
case 1
case 4
dateSep = 'q';
case 12
dateSep = 'm';
case 52
dateSep = 'w';
otherwise
error('Unknown frequency %d', dd.freq);
end
m = cell(0);
for i = 1:dd.ndat
if isempty(dateSep)
newdate = num2str(dd.time(i,1));
else
newdate = [num2str(dd.time(i,1)) dateSep num2str(dd.time(i,2))];
end
m = { m{:} newdate };
end
end end
\ No newline at end of file
...@@ -18,10 +18,5 @@ function e = addGraph(e, varargin) ...@@ -18,10 +18,5 @@ function e = addGraph(e, varargin)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(nargin >= 1 && nargin <= 3) e.objArray = e.objArray.addObj(graph(varargin{:}));
if nargin == 1
e.objArray = e.objArray.addObj(graph());
else
e.objArray = e.objArray.addObj(varargin{:});
end
end end
\ No newline at end of file
...@@ -18,10 +18,5 @@ function e = addTable(e, varargin) ...@@ -18,10 +18,5 @@ function e = addTable(e, varargin)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(nargin >= 1 && nargin <= 3) e.objArray = e.objArray.addObj(table(varargin{:}));
if nargin == 1
e.objArray = e.objArray.addObj(table());
else
e.objArray = e.objArray.addObj(varargin{:});
end
end end
\ No newline at end of file
function o = createGraph(o)
%function o = createGraph(o)
% Create the graph
%
% INPUTS
% none
%
% OUTPUTS
% none
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 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(~isempty(o.data));
assert(isa(o.data, 'dynSeries')) ;
if ~isempty(o.figname)
warning('Will overwrite %s with new graph\n', o.figname);
end
%o = readConfig(o);
h = figure('visible','off');
hold on;
box on;
%set(0, 'CurrentFigure',h);
%set(h, 'PaperPositionMode', 'auto');
%set(h, 'units', 'normalized', 'outerposition', [0 0 1 1]);
if strcmpi(o.seriestoplot, 'all')
data = o.data.data;
else
data = o.data{o.seriestoplot{:}}.data;
end
x=[1:1:o.data.nobs];
xlabels=getDatesCellStringArray(o.data.time);
plot(x, data);
if ~isempty(o.shade)
x1 = strmatch(lower(o.shade{1}), xlabels, 'exact');
x2 = strmatch(lower(o.shade{2}), xlabels, 'exact');
yrange = get(gca, 'YLim');
% From ShadePlotForEmpahsis (Matlab Exchange)
% use patch bc area doesn't work with matlab2tikz
patch([repmat(x1, 1, 2) repmat(x2, 1, 2)], [yrange fliplr(yrange)], ...
'b', 'FaceAlpha', .2);
end
set(gca,'XTick', x);
set(gca,'XTickLabel', xlabels);
if o.legend
if strcmpi(o.seriestoplot, 'all')
lh = legend(o.data.name);
else
lh = legend(o.seriestoplot{:});
end
set(lh, 'orientation', o.legend_orientation);
set(lh, 'Location', o.legend_location);
set(lh, 'FontSize', o.legend_font_size);
legend('boxoff');
end
if ~isempty(o.xlabel)
xlabel(['$\textbf{\footnotesize ' o.xlabel '}$'],'Interpreter','LaTex');
end
if ~isempty(o.ylabel)
ylabel(['$\textbf{\footnotesize ' o.ylabel '}$'],'Interpreter','LaTex');
end
if ~isempty(o.title)
title(['$\textbf{\large ' o.title '}$'],'Interpreter','LaTex');
end
drawnow;
o.figname = ['figure-' num2str(cputime) '.tex'];
matlab2tikz('filename', o.figname, ...
'showInfo', false, ...
'showWarnings', false, ...
'checkForUpdates', false);
box off;
hold off;
close(h);
clear h;
end
...@@ -30,9 +30,19 @@ function display(o) ...@@ -30,9 +30,19 @@ function display(o)
name = 'report.page.section.graph'; name = 'report.page.section.graph';
disp(' '); disp(' ');
disp([name '.caption = ']); disp([name '.title = ']);
disp(' '); disp(' ');
disp([' ''' o.caption '''']); disp([' ''' o.title '''']);
disp(' ');
disp([name '.xlabel = ']);
disp(' ');
disp([' ''' o.xlabel '''']);
disp(' ');
disp([name '.ylabel = ']);
disp(' ');
disp([' ''' o.ylabel '''']);
disp(' '); disp(' ');
disp([name '.footnote = ']); disp([name '.footnote = ']);
...@@ -40,7 +50,32 @@ disp(' '); ...@@ -40,7 +50,32 @@ disp(' ');
disp([' ''' o.footnote '''']); disp([' ''' o.footnote '''']);
disp(' '); disp(' ');
disp([name '.filename = ']); disp([name '.figname = ']);
disp(' ');
disp([' ''' o.figname '''']);
disp(' ');
disp([name '.data = ']);
disp(' ');
display(o.data);
disp(' ');
disp([name '.seriestoplot = ']);
disp(' ');
disp(o.seriestoplot);
disp(' ');
disp([name '.config = ']);
disp(' ');
disp([' ''' o.config '''']);
disp(' ');
disp([name '.legend = ']);
disp(' ');
disp(o.legend);
disp(' ');
disp([name '.shade = ']);
disp(' '); disp(' ');
disp([' ''' o.filename '''']); disp(o.shade);
end end
\ No newline at end of file
...@@ -30,11 +30,24 @@ function o = graph(varargin) ...@@ -30,11 +30,24 @@ function o = graph(varargin)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
o = struct; o = struct;
o.caption = '';
o.config = '';
o.title = '';
o.ylabel = '';
o.xlabel = '';
o.zlabel = '';
o.footnote = ''; o.footnote = '';
o.filename = '';
o.figname = '';
o.data = ''; o.data = '';
o.config = ''; o.seriestoplot = 'all';
o.shade = ''; %{1959q1:1964q4}
o.legend = false;
o.legend_location = 'SouthEast';
o.legend_orientation = 'horizontal';
o.legend_font_size = 8;
if nargin == 1 if nargin == 1
assert(isa(varargin{1}, 'graph'),['With one arg to Graph constructor, ' ... assert(isa(varargin{1}, 'graph'),['With one arg to Graph constructor, ' ...
......
function write(o, fid, texIndent) function o = write(o, fid)
%function write(o, fid) %function o = write(o, fid)
% Write a Page object % Write a Graph object
% %
% INPUTS % INPUTS
% none % fid - int, file id
% %
% OUTPUTS % OUTPUTS
% none % o - this
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
...@@ -28,13 +28,9 @@ function write(o, fid, texIndent) ...@@ -28,13 +28,9 @@ function write(o, fid, texIndent)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(fid > 0); assert(fid ~= -1);
assert(isnumeric(texIndent)); if isempty(o.figname)
o = createGraph(o);
fprintf(fid, '%d\% Page Object\n', texIndent); end
fprintf(fid, '%d\newpage\n', texIndent); fprintf(fid, '\\input{%s}', o.figname);
o.sections.write(fid, texIndent+2);
fprintf(fid, '%d\% End Page Object\n', texIndent);
end end
\ No newline at end of file
...@@ -30,10 +30,5 @@ function p = addSection(p, varargin) ...@@ -30,10 +30,5 @@ function p = addSection(p, varargin)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(isa(p, 'page'), 'First argument must be a page object'); p.sections = p.sections.addSection(varargin{:});
if nargin == 1
p.sections = p.sections.addSection();
elseif nargin == 2 || nargin == 3
p.sections = p.sections.addSection(varargin{:});
end
end end
...@@ -30,12 +30,13 @@ function o = page(varargin) ...@@ -30,12 +30,13 @@ function o = page(varargin)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
o = struct; o = struct;
o.caption = ''; o.paper = '';
o.orientation = 'portrait'; o.title = '';
o.orientation = '';
o.sections = sections(); o.sections = sections();
if nargin == 1 if nargin == 1
assert(isa(varargin{1}, 'page'),['With one arg to Page constructor, ' ... assert(isa(varargin{1}, 'page'), ['With one arg to Page constructor, ' ...
'you must pass a page object']); 'you must pass a page object']);
o = varargin{1}; o = varargin{1};
return; return;
......
...@@ -23,13 +23,6 @@ switch S(1).type ...@@ -23,13 +23,6 @@ switch S(1).type
switch S(1).subs switch S(1).subs
case fieldnames(A) case fieldnames(A)
A = A.(S(1).subs); A = A.(S(1).subs);
case {'write'}
if areParensNext(S)
write(A, S(2).subs{:})
S = shiftS(S);
else
assert(false);
end
case methods(A) case methods(A)
if areParensNext(S) if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:}); A = feval(S(1).subs, A, S(2).subs{:});
......
function write(o, fid, indent) function o = write(o, fid)
%function write(o, fid, indent) %function o = write(o, fid)
% Write a Page object % Write a Page object
% %
% INPUTS % INPUTS
% fid - int, file id % fid - int, file id
% indent - char, number of spaces to indent tex code
% %
% OUTPUTS % OUTPUTS
% none % o - this
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
...@@ -31,14 +30,19 @@ function write(o, fid, indent) ...@@ -31,14 +30,19 @@ function write(o, fid, indent)
assert(fid ~= -1); assert(fid ~= -1);
fprintf(fid, '\n%s%% Page Object\n', indent); fprintf(fid, '\n%% Page Object\n');
if ~isempty(o.title)
fprintf(fid, '\\centerline{{\\Large %s}}\n', o.title);
end
if strcmpi(o.orientation, 'landscape') if strcmpi(o.orientation, 'landscape')
fprintf(fid, '%s\\begin{landscape}\n', indent); fprintf(fid, '\\begin{landscape}\n')
end end
o.sections.write(fid, addIndentation(indent));
o.sections.write(fid);
if strcmpi(o.orientation, 'landscape') if strcmpi(o.orientation, 'landscape')
fprintf(fid, '%s\\end{landscape}\n', indent); fprintf(fid, '\\end{landscape}\n');
end end
fprintf(fid, '%s\\clearpage\n', indent); fprintf(fid, '\\clearpage\n');
fprintf(fid, '%s%% End Page Object\n\n', indent); fprintf(fid, '%% End Page Object\n\n');
end end
\ No newline at end of file
...@@ -18,10 +18,11 @@ function ps = addPage(ps, varargin) ...@@ -18,10 +18,11 @@ function ps = addPage(ps, varargin)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(nargin >= 1 && nargin <= 3) ps.objArray = ps.objArray.addObj(page(varargin{:}));
if nargin == 1 %assert(nargin >= 1 && nargin <= 3)
ps.objArray = ps.objArray.addObj(page()); %if nargin == 1
else % ps.objArray = ps.objArray.addObj(page());
ps.objArray = ps.objArray.addObj(varargin{:}); %else
end % ps.objArray = ps.objArray.addObj(varargin{:});
%end
end end
\ No newline at end of file
...@@ -23,13 +23,6 @@ switch S(1).type ...@@ -23,13 +23,6 @@ switch S(1).type
switch S(1).subs switch S(1).subs
case fieldnames(A) case fieldnames(A)
A = A.(S(1).subs); A = A.(S(1).subs);
case {'write'}
if areParensNext(S)
write(A, S(2).subs{:})
S = shiftS(S);
else
assert(false);
end
case methods(A) case methods(A)
if areParensNext(S) if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:}); A = feval(S(1).subs, A, S(2).subs{:});
......
function write(o, fid, indent) function o = write(o, fid)
%function write(o, fid, indent) %function o = write(o, fid)
% Write Pages object % Write Pages object
% %
% INPUTS % INPUTS
% fid - int, file id % fid - int, file id
% indent - char, number of spaces to indent tex code
% %
% OUTPUTS % OUTPUTS
% none % o - this
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
...@@ -30,10 +29,10 @@ function write(o, fid, indent) ...@@ -30,10 +29,10 @@ function write(o, fid, indent)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(fid ~= -1); assert(fid ~= -1);
fprintf(fid, '\n%s%% Pages Object\n', indent); fprintf(fid, '\n%% Pages Object\n');
nps = numPages(o); nps = numPages(o);
for i=1:nps for i=1:nps
o.objArray(i).write(fid, addIndentation(indent)); o.objArray(i).write(fid);
end end
fprintf(fid, '%s%% End Pages Object\n\n', indent); fprintf(fid, '%% End Pages Object\n\n');
end end
\ No newline at end of file
function r = addPage(r, varargin) function o = addPage(o, varargin)
%function r = addPage(r, varargin) %function o = addPage(o, varargin)
% Add a page to the Cell Array of pages in the report % Add a page to the Cell Array of pages in the report
% %
% INPUTS % INPUTS
...@@ -30,21 +30,22 @@ function r = addPage(r, varargin) ...@@ -30,21 +30,22 @@ function r = addPage(r, varargin)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(nargin >= 1 && nargin <= 3, ['incorrect number of arguments passed ' ... %assert(nargin >= 1 && nargin <= 3, ['incorrect number of arguments passed ' ...
'to addPage']); % 'to addPage']);
assert(isa(r, 'report'), 'First argument must be a report object'); %assert(isa(r, 'report'), 'First argument must be a report object');
if nargin > 1 %if nargin > 1
assert(isa(varargin{1},'page'), ['Optional 2nd arg to addPage must be a ' ... % assert(isa(varargin{1},'page'), ['Optional 2nd arg to addPage must be a ' ...
'Page']); % 'Page']);
if nargin > 2 % if nargin > 2
assert(isnumeric(varargin{2}), ['Optional 3rd arg to addPage must be ' ... % assert(isnumeric(varargin{2}), ['Optional 3rd arg to addPage must be ' ...
'an index']); % 'an index']);
end % end
end %end
if nargin == 1 if nargin == 1
r.pages = r.pages.addPage(); o.pages = o.pages.addPage('orientation', o.orientation, 'paper', o.paper);
elseif nargin == 2 || nargin == 3 else
r.pages = r.pages.addPage(varargin{:}); o.pages = o.pages.addPage('orientation', o.orientation, 'paper', ...
o.paper, varargin{:});
end end
end end
...@@ -34,6 +34,7 @@ o = struct; ...@@ -34,6 +34,7 @@ o = struct;
o.title = ''; o.title = '';
o.orientation = 'portrait'; o.orientation = 'portrait';
o.paper = 'a4'; o.paper = 'a4';
o.margin = '2cm';
o.pages = pages(); o.pages = pages();
o.filename = 'report.tex'; o.filename = 'report.tex';
o.config = ''; o.config = '';
......
...@@ -23,13 +23,6 @@ switch S(1).type ...@@ -23,13 +23,6 @@ switch S(1).type
switch S(1).subs switch S(1).subs
case fieldnames(A) case fieldnames(A)
A = A.(S(1).subs); A = A.(S(1).subs);
case {'write'}