Mercurial > hg > octave-nkf
changeset 6425:0cc5ca7b1e91
[project @ 2007-03-21 15:57:19 by jwe]
author | jwe |
---|---|
date | Wed, 21 Mar 2007 15:57:19 +0000 |
parents | 05a48d6cf163 |
children | 182c4b62775d |
files | scripts/ChangeLog scripts/plot/__go_draw_axes__.m scripts/plot/drawnow.m scripts/plot/subplot.m src/ChangeLog src/graphics.cc |
diffstat | 6 files changed, 177 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,7 +1,12 @@ +2007-03-20 David Bateman <dbateman@free.fr> + + * plot/__go_draw_axes__.m: Handle some colors with older gnuplot. + 2007-03-21 John W. Eaton <jwe@octave.org> * plot/subplot.m: If we find an existing subplot region, set it to be the "currentaxes" property for the current figure. + Delete old axes objects if the new axes object overlaps the old. 2007-03-20 David Bateman <dbateman@free.fr>
--- a/scripts/plot/__go_draw_axes__.m +++ b/scripts/plot/__go_draw_axes__.m @@ -355,10 +355,15 @@ else titlespec{data_idx} = strcat ("title \"", obj.keylabel, "\""); endif - style = do_linestyle_command (obj, data_idx, plot_stream); + [style, typ] = do_linestyle_command (obj, data_idx, plot_stream); usingclause{data_idx} = ""; - withclause{data_idx} = sprintf ("with %s linestyle %d", - style, data_idx); + if (have_newer_gnuplot || isnan (typ)) + withclause{data_idx} = sprintf ("with %s linestyle %d", + style, data_idx); + else + withclause{data_idx} = sprintf ("with %s linetype %d", + style, typ); + endif parametric(i) = true; if (! isempty (obj.zdata)) nd = 3; @@ -479,7 +484,7 @@ case "surface" data_idx++; - style = do_linestyle_command (obj, data_idx, plot_stream); + [style, typ] = do_linestyle_command (obj, data_idx, plot_stream); filespec{data_idx} = '-'; if (isempty (obj.keylabel)) titlespec{data_idx} = "title \"\""; @@ -487,8 +492,13 @@ titlespec{data_idx} = strcat ("title \"", obj.keylabel, "\""); endif usingclause{data_idx} = ""; - withclause{data_idx} = sprintf ("with %s linestyle %d", - style, data_idx); + if (have_newer_gnuplot || isnan (typ)) + withclause{data_idx} = sprintf ("with %s linestyle %d", + style, data_idx); + else + withclause{data_idx} = sprintf ("with %s linetype %d", + style, typ); + endif parametric(i) = false; nd = 3; xdat = obj.xdata; @@ -764,7 +774,7 @@ endfunction -function style = do_linestyle_command (obj, idx, plot_stream) +function [style, typ] = do_linestyle_command (obj, idx, plot_stream) persistent have_newer_gnuplot ... = compare_versions (__gnuplot_version__ (), "4.0", ">"); @@ -775,12 +785,35 @@ fprintf (plot_stream, "set style line %d", idx); found_style = false; + typ = NaN; - if (isfield (obj, "color") && have_newer_gnuplot) + if (isfield (obj, "color")) color = obj.color; if (isnumeric (color)) - fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", - round (255*color)); + if (have_newer_gnuplot) + fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", + round (255*color)); + else + if (isequal (color, [0,0,0])) + typ = -1; + elseif (isequal (color, [1,0,0])) + typ = 1; + elseif (isequal (color, [0,1,0])) + typ = 2; + elseif (isequal (color, [0,0,1])) + typ = 3; + elseif (isequal (color, [1,0,1])) + typ = 4; + elseif (isequal (color, [0,1,1])) + typ = 5; + elseif (isequal (color, [1,1,1])) + typ = 6; + elseif (isequal (color, [1,1,0])) + typ = 7; + else + typ = 2; + endif + endif endif found_style = true; endif
--- a/scripts/plot/drawnow.m +++ b/scripts/plot/drawnow.m @@ -26,60 +26,82 @@ function drawnow (term, file) + if (nargin == 2) + h = get (0, "currentfigure"); + if (h) + f = get (h); + plot_stream = []; + unwind_protect + plot_stream = open_gnuplot_stream ([], term, file); + __go_draw_figure__ (f, plot_stream); + unwind_protect_cleanup + if (! isempty (plot_stream)) + pclose (plot_stream); + endif + end_unwind_protect + else + error ("drawnow: nothing to draw"); + endif + elseif (nargin == 0) + for h = __go_figure_handles__ () + if (! (isnan (h) || h == 0)) + f = get (h); + plot_stream = f.__plot_stream__; + figure_is_visible = strcmp (f.visible, "on"); + if (figure_is_visible) + if (isempty (plot_stream)) + plot_stream = open_gnuplot_stream (h); + endif + __go_draw_figure__ (f, plot_stream); + elseif (! isempty (plot_stream)) + pclose (plot_stream); + set (h, "__plot_stream__", []); + endif + __request_drawnow__ (false); + endif + endfor + else + print_usage (); + endif + + __request_drawnow__ (false); + +endfunction + +function plot_stream = open_gnuplot_stream (h, term, file) + ## If drawnow is cleared, it is possible to register __go_close_all__ ## more than once, but that is not fatal. persistent __go_close_all_registered__; - ## Use this instead of calling gcf to avoid creating a figure. - - h = get (0, "currentfigure"); + cmd = gnuplot_binary (); - if (h) - - f = get (h); - - plot_stream = f.__plot_stream__; + if (! isempty (h) && gnuplot_use_title_option ()) + cmd = sprintf ("%s -title \"Figure %d\"", cmd, h); + endif - if (isempty (plot_stream)) - cmd = gnuplot_binary (); - if (gnuplot_use_title_option ()) - cmd = sprintf ("%s -title \"Figure %d\"", cmd, h); - endif - plot_stream = popen (cmd, "w"); - if (plot_stream < 0) - error ("drawnow: failed to open connection to gnuplot"); - else - set (h, "__plot_stream__", plot_stream); - if (isunix () && isempty (getenv ("DISPLAY"))) - fprintf (plot_stream, "set terminal dumb\n;"); - endif - if (isempty (__go_close_all_registered__)) - atexit ("__go_close_all__"); - __go_close_all_registered__ = true; - endif - endif + plot_stream = popen (cmd, "w"); + + if (plot_stream < 0) + error ("drawnow: failed to open connection to gnuplot"); + else + + if (! isempty (h)) + set (h, "__plot_stream__", plot_stream); endif - if (nargin == 2) - fprintf (plot_stream, - "set terminal push; set terminal %s; set output '%s'\n", - term, file); - endif - - if (nargin == 2 || strcmp (f.visible, "on")) - __go_draw_figure__ (f, plot_stream); + if (nargin == 3) + fprintf (plot_stream, "set terminal %s\n;", term); + fprintf (plot_stream, "set output \"%s\"\n;", file); + elseif (isunix () && isempty (getenv ("DISPLAY"))) + fprintf (plot_stream, "set terminal dumb\n;"); endif - __request_drawnow__ (false); - - if (nargin == 2) - fputs (plot_stream, "set terminal pop; set output;\n"); + if (isempty (__go_close_all_registered__)) + atexit ("__go_close_all__"); + __go_close_all_registered__ = true; endif - else - - __request_drawnow__ (false); - endif endfunction
--- a/scripts/plot/subplot.m +++ b/scripts/plot/subplot.m @@ -117,10 +117,13 @@ yp = fix ((index-1)/columns); xp = index - yp*columns - 1; - xorigin = xp * xsize; - yorigin = (rows - yp - 1) * ysize; + x0 = xp * xsize; + y0 = (rows - yp - 1) * ysize; - pos = [xorigin, yorigin, xsize, ysize]; + pos = [x0, y0, xsize, ysize]; + + x1 = x0 + xsize; + y1 = y0 + ysize; cf = gcf (); @@ -132,10 +135,23 @@ for child = obj.children obj = get (child); if (strcmp (obj.type, "axes")) - if (obj.outerposition == pos) + objpos = obj.outerposition; + if (objpos == pos) + ## If the new axes are in exactly the same position as an + ## existing axes object, use the existing axes. found = true; tmp = child; break; + else + ## If the new axes overlap an old axes object, delete the old + ## axes. + objx0 = objpos(1); + objx1 = objx0 + objpos(3); + objy0 = objpos(2); + objy1 = objy0 + objpos(4); + if (! (x0 >= objx1 || x1 <= objx0 || y0 >= objy1 || y1 <= objy0)) + delete (child); + endif endif endif endfor
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -2,6 +2,11 @@ * graphics.cc (axes::axes_properties::set_defaults): Reverse sense of mode test for setting outerposition property. + (figure::figure_properties::set): If setting visible property, + make this figure the current figure. + (gh_manager::figure_handle_list, gh_manager::do_figure_handle_list): + New functions. + (F__go_figure_handles__): New function. * sysdep.cc (Fpause): Also call drawnow if nargin == 0. (Fkbhit, Fsleep, Fusleep): Also call drawnow here.
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -701,9 +701,14 @@ return instance_ok () ? instance->do_current_figure () : octave_NaN; } - static Matrix list (void) + static Matrix handle_list (void) { - return instance_ok () ? instance->do_list () : Matrix (); + return instance_ok () ? instance->do_handle_list () : Matrix (); + } + + static Matrix figure_handle_list (void) + { + return instance_ok () ? instance->do_figure_handle_list () : Matrix (); } private: @@ -800,7 +805,7 @@ graphics_handle do_make_figure_handle (double val); - Matrix do_list (void) + Matrix do_handle_list (void) { Matrix retval (1, handle_map.size ()); octave_idx_type i = 0; @@ -809,6 +814,17 @@ return retval; } + Matrix do_figure_handle_list (void) + { + Matrix retval (1, figure_list.size ()); + octave_idx_type i = 0; + for (const_figure_list_iterator p = figure_list.begin (); + p != figure_list.end (); + p++) + retval(i++) = *p; + return retval; + } + void do_push_figure (const graphics_handle& h); void do_pop_figure (const graphics_handle& h); @@ -1337,7 +1353,17 @@ else if (name.compare ("colormap")) colormap = colormap_property (val); else if (name.compare ("visible")) - visible = val; + { + std::string s = val.string_value (); + + if (! error_state) + { + if (s == "on") + xset (0, "currentfigure", __myhandle__); + + visible = val; + } + } else if (name.compare ("paperorientation")) paperorientation = val; else @@ -3415,7 +3441,16 @@ Return current list of function handles.\n\ @end deftypefn") { - return octave_value (gh_manager::list ()); + return octave_value (gh_manager::handle_list ()); +} + +DEFUN (__go_figure_handles__, , , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ +Return current list of function handles.\n\ +@end deftypefn") +{ + return octave_value (gh_manager::figure_handle_list ()); } /*