reporting: support vertical lines

time-shift
Houtan Bastani 2014-05-20 11:33:57 +02:00
parent 106879c46e
commit d470ef16ca
6 changed files with 56 additions and 9 deletions

View File

@ -11356,7 +11356,7 @@ Whether or not to show vertical lines separating the columns. Default: @code{fal
@end defmethod
@anchor{addSeries}
@defmethod Report addSeries data, graphLegendName, graphLineColor, graphLineStyle, graphLineWidth, graphMarker, graphMarkerEdgeColor, graphMarkerFaceColor, graphMarkerSize, graphMiscTikzAddPlotOptions, tableDataRhs, tableRowColor, tableRowIndent, tableShowMarkers, tableAlignRight, tableNegColor, tablePosColor, tableSubSectionHeader, zeroTol
@defmethod Report addSeries data, graphLegendName, graphLineColor, graphLineStyle, graphLineWidth, graphMarker, graphMarkerEdgeColor, graphMarkerFaceColor, graphMarkerSize, graphMiscTikzAddPlotOptions, graphVline, tableDataRhs, tableRowColor, tableRowIndent, tableShowMarkers, tableAlignRight, tableNegColor, tablePosColor, tableSubSectionHeader, zeroTol
Adds a @code{Series} to a @code{Graph} or a @code{Table}.
@optionshead
@table @code
@ -11400,6 +11400,9 @@ above, you can pass a string such as the following to this option:
used for desired @code{PGFPLOTS/Ti}@i{k}@code{Z} options that have not been
incorporated into Dynare Reproting. Default: @code{empty}
@item graphVline, @code{dates}
Use this option to draw a vertical line at a given date. Default: @code{empty}
@item tableDataRhs, @code{dseries}
A series to be added to the right of the current series. Usefull for
displaying aggregate data for a series. @i{e.g} if the series is

View File

@ -182,7 +182,10 @@ end
for i=1:ne
o.series{i}.writeSeriesForGraph(fid, dd);
if o.showLegend
fprintf(fid, '\\addlegendentry{%s}\n', o.series{i}.getTexName());
le = o.series{i}.getTexName();
if ~isempty(le)
fprintf(fid, '\\addlegendentry{%s}\n', le);
end
end
end

View File

@ -1,7 +1,7 @@
function s = getTexName(o)
%function s = getTexName(o)
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -18,6 +18,12 @@ function s = getTexName(o)
% 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) && size(o.data, 2) == 1);
s = o.data.tex{:};
if isempty(o.data)
% for the case when there is no data in the series
% e.g. graphVline was passed
s = '';
else
assert(size(o.data,2) == 1);
s = o.data.tex{:};
end
end

View File

@ -48,6 +48,8 @@ o.graphMarkerSize = 1;
o.graphMiscTikzAddPlotOptions = '';
o.graphVline = dates();
o.tableShowMarkers = false;
o.tableNegColor = 'red';
o.tablePosColor = 'blue';

View File

@ -30,8 +30,10 @@ function o = writeSeriesForGraph(o, fid, xrange)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
%% Validate options provided by user
assert(~isempty(o.data) && isa(o.data, 'dseries'), ['@report_series.writeSeriesForGraph: must ' ...
'provide data as a dseries']);
if isempty(o.graphVline)
assert(~isempty(o.data) && isa(o.data, 'dseries'), ['@report_series.writeSeriesForGraph: must ' ...
'provide data as a dseries']);
end
assert(ischar(o.graphMiscTikzAddPlotOptions), ['@report_series.writeSeriesForGraph: ' ...
'graphMiscTikzAddPlotOptions file must be a string']);
@ -64,12 +66,40 @@ assert(isfloat(o.graphMarkerSize) && o.graphMarkerSize > 0, ...
assert(~(strcmp(o.graphLineStyle, 'none') && isempty(o.graphMarker)), ['@report_series.writeSeriesForGraph: ' ...
'you must provide at least one of graphLineStyle and graphMarker']);
% Validate xrange
% Validate graphVline
assert(isdates(o.graphVline), '@report_series.writeSeriesForGraph: graphVline must be a dates');
% Zero tolerance
assert(isfloat(o.zeroTol), '@report_series.write: zeroTol must be a float');
%% graphVline
if ~isempty(o.graphVline)
for i=1:o.graphVline.ndat
fprintf(fid, '%%vline %d\n\\begin{pgfonlayer}{background1}\n\\draw[color=%s,%s,line width=%fpt,line join=round',...
i, o.graphLineColor, o.graphLineStyle, o.graphLineWidth);
if ~isempty(o.graphMarker)
if isempty(o.graphMarkerEdgeColor)
o.graphMarkerEdgeColor = o.graphLineColor;
end
if isempty(o.graphMarkerFaceColor)
o.graphMarkerFaceColor = o.graphLineColor;
end
fprintf(fid, ',mark=%s,mark size=%f,every mark/.append style={draw=%s,fill=%s}',...
o.graphMarker,o.graphMarkerSize,o.graphMarkerEdgeColor,o.graphMarkerFaceColor);
end
if ~isempty(o.graphMiscTikzAddPlotOptions)
fprintf(fid, ',%s', o.graphMiscTikzAddPlotOptions);
end
stringsdd = strings(xrange);
x = find(strcmpi(date2string(o.graphVline(i)), stringsdd));
fprintf(fid, ['] (axis cs:%d,\\pgfkeysvalueof{/pgfplots/ymin}) -- (axis ' ...
'cs:%d,\\pgfkeysvalueof{/pgfplots/ymax});\n\\end{pgfonlayer}\n'], ...
x, x);
end
return
end
%%
if isempty(xrange) || all(xrange == o.data.dates)
ds = o.data;

View File

@ -184,6 +184,9 @@ rep = rep.addSeries('data', db_q{'LRPFOOD_BAR_WORLD'}, ...
'graphLineColor', 'green', ...
'graphLineStyle', 'solid', ...
'graphLineWidth', 1.5);
rep = rep.addSeries('graphVline', dates('2009q2'):dates('2010q1'), ...
'graphLineColor', 'red', ...
'graphLineWidth', 1.5);
% Pae 2
rep = rep.addPage('title', {'Jan1 vs Jan2', 'World Oil and Food Prices'}, ...