# HG changeset patch # User Rik # Date 1302832374 25200 # Node ID 2846ea58b2885f1d5610a044d83c94a0601b9894 # Parent 307e177dbaa85ffd7c9402d1f66c59708a1b85a1 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 diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-14 Rik + + * NEWS: Add colstyle to list of new functions for 3.4 + 2011-04-04 Rik * NEWS: Add perror, strerror to list of functions deprecated in 3.4 diff --git a/NEWS b/NEWS --- 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 diff --git a/doc/ChangeLog b/doc/ChangeLog --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2011-04-14 Rik + + * interpreter/plot.txi: Add colstyle function to documentation. + 2011-04-12 Rik * interpreter/expr.txi: Correct use of it's -> its in documentation. diff --git a/doc/interpreter/plot.txi b/doc/interpreter/plot.txi --- 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 diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2011-04-13 David Bateman + + * plot/colstyle.m : New function. + * plot/module.mk plot_FCN_FILES) : Add it here. + 2011-04-12 Ben Abbott * miscellaneous/getappdata.m: If no property name is provided, return diff --git a/scripts/plot/colstyle.m b/scripts/plot/colstyle.m 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 +## . + +## -*- 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) + diff --git a/scripts/plot/module.mk b/scripts/plot/module.mk --- a/scripts/plot/module.mk +++ b/scripts/plot/module.mk @@ -67,6 +67,7 @@ plot/close.m \ plot/closereq.m \ plot/colorbar.m \ + plot/colstyle.m \ plot/comet.m \ plot/comet3.m \ plot/compass.m \