[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#391033: [Pkg-octave-devel] Bug#391033: octave2.9: bad behaviour with hold on/off



On  4-Oct-2006, Francesco Potorti` wrote:

| Package: octave2.9
| Version: 2.9.7-2
| Severity: normal
| 
| In Octave 2.1, these two commands give the same result: they first show
| a segment for one second, then they show two segments:
| 
| plot([1,2],[3,4]);sleep(1);clearplot;hold on;plot([0,1],[3,4]);plot([3,2],[3,4]);hold off
| plot([1,2],[3,4]);sleep(1);hold on;clearplot;plot([0,1],[3,4]);plot([3,2],[3,4]);hold off
| 
| In Octave 2.9, they do different things, both wrong:
| 
| - the first command line shows one segment, then three segments
| - the second command line shows one segment, then another single segment
|   and, in quick succession, yet another single segment

I think the behavior for the second example above is correct.  The
clearplot function is now the same as clf, which in Matlab also has
the effect of turning the hold state off.

To fix the first example, please try the following patch and let me
know if you notice any unexpected side effects from it.

Thanks,

jwe

scripts/ChangeLog:

2006-10-04  John W. Eaton  <jwe@octave.org>

	* plot/__clear_plot__.m: New function.
	* plot/__setup_plot__.m: Use __clear_plot__.


src/ChangeLog:

2006-10-04  John W. Eaton  <jwe@octave.org>

	* DLD-FUNCTIONS/__gnuplot_raw__.l (Fclearplot):
	Also call __clear_plot__.


Index: scripts/plot/__clear_plot__.m
===================================================================
RCS file: scripts/plot/__clear_plot__.m
diff -N scripts/plot/__clear_plot__.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ scripts/plot/__clear_plot__.m	4 Oct 2006 14:36:46 -0000
@@ -0,0 +1,42 @@
+## Copyright (C) 2006 John W. Eaton
+##
+## 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 2, 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, write to the Free
+## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+## 02110-1301, USA.
+
+function __clear_plot__ (cmd, sep, clear_data)
+
+  __plot_globals__
+
+  if (nargin < 3)
+    clear_data = true;
+    if (nargin < 2)
+      sep = "";
+      if (nargin < 1)
+	cmd = "";
+      endif
+    endif
+  endif
+
+  __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = cmd;
+  __plot_command_sep__ = sep;
+
+  if (clear_data)
+    __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = [];
+    __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = 1;
+  endif
+
+endfunction
Index: scripts/plot/__setup_plot__.m
===================================================================
RCS file: /cvs/octave/scripts/plot/__setup_plot__.m,v
retrieving revision 1.2
diff -u -u -r1.2 __setup_plot__.m
--- scripts/plot/__setup_plot__.m	26 Sep 2006 21:16:52 -0000	1.2
+++ scripts/plot/__setup_plot__.m	4 Oct 2006 14:36:46 -0000
@@ -22,16 +22,20 @@
   __plot_globals__
 
   if (ishold ())
-    if (isempty (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}))
-      __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = plotcmd;
-      __plot_command_sep__ = "";
+    cmd = __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__};
+    if (isempty (cmd))
+      cmd = plotcmd;
+      sep = "";
     else
-      __plot_command_sep__ = ",\\\n";
+      sep = ",\\\n";
     endif
+    clear_data = false;
   else
-    __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = plotcmd;
-    __plot_command_sep__ = "";
-    __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = [];
-    __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = 1;
+    cmd = plotcmd;
+    sep = "";
+    clear_data = true;
   endif
+
+  __clear_plot__ (cmd, sep, clear_data);
+
 endfunction
Index: src/DLD-FUNCTIONS/__gnuplot_raw__.l
===================================================================
RCS file: /cvs/octave/src/DLD-FUNCTIONS/__gnuplot_raw__.l,v
retrieving revision 1.12
diff -u -u -r1.12 __gnuplot_raw__.l
--- src/DLD-FUNCTIONS/__gnuplot_raw__.l	23 Aug 2006 19:54:47 -0000	1.12
+++ src/DLD-FUNCTIONS/__gnuplot_raw__.l	4 Oct 2006 14:36:50 -0000
@@ -1601,9 +1601,11 @@
   octave_value_list args;
 
   args(0) = "off";
-
   feval ("hold", args);
 
+  args.resize (0);
+  feval ("__clear_plot__", args);
+
   return octave_value_list ();
 }
 




Reply to: