Skip to content
Snippets Groups Projects
Commit a9ff5c74 authored by Houtan Bastani's avatar Houtan Bastani
Browse files

reporting: @series class

parent 85d4bd69
Branches
No related tags found
No related merge requests found
function display(o)
%function display(o)
% Display a Series object
%
% INPUTS
% o [series] series object
%
% 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.graph.series';
disp(' ');
disp([name '.data = ']);
disp(' ');
display(o.data);
disp(' ');
disp([name '.color = ']);
disp(' ');
disp([' ''' o.color '''']);
disp(' ');
disp([name '.line_style = ']);
disp(' ');
disp([' ''' o.line_style '''']);
disp(' ');
disp([name '.line_width = ']);
disp(' ');
disp([' ''' o.line_width '''']);
disp(' ');
disp([name '.marker = ']);
disp(' ');
disp([' ''' o.marker '''']);
disp(' ');
disp([name '.marker_edge_color = ']);
disp(' ');
disp([' ''' o.marker_edge_color '''']);
disp(' ');
disp([name '.marker_face_color = ']);
disp(' ');
disp([' ''' o.marker_face_color '''']);
disp(' ');
disp([name '.marker_size = ']);
disp(' ');
disp([' ''' o.marker_size '''']);
end
\ No newline at end of file
function dd = getLine(o, xrange)
%function dd = getLine(o, xrange)
% Create the series
%
% INPUTS
% o [series] series object
% xrange [dynDates] range of x values for line
%
% OUTPUTS
% dd [dynDates] dynDates representing the range of the line
%
% 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/>.
%% Validate options provided by user
assert(~isempty(o.data) && isa(o.data, 'dynSeries'), ['@series.series: must ' ...
'provide data as a dynSeries']);
% Line
assert(ischar(o.color), '@series.series: color must be a string');
valid_line_style = {'none', '-', '--', ':', '-.'};
assert(any(strcmp(o.line_style, valid_line_style)), ...
['@series.series: line_style must be one of ' strjoin(valid_line_style, ' ')]);
assert(isfloat(o.line_width), ['@series.series: line_width must be a ' ...
'positive number']);
% Marker
valid_marker = {'+', 'o', '*', '.', 'x', 's', 'square', 'd', 'diamond', ...
'^', 'v', '>', '<', 'p', 'pentagram', 'h', 'hexagram', ...
'none'};
assert(isempty(o.marker) || any(strcmp(o.marker, valid_marker)), ...
['@series.series: marker must be one of ' strjoin(valid_marker)]);
assert(ischar(o.marker_edge_color), '@series.series: marker_edge_color must be a string');
assert(ischar(o.marker_face_color), '@series.series: marker_face_color must be a string');
assert(isfloat(o.marker_size), ['@series.series: marker_size must be a ' ...
'positive number']);
% Marker & Line
assert(~(strcmp(o.line_style, 'none') && isempty(o.marker)), ['@series.series: ' ...
'you must provide at least one of line_style and marker']);
% Validate xrange
assert(isempty(xrange) || isa(xrange, 'dynDates'));
%%
ds = o.data;
if ~isempty(xrange)
ds = o.data(xrange);
end
dd = ds.time;
opt = {'XData', 1:length(ds.data)};
opt = {opt{:}, 'YData', ds.data};
opt = {opt{:}, 'Color', o.color};
opt = {opt{:}, 'LineStyle', o.line_style};
opt = {opt{:}, 'LineWidth', o.line_width};
if ~isempty(o.marker)
opt = {opt{:}, 'Marker', o.marker};
opt = {opt{:}, 'MarkerSize', o.marker_size};
opt = {opt{:}, 'MarkerEdgeColor', o.marker_edge_color};
opt = {opt{:}, 'MarkerFaceColor', o.marker_face_color};
end
line(opt{:});
end
function o = series(varargin)
%function o = series(varargin)
% Series Class Constructor
%
% INPUTS
% varargin 0 args : empty series object
% 1 arg : must be series object (return a copy of arg)
% > 1 args: option/value pairs (see structure below for
% options)
%
% OUTPUTS
% o [series] series 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/>.
o = struct;
o.data = '';
o.color = 'k';
o.line_style = '-';
o.line_width = 0.5;
o.marker = '';
o.marker_edge_color = 'auto';
o.marker_face_color = 'auto';
o.marker_size = 6;
if nargin == 1
assert(isa(varargin{1}, 'series'),['@series.series: with one arg you ' ...
'must pass a series object']);
o = varargin{1};
return;
elseif nargin > 1
if round(nargin/2) ~= nargin/2
error(['@series.series: options must be supplied in name/value ' ...
'pairs.']);
end
optNames = lower(fieldnames(o));
% overwrite default values
for pair = reshape(varargin, 2, [])
field = lower(pair{1});
if any(strmatch(field, optNames, 'exact'))
o.(field) = pair{2};
else
error('@series.series: %s is not a recognized option.', field);
end
end
end
% Create series object
o = class(o, 'series');
end
\ No newline at end of file
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 '.'
switch S.subs
case fieldnames(A)
B.(S.subs) = V;
otherwise
error(['@series.subsasgn: field ' S.subs 'does not exist']);
end
otherwise
error('@series.subsasgn: syntax error');
end
end
\ No newline at end of file
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(['@series.subsref: unknown field or method: ' S(1).subs]);
end
case {'()', '{}'}
error(['@series.subsref: ' S(1).type ' indexing not supported.']);
otherwise
error('@series.subsref: impossible case')
end
S = shiftS(S);
if length(S) >= 1
A = subsref(A, S);
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment