diff --git a/doc/dynare.texi b/doc/dynare.texi index 60e3fca4be41fa685d9eab1d6dc9ee4d4d3f731c..e299c00d29fc234251e36b1582adb3cc079a85b7 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -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 diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m index f02283b5a7b6f937a3e6b3b41230efab807b0b3d..8b649b58978b109bbed14a17b1414d882e7cec70 100644 --- a/matlab/reports/@graph/writeGraphFile.m +++ b/matlab/reports/@graph/writeGraphFile.m @@ -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 diff --git a/matlab/reports/@report_series/getTexName.m b/matlab/reports/@report_series/getTexName.m index 90e6ba23358cd0fbc33b76f85a9da58f7c763fcd..0672508f9bbffbf2b2f0fe2263ec181e1c5e52ff 100644 --- a/matlab/reports/@report_series/getTexName.m +++ b/matlab/reports/@report_series/getTexName.m @@ -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 \ No newline at end of file diff --git a/matlab/reports/@report_series/report_series.m b/matlab/reports/@report_series/report_series.m index 611277686e8579fe62a1454b5ea14a2c0b371cc5..5f06d853099314b2aa93e018b72e456fcd50ba2c 100644 --- a/matlab/reports/@report_series/report_series.m +++ b/matlab/reports/@report_series/report_series.m @@ -48,6 +48,8 @@ o.graphMarkerSize = 1; o.graphMiscTikzAddPlotOptions = ''; +o.graphVline = dates(); + o.tableShowMarkers = false; o.tableNegColor = 'red'; o.tablePosColor = 'blue'; diff --git a/matlab/reports/@report_series/writeSeriesForGraph.m b/matlab/reports/@report_series/writeSeriesForGraph.m index f45f4a92892a3589e0906bd663cb6a998021c767..c834d7d40b8c3cae94c300717edcfc2f91cca613 100644 --- a/matlab/reports/@report_series/writeSeriesForGraph.m +++ b/matlab/reports/@report_series/writeSeriesForGraph.m @@ -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; diff --git a/tests/reporting/runDynareReport.m b/tests/reporting/runDynareReport.m index f6e51afa3fbc2679daeaace701c2e18930508fa4..812f948a00c73343abe3a5351390d691a6898174 100644 --- a/tests/reporting/runDynareReport.m +++ b/tests/reporting/runDynareReport.m @@ -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'}, ...