From daf6189e9c181c62a228f9f9c9b694d4588e5902 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Thu, 20 Feb 2014 16:35:05 +0100 Subject: [PATCH] reporting: add option 'ALL' to xTickLabels --- doc/dynare.texi | 2 +- matlab/reports/@graph/graph.m | 9 ++++++--- matlab/reports/@graph/writeGraphFile.m | 8 ++++++-- tests/reporting/runDynareReport.m | 5 ++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index b371d9f80f..7fe9df42db 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -10882,7 +10882,7 @@ last dates of the @code{dseries} and, if passed, the index associated with the first date of the @ref{shade} option. @anchor{xTickLabels} -@item xTickLabels, @code{CELL_ARRAY_STRINGS} +@item xTickLabels, @code{CELL_ARRAY_STRINGS} | `ALL' The labels to be mapped to the ticks provided by @ref{xTicks}. Default: the first and last dates of the @code{dseries} and, if passed, the date first date of the @ref{shade} option. diff --git a/matlab/reports/@graph/graph.m b/matlab/reports/@graph/graph.m index 7b710e3fc2..e79b402f60 100644 --- a/matlab/reports/@graph/graph.m +++ b/matlab/reports/@graph/graph.m @@ -161,10 +161,13 @@ assert(isempty(o.graphSize) || ((isfloat(o.graphSize) && length(o.graphSize) == 'entries, [width height]']); assert(isempty(o.xTicks) || isfloat(o.xTicks),... '@graph.graph: xTicks must be a numerical array'); -assert(iscellstr(o.xTickLabels), ... - '@graph.graph: xTickLabels must be a cell array of strings'); +assert(iscellstr(o.xTickLabels) || (ischar(o.xTickLabels) && strcmpi(o.xTickLabels, 'ALL')), ... + ['@graph.graph: xTickLabels must be a cell array of strings or ' ... + 'equivalent to the string ''ALL''']); if ~isempty(o.xTickLabels) - assert(~isempty(o.xTicks), '@graph.graph: if you set xTickLabels, you must set xTicks'); + assert((ischar(o.xTickLabels) && strcmpi(o.xTickLabels, 'ALL')) || ... + ~isempty(o.xTicks), ['@graph.graph: if you set xTickLabels and ' ... + 'it''s not equal to ''ALL'', you must set xTicks']); end if ~isempty(o.xTicks) assert(~isempty(o.xTickLabels), '@graph.graph: if you set xTicks, you must set xTickLabels'); diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m index db44025b38..56d458f6c4 100644 --- a/matlab/reports/@graph/writeGraphFile.m +++ b/matlab/reports/@graph/writeGraphFile.m @@ -56,11 +56,11 @@ if isempty(o.xrange) else dd = o.xrange; end -stringsdd = strings(dd); fprintf(fid, '\\begin{axis}[%%\n'); % set tick labels if isempty(o.xTickLabels) + stringsdd = strings(dd); if ~isempty(o.shade) x1 = find(strcmpi(date2string(o.shade(1)), stringsdd)); x = [1 x1 dd.ndat]; @@ -70,10 +70,13 @@ if isempty(o.xTickLabels) xTickLabels = [stringsdd(1) stringsdd(end)]; end fprintf(fid, 'xminorticks=true,\nyminorticks=true,\n'); -else +elseif iscell(o.xTickLabels) fprintf(fid,'minor xtick,\n'); x = o.xTicks; xTickLabels = o.xTickLabels; +else + x = [1:dd.ndat]; + xTickLabels = strings(dd); end fprintf(fid, 'xticklabels={'); xlen = length(x); @@ -167,6 +170,7 @@ for i=1:ne end if ~isempty(o.shade) + stringsdd = strings(dd); x1 = find(strcmpi(date2string(o.shade(1)), stringsdd)); x2 = find(strcmpi(date2string(o.shade(end)), stringsdd)); assert(~isempty(x1) && ~isempty(x2), ['@graph.writeGraphFile: either ' ... diff --git a/tests/reporting/runDynareReport.m b/tests/reporting/runDynareReport.m index 4bdd4ffc75..684a320fdc 100644 --- a/tests/reporting/runDynareReport.m +++ b/tests/reporting/runDynareReport.m @@ -222,9 +222,8 @@ rep = rep.addSeries('data', dc_q{'LRPOIL_BAR_WORLD'}, ... rep = rep.addGraph('title', 'World Real Food Price', ... 'xrange', prange, ... 'shade', srange, ... - 'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ... - 'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},... - 'xTickLabelRotation', 0,... + 'xTickLabels','ALL',... + 'xTickLabelRotation', 45,... 'xAxisTight',false,... 'yAxisTight',true); rep = rep.addSeries('data', db_q{'LRPFOOD_WORLD'}, ... -- GitLab