reporting: table

time-shift
Houtan Bastani 2013-03-08 18:59:26 +01:00
parent 22caa866b7
commit 8d36cc802c
6 changed files with 141 additions and 27 deletions

View File

@ -49,10 +49,10 @@ end
%set(h, 'PaperPositionMode', 'auto');
%set(h, 'units', 'normalized', 'outerposition', [0 0 1 1]);
if strcmpi(o.seriestoplot, 'all')
if strcmpi(o.seriestouse, 'all')
data = o.data.data;
else
data = o.data{o.seriestoplot{:}}.data;
data = o.data{o.seriestouse{:}}.data;
end
x=[1:1:o.data.nobs];
@ -65,6 +65,13 @@ if ~isempty(o.shade)
x2 = strmatch(lower(o.shade{2}), xlabels, 'exact');
yrange = get(gca, 'YLim');
if isempty(x1)
error([o.shade{1} ' not in date range of provided data']);
end
if isempty(x2)
error([o.shade{2} ' not in date range of provided data']);
end
% 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)], ...
@ -75,10 +82,10 @@ set(gca,'XTick', x);
set(gca,'XTickLabel', xlabels);
if o.legend
if strcmpi(o.seriestoplot, 'all')
if strcmpi(o.seriestouse, 'all')
lh = legend(o.data.name);
else
lh = legend(o.seriestoplot{:});
lh = legend(o.seriestouse{:});
end
set(lh, 'orientation', o.legend_orientation);
set(lh, 'Location', o.legend_location);
@ -87,15 +94,15 @@ if o.legend
end
if ~isempty(o.xlabel)
xlabel(['$\textbf{\footnotesize ' o.xlabel '}$'],'Interpreter','LaTex');
xlabel(['$\textbf{\footnotesize ' o.xlabel '}$'], 'Interpreter', 'LaTex');
end
if ~isempty(o.ylabel)
ylabel(['$\textbf{\footnotesize ' o.ylabel '}$'],'Interpreter','LaTex');
ylabel(['$\textbf{\footnotesize ' o.ylabel '}$'], 'Interpreter', 'LaTex');
end
if ~isempty(o.title)
title( o.title , 'interpreter', 'none', 'FontSize', 20);
title( o.title, 'Interpreter', 'LaTex');
end
drawnow;

View File

@ -41,7 +41,7 @@ o.footnote = '';
o.figname = '';
o.data = '';
o.seriestoplot = 'all';
o.seriestouse = 'all';
o.shade = ''; %{1959q1:1964q4}
o.grid = true;

View File

@ -41,7 +41,7 @@ if strcmpi(o.orientation, 'landscape')
fprintf(fid, ',landscape');
end
fprintf(fid, ']{geometry}\n');
fprintf(fid, '\\usepackage{graphicx, pdflscape, pgf, pgfplots}\n');
fprintf(fid, '\\usepackage{pdflscape, pgf, pgfplots, booktabs}\n');
fprintf(fid, ['\\makeatletter\n' ...
'\\def\\blfootnote{\\gdef\\@thefnmark{}\\@footnotetext}\n' ...
'\\makeatother\n']);
@ -53,6 +53,12 @@ if o.showdate
fprintf(fid, '\\renewcommand{\\footrulewidth}{0.5pt}\n');
fprintf(fid, '\\rfoot{\\scriptsize\\reportdate\\today\\ -- \\currenttime}\n');
end
% May not need these.....
fprintf(fid, '\\renewcommand{\\textfraction}{0.05}\n');
fprintf(fid, '\\renewcommand{\\topfraction}{0.8}\n');
fprintf(fid, '\\renewcommand{\\bottomfraction}{0.8}\n');
fprintf(fid, '\\usepackage[Export,PGF]{adjustbox}\n');
fprintf(fid, '\\begin{document}\n');
o.pages.write(fid);

View File

@ -31,29 +31,27 @@ function o = write(o, fid)
assert(fid ~= -1);
fprintf(fid, '%% Section Object\n');
fprintf(fid, '\\begin{table}[%shtpb]\n', o.align);
fprintf(fid, '\\resizebox{\\textwidth}{!}{\n');
fprintf(fid, '\\begin{tabular}{');
%fprintf(fid, '\\begin{table}[%shtpb]%%\n', o.align);
fprintf(fid, ' \\vspace{15px}\n');
fprintf(fid, '\\centering\n');
fprintf(fid, '\\noindent\\maxsizebox{\\textwidth}{!}{%%\n');
fprintf(fid, '\\begin{tabular}[t]{');
for i=1:o.cols
fprintf(fid, 'c');
end
fprintf(fid, '}\n');
% Calculate scaling factor
%sf = round(100/o.cols)/100-.01;
ne = numElements(o);
for i=1:ne
o.elements(i).write(fid);
if rem(i, o.cols)
fprintf(fid, ' & ');
else
fprintf(fid, '\\\\\n');
fprintf(fid, ' \\\\\n');
end
end
fprintf(fid, '\\end{tabular}\n');
fprintf(fid, '}\n');
fprintf(fid, '\\end{table}\n');
fprintf(fid, '\\end{tabular}%%\n');
fprintf(fid, '}%%\n');
%fprintf(fid, '\\end{table}%%\n');
fprintf(fid, '%% End Section Object\n\n');
end

