diff --git a/matlab/reporting/@graph/createGraph.m b/matlab/reporting/@graph/createGraph.m index 4e46ea97f88fe45c069e6fa4b3a045aeb279c0f2..696a93df6b20c65540a88218e2e12966d0ec9aae 100644 --- a/matlab/reporting/@graph/createGraph.m +++ b/matlab/reporting/@graph/createGraph.m @@ -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; diff --git a/matlab/reporting/@graph/graph.m b/matlab/reporting/@graph/graph.m index ae98ab810f0ce7b58844acc09514fe3b23de9ede..759df6fe9f775fa33b2f24f0aacfa9bf76263641 100644 --- a/matlab/reporting/@graph/graph.m +++ b/matlab/reporting/@graph/graph.m @@ -41,7 +41,7 @@ o.footnote = ''; o.figname = ''; o.data = ''; -o.seriestoplot = 'all'; +o.seriestouse = 'all'; o.shade = ''; %{1959q1:1964q4} o.grid = true; diff --git a/matlab/reporting/@report/write.m b/matlab/reporting/@report/write.m index 0caab5df55a154b428e728bf90d8aae297f43bbb..456f58a76e35a65c127d180f28b533e13986212f 100644 --- a/matlab/reporting/@report/write.m +++ b/matlab/reporting/@report/write.m @@ -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); diff --git a/matlab/reporting/@section/write.m b/matlab/reporting/@section/write.m index 85e451fdf62f414d34be3c2299c3295d3d2b111e..4848ad8302c0081dae2e397a7504f7945451a407 100644 --- a/matlab/reporting/@section/write.m +++ b/matlab/reporting/@section/write.m @@ -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 \ No newline at end of file diff --git a/matlab/reporting/@table/table.m b/matlab/reporting/@table/table.m index bf12a8b677feba4f210385a63d4e20c3b20e44b0..95fb4fcfe30116825be3ae85a69e8d5f88fa2927 100644 --- a/matlab/reporting/@table/table.m +++ b/matlab/reporting/@table/table.m @@ -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, ' ... diff --git a/matlab/reporting/@table/write.m b/matlab/reporting/@table/write.m index 129ae38a1ac13bfe0e5ceef37afaf0089dc708a2..bed5b945e633910c9b25b2196fa97acde01c39e8 100644 --- a/matlab/reporting/@table/write.m +++ b/matlab/reporting/@table/write.m @@ -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 \ No newline at end of file +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