diff --git a/doc/dynare.texi b/doc/dynare.texi index c66fa4b5a783f31b34aca7fa1f49ca574f00c872..407030117a01020a7f6313d9eca583137bbd3a88 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -11503,7 +11503,7 @@ reports. Default: @code{`black'} @end table @end defmethod -@defmethod Report addTable data, showHlines, precision, range, seriesToUse, tableDirName, tableName, title, titleFormat, vlineAfter, vlineAfterEndOfPeriod, showVlines, writeCSV +@defmethod Report addTable data, highlightRows, showHlines, precision, range, seriesToUse, tableDirName, tableName, title, titleFormat, vlineAfter, vlineAfterEndOfPeriod, showVlines, writeCSV Adds a @code{Table} to a @code{Section}. @optionshead @table @code @@ -11511,6 +11511,12 @@ Adds a @code{Table} to a @code{Section}. @item data, @code{dseries} @xref{data}. +@item highlightRows, @code{CELL_ARRAY_STRINGS} +A cell array containing the colors to use for row highlighting. See +@ref{shadeColor} for how to use colors with reports. Highlighting for a +specific row can be overridden by using the @ref{tableRowColor} option to +@ref{addSeries}. Default: @code{empty} + @item showHlines, @code{BOOLEAN} Whether or not to show horizontal lines separating the rows. Default: @code{false} @@ -11627,6 +11633,7 @@ quarterly @code{tableDataRhs} could point to the yearly averages of the quarterly series. This would cause quarterly data to be displayed followed by annual data. Default: @code{empty} +@anchor{tableRowColor} @item tableRowColor, @code{STRING} The color that you want the row to be. Predefined values include @code{LightCyan} and @code{Gray}. Default: @code{white}. diff --git a/matlab/reports/@report_series/writeSeriesForTable.m b/matlab/reports/@report_series/writeSeriesForTable.m index bd4f70b672df50796faa4583fd55f50c9d543402..77bc82a3b1704944a5394b7b777fdf4ceba66078 100644 --- a/matlab/reports/@report_series/writeSeriesForTable.m +++ b/matlab/reports/@report_series/writeSeriesForTable.m @@ -1,5 +1,5 @@ -function o = writeSeriesForTable(o, fid, dates, precision, ncols) -%function o = writeSeriesForTable(o, fid, dates, precision, ncols) +function o = writeSeriesForTable(o, fid, dates, precision, ncols, rowcolor) +%function o = writeSeriesForTable(o, fid, dates, precision, ncols, rowcolor) % Write Table Row % % INPUTS @@ -8,6 +8,7 @@ function o = writeSeriesForTable(o, fid, dates, precision, ncols) % dates [dates] dates for report_series slice % precision [float] precision with which to print the data % ncols [int] total number of columns in table +% rowcolor [string] string to color this row % % % OUTPUTS @@ -65,7 +66,11 @@ assert(isfloat(o.tableMarkerLimit), '@report_series.writeSeriesForTable: tableMa %% Write Output fprintf(fid, '%% Table Row (report_series)\n'); -if ~isempty(o.tableRowColor) +if ~isempty(o.tableRowColor) && ~strcmpi(o.tableRowColor, 'white') + fprintf(fid, '\\rowcolor{%s}', o.tableRowColor); +elseif ~isempty(rowcolor) + fprintf(fid, '\\rowcolor{%s}', rowcolor); +else fprintf(fid, '\\rowcolor{%s}', o.tableRowColor); end if ~isempty(o.tableSubSectionHeader) diff --git a/matlab/reports/@report_table/report_table.m b/matlab/reports/@report_table/report_table.m index ddc6c225ca79b0fa59c687ba72defa24de837eee..effd07e517b97963cdcee638c0351ce40c486cd7 100644 --- a/matlab/reports/@report_table/report_table.m +++ b/matlab/reports/@report_table/report_table.m @@ -51,6 +51,8 @@ o.range = {}; o.precision = 1; o.writeCSV = false; +o.highlightRows = {''}; + if nargin == 1 assert(isa(varargin{1}, 'report_table'),['With one arg to Report_Table constructor, ' ... 'you must pass a report_table object']); @@ -117,6 +119,7 @@ assert(iscellstr(o.titleFormat), ... assert(ischar(o.tableName), '@report_table.report_table: tableName must be a string'); assert(ischar(o.tableDirName), '@report_table.report_table: tableDirName must be a string'); assert(islogical(o.writeCSV), '@report_table.report_table: writeCSV must be either true or false'); +assert(iscellstr(o.highlightRows), '@report_table.report_table: highlightRowsmust be a cell string'); % using o.seriesToUse, create series objects and put them in o.series if ~isempty(o.data) diff --git a/matlab/reports/@report_table/writeTableFile.m b/matlab/reports/@report_table/writeTableFile.m index 7c0b7d1d906b93192f5fca21c534dd872cf1e3d6..01e04adaa58fa4417a43be9d5408ec1a885e98a5 100644 --- a/matlab/reports/@report_table/writeTableFile.m +++ b/matlab/reports/@report_table/writeTableFile.m @@ -175,7 +175,7 @@ if o.writeCSV csvseries = dseries(); end for i=1:ne - o.series{i}.writeSeriesForTable(fid, o.range, o.precision, ncols); + o.series{i}.writeSeriesForTable(fid, o.range, o.precision, ncols, o.highlightRows{mod(i,length(o.highlightRows))+1}); if o.writeCSV if isempty(o.series{i}.tableSubSectionHeader) csvseries = [csvseries ... diff --git a/tests/reporting/CountryTablePage.m b/tests/reporting/CountryTablePage.m index 4f91d9fe34531351e5d0cdb2d84e63034f5530f8..e73b865b28c379639841f6d8bbdf390109950c2e 100644 --- a/tests/reporting/CountryTablePage.m +++ b/tests/reporting/CountryTablePage.m @@ -44,7 +44,8 @@ notForOtherThree = {'BLT_', 'UNR_', 'UNR_BAR_', 'UNR_GAP_'}; rep = rep.addTable('title', countryName, ... 'range', {trange, dates('2012a'):dates('2014a')}, ... 'vlineAfter', {vline_after dates('2014q4')}, ... - 'writeCSV', true); + 'writeCSV', true, ... + 'highlightRows', {'gray!22', 'cyan!33', 'blue!44', 'red!55'}); diff --git a/tests/reporting/runDynareReport.m b/tests/reporting/runDynareReport.m index 305e2736d6bcae3c651e427bf62c2de31b53455d..4ce50f40835efc17a711a03eb2e0930403c75ff9 100644 --- a/tests/reporting/runDynareReport.m +++ b/tests/reporting/runDynareReport.m @@ -44,7 +44,8 @@ rep = rep.addVspace(); % Table 1 rep = rep.addTable('title', {'Real GDP Growth','subtitle 1', 'subtitle 2'}, ... 'range', larange, ... - 'vlineAfter', dates('2011y')); + 'vlineAfter', dates('2011y'), ... + 'highlightRows', {'gray!25','white','green!22'}); rep = AnnualTable(rep, db_a, dc_a, 'PCH_GROWTH4_', larange); rep = rep.addVspace('number', 2);