diff --git a/matlab/reporting/@series/display.m b/matlab/reporting/@series/display.m new file mode 100644 index 0000000000000000000000000000000000000000..df38e8440495e60d1756ec1b9f188fb55d2b9f20 --- /dev/null +++ b/matlab/reporting/@series/display.m @@ -0,0 +1,71 @@ +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 diff --git a/matlab/reporting/@series/getLine.m b/matlab/reporting/@series/getLine.m new file mode 100644 index 0000000000000000000000000000000000000000..cd06faa26cc86089e7dfede0e79b9e3157b33e36 --- /dev/null +++ b/matlab/reporting/@series/getLine.m @@ -0,0 +1,85 @@ +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 diff --git a/matlab/reporting/@series/series.m b/matlab/reporting/@series/series.m new file mode 100644 index 0000000000000000000000000000000000000000..33e07c12b95812805ed73d321b1b46161f712f46 --- /dev/null +++ b/matlab/reporting/@series/series.m @@ -0,0 +1,73 @@ +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 diff --git a/matlab/reporting/@series/subsasgn.m b/matlab/reporting/@series/subsasgn.m new file mode 100644 index 0000000000000000000000000000000000000000..cb14b1e4eb93404ca4d5d17394a9be4c33853b4e --- /dev/null +++ b/matlab/reporting/@series/subsasgn.m @@ -0,0 +1,42 @@ +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 diff --git a/matlab/reporting/@series/subsref.m b/matlab/reporting/@series/subsref.m new file mode 100644 index 0000000000000000000000000000000000000000..5fb142fcfe68361c898a88b45bf377df81c5ed64 --- /dev/null +++ b/matlab/reporting/@series/subsref.m @@ -0,0 +1,46 @@ +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