reporting: @series support writing colors/marking table rows

remove-priordens
Houtan Bastani 2013-04-02 15:00:00 +02:00
parent 57c10f5ff8
commit ee7f2fb7d0
3 changed files with 82 additions and 24 deletions

View File

@ -44,6 +44,10 @@ o.graph_marker_edge_color = 'auto';
o.graph_marker_face_color = 'auto';
o.graph_marker_size = 6;
o.table_markers = false;
o.table_neg_color = 'red';
o.table_pos_color = 'blue';
if nargin == 1
assert(isa(varargin{1}, 'series'),['@series.series: with one arg you ' ...
'must pass a series object']);

View File

@ -0,0 +1,74 @@
function o = write(o, fid, dates, precision)
%function o = write(o, fid, dates, precision)
% Write Table Row
%
% INPUTS
% o [series] series object
% xrange [dynDates] range of x values for line
%
% OUTPUTS
% o [series] series object
%
% 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/>.
%% Validate options passed to function
assert(fid ~= -1);
assert(isa(dates, 'dynDates'));
assert(isint(precision));
%% Validate options provided by user
assert(~isempty(o.data) && isa(o.data, 'dynSeries'), ...
'@series.write: must provide data as a dynSeries');
assert(ischar(o.color), '@series.write: color must be a string');
assert(ischar(o.table_neg_color), '@series.write: table_neg_color must be a string');
assert(ischar(o.table_pos_color), '@series.write: table_pos_color must be a string');
assert(islogical(o.table_markers), '@series.write: table_markers must be a string');
%% Write Output
dataString = ['%.' num2str(precision) 'f'];
precision = 10^precision;
fprintf(fid, '%% Table Row (series)\n');
fprintf(fid, '%s', o.data.name{:});
data = o.data(dates);
data = data.data;
for i=1:size(data,1)
thisCellData = round(data(i)*precision)/precision;
fprintf(fid, ' &');
if o.table_markers
if thisCellData < 0
fprintf(fid, '\\color{%s}', o.table_neg_color);
elseif thisCellData > 0
fprintf(fid, '\\color{%s}', o.table_pos_color);
end
fprintf(fid, '[');
end
fprintf(fid, dataString, thisCellData);
if o.table_markers
fprintf(fid, ']');
end
end
fprintf(fid, ' \\\\\n\n');
end

View File

@ -49,16 +49,6 @@ else
end
ndates = dates.ndat;
ne = o.seriesElements.numElements();
ds = dynSeries();
for i=1:ne
if isempty(ds)
ds = o.seriesElements(i).getData(dates);
else
ds = [ds o.seriesElements(i).getData(dates)];
end
end
disp('creating table.........');
fprintf(fid, '%% Table Object\n');
fprintf(fid, '\\setlength{\\tabcolsep}{4pt}\n');
@ -126,20 +116,10 @@ end
fprintf(fid, '\\\\%%\n');
fprintf(fid, '%%\n');
% Table Data
vars = ds.name;
nvars = size(vars);
data = ds.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');
% Write Table Data
ne = o.seriesElements.numElements();
for i=1:ne
o.seriesElements(i).write(fid, dates, o.precision);
end
fprintf(fid, '\\bottomrule\n');