reporting: @graph, @series, support syntax simplification

time-shift
Houtan Bastani 2013-03-28 16:46:00 +01:00
parent aecd2a89ad
commit 430f7b538f
17 changed files with 383 additions and 36 deletions

View File

@ -0,0 +1,22 @@
function o = addSeries(o, varargin)
% function o = addSeries(o, varargin)
% 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/>.
o.seriesElements = o.seriesElements.addSeries(varargin{:});
end

View File

@ -28,15 +28,11 @@ function o = createGraph(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));
if ~isempty(o.figname)
warning('@graph.createGraph: will overwrite %s with new graph\n', ...
o.figname);
end
%o = readConfig(o);
disp('creating plot..........');
h = figure('visible','off');
hold on;
@ -45,25 +41,25 @@ if o.grid
grid on;
set(gca, 'GridLineStyle', '--');
end
%set(0, 'CurrentFigure',h);
%set(h, 'PaperPositionMode', 'auto');
%set(h, 'units', 'normalized', 'outerposition', [0 0 1 1]);
if isempty(o.seriestouse)
ds = o.data;
else
ds = o.data{o.seriestouse{:}};
ne = o.seriesElements.numel();
dd = dynDates();
for i=1:ne
ddt = o.seriesElements(i).getLine(o.xrange);
if isempty(dd)
dd = ddt;
continue
end
if ddt(1) < dd(1)
dd = union(ddt(1):dd(1), dd);
end
if ddt(ddt.ndat) > dd(dd.ndat)
dd = union(dd, dd(dd.ndat):ddt(ddt.ndat));
end
end
if ~isempty(o.xrange)
ds = ds(o.xrange);
end
data = ds.data;
x = 1:1:ds.nobs;
xlabels = getDatesCellStringArray(ds.time);
plot(x, data);
x = 1:1:dd.ndat;
xlabels = getDatesCellStringArray(dd);
if ~isempty(o.yrange)
ylim(o.yrange);
@ -87,7 +83,7 @@ set(gca,'XTick', x);
set(gca,'XTickLabel', xlabels);
if o.legend
lh = legend(ds.name);
lh = legend(o.seriesElements.getNames());
set(lh, 'orientation', o.legend_orientation);
set(lh, 'Location', o.legend_location);
set(lh, 'FontSize', o.legend_font_size);

View File

