time | Calls | line |
|---|
| | 1 | function out = rulerFunctions(func, numargsout, args)
|
| | 2 | % This function is undocumented and may change in a future release.
|
| | 3 |
|
| | 4 | % Copyright 2016-2020 The MathWorks, Inc.
|
| | 5 |
|
| | 6 | % --- Input parsing and error checking ---
|
| | 7 |
|
| | 8 | % Parse the function name into pieces.
|
0.002 | 10 | 9 | [axle, ruler, family, prop, mode] = parseFunctionName(func);
|
| | 10 |
|
| | 11 | % Count how many arguments were passed into the parent function
|
< 0.001 | 10 | 12 | nargs = numel(args);
|
| | 13 |
|
| | 14 | % Make sure we have 0-2 input arguments to the calling function.
|
< 0.001 | 10 | 15 | if nargs > 2
|
| | 16 | throwAsCaller(MException(message('MATLAB:narginchk:tooManyInputs')))
|
< 0.001 | 10 | 17 | end
|
| | 18 |
|
| | 19 | % Make sure we have either 0 or 1 output arguments to the calling function.
|
< 0.001 | 10 | 20 | if numargsout > 1
|
| | 21 | throwAsCaller(MException(message('MATLAB:nargoutchk:tooManyOutputs')));
|
< 0.001 | 10 | 22 | end
|
| | 23 |
|
| | 24 | % Helper function to validate the acceptable types of axes.
|
| | 25 | % Axes types are listed separately to prevent mixed vectors.
|
< 0.001 | 10 | 26 | isAxes = @(ax) isa(ax,'matlab.graphics.axis.Axes') || ...
|
| | 27 | isa(ax, 'matlab.graphics.axis.PolarAxes') || ...
|
| | 28 | isa(ax, 'matlab.graphics.axis.GeographicAxes') || ...
|
| | 29 | isa(ax, 'matlab.graphics.illustration.ColorBar') || ...
|
| | 30 | isa(ax, 'matlab.graphics.chart.Chart');
|
| | 31 |
|
| | 32 | % Parse the input arguments to look for an Axes.
|
< 0.001 | 10 | 33 | if nargs > 0 && isscalar(args{1}) && (isgraphics(args{1},'axes') || ...
|
| | 34 | isgraphics(args{1},'polaraxes') || ...
|
| | 35 | isgraphics(args{1},'geoaxes') || ...
|
| | 36 | isgraphics(args{1},'colorbar'))
|
| | 37 | % The first input is a single axes or colorbar.
|
| | 38 | ax = handle(args{1});
|
| | 39 | args = args(2:end);
|
| | 40 | nargs = nargs - 1;
|
0.001 | 10 | 41 | elseif nargs > 0 && ~isempty(args{1}) && isAxes(args{1}) && all(isvalid(args{1}(:)))
|
| | 42 | % The first input is an array of axes, charts, or colorbars.
|
| | 43 | ax = args{1}(:);
|
| | 44 | args = args(2:end);
|
| | 45 | nargs = nargs - 1;
|
< 0.001 | 10 | 46 | elseif nargs > 0 && isa(args{1},'matlab.graphics.Graphics')
|
| | 47 | if ~isempty(args{1}) && all(isvalid(args{1}(:))) && all(arrayfun(isAxes,args{1}(:)))
|
| | 48 | % Mixed list of different types of axes.
|
| | 49 | throwAsCaller(MException(message('MATLAB:rulerFunctions:MixedAxesVector')));
|
| | 50 | else
|
| | 51 | % Empty vector or one of the objects is not an axes or has been deleted.
|
| | 52 | throwAsCaller(MException(message('MATLAB:rulerFunctions:InvalidObject')));
|
| | 53 | end
|
< 0.001 | 10 | 54 | elseif nargs == 2
|
| | 55 | % If we have two input arguments and the first input is not a valid
|
| | 56 | % graphics object, then the user specified an invalid syntax.
|
| | 57 | throwAsCaller(MException(message('MATLAB:rulerFunctions:InvalidAxes')));
|
< 0.001 | 10 | 58 | else
|
| | 59 | % No axes handle provided, so use the current Axes.
|
< 0.001 | 10 | 60 | ax = gca;
|
< 0.001 | 10 | 61 | end
|
| | 62 |
|
< 0.001 | 10 | 63 | fh = [];
|
< 0.001 | 10 | 64 | if isa(ax,'matlab.graphics.chart.Chart')
|
| | 65 | % Subclasses of matlab.graphics.chart.Chart will implement individual
|
| | 66 | % ruler functions if they are supported.
|
| | 67 |
|
| | 68 | % Error if the function does not exist as a method on the chart.
|
| | 69 | if(~isPublicMethod(ax,func))
|
| | 70 | throwAsCaller(MException(message('MATLAB:Chart:UnsupportedConvenienceFunction', func, ax(1).Type)));
|
| | 71 | end
|
| | 72 |
|
| | 73 | % Store a function handle for use later.
|
| | 74 | fh = str2func(func);
|
| | 75 | ruler = ax;
|
< 0.001 | 10 | 76 | elseif isa(ax,'matlab.graphics.axis.GeographicAxes')
|
| | 77 | throwAsCaller(MException(message('MATLAB:Chart:UnsupportedConvenienceFunction', func, ax(1).Type)));
|
< 0.001 | 10 | 78 | elseif isempty(ruler) && all(isprop(ax,prop))
|
| | 79 | % Limits are set on the Axes directly so that PreSet/PostSet events are
|
| | 80 | % triggered, and for compatibility with colorbars.
|
< 0.001 | 10 | 81 | ruler = ax;
|
| | 82 | elseif all(isprop(ax,ruler))
|
| | 83 | % All other properties are set on the Rulers directly.
|
| | 84 | ruler = vertcat(ax(:).(ruler));
|
| | 85 | elseif isa(ax, 'matlab.graphics.illustration.ColorBar')
|
| | 86 | % Colorbars support the xlim and ylim commands only for compatibility.
|
| | 87 | throwAsCaller(MException(message('MATLAB:rulerFunctions:ColorBar',func)));
|
| | 88 | else
|
| | 89 | % The axes specified is not compatible with this function (such as
|
| | 90 | % calling xlim on a PolarAxes).
|
| | 91 | throwAsCaller(axesTypeMismatch(axle, family));
|
< 0.001 | 10 | 92 | end
|
| | 93 |
|
| | 94 | % Filter out tickformat functions on CategoricalRuler
|
< 0.001 | 10 | 95 | if strcmp(family,'tickformat') && ...
|
| | 96 | any(isa(ruler,'matlab.graphics.axis.decorator.CategoricalRuler'))
|
| | 97 | throwAsCaller(MException(message('MATLAB:rulerFunctions:Categorical',func)));
|
< 0.001 | 10 | 98 | end
|
| | 99 |
|
| | 100 | % --- Get/Set the property based on the inputs ---
|
| | 101 |
|
| | 102 | % Initialize output variables.
|
< 0.001 | 10 | 103 | out = cell(0);
|
| | 104 |
|
< 0.001 | 10 | 105 | if nargs == 0
|
| | 106 | % If no additional inputs were provided, return the current value of
|
| | 107 | % the property.
|
| | 108 | if ~isempty(fh)
|
| | 109 | % Call the chart specific implementation.
|
| | 110 | try
|
| | 111 | out{1} = fh(ruler, args{:});
|
| | 112 | catch err
|
| | 113 | throwAsCaller(err);
|
| | 114 | end
|
| | 115 | elseif isscalar(ruler)
|
| | 116 | out{1} = ruler.(prop);
|
| | 117 | else
|
| | 118 | out{1} = {ruler(:).(prop)}';
|
| | 119 | end
|
| | 120 | return
|
< 0.001 | 10 | 121 | end
|
| | 122 |
|
| | 123 | % Grab the value from the remaining input arguments.
|
< 0.001 | 10 | 124 | val = args{1};
|
| | 125 |
|
| | 126 | % If the property has a mode setting, check if the user is trying to
|
| | 127 | % change or query the mode.
|
0.001 | 10 | 128 | if ~isempty(mode) && matlab.graphics.internal.isCharOrString(val)
|
| | 129 | switch lower(val)
|
| | 130 | case 'mode'
|
| | 131 | % The user requested the current property mode
|
| | 132 | if ~isempty(fh)
|
| | 133 | % Call the chart specific implementation.
|
| | 134 | try
|
| | 135 | out{1} = fh(ruler, 'mode');
|
| | 136 | catch err
|
| | 137 | throwAsCaller(err);
|
| | 138 | end
|
| | 139 | elseif isscalar(ruler)
|
| | 140 | out{1} = ruler.(mode);
|
| | 141 | else
|
| | 142 | out{1} = {ruler(:).(mode)}';
|
| | 143 | end
|
| | 144 | return
|
| | 145 | case {'auto','manual'}
|
| | 146 | % The user is trying to set the property mode
|
| | 147 |
|
| | 148 | if isempty(fh)
|
| | 149 | % No output arguments are returned when you set the
|
| | 150 | % property mode.
|
| | 151 | if numargsout > 0
|
| | 152 | throwAsCaller(MException(message('MATLAB:nargoutchk:tooManyOutputs')));
|
| | 153 | end
|
| | 154 |
|
| | 155 | % Set the mode
|
| | 156 | set(ruler,mode,val);
|
| | 157 |
|
| | 158 | % This command notifies the Live Editor of potential changes to the figure.
|
| | 159 | matlab.graphics.internal.markFigure(ax);
|
| | 160 | return
|
| | 161 | end
|
| | 162 | case {'tickaligned','tight','padded'}
|
| | 163 | if isprop(ax,[axle 'LimitMethod'])
|
| | 164 | set(ax,[axle 'LimitMethod'],val);
|
| | 165 | set(ruler,mode,'auto');
|
| | 166 | return
|
| | 167 | end
|
| | 168 | end
|
< 0.001 | 10 | 169 | end
|
| | 170 |
|
| | 171 | % Call the chart specific implementation of the ruler function. Use the
|
| | 172 | % same number of outputs to defer error handling to the method.
|
< 0.001 | 10 | 173 | if ~isempty(fh)
|
| | 174 | out = cell(1,numargsout);
|
| | 175 | try
|
| | 176 | if numargsout == 0
|
| | 177 | fh(ax,val);
|
| | 178 | else
|
| | 179 | [out{1:nargout}] = fh(ax,val);
|
| | 180 | end
|
| | 181 | catch err
|
| | 182 | throwAsCaller(err);
|
| | 183 | end
|
| | 184 | return
|
< 0.001 | 10 | 185 | end
|
| | 186 |
|
| | 187 | % No output arguments are returned when you set the property.
|
< 0.001 | 10 | 188 | if numargsout > 0
|
| | 189 | throwAsCaller(MException(message('MATLAB:nargoutchk:tooManyOutputs')));
|
< 0.001 | 10 | 190 | end
|
| | 191 |
|
| | 192 | % Try to set the property to the specified value.
|
< 0.001 | 10 | 193 | try
|
< 0.001 | 10 | 194 | switch family
|
< 0.001 | 10 | 195 | case {'lim','ticks','tickangle'}
|
0.002 | 10 | 196 | set(ruler,prop,val);
|
| | 197 | case 'ticklabels'
|
| | 198 | matlab.graphics.internal.ruler.setTickLabel(ruler, val);
|
| | 199 | case 'tickformat'
|
| | 200 | matlab.graphics.internal.ruler.setTickFormat(ruler, val);
|
< 0.001 | 10 | 201 | end
|
| | 202 | catch err
|
| | 203 | % Check for recognized errors and replace them with custom error
|
| | 204 | % messages specific to the convenience function.
|
| | 205 | err = swapKnownErrorIDs(err, axle, val);
|
| | 206 |
|
| | 207 | % Exclude LimitMethod options in error message from polar axes and
|
| | 208 | % colorbar rulers. Note that the R/Theta options can be removed when
|
| | 209 | % LimitMethods are documented for polaraxes.
|
| | 210 | if strcmp(err.identifier,'MATLAB:rulerFunctions:InvalidLimitsMode') && ...
|
| | 211 | (strcmp(axle,'R') || strcmp(axle,'Theta') || ~isprop(ruler,[axle 'LimitMethod']))
|
| | 212 | msg=message('MATLAB:rulerFunctions:InvalidLimitsModeOnly').getString;
|
| | 213 | err=MException('MATLAB:rulerFunctions:InvalidLimitsMode', ...
|
| | 214 | msg);
|
| | 215 | end
|
| | 216 |
|
| | 217 | throwAsCaller(err);
|
< 0.001 | 10 | 218 | end
|
| | 219 |
|
| | 220 | % This command notifies the Live Editor of potential changes to the figure.
|
0.006 | 10 | 221 | matlab.graphics.internal.markFigure(ax);
|
| | 222 |
|
< 0.001 | 10 | 223 | end
|
Other subfunctions in this file are not included in this listing.