Mercurial > hg > octave-lyh
annotate scripts/plot/legend.m @ 11434:1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sun, 02 Jan 2011 21:11:24 -0500 |
parents | a140991387fb |
children | aed2c50c3082 |
rev | line source |
---|---|
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
1 ## Copyright (C) 2010 David Bateman |
6146 | 2 ## |
6440 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6440 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
6146 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6146 | 18 |
19 ## -*- texinfo -*- | |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
20 ## @deftypefn {Function File} {} legend (@var{str1}, @var{str2}, @dots{}) |
6146 | 21 ## @deftypefnx {Function File} {} legend (@var{matstr}) |
22 ## @deftypefnx {Function File} {} legend (@var{cell}) | |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
23 ## @deftypefnx {Function File} {} legend (@dots{}, "location", @var{pos}) |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
24 ## @deftypefnx {Function File} {} legend (@dots{}, "orientation", @var{orient}) |
10662
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
25 ## @deftypefnx {Function File} {} legend (@var{hax}, @dots{}) |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
26 ## @deftypefnx {Function File} {} legend (@var{hobjs}, @dots{}) |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
27 ## @deftypefnx {Function File} {} legend (@var{hax}, @var{hobjs}, @dots{}) |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
28 ## @deftypefnx {Function File} {} legend ("@var{option}") |
6146 | 29 ## |
10662
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
30 ## Display a legend for the axes with handle @var{hax}, or the current axes, |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
31 ## using the specified strings as labels. Legend entries may be specified |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
32 ## as individual character string arguments, a character array, or a cell |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
33 ## array of character strings. If the handles, @var{hobjs}, are not specified |
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
34 ## then the legend's strings will be associated with the axes' descendants. |
10662
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
35 ## Legend works on line graphs, bar graphs, etc. |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
36 ## A plot must exist before legend is called. |
6146 | 37 ## |
6895 | 38 ## The optional parameter @var{pos} specifies the location of the legend |
39 ## as follows: | |
6146 | 40 ## |
6977 | 41 ## @multitable @columnfractions 0.06 0.14 0.80 |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
42 ## |
6977 | 43 ## @item @tab north @tab |
44 ## center top | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
45 ## |
6977 | 46 ## @item @tab south @tab |
47 ## center bottom | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
48 ## |
6977 | 49 ## @item @tab east @tab |
50 ## right center | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
51 ## |
6977 | 52 ## @item @tab west @tab |
53 ## left center | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
54 ## |
6977 | 55 ## @item @tab northeast @tab |
56 ## right top (default) | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
57 ## |
6977 | 58 ## @item @tab northwest @tab |
59 ## left top | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
60 ## |
6977 | 61 ## @item @tab southeast @tab |
62 ## right bottom | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
63 ## |
6977 | 64 ## @item @tab southwest @tab |
65 ## left bottom | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
66 ## |
6977 | 67 ## @item |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
68 ## |
6977 | 69 ## @item @tab outside @tab |
70 ## can be appended to any location string | |
6146 | 71 ## @end multitable |
72 ## | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
73 ## The optional parameter @var{orient} determines if the key elements |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
74 ## are placed vertically or horizontally. The allowed values are "vertical" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
75 ## or "horizontal" with the default being "vertical". |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
76 ## |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
77 ## The following customizations are available using @var{option}: |
6146 | 78 ## |
7148 | 79 ## @table @asis |
6895 | 80 ## @item "show" |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
81 ## Show legend on the plot |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
82 ## |
6895 | 83 ## @item "hide" |
7148 | 84 ## @itemx "off" |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
85 ## Hide legend on the plot |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
86 ## |
6895 | 87 ## @item "boxon" |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
88 ## Show a box around legend |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
89 ## |
6895 | 90 ## @item "boxoff" |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
91 ## Hide the box around legend |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
92 ## |
6895 | 93 ## @item "left" |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
94 ## Place text to the left of the keys |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
95 ## |
6895 | 96 ## @item "right" |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
97 ## Place text to the right of the keys |
6146 | 98 ## @end table |
99 ## @end deftypefn | |
100 | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
101 function [hlegend2, hobjects2, hplot2, text_strings2] = legend (varargin) |
6146 | 102 |
11246
c463aed850b0
allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents:
11200
diff
changeset
|
103 if (nargin > 0 |
c463aed850b0
allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents:
11200
diff
changeset
|
104 && (! ishandle (varargin{1}) |
c463aed850b0
allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents:
11200
diff
changeset
|
105 || (strcmp (get (varargin{1}, "type"), "axes") |
c463aed850b0
allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents:
11200
diff
changeset
|
106 && ! strcmp (get (varargin{1}, "tag"), "legend")))) |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
107 [ca, varargin, nargs] = __plt_get_axis_arg__ ("legend", varargin{:}); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
108 fig = get (ca, "parent"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
109 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
110 fig = get (0, "currentfigure"); |
11246
c463aed850b0
allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents:
11200
diff
changeset
|
111 if (isempty (fig)) |
c463aed850b0
allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents:
11200
diff
changeset
|
112 fig = gcf (); |
c463aed850b0
allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents:
11200
diff
changeset
|
113 endif |
c463aed850b0
allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents:
11200
diff
changeset
|
114 ca = gca (); |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
115 endif |
6146 | 116 |
11199
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
117 if (strcmp (get (ca, "tag"), "plotyy")) |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
118 plty = get(ca (strcmp (get (ca, "tag"), "plotyy")), "userdata"); |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
119 if (isscalar (plty)) |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
120 ca = [ca, plty]; |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
121 else |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
122 ca = [ca, plty{:}]; |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
123 endif |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
124 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
125 |
11246
c463aed850b0
allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents:
11200
diff
changeset
|
126 if (nargin > 0 && all (ishandle (varargin{1}))) |
10662
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
127 kids = flipud (varargin{1}(:)); |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
128 varargin(1) = []; |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
129 else |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
130 kids = ca; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
131 kids (strcmp (get (ca, "tag"), "legend")) = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
132 if (isscalar (kids)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
133 kids = get(kids, "children")(:); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
134 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
135 kids = [get(kids, "children"){:}](:); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
136 endif |
10662
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
137 endif |
11246
c463aed850b0
allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents:
11200
diff
changeset
|
138 nargs = numel (varargin); |
10662
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
139 nkids = numel (kids); |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
140 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
141 orientation = "default"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
142 position = "default"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
143 show = "create"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
144 textpos = "default"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
145 box = "default"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
146 |
6146 | 147 if (nargs > 0) |
148 pos = varargin{nargs}; | |
149 if (isnumeric (pos) && isscalar (pos) && round (pos) == pos) | |
6395 | 150 if (pos >= -1 && pos <= 4) |
11003
b1cfff739af5
legend.m: Index location cellstr to obtain a string.
Ben Abbott <bpabbott@mac.com>
parents:
10999
diff
changeset
|
151 position = [{"northeastoutside", "best", "northeast", |
b1cfff739af5
legend.m: Index location cellstr to obtain a string.
Ben Abbott <bpabbott@mac.com>
parents:
10999
diff
changeset
|
152 "northwest", "southwest", "southeast"}] {pos + 2}; |
10549 | 153 nargs--; |
6146 | 154 else |
10549 | 155 error ("legend: invalid position specified"); |
6146 | 156 endif |
157 endif | |
158 endif | |
6977 | 159 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
160 while (nargs > 1) |
6977 | 161 pos = varargin{nargs-1}; |
7054 | 162 str = varargin{nargs}; |
6977 | 163 if (strcmpi (pos, "location") && ischar (str)) |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
164 position = lower (str); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
165 nargs -= 2; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
166 elseif (strcmpi (pos, "orientation") && ischar (str)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
167 orientation = lower (str); |
10989
6ea65c5de87a
Respect the units and paperunits figure properties and the units and fontunits axes properties
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
168 nargs -= 2; |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
169 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
170 break; |
6977 | 171 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
172 endwhile |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
173 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
174 ## Validate the orientation |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
175 switch (orientation) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
176 case {"vertical", "horizontal","default"} |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
177 otherwise |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
178 error ("legend: unrecognized legend orientation"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
179 endswitch |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
180 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
181 ## Validate the position type is valid |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
182 outside = false; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
183 inout = findstr (position, "outside"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
184 if (! isempty (inout)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
185 outside = true; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
186 position = position(1:inout-1); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
187 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
188 outside = false; |
6977 | 189 endif |
6146 | 190 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
191 switch (position) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
192 case {"north", "south", "east", "west", "northeast", "northwest", ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
193 "southeast", "southwest", "default"} |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
194 case "best" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
195 warning ("legend: 'Best' not yet implemented for location specifier\n"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
196 position = "northeast"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
197 otherwise |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
198 error ("legend: unrecognized legend position"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
199 endswitch |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
200 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
201 hlegend = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
202 fkids = get (fig, "children"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
203 for i = 1 : numel(fkids) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
204 if (ishandle (fkids (i)) && strcmp (get (fkids (i), "type"), "axes") |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
205 && (strcmp (get (fkids (i), "tag"), "legend"))) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
206 udata = get (fkids (i), "userdata"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
207 if (! isempty (intersect (udata.handle, ca))) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
208 hlegend = fkids (i); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
209 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
210 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
211 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
212 endfor |
6257 | 213 |
6146 | 214 if (nargs == 1) |
215 arg = varargin{1}; | |
216 if (ischar (arg)) | |
217 if (rows (arg) == 1) | |
10549 | 218 str = tolower (deblank (arg)); |
219 switch (str) | |
220 case {"off", "hide"} | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
221 show = "off"; |
10549 | 222 nargs--; |
223 case "show" | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
224 show = "on"; |
10549 | 225 nargs--; |
226 case "toggle" | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
227 if (isempty (hlegend) || strcmp (get (hlegend, "visible"), "off")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
228 show = "on"; |
10549 | 229 else |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
230 show = "off"; |
10549 | 231 endif |
232 nargs--; | |
233 case "boxon" | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
234 box = "on"; |
10549 | 235 nargs--; |
236 case "boxoff" | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
237 box = "off"; |
10549 | 238 nargs--; |
239 case "left" | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
240 textpos = "left"; |
10549 | 241 nargs--; |
242 case "right" | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
243 textpos = "right"; |
10549 | 244 nargs--; |
245 otherwise | |
246 endswitch | |
6146 | 247 else |
10549 | 248 varargin = cellstr (arg); |
249 nargs = numel (varargin); | |
6146 | 250 endif |
251 elseif (iscellstr (arg)) | |
8529
774b44619c5c
Fix legend order for both horizontal and vertical string cell.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8343
diff
changeset
|
252 varargin = arg; |
6146 | 253 nargs = numel (varargin); |
254 else | |
255 error ("legend: expecting argument to be a character string"); | |
256 endif | |
257 endif | |
258 | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
259 if (strcmp (show, "off")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
260 if (! isempty (hlegend)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
261 set (get (hlegend, "children"), "visible", "off"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
262 hlegend = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
263 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
264 hobjects = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
265 hplots = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
266 text_strings = {}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
267 elseif (strcmp (show, "on")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
268 if (! isempty (hlegend)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
269 set (get (hlegend, "children"), "visible", "on"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
270 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
271 hobjects = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
272 hplots = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
273 text_strings = {}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
274 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
275 elseif (strcmp (box, "on")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
276 if (! isempty (hlegend)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
277 set (hlegend, "visible", "on", "box", "on"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
278 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
279 elseif (strcmp (box, "off")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
280 if (! isempty (hlegend)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
281 set (hlegend, "box", "off", "visible", "off"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
282 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
283 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
284 hobjects = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
285 hplots = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
286 text_strings = {}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
287 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
288 if (nargs > 0) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
289 have_data = false; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
290 for k = 1:nkids |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
291 typ = get (kids(k), "type"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
292 if (strcmp (typ, "line") || strcmp (typ, "surface") |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
293 || strcmp (typ, "patch") || strcmp (typ, "hggroup")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
294 have_data = true; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
295 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
296 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
297 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
298 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
299 if (! have_data) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
300 warning ("legend: plot data is empty; setting key labels has no effect"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
301 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
302 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
303 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
304 if (strcmp (textpos, "default")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
305 warned = false; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
306 k = nkids; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
307 for i = 1 : nargs |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
308 arg = varargin{i}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
309 if (ischar (arg)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
310 typ = get (kids(k), "type"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
311 while (k > 0 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
312 && ! (strcmp (typ, "line") || strcmp (typ, "surface") |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
313 || strcmp (typ, "patch") || strcmp (typ, "hggroup"))) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
314 typ = get (kids(--k), "type"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
315 endwhile |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
316 if (k > 0) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
317 if (strcmp (get (kids(k), "type"), "hggroup")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
318 hgkids = get (kids(k), "children"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
319 for j = 1 : length (hgkids) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
320 hgobj = get (hgkids (j)); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
321 if (isfield (hgobj, "displayname")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
322 set (hgkids(j), "displayname", arg); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
323 hplots = [hplots, hgkids(j)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
324 text_strings = {text_strings{:}, arg}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
325 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
326 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
327 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
328 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
329 set (kids(k), "displayname", arg); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
330 hplots = [hplots, kids(k)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
331 text_strings = {text_strings{:}, arg}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
332 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
333 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
334 if (--k == 0) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
335 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
336 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
337 elseif (! warned) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
338 warned = true; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
339 warning ("legend: ignoring extra labels"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
340 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
341 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
342 error ("legend: expecting argument to be a character string"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
343 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
344 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
345 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
346 k = nkids; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
347 while (k > 0) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
348 typ = get (kids(k), "type"); |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
349 while (k > 1 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
350 && ! (strcmp (typ, "line") || strcmp (typ, "surface") |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
351 || strcmp (typ, "patch") || strcmp (typ, "hggroup"))) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
352 typ = get (kids(--k), "type"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
353 endwhile |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
354 if (! (strcmp (typ, "line") || strcmp (typ, "surface") |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
355 || strcmp (typ, "patch") || strcmp (typ, "hggroup"))) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
356 break |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
357 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
358 if (k > 0) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
359 if (strcmp (get (kids(k), "type"), "hggroup")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
360 hgkids = get (kids(k), "children"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
361 for j = 1 : length (hgkids) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
362 hgobj = get (hgkids (j)); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
363 if (isfield (hgobj, "displayname") |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
364 && ! isempty (hgobj.displayname)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
365 hplots = [hplots, hgkids(j)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
366 text_strings = {text_strings{:}, hbobj.displayname}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
367 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
368 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
369 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
370 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
371 if (! isempty (get (kids (k), "displayname"))) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
372 hplots = [hplots, kids(k)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
373 text_strings = {text_strings{:}, get(kids (k), "displayname")}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
374 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
375 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
376 if (--k == 0) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
377 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
378 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
379 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
380 endwhile |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
381 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
382 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
383 if (isempty (hplots)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
384 if (! isempty (hlegend)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
385 fkids = get (fig, "children"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
386 delete (fkids (fkids == hlegend)); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
387 hlegend = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
388 hobjects = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
389 hplots = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
390 text_strings = {}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
391 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
392 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
393 ## Delete the old legend if it exists |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
394 if (! isempty (hlegend)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
395 if (strcmp (textpos, "default")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
396 textpos = get (hlegend, "textposition"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
397 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
398 if (strcmp (position, "default")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
399 position = get (hlegend, "location"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
400 inout = findstr (position, "outside"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
401 if (! isempty (inout)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
402 outside = true; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
403 position = position(1:inout-1); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
404 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
405 outside = false; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
406 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
407 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
408 if (strcmp (orientation, "default")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
409 orientation = get (hlegend, "orientation"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
410 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
411 box = get (hlegend, "box"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
412 fkids = get (fig, "children"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
413 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
414 if (strcmp (textpos, "default")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
415 textpos = "left"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
416 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
417 if (strcmp (position, "default")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
418 position = "northeast"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
419 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
420 if (strcmp (orientation, "default")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
421 orientation = "vertical"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
422 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
423 box = "off"; |
6272 | 424 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
425 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
426 ## Get axis size and fontsize in points. |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
427 ## Rely on listener to handle coversion. |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
428 units = get (ca(1), "units"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
429 fontunits = get (ca(1), "fontunits"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
430 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
431 set (ca(1), "units", "points"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
432 set (ca(1), "fontunits", "points"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
433 ca_pos = get (ca(1), "position"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
434 ca_outpos = get (ca(1), "outerposition"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
435 ca_fontsize = get (ca(1), "fontsize"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
436 unwind_protect_cleanup |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
437 set (ca(1), "units", units); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
438 set (ca(1), "fontunits", fontunits); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
439 end_unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
440 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
441 ## Padding between legend entries horizontally and vertically |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
442 xpad = 2; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
443 ypad = 2; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
444 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
445 ## Length of line segments in the legend in points |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
446 linelength = 15; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
447 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
448 ## Create the axis first |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
449 ## FIXME hlegend should inherit properties from "ca" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
450 curaxes = get (fig, "currentaxes"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
451 unwind_protect |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
452 ud = ancestor(hplots, "axes"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
453 if (!isscalar(ud)) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
454 ud = unique ([ud{:}]); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
455 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
456 if (isempty (hlegend)) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
457 addprops = true; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
458 hlegend = axes ("tag", "legend", "userdata", struct ("handle", ud), |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
459 "box", box, "outerposition", [0, 0, 0, 0], |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
460 "xtick", [], "ytick", [], "xticklabel", "", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
461 "yticklabel", "", "zticklabel", "", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
462 "xlim", [0, 1], "ylim", [0, 1], "visible", "off", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
463 "activepositionproperty", "position"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
464 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
465 addprops = false; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
466 axes (hlegend); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
467 delete (get (hlegend, "children")); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
468 endif |
11434
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
469 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
470 ## Add text label to the axis first, checking their extents |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
471 nentries = numel (hplots); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
472 texthandle = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
473 maxwidth = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
474 maxheight = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
475 for k = 1 : nentries |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
476 if (strcmp (textpos, "right")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
477 texthandle = [texthandle, text(0, 0, text_strings {k}, |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
478 "horizontalalignment", "left", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
479 "userdata", hplots(k))]; |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
480 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
481 texthandle = [texthandle, text(0, 0, text_strings {k}, |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
482 "horizontalalignment", "right", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
483 "userdata", hplots(k))]; |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
484 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
485 units = get (texthandle (end), "units"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
486 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
487 set (texthandle (end), "units", "points"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
488 extents = get (texthandle (end), "extent"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
489 maxwidth = max (maxwidth, extents (3)); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
490 maxheight = max (maxheight, extents (4)); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
491 unwind_protect_cleanup |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
492 set (texthandle (end), "units", units); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
493 end_unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
494 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
495 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
496 num1 = nentries; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
497 if (strcmp (orientation, "vertical")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
498 height = nentries * (ypad + maxheight); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
499 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
500 if (height > ca_pos (4)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
501 ## Avoid shrinking the height of the axis to zero if outside |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
502 num1 = ca_pos(4) / (maxheight + ypad) / 2; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
503 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
504 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
505 if (height > 0.9 * ca_pos (4)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
506 num1 = 0.9 * ca_pos(4) / (maxheight + ypad); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
507 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
508 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
509 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
510 width = nentries * (ypad + maxwidth); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
511 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
512 if (width > ca_pos (3)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
513 ## Avoid shrinking the width of the axis to zero if outside |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
514 num1 = ca_pos(3) / (maxwidth + ypad) / 2; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
515 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
516 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
517 if (width > 0.9 * ca_pos (3)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
518 num1 = 0.9 * ca_pos(3) / (maxwidth + ypad); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
519 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
520 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
521 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
522 num2 = ceil (nentries / num1); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
523 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
524 xstep = 3 * xpad + (maxwidth + linelength); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
525 if (strcmp (textpos, "right")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
526 xoffset = xpad; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
527 txoffset = 2 * xpad + linelength; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
528 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
529 xoffset = 2 * xpad + maxwidth; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
530 txoffset = xpad + maxwidth; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
531 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
532 ystep = (ypad + maxheight); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
533 yoffset = ystep / 2; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
534 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
535 ## Place the legend in the desired position |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
536 if (strcmp (orientation, "vertical")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
537 lpos = [0, 0, num2 * xstep, num1 * ystep]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
538 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
539 lpos = [0, 0, num1 * xstep, num2 * ystep]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
540 endif |
11120
a44f979a35ce
style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents:
11033
diff
changeset
|
541 switch (position) |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
542 case "north" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
543 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
544 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
545 ca_outpos(2) + ca_outpos(4) - lpos(4), lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
546 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
547 new_pos = [ca_pos(1), ca_pos(2), ca_pos(3), ca_pos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
548 new_outpos = [ca_outpos(1), ca_outpos(2), ca_outpos(3), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
549 ca_outpos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
550 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
551 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
552 ca_pos(2) + ca_pos(4) - lpos(4) - ypad, lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
553 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
554 case "south" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
555 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
556 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ca_outpos(2), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
557 lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
558 new_pos = [ca_pos(1), ca_pos(2) + lpos(4), ca_pos(3), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
559 ca_pos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
560 new_outpos = [ca_outpos(1), ca_outpos(2) + lpos(4), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
561 ca_outpos(3), ca_outpos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
562 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
563 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
564 ca_pos(2) + ypad, lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
565 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
566 case "east" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
567 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
568 lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
569 ca_pos(2) + (ca_pos(4) - lpos(4)) / 2, lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
570 new_pos = [ca_pos(1), ca_pos(2), ca_pos(3) - lpos(3), ca_pos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
571 new_outpos = [ca_outpos(1), ca_outpos(2), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
572 ca_outpos(3) - lpos(3), ca_outpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
573 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
574 lpos = [ca_pos(1) + ca_pos(3) - lpos(3) - ypad, ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
575 ca_pos(2) + (ca_pos(4) - lpos(4)) / 2, lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
576 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
577 case "west" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
578 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
579 lpos = [ca_outpos(1), ca_pos(2) + (ca_pos(4) - lpos(4)) / 2, ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
580 lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
581 new_pos = [ca_pos(1) + lpos(3), ca_pos(2), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
582 ca_pos(3) - lpos(3), ca_pos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
583 new_outpos = [ca_outpos(1) + lpos(3), ca_outpos(2), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
584 ca_outpos(3) - lpos(3), ca_outpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
585 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
586 lpos = [ca_pos(1) + ypad, ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
587 ca_pos(2) + (ca_pos(4) - lpos(4)) / 2, lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
588 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
589 case "northeast" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
590 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
591 lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
592 ca_outpos(2) + ca_outpos(4) - lpos(4), lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
593 new_pos = [ca_pos(1), ca_pos(2), ca_pos(3) - lpos(3), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
594 ca_pos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
595 new_outpos = [ca_outpos(1), ca_outpos(2), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
596 ca_outpos(3) - lpos(3), ca_outpos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
597 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
598 lpos = [ca_pos(1) + ca_pos(3) - lpos(3) - ypad, ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
599 ca_pos(2) + ca_pos(4) - lpos(4) - ypad, lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
600 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
601 case "northwest" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
602 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
603 lpos = [ca_outpos(1), ca_outpos(2) + ca_outpos(4) - lpos(4), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
604 lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
605 new_pos = [ca_pos(1) + lpos(3), ca_pos(2), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
606 ca_pos(3) - lpos(3), ca_pos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
607 new_outpos = [ca_outpos(1) + lpos(3), ca_outpos(2), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
608 ca_outpos(3) - lpos(3), ca_outpos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
609 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
610 lpos = [ca_pos(1) + ypad, ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
611 ca_pos(2) + ca_pos(4) - lpos(4) - ypad, lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
612 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
613 case "southeast" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
614 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
615 lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3), ca_outpos(2), |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
616 lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
617 new_pos = [ca_pos(1), ca_pos(2) + lpos(4), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
618 ca_pos(3) - lpos(3), ca_pos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
619 new_outpos = [ca_outpos(1), ca_outpos(2) + lpos(4), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
620 ca_outpos(3) - lpos(3), ca_outpos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
621 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
622 lpos = [ca_pos(1) + ca_pos(3) - lpos(3) - ypad, ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
623 ca_pos(2) + ypad, lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
624 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
625 case "southwest" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
626 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
627 lpos = [ca_outpos(1), ca_outpos(2), 0, lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
628 new_pos = [ca_pos(1) +lpos(3), ca_pos(2) + lpos(4), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
629 ca_pos(3) - lpos(3), ca_pos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
630 new_outpos = [ca_outpos(1) + lpos(3), ca_outpos(2) + lpos(4), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
631 ca_outpos(3) - lpos(3), ca_outpos(4) - lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
632 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
633 lpos = [ca_pos(1) + ypad, ca_pos(2) + ypad, lpos(3), lpos(4)]; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
634 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
635 endswitch |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
636 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
637 units = get (hlegend, "units"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
638 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
639 set (hlegend, "units", "points"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
640 set (hlegend, "position", lpos, "outerposition", lpos); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
641 unwind_protect_cleanup |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
642 set (hlegend, "units", units); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
643 end_unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
644 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
645 ## Now write the line segments and place the text objects correctly |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
646 xk = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
647 yk = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
648 for k = 1 : numel (hplots) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
649 hobjects = [hobjects, texthandle (k)]; |
11120
a44f979a35ce
style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents:
11033
diff
changeset
|
650 switch (get (hplots(k), "type")) |
10999
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
651 case "line" |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
652 color = get (hplots(k), "color"); |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
653 style = get (hplots(k), "linestyle"); |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
654 if (! strcmp (style, "none")) |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
655 l1 = line ("xdata", ([xoffset, xoffset + linelength] + xk * xstep) / lpos(3), |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
656 "ydata", [1, 1] .* (lpos(4) - yoffset - yk * ystep) / lpos(4), |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
657 "color", color, "linestyle", style, "marker", "none", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
658 "userdata", hplots (k)); |
10999
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
659 hobjects = [hobjects, l1]; |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
660 endif |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
661 marker = get (hplots(k), "marker"); |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
662 if (! strcmp (marker, "none")) |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
663 l1 = line ("xdata", (xoffset + 0.5 * linelength + xk * xstep) / lpos(3), |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
664 "ydata", (lpos(4) - yoffset - yk * ystep) / lpos(4), |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
665 "color", color, "linestyle", "none", "marker", marker, |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
11003
diff
changeset
|
666 "markeredgecolor", get (hplots (k), "markeredgecolor"), |
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
11003
diff
changeset
|
667 "markerfacecolor", get (hplots (k), "markerfacecolor"), |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
668 "markersize", get (hplots (k), "markersize"), |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
669 "userdata", hplots (k)); |
10999
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
670 hobjects = [hobjects, l1]; |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
671 endif |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
672 |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
673 addlistener(hplots(k), "color", {@updateline, hlegend, linelength}); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
674 addlistener(hplots(k), "linestyle", {@updateline, hlegend, linelength}); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
675 addlistener(hplots(k), "marker", {@updateline, hlegend, linelength}); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
676 addlistener(hplots(k), "markeredgecolor", {@updateline, hlegend, linelength}); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
677 addlistener(hplots(k), "markerfacecolor", {@updateline, hlegend, linelength}); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
678 addlistener(hplots(k), "markersize", {@updateline, hlegend, linelength}); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
679 addlistener(hplots(k), "displayname", {@updateline, hlegend, linelength}); |
10999
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
680 case "patch" |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
681 case "surface" |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
682 endswitch |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
683 set (texthandle (k), "position", [(txoffset + xk * xstep) / lpos(3), ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
684 (lpos(4) - yoffset - yk * ystep) / lpos(4)]); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
685 if (strcmp (orientation, "vertical")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
686 yk++; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
687 if (yk > num1) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
688 yk = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
689 xk++; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
690 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
691 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
692 xk++; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
693 if (xk > num1) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
694 xk = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
695 yk++; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
696 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
697 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
698 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
699 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
700 ## Add an invisible text object to original axis |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
701 ## that when it is destroyed will remove the legend |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
702 t1 = text (0, 0, "", "parent", ca(1), "tag", "legend", |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
703 "handlevisibility", "off", "visible", "off", |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
704 "xliminclude", "off", "yliminclude", "off"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
705 set (t1, "deletefcn", {@deletelegend1, hlegend}); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
706 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
707 ## Resize the axis the legend is attached to if the |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
708 ## legend is "outside" the plot and create listener to |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
709 ## resize axis to original size if the legend is deleted, |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
710 ## hidden or shown |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
711 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
712 for i = 1 : numel (ca) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
713 units = get (ca(i), "units"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
714 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
715 set (ca(i), "units", "points"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
716 set (ca (i), "position", new_pos, "outerposition", new_outpos); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
717 unwind_protect_cleanup |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
718 set (ca(i), "units", units); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
719 end_unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
720 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
721 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
722 set (hlegend, "deletefcn", {@deletelegend2, ca, ... |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
723 ca_pos, ca_outpos, t1, hplots}); |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
724 addlistener (hlegend, "visible", {@hideshowlegend, ca, ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
725 ca_pos, new_pos, ... |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
726 ca_outpos, new_outpos}); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
727 else |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
728 set (hlegend, "deletefcn", {@deletelegend2, ca, [], [], t1, hplots}); |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
729 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
730 |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
731 if (addprops) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
732 addproperty ("edgecolor", hlegend, "color", [0, 0, 0]); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
733 addproperty ("textcolor", hlegend, "color", [0, 0, 0]); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
734 addproperty ("location", hlegend, "radio", "north|south|east|west|{northeast}|southeast|northwest|southwest|northoutside|southoutside|eastoutside|westoutside|northeastoutside|southeastoutside|northwestoutside|southwestoutside"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
735 addproperty ("orientation", hlegend, "radio", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
736 "{vertical}|horizontal"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
737 addproperty ("string", hlegend, "any", text_strings); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
738 addproperty ("textposition", hlegend, "radio", "{left}|right"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
739 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
740 set (hlegend, "string", text_strings); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
741 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
742 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
743 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
744 set (hlegend, "location", strcat (position, "outside"), |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
745 "orientation", orientation, "textposition", textpos); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
746 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
747 set (hlegend, "location", position, "orientation", orientation, |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
748 "textposition", textpos); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
749 endif |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
750 if (addprops) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
751 addlistener (hlegend, "edgecolor", @updatelegendtext); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
752 addlistener (hlegend, "textcolor", @updatelegendtext); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
753 addlistener (hlegend, "interpreter", @updatelegendtext); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
754 addlistener (hlegend, "location", @updatelegend); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
755 addlistener (hlegend, "orientation", @updatelegend); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
756 addlistener (hlegend, "string", @updatelegend); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
757 addlistener (hlegend, "textposition", @updatelegend); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
758 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
759 unwind_protect_cleanup |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
760 set (fig, "currentaxes", curaxes); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
761 end_unwind_protect |
6272 | 762 endif |
6147 | 763 endif |
764 | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
765 if (nargout > 0) |
11134
7c045d801702
legend.m: Trivial fix to allow legend handle to be returned.
Ben Abbott <bpabbott@mac.com>
parents:
11120
diff
changeset
|
766 hlegend2 = hlegend; |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
767 hobjects2 = hobjects; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
768 hplot2 = hplots; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
769 text_strings2 = text_strings; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
770 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
771 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
772 endfunction |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
773 |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
774 function updatelegend (h, d) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
775 persistent recursive = false; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
776 if (! recursive) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
777 recursive = true; |
11434
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
778 hax = getfield (get (h, "userdata"), "handle"); |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
779 [hplots, text_strings] = getlegenddata (h); |
11434
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
780 h = legend (hax, flipud (hplots), get (h, "string")); |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
781 recursive = false; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
782 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
783 endfunction |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
784 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
785 function updatelegendtext (h, d) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
786 kids = get (h, "children"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
787 k = numel (kids); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
788 in = get (h, "interpreter"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
789 tc = get (h, "textcolor"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
790 while (k > 0) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
791 typ = get (kids(k), "type"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
792 while (k > 0 && ! strcmp (typ, "text")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
793 typ = get (kids(--k), "type"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
794 endwhile |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
795 if (k > 0) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
796 set (kids (k), "interpreter", in, "color", tc); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
797 if (--k == 0) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
798 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
799 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
800 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
801 endwhile |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
802 endfunction |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
803 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
804 function hideshowlegend (h, d, ca, pos1, pos2, outpos1, outpos2) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
805 isvisible = strcmp (get (h, "visible"), "off"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
806 if (! isvisible) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
807 kids = get (h, "children"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
808 for i = 1 : numel (kids) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
809 if (! strcmp (get (kids(i), "visible"), "off")) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
810 isvisible = true; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
811 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
812 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
813 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
814 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
815 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
816 for i = 1 : numel (ca) |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
11134
diff
changeset
|
817 if (ishandle (ca(i)) && strcmp (get (ca(i), "type"), "axes") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
11134
diff
changeset
|
818 && (isempty (gcbf()) || strcmp (get (gcbf(), "beingdeleted"),"off")) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
11134
diff
changeset
|
819 && strcmp (get (ca(i), "beingdeleted"), "off")) |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
820 units = get (ca(i), "units"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
821 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
822 set (ca(i), "units", "points"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
823 if (isvisible) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
824 set (ca(i), "position", pos2, "outerposition", outpos2); |
10990
529b36293297
Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents:
10989
diff
changeset
|
825 else |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
826 set (ca(i), "position", pos1, "outerposition", outpos1); |
10990
529b36293297
Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents:
10989
diff
changeset
|
827 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
828 unwind_protect_cleanup |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
829 set (ca(i), "units", units); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
830 end_unwind_protect |
10990
529b36293297
Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents:
10989
diff
changeset
|
831 endif |
529b36293297
Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents:
10989
diff
changeset
|
832 endfor |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
833 endfunction |
10989
6ea65c5de87a
Respect the units and paperunits figure properties and the units and fontunits axes properties
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
834 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
835 function deletelegend1 (h, d, ca) |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
11134
diff
changeset
|
836 if (ishandle (ca) && strcmp (get (ca, "type"), "axes") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
11134
diff
changeset
|
837 && (isempty (gcbf()) || strcmp (get (gcbf(), "beingdeleted"),"off")) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
11134
diff
changeset
|
838 && strcmp (get (ca, "beingdeleted"), "off")) |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
839 delete (ca); |
10989
6ea65c5de87a
Respect the units and paperunits figure properties and the units and fontunits axes properties
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
840 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
841 endfunction |
10989
6ea65c5de87a
Respect the units and paperunits figure properties and the units and fontunits axes properties
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
842 |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
843 function deletelegend2 (h, d, ca, pos, outpos, t1, hplots) |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
844 for i = 1 : numel (ca) |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
11134
diff
changeset
|
845 if (ishandle (ca(i)) && strcmp (get (ca(i), "type"), "axes") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
11134
diff
changeset
|
846 && (isempty (gcbf()) || strcmp (get (gcbf(), "beingdeleted"),"off")) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
11134
diff
changeset
|
847 && strcmp (get (ca(i), "beingdeleted"), "off")) |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
848 if (!isempty (pos) && !isempty(outpos)) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
849 units = get (ca(i), "units"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
850 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
851 set (ca(i), "units", "points"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
852 set (ca(i), "position", pos, "outerposition", outpos, "deletefcn", ""); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
853 unwind_protect_cleanup |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
854 set (ca(i), "units", units); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
855 end_unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
856 endif |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
857 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
858 endfor |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
859 set (t1, "deletefcn", ""); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
860 delete (t1); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
861 for i = 1 : numel (hplots) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
862 if (strcmp (get (hplots (i), "type"), "line")) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
863 dellistener (hplots (i), "color"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
864 dellistener (hplots (i), "linestyle"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
865 dellistener (hplots (i), "marker"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
866 dellistener (hplots (i), "markeredgecolor"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
867 dellistener (hplots (i), "markerfacecolor"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
868 dellistener (hplots (i), "markersize"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
869 dellistener (hplots (i), "displayname"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
870 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
871 endfor |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
872 endfunction |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
873 |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
874 function updateline (h, d, hlegend, linelength) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
875 lm = []; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
876 ll = []; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
877 kids = get (hlegend, "children"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
878 for i = 1 : numel (kids) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
879 if (get (kids (i), "userdata") == h |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
880 && strcmp (get (kids(i), "type"), "line")) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
881 if (strcmp (get (kids (i), "marker"), "none")) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
882 ll = kids (i); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
883 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
884 lm = kids (i); |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
885 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
886 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
887 endfor |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
888 |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
889 linestyle = get (h, "linestyle"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
890 marker = get (h, "marker"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
891 displayname = get (h, "displayname"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
892 |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
893 if ((isempty (displayname) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
894 || (strcmp (marker, "none") && strcmp (linestyle, "none"))) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
895 && (! isempty (lm) || isempty (ll))) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
896 ## An element was removed from the legend. Need to recall the |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
897 ## legend function to recreate a new legend |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
898 [hplots, text_strings] = getlegenddata (hlegend); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
899 for i = 1 : numel (hplots) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
900 if (hplots (i) == h) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
901 hplots(i) = []; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
902 text_strings(i) = []; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
903 break; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
904 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
905 endfor |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
906 legend (hplots, text_strings); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
907 elseif ((!isempty (displayname) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
908 && (! strcmp (marker, "none") || ! strcmp (linestyle, "none"))) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
909 && isempty (lm) && isempty (ll)) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
910 ## An element was added to the legend. Need to recall the |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
911 ## legend function to recreate a new legend |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
912 [hplots, text_strings] = getlegenddata (hlegend); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
913 hplots = [hplots, h]; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
914 text_strings = {text_strings{:}, displayname}; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
915 legend (hplots, text_strings); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
916 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
917 if (! isempty (ll)) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
918 ypos1 = get (ll,"ydata"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
919 xpos1 = get (ll,"xdata"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
920 ypos2 = ypos1(1); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
921 xpos2 = sum(xpos1) / 2; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
922 delete (ll); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
923 if (! isempty (lm)) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
924 delete (lm); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
925 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
926 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
927 ypos2 = get (lm,"ydata"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
928 xpos2 = get (lm,"xdata"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
929 ypos1 = [ypos2, ypos2]; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
930 xpos1 = xpos2 + [-0.5, 0.5] * linelength; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
931 delete (lm); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
932 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
933 if (! strcmp (linestyle, "none")) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
934 line ("xdata", xpos1, "ydata", ypos1, "color", get (h, "color"), |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
935 "linestyle", get (h, "linestyle"), "marker", "none", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
936 "userdata", h, "parent", hlegend); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
937 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
938 if (! strcmp (marker, "none")) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
939 line ("xdata", xpos2, "ydata", ypos2, "color", get (h, "color"), |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
940 "marker", marker, "markeredgecolor", get (h, "markeredgecolor"), |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
941 "markerfacecolor", get (h, "markerfacecolor"), |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
942 "markersize", get (h, "markersize"), "linestyle", "none", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
943 "userdata", h, "parent", hlegend); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
944 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
945 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
946 endfunction |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
947 |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
948 function [hplots, text_strings] = getlegenddata (hlegend) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
949 hplots = []; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
950 text_strings = {}; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
951 ca = getfield (get (hlegend, "userdata"), "handle"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
952 kids = []; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
953 for i = 1 : numel (ca) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
954 kids = [kids; get(ca (i), "children")]; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
955 endfor |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
956 k = numel (kids); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
957 while (k > 0) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
958 typ = get (kids(k), "type"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
959 while (k > 0 |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
960 && ! (strcmp (typ, "line") || strcmp (typ, "surface") |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
961 || strcmp (typ, "patch") || strcmp (typ, "hggroup"))) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
962 typ = get (kids(--k), "type"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
963 endwhile |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
964 if (k > 0) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
965 if (strcmp (get (kids(k), "type"), "hggroup")) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
966 hgkids = get (kids(k), "children"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
967 for j = 1 : length (hgkids) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
968 hgobj = get (hgkids (j)); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
969 if (isfield (hgobj, "displayname") |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
970 && ! isempty (hgobj.displayname)) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
971 hplots = [hplots, hgkids(j)]; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
972 text_strings = {text_strings{:}, hbobj.displayname}; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
973 break; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
974 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
975 endfor |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
976 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
977 if (! isempty (get (kids (k), "displayname"))) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
978 hplots = [hplots, kids(k)]; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
979 text_strings = {text_strings{:}, get(kids (k), "displayname")}; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
980 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
981 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
982 if (--k == 0) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
983 break; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
984 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
985 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
986 endwhile |
6146 | 987 endfunction |
988 | |
11418
a140991387fb
legend.m: Add demo to legend for inline key.
Ben Abbott <bpabbott@mac.com>
parents:
11363
diff
changeset
|
989 %!demo |
a140991387fb
legend.m: Add demo to legend for inline key.
Ben Abbott <bpabbott@mac.com>
parents:
11363
diff
changeset
|
990 %! clf |
a140991387fb
legend.m: Add demo to legend for inline key.
Ben Abbott <bpabbott@mac.com>
parents:
11363
diff
changeset
|
991 %! x = 0:1; |
11434
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
992 %! plot (x, x, ";I am Blue;", x, 2*x, x, 3*x, ";I am Red;") |
8343
9f34f7636fe0
legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents:
8291
diff
changeset
|
993 |
9f34f7636fe0
legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents:
8291
diff
changeset
|
994 %!demo |
8790
a013ff655ca4
Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents:
8746
diff
changeset
|
995 %! clf |
9451 | 996 %! plot(1:10, 1:10, 1:10, fliplr(1:10)); |
997 %! title("incline is blue and decline is green"); | |
11434
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
998 %! legend({"I am blue", "I am green"}, "location", "east"); |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
999 %! legend({"I am blue", "I am green"}, "location", "east"); |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1000 %! legend hide |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1001 %! legend show |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1002 |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1003 %!demo |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1004 %! clf |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1005 %! plot(1:10, 1:10, 1:10, fliplr(1:10)); |
11434
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1006 %! title("Legend is hidden") |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1007 %! legend({"I am blue", "I am green"}, "location", "east"); |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1008 %! legend hide |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1009 |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1010 %!demo |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1011 %! clf |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1012 %! plot(1:10, 1:10, 1:10, fliplr(1:10)); |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1013 %! title("Legend with box on") |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1014 %! legend({"I am blue", "I am green"}, "location", "east"); |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1015 %! legend boxon |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1016 |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1017 %!demo |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1018 %! clf |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1019 %! plot(1:10, 1:10, 1:10, fliplr(1:10)); |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1020 %! title("Legend with text to the right") |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1021 %! legend({"I am blue", "I am green"}, "location", "east"); |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1022 %! legend right |
9451 | 1023 |
1024 %!demo | |
1025 %! clf | |
6146 | 1026 %! plot(1:10, 1:10); |
1027 %! title("a very long label can sometimes cause problems"); | |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1028 %! legend({"hello world"}, "location", "northeastoutside"); |
6146 | 1029 |
1030 %!demo | |
8790
a013ff655ca4
Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents:
8746
diff
changeset
|
1031 %! clf |
9451 | 1032 %! plot(1:10, 1:10); |
1033 %! title("a very long label can sometimes cause problems"); | |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1034 %! legend("hello world", "location", "northeastoutside"); |
9451 | 1035 |
1036 %!demo | |
1037 %! clf | |
6146 | 1038 %! labels = {}; |
1039 %! for i = 1:5 | |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1040 %! h = plot(1:100, i + rand(100,1)); hold on; |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1041 %! set (h, "color", get (gca, "colororder")(i,:)) |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1042 %! labels = {labels{:}, cstrcat("Signal ", num2str(i))}; |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1043 %! endfor |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1044 %! hold off; |
6146 | 1045 %! title("Signals with random offset and uniform noise") |
1046 %! xlabel("Sample Nr [k]"); ylabel("Amplitude [V]"); | |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1047 %! legend(labels, "location", "southoutside"); |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1048 %! legend("boxon"); |
9451 | 1049 |
1050 %!demo | |
1051 %! clf | |
1052 %! labels = {}; | |
1053 %! for i = 1:5 | |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1054 %! h = plot(1:100, i + rand(100,1)); hold on; |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1055 %! set (h, "color", get (gca, "colororder")(i,:)) |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1056 %! labels = {labels{:}, cstrcat("Signal ", num2str(i))}; |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1057 %! endfor |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1058 %! hold off; |
9451 | 1059 %! title("Signals with random offset and uniform noise") |
1060 %! xlabel("Sample Nr [k]"); ylabel("Amplitude [V]"); | |
1061 %! legend(labels{:}, "location", "southoutside") | |
1062 %! legend("boxon") | |
1063 | |
1064 %!demo | |
9457
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1065 %! clf |
9451 | 1066 %! x = linspace (0, 10); |
1067 %! plot (x, x); | |
1068 %! hold ("on"); | |
1069 %! stem (x, x.^2, 'g') | |
1070 %! legend ("linear"); | |
1071 %! hold ("off"); | |
1072 | |
1073 %!demo | |
9457
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1074 %! clf |
9451 | 1075 %! x = linspace (0, 10); |
1076 %! plot (x, x, x, x.^2); | |
1077 %! legend ("linear"); | |
1078 | |
1079 %!demo | |
9457
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1080 %! clf |
9451 | 1081 %! x = linspace (0, 10); |
1082 %! plot (x, x, x, x.^2); | |
1083 %! legend ("linear", "quadratic"); | |
9457
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1084 |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1085 %!demo |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1086 %! clf |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1087 %! rand_2x3_data1 = [0.341447, 0.171220, 0.284370; 0.039773, 0.731725, 0.779382]; |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1088 %! bar (rand_2x3_data1); |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1089 %! ylim ([0 1.2]); |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1090 %! legend ({"1st Bar", "2nd Bar", "3rd Bar"}); |
9457
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1091 |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1092 %!demo |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1093 %! clf |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1094 %! rand_2x3_data2 = [0.44804, 0.84368, 0.23012; 0.72311, 0.58335, 0.90531]; |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1095 %! bar (rand_2x3_data2); |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1096 %! ylim ([0 1.2]); |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1097 %! legend ("1st Bar", "2nd Bar", "3rd Bar"); |
10662
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1098 |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1099 %!demo |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1100 %! clf |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1101 %! x = 0:0.1:7; |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1102 %! h = plot (x, sin(x), x, cos(x), x, sin(x.^2/10), x, cos(x.^2/10)); |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1103 %! title ("Only the sin() objects have keylabels"); |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1104 %! legend (h([1, 3]), {"sin(x)", "sin(x^2/10)"}, "location", "southwest"); |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1105 |