View File

@ -30,11 +30,19 @@ function o = table(varargin)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
o = struct;
o.caption = '';
o.title = '';
o.footnote = '';
o.config = '';
o.hlines = false;
o.vlines = false;
o.data = '';
o.datatitles = '';
o.seriestouse = 'all';
o.range = '';
o.precision = 1;
if nargin == 1
assert(isa(varargin{1}, 'table'),['With one arg to Table constructor, ' ...

View File

@ -3,10 +3,11 @@ function o = write(o, fid)
% Write a Table object
%
% INPUTS
% o - Table Object
% fid - int, file id
%
% OUTPUTS
% o - this
% o - Table Object
%
% SPECIAL REQUIREMENTS
% none
@ -28,10 +29,104 @@ function o = write(o, fid)
% 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 > 0);
assert(isnumeric(texIndent));
assert(fid ~= -1);
if isempty(o.data)
return
end
fprintf(fid, '%% Page Object\n');
%number of left-hand columns, 1 until we allow the user to group data,
% e.g.: GDP Europe
% GDP France
% GDP Germany
% this example would be two lh columns, with GDP Europe spanning both
nlhc = 1;
fprintf(fid, '%% End Page Object\n');
end
disp('creating table.........');
fprintf(fid, '%% Table Object\n');
fprintf(fid, '\\begin{tabular}{l');
dates = o.data.time;
ndates = dates.ndat;
for i=1:ndates
fprintf(fid, 'r');
end
fprintf(fid, '}%%\n');
if ~isempty(o.title)
fprintf(fid, '\\multicolumn{%d}{c}{%s} \\\\\n', ndates+nlhc, o.title);
end
fprintf(fid, '\\toprule%%\n');
datedata = dates.time;
years = unique(datedata(:, 1));
thdr = num2cell(years, size(years, 1));
lind = nlhc;
switch dates.freq
case 1
for i=1:size(thdr, 1)
fprintf(fid, ' & %d', thdr{i, 1});
end
fprintf(fid, '\\\\%%\n');
for i=1:size(thdr, 1)
rind = lind + 1;
fprintf(fid, '\\cmidrule(l{.5em}r{.5em}){%d-%d}', lind+1, rind);
lind = rind;
end
case 4
thdr{1, 2} = datedata(:, 2)';
if size(thdr, 1) > 1
for i=2:size(thdr, 1)
split = find(thdr{i-1, 2} == 4, 1, 'first');
if isempty(split)
error('@table.write: Shouldn''t arrive here');
else
thdr{i, 2} = thdr{i-1, 2}(split+1:end);
thdr{i-1, 2} = thdr{i-1, 2}(1:split);
end
end
end
for i=1:size(thdr, 1)
fprintf(fid, ' & \\multicolumn{%d}{c}{%d}', size(thdr{i,2}, 2), thdr{i,1});
end
fprintf(fid, '\\\\%%\n');
for i=1:size(thdr, 1)
rind = lind + size(thdr{i,2}, 2);
fprintf(fid, '\\cmidrule(l{.5em}r{.5em}){%d-%d}', lind+1, rind);
lind = rind;
end
for i=1:size(thdr, 1)
quarters = thdr{i, 2};
for j=1:size(quarters, 2)
fprintf(fid, ' & Q%d', quarters(j));
end
end
fprintf(fid, '\\\\%%\n');
for i=1:ndates
fprintf(fid, '\\cmidrule(l{.5em}r{.5em}){%d-%d}', i+nlhc, i+nlhc);
end
case 12
otherwise
error('@table.write: invalid dynSeries Dates');
end
fprintf(fid, '%%\n');
vars = o.data.name;
nvars = size(vars);
data = o.data.data;
assert(isint(o.precision));
precision = 10^o.precision;
dataString = [' & %.' num2str(o.precision) 'f'];
for i=1:nvars
fprintf(fid, '%% Table Row %d\n', i);
fprintf(fid, '%s', vars{i});
for j=1:ndates
fprintf(fid, dataString, round(data(j,i)*precision)/precision);
end
fprintf(fid, ' \\\\\n\n');
end
fprintf(fid, '\\bottomrule%%\n');
fprintf(fid, '\\end{tabular}%%\n');
fprintf(fid, '%% End Table Object\n');
end