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	Wed Apr 13 21:09:03 2011 -0700
+++ b/ChangeLog	Thu Apr 14 18:52:54 2011 -0700
@@ -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	Wed Apr 13 21:09:03 2011 -0700
+++ b/NEWS	Thu Apr 14 18:52:54 2011 -0700
@@ -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	Wed Apr 13 21:09:03 2011 -0700
+++ b/doc/ChangeLog	Thu Apr 14 18:52:54 2011 -0700
@@ -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	Wed Apr 13 21:09:03 2011 -0700
+++ b/doc/interpreter/plot.txi	Thu Apr 14 18:52:54 2011 -0700
@@ -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	Wed Apr 13 21:09:03 2011 -0700
+++ b/scripts/ChangeLog	Thu Apr 14 18:52:54 2011 -0700
@@ -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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/colstyle.m	Thu Apr 14 18:52:54 2011 -0700
@@ -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)
+
--- a/scripts/plot/module.mk	Wed Apr 13 21:09:03 2011 -0700
+++ b/scripts/plot/module.mk	Thu Apr 14 18:52:54 2011 -0700
@@ -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 \