@ -54,16 +54,6 @@ disp([name '.figname = ']);
disp(' ');
disp([' ''' o.figname '''']);
disp(' ');
disp([name '.data = ']);
disp(' ');
display(o.data);
disp(' ');
disp([name '.seriestoplot = ']);
disp(' ');
disp(o.seriestoplot);
disp(' ');
disp([name '.config = ']);
disp(' ');
@ -78,4 +68,9 @@ disp(' ');
disp([name '.shade = ']);
disp(' ');
disp(o.shade);
disp(' ');
disp([name '.seriesElements = ']);
disp(' ');
o.seriesElements.getSeriesElements()
end

View File

@ -35,6 +35,8 @@ o = struct;
o.config = '';
o.seriesElements = seriesElements();
o.title = '';
o.ylabel = '';
o.xlabel = '';
@ -112,11 +114,26 @@ assert(isempty(o.yrange) || (isfloat(o.yrange) && length(o.yrange) == 2 && ...
o.yrange(1) < o.yrange(2)), ...
['@graph.graph: yrange is specified an array with two float entries, ' ...
'the lower bound and upper bound.']);
assert(~isempty(o.data) && isa(o.data, 'dynSeries'), ['@graph.graph: must ' ...
'provide data as a dynSeries']);
assert(isempty(o.data) || isa(o.data, 'dynSeries'), ['@graph.graph: data must ' ...
'be a dynSeries']);
assert(isempty(o.seriestouse) || iscellstr(o.seriestouse), ['@graph.graph: ' ...
'series to use must be a cell array of string(s)']);
% using o.seriestouse, create series objects and put them in o.seriesElements
if ~isempty(o.data)
if isempty(o.seriestouse)
for i=1:o.data.vobs
o.seriesElements = o.seriesElements.addSeries('data', o.data{o.name{i}});
end
else
for i=1:length(o.seriestouse)
o.seriesElements = o.seriesElements.addSeries('data', o.data{o.seriestouse{i}});
end
end
end
o = rmfield(o, 'seriestouse');
o = rmfield(o, 'data');
% Create graph object
o = class(o, 'graph');
end

View File

@ -29,6 +29,10 @@ if length(S) > 1
end
switch S.type
case '()'
index = S.subs{:};
assert(isnumeric(index));
B.seriesElements(index) = V;
case '.'
switch S.subs
case fieldnames(A)

View File

@ -33,7 +33,9 @@ switch S(1).type
otherwise
error(['@graph.subsref: unknown field or method: ' S(1).subs]);
end
case {'()', '{}'}
case '()'
A = A.seriesElements.getSeriesElements(S(1).subs{:});
case '{}'
error(['@graph.subsref: ' S(1).type ' indexing not supported.']);
otherwise
error('@graph.subsref: impossible case')

View File

@ -0,0 +1,23 @@
function o = element(o, index)
% function o = element(o, index)
% 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/>.
assert(isint(index));
o = o.elements(index);
end

View File

@ -32,8 +32,15 @@ switch S.type
case '()'
index = S.subs{:};
assert(isnumeric(index));
B(index) = V;
B.elements(index) = V;
case '.'
switch S.subs
case fieldnames(A)
B.(S.subs) = V;
otherwise
error(['@section.subsasgn: field ' S.subs 'does not exist']);
end
otherwise
error('@section.subsasgn: syntax error')
error('@section.subsasgn: syntax error');
end
end

View File

@ -0,0 +1,23 @@
function s = getName(o)
%function s = getName(o)
% 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/>.
assert(~isempty(o.data) && numel(o.data) == 1);
s = o.data(1).name();
end

View File

@ -0,0 +1,22 @@
function o = addSeries(o, varargin)
% function o = addSeries(o, varargin)
% 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/>.
o.objArray = o.objArray.addObj(series(varargin{:}));
end

View File

@ -0,0 +1,37 @@
function display(o)
%function display(o)
% Display a Elements object
%
% INPUTS
% none
%
% OUTPUTS
% none
%
% 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/>.
name = 'report.page.section.elements.seriesElement';
disp(' ');
disp([name ' = ']);
disp(' ');
disp(getSeriesElements(o));
end

View File

@ -0,0 +1,26 @@
function names = getNames(o, varargin)
% function names = getNames(o, varargin)
% 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/>.
se = o.objArray.getObjs(varargin{:});
names = {};
for i=1:length(se)
names(i) = se{i}.getName();
end
end

View File

@ -0,0 +1,22 @@
function o = getSeriesElements(o, varargin)
% function o = getSeriesElements(o, varargin)
% 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/>.
o = o.objArray.getObjs(varargin{:});
end

View File

@ -0,0 +1,22 @@
function n = numel(o)
% function n = numel(o)
% 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/>.
n = o.objArray.numObjs();
end

View File

@ -0,0 +1,42 @@
function o = seriesElements(varargin)
%function o = seriesElements(varargin)
% SeriesElements Class Constructor
%
% INPUTS
% Optional seriesElements object
%
% OUTPUTS
% seriesElements 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/>.
switch nargin
case 0
o = class(struct, 'seriesElements', objArray());
case 1
assert(isa(varargin{1}, 'seriesElements'), ...
['@seriesElements.seriesElements: with one arg, you must pass an seriesElements ' ...
'object or a char.']);
o = varargin{1};
otherwise
error('@seriesElements.seriesElements: invalid number of arguments');
end
end

View File

@ -0,0 +1,39 @@
function B = subsasgn(A, S, V)
% function B = subsasgn(A, S, V)
% 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/>.
B = A;
if length(S) > 1
for i=1:(length(S)-1)
B = subsref(B, S(i));
end
B = subsasgn(B, S(end), V);
B = subsasgn(A, S(1:(end-1)), B);
return
end
switch S.type
case '()'
index = S.subs{:};
assert(isnumeric(index));
B.objArray(index) = V;
otherwise
error('@seriesElements.subsasign: syntax error');
end
end

View File

@ -0,0 +1,48 @@
function A = subsref(A, S)
%function A = subsref(A, S)
% 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/>.
switch S(1).type
case '.'
switch S(1).subs
case fieldnames(A)
A = A.(S(1).subs);
case methods(A)
if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:});
S = shiftS(S);
else
A = feval(S(1).subs, A);
end
otherwise
error(['@seriesElements.subsref: unknown field or method: ' S(1).subs]);
end
case '()'
A = getSeriesElements(A, S(1).subs{:});
case '{}'
error(['@seriesElements.subsref: ' S(1).type ' indexing not supported.']);
otherwise
error('@seriesElements.subsref: impossible case');
end
S = shiftS(S);
if length(S) >= 1
A = subsref(A, S);
end
end