annotate scripts/plot/__go_draw_figure__.m @ 10995:e81914f3921f

Update legend code to support fltk (fixes #29348 and partially fixes #30461)
author David Bateman <dbateman@free.fr>
date Sat, 18 Sep 2010 22:30:41 +0200
parents dd6b90f44ae5
children f0e9befd6a1c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8889
diff changeset
1 ## Copyright (C) 2005, 2007, 2008, 2009 John W. Eaton
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
2 ##
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
4 ##
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
8 ## your option) any later version.
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
9 ##
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
14 ##
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
18
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8249
diff changeset
19 ## -*- texinfo -*-
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8249
diff changeset
20 ## @deftypefn {Function File} {} __go_draw_figure__ (@var{h}, @var{plot_stream}, @var{enhanced}, @var{mono})
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6619
diff changeset
21 ## Undocumented internal function.
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8249
diff changeset
22 ## @end deftypefn
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
23
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
24 ## Author: jwe
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
25
10913
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10725
diff changeset
26 function __go_draw_figure__ (h, plot_stream, enhanced, mono)
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
27
10913
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10725
diff changeset
28 if (nargin == 4)
8249
1f429086565c [mq]: hidden-children
John W. Eaton <jwe@octave.org>
parents: 8224
diff changeset
29 htype = get (h, "type");
1f429086565c [mq]: hidden-children
John W. Eaton <jwe@octave.org>
parents: 8224
diff changeset
30 if (strcmp (htype, "figure"))
9098
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
31 ## Get complete list of children.
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
32 kids = allchild (h);
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
33 nkids = length (kids);
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
34
9098
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
35 if (nkids > 0)
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
36 fputs (plot_stream, "\nreset;\n");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
37 fputs (plot_stream, "set autoscale keepfix;\n");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
38 fputs (plot_stream, "set origin 0, 0\n");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
39 fputs (plot_stream, "set size 1, 1\n");
10119
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
40 bg = get (h, "color");
10136
ee18258bc002 Also treat white figure and axes color properties
David Bateman <dbateman@free.fr>
parents: 10120
diff changeset
41 if (isnumeric (bg))
10119
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
42 fprintf (plot_stream, "set obj 1 rectangle from screen 0,0 to screen 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * bg);
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
43 bg_is_set = true;
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
44 else
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
45 bg_is_set = false;
1e38d9ed1e28 Respect figure and axes color properties for gnuplot backend
David Bateman <dbateman@free.fr>
parents: 9944
diff changeset
46 endif
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
47 for i = nkids:-1:1
10568
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
48 type = get (kids(i), "type");
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
49 switch (type)
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
50 case "axes"
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
51 if (strcmpi (get (kids (i), "tag"), "legend"))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
52 continue;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
53 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
54
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
55 ## Rely upon listener to convert axes position
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
56 ## to "normalized" units.
10568
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
57 orig_axes_units = get (kids(i), "units");
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
58 orig_axes_position = get (kids(i), "position");
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
59 unwind_protect
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
60 set (kids(i), "units", "normalized");
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
61 fg = get (kids(i), "color");
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
62 if (isnumeric (fg) && strcmp (get (kids(i), "visible"), "on"))
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
63 fprintf (plot_stream, "set obj 2 rectangle from graph 0,0 to graph 1,1 behind fc rgb \"#%02x%02x%02x\"\n", 255 * fg);
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
64 fg_is_set = true;
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
65 else
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
66 fg_is_set = false;
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
67 endif
10725
3c59ce262c66 Add the whitebg function
David Bateman <dbateman@free.fr>
parents: 10568
diff changeset
68 if (bg_is_set)
3c59ce262c66 Add the whitebg function
David Bateman <dbateman@free.fr>
parents: 10568
diff changeset
69 fprintf (plot_stream, "set border linecolor rgb \"#%02x%02x%02x\"\n", 255 * (1 - bg));
3c59ce262c66 Add the whitebg function
David Bateman <dbateman@free.fr>
parents: 10568
diff changeset
70 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
71 ## Find if this axes has an associated legend axes and pass it
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
72 ## to __go_draw_axes__
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
73 hlegend = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
74 fkids = get (h, "children");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
75 for j = 1 : numel(fkids)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
76 if (ishandle (fkids (j))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
77 && strcmp (get (fkids (j), "type"), "axes")
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
78 && (strcmp (get (fkids (j), "tag"), "legend")))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
79 udata = get (fkids (j), "userdata");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
80 if (! isempty (intersect (udata.handle, kids (i))))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
81 hlegend = fkids (j);
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
82 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
83 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
84 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
85 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
86 __go_draw_axes__ (kids(i), plot_stream, enhanced, mono,
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
87 bg_is_set, hlegend);
10913
dd6b90f44ae5 Unify gnuplot printing with the fltk backend.
Ben Abbott <bpabbott@mac.com>
parents: 10725
diff changeset
88 unwind_protect_cleanup
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
89 ## Return axes "units" and "position" back to
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10913
diff changeset
90 ## their original values.
10568
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
91 set (kids(i), "units", orig_axes_units);
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
92 set (kids(i), "position", orig_axes_position);
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
93 bg_is_set = false;
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
94 if (fg_is_set)
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
95 fputs (plot_stream, "unset obj 2\n");
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
96 endif
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
97 end_unwind_protect
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
98 otherwise
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
99 error ("__go_draw_figure__: unknown object class, %s", type);
046b713d21dc __go_draw_figure__.m: Hidden axes may have visible children.
Ben Abbott <bpabbott@mac.com>
parents: 10528
diff changeset
100 endswitch
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
101 endfor
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
102 fputs (plot_stream, "\nunset multiplot;\n");
9098
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
103 else
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
104 fputs (plot_stream, "\nreset; clear;\n");
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
105 fflush (plot_stream);
9098
5ecdb3d3568f Allow fontsize to be specified for all objects with fontname == "*".
Ben Abbott <bpabbott@mac.com>
parents: 9062
diff changeset
106 endif
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
107 else
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
108 error ("__go_draw_figure__: expecting figure object, found `%s'",
10473
169be980faf9 __go_draw_figure__.m: Untabify.
Ben Abbott <bpabbott@mac.com>
parents: 10159
diff changeset
109 htype);
6405
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
110 endif
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
111 else
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
112 print_usage ();
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
113 endif
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
114
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
115 endfunction
b298a4c12fc3 [project @ 2007-03-14 16:51:28 by jwe]
jwe
parents:
diff changeset
116