Mercurial > hg > octave-avbm
changeset 12607:2846ea58b288 stable
colstyle.m: Add new function (bug #33063)
* NEWS: Update list of new functions in 3.4 release
* plot.txi: Add documentation entry in manual
* plot/module.mk: Add function to build list
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 14 Apr 2011 18:52:54 -0700 |
parents | 307e177dbaa8 |
children | 16cca721117b |
files | ChangeLog NEWS doc/ChangeLog doc/interpreter/plot.txi scripts/ChangeLog scripts/plot/colstyle.m scripts/plot/module.mk |
diffstat | 7 files changed, 117 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-14 Rik <octave@nomad.inbox5.com> + + * NEWS: Add colstyle to list of new functions for 3.4 + 2011-04-04 Rik <octave@nomad.inbox5.com> * NEWS: Add perror, strerror to list of functions deprecated in 3.4
--- a/NEWS +++ b/NEWS @@ -350,16 +350,15 @@ exponent where the exponent is a multiple of 3. ** The following functions are new in Octave 3.4: - - accumdim erfcx nfields pqpnonneg uigetdir - bitpack fileread nth_element quadcc uigetfile - bitunpack fminbnd onCleanup randi uiputfile - blkmm fskipl pbaspect repelems uimenu - cbrt ifelse pie3 reset whitebg - curl ishermitian powerset rsf2csf - chop isindex ppder saveas - daspect luupdate ppint strread - divergence merge ppjumps textread + accumdim divergence merge ppjumps textread + bitpack erfcx nfields pqpnonneg uigetdir + bitunpack fileread nth_element quadcc uigetfile + blkmm fminbnd onCleanup randi uiputfile + cbrt fskipl pbaspect repelems uimenu + curl ifelse pie3 reset whitebg + chop ishermitian powerset rsf2csf + colstyle isindex ppder saveas + daspect luupdate ppint strread ** Using the image function to view images with external programs such as display, xv, and xloadimage is no longer supported. The
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2011-04-14 Rik <octave@nomad.inbox5.com> + + * interpreter/plot.txi: Add colstyle function to documentation. + 2011-04-12 Rik <octave@nomad.inbox5.com> * interpreter/expr.txi: Correct use of it's -> its in documentation.
--- a/doc/interpreter/plot.txi +++ b/doc/interpreter/plot.txi @@ -2549,6 +2549,11 @@ of 2 is twice as large as the default, etc. @end table +The @code{colstyle} function will parse a @code{plot}-style specification +and will return the color, line, and marker values that would result. + +@DOCSTRING(colstyle) + @node Callbacks @subsection Callbacks @cindex callbacks
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2011-04-13 David Bateman <dbateman@free.fr> + + * plot/colstyle.m : New function. + * plot/module.mk plot_FCN_FILES) : Add it here. + 2011-04-12 Ben Abbott <bpabbott@mac.com> * miscellaneous/getappdata.m: If no property name is provided, return
new file mode 100644 --- /dev/null +++ b/scripts/plot/colstyle.m @@ -0,0 +1,89 @@ +## Copyright (C) 2011 David Bateman +## +## This file is part of Octave. +## +## Octave 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. +## +## Octave 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 Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{style}, @var{color}, @var{marker}, @var{msg}] =} colstyle (@var{linespec}) +## Parse @var{linespec} and return the line style, color, and markers given. +## In the case of an error, the string @var{msg} will return the text of the +## error. +## @end deftypefn + +function [l, c, m, msg] = colstyle (style) + + if (nargin != 1) + print_usage (); + endif + + if (! ischar (style)) + error ("colstyle: STYLE must be a string"); + endif + + try + opt = __pltopt__ ("colstyle", style); + l = opt.linestyle; + c = opt.color; + m = opt.marker; + msg = []; + switch (c) + case [0 0 0] + c = "k"; + case [1 0 0] + c = "r"; + case [0 1 0] + c = "g"; + case [0 0 1] + c = "b"; + case [1 1 0] + c = "y"; + case [1 0 1] + c = "m"; + case [0 1 1] + c = "c"; + case [0 1 1] + c = "w"; + endswitch + catch + l = c = m = []; + msg = lasterr (); + end_try_catch + +endfunction + +%!test +%! [l, c, m, msg] = colstyle ("r:x"); +%! assert (isempty (msg)); +%! assert (l, ":"); +%! assert (c, "r"); +%! assert (m, "x"); + +%!test +%! [l, c, m, msg] = colstyle ("."); +%! assert (isempty (msg)); +%! assert (l, "none"); +%! assert (c, []); +%! assert (m, "."); + +%!test +%! [l, c, m, msg] = colstyle ("~"); +%! assert (msg, "colstyle: unrecognized format character: `~'"); + +%% Test input validation +%!error colstyle () +%!error colstyle (1, 2) +%!error colstyle (1.5) +