Mercurial > octave-nkf
annotate scripts/plot/legend.m @ 11199:91c606a68693
minor fix to previous changeset
author | David Bateman <dbateman@free.fr> |
---|---|
date | Sun, 07 Nov 2010 22:48:50 +0100 |
parents | 9f080d23396f |
children | abc0c6b0a4c4 |
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 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
103 if (! ishandle (varargin {1}) || (strcmp (get (varargin {1}, "type"), "axes") |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
104 && ! 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
|
105 [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
|
106 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
|
107 else |
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 (0, "currentfigure"); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
109 ca = 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
|
110 endif |
6146 | 111 |
11199
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
112 if (strcmp (get (ca, "tag"), "plotyy")) |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
113 plty = get(ca (strcmp (get (ca, "tag"), "plotyy")), "userdata"); |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
114 if (isscalar (plty)) |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
115 ca = [ca, plty]; |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
116 else |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
117 ca = [ca, plty{:}]; |
91c606a68693
minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents:
11198
diff
changeset
|
118 endif |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
119 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
120 |
10662
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
121 if (all (ishandle (varargin{1}))) |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
122 kids = flipud (varargin{1}(:)); |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
123 varargin(1) = []; |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
124 nargs = numel (varargin); |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
125 else |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
126 kids = ca; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
131 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
|
132 endif |
10662
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
133 endif |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
134 nkids = numel (kids); |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
135 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
136 orientation = "default"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
137 position = "default"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
138 show = "create"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
139 textpos = "default"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
140 box = "default"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
141 |
6146 | 142 if (nargs > 0) |
143 pos = varargin{nargs}; | |
144 if (isnumeric (pos) && isscalar (pos) && round (pos) == pos) | |
6395 | 145 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
|
146 position = [{"northeastoutside", "best", "northeast", |
b1cfff739af5
legend.m: Index location cellstr to obtain a string.
Ben Abbott <bpabbott@mac.com>
parents:
10999
diff
changeset
|
147 "northwest", "southwest", "southeast"}] {pos + 2}; |
10549 | 148 nargs--; |
6146 | 149 else |
10549 | 150 error ("legend: invalid position specified"); |
6146 | 151 endif |
152 endif | |
153 endif | |
6977 | 154 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
155 while (nargs > 1) |
6977 | 156 pos = varargin{nargs-1}; |
7054 | 157 str = varargin{nargs}; |
6977 | 158 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
|
159 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
|
160 nargs -= 2; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
165 break; |
6977 | 166 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
167 endwhile |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
168 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
169 ## 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
|
170 switch (orientation) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
171 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
|
172 otherwise |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
173 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
|
174 endswitch |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
175 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
176 ## 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
|
177 outside = false; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
178 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
|
179 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
|
180 outside = true; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
181 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
|
182 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
183 outside = false; |
6977 | 184 endif |
6146 | 185 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
186 switch (position) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
187 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
|
188 "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
|
189 case "best" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
190 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
|
191 position = "northeast"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
192 otherwise |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
193 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
|
194 endswitch |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
195 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
196 hlegend = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 && (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
|
201 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
|
202 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
|
203 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
|
204 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
205 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
206 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
207 endfor |
6257 | 208 |
6146 | 209 if (nargs == 1) |
210 arg = varargin{1}; | |
211 if (ischar (arg)) | |
212 if (rows (arg) == 1) | |
10549 | 213 str = tolower (deblank (arg)); |
214 switch (str) | |
215 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
|
216 show = "off"; |
10549 | 217 nargs--; |
218 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
|
219 show = "on"; |
10549 | 220 nargs--; |
221 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
|
222 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
|
223 show = "on"; |
10549 | 224 else |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
225 show = "off"; |
10549 | 226 endif |
227 nargs--; | |
228 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
|
229 box = "on"; |
10549 | 230 nargs--; |
231 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
|
232 box = "off"; |
10549 | 233 nargs--; |
234 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
|
235 textpos = "left"; |
10549 | 236 nargs--; |
237 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
|
238 textpos = "right"; |
10549 | 239 nargs--; |
240 otherwise | |
241 endswitch | |
6146 | 242 else |
10549 | 243 varargin = cellstr (arg); |
244 nargs = numel (varargin); | |
6146 | 245 endif |
246 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
|
247 varargin = arg; |
6146 | 248 nargs = numel (varargin); |
249 else | |
250 error ("legend: expecting argument to be a character string"); | |
251 endif | |
252 endif | |
253 | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 hlegend = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
258 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
259 hobjects = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
260 hplots = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
261 text_strings = {}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
262 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
|
263 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
|
264 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
|
265 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
266 hobjects = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
267 hplots = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
268 text_strings = {}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
269 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
278 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
279 hobjects = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
280 hplots = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
281 text_strings = {}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
282 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 || 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
|
289 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
|
290 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
291 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
292 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
293 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
294 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
|
295 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
|
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 endif |
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 (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
|
300 warned = false; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
301 k = nkids; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 && ! (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
|
308 || 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
|
309 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
|
310 endwhile |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
321 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
322 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
323 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
328 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
329 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
|
330 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
331 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
332 elseif (! warned) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
333 warned = true; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
334 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
|
335 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
336 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
337 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
|
338 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
339 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
340 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
341 k = nkids; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 && ! (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
|
346 || 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
|
347 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
|
348 endwhile |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
349 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
|
350 || 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
|
351 break |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
352 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 && ! 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
|
360 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
|
361 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
|
362 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
363 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
364 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
365 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
366 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
|
367 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
|
368 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
|
369 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
370 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
371 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
|
372 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
373 endif |
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 endwhile |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
376 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
377 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
378 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
|
379 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
|
380 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
|
381 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
|
382 hlegend = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
383 hobjects = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
384 hplots = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
385 text_strings = {}; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
386 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
387 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
388 ## 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
|
389 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
|
390 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
|
391 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
|
392 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
393 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
|
394 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
|
395 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
|
396 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
|
397 outside = true; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
398 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
|
399 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
400 outside = false; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
401 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
402 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
403 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
|
404 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
|
405 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
406 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
|
407 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
|
408 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
409 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
|
410 textpos = "left"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
411 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
412 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
|
413 position = "northeast"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
414 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
415 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
|
416 orientation = "vertical"; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
417 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
418 box = "off"; |
6272 | 419 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
420 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
421 ## Force the figure to be drawn here, so that the figure position |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
422 ## is updated correctly before reading it |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
423 drawnow (); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
424 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
425 ## 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
|
426 ## 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
|
427 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
|
428 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
|
429 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
440 ## 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
|
441 xpad = 2; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
442 ypad = 2; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
443 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
444 ## 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
|
445 linelength = 15; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
446 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
447 ## 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
|
448 ## 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
|
449 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
|
450 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
|
451 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
|
452 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
|
453 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
|
454 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
455 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
|
456 addprops = true; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
457 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
|
458 "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
|
459 "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
|
460 "yticklabel", "", "zticklabel", "", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
461 "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
|
462 "activepositionproperty", "position"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
463 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
464 addprops = false; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
465 axes (hlegend); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
466 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
|
467 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
468 ## 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
|
469 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
|
470 texthandle = []; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
471 maxwidth = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
472 maxheight = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
473 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
|
474 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
|
475 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
|
476 "horizontalalignment", "left", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
477 "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
|
478 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
479 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
|
480 "horizontalalignment", "right", |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
481 "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
|
482 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
483 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
|
484 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
485 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
|
486 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
|
487 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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
493 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
494 num1 = nentries; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
495 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
|
496 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
|
497 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
498 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
|
499 ## 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
|
500 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
|
501 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
502 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
503 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
|
504 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
|
505 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
506 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
507 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
508 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
|
509 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
510 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
|
511 ## 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
|
512 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
|
513 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
514 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
515 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
|
516 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
|
517 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
518 endif |
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 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
|
521 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
522 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
|
523 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
|
524 xoffset = xpad; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
525 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
|
526 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
527 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
|
528 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
|
529 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
530 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
|
531 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
|
532 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
533 ## 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
|
534 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
|
535 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
|
536 else |
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, 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
|
538 endif |
11120
a44f979a35ce
style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents:
11033
diff
changeset
|
539 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
|
540 case "north" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
541 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
542 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
|
543 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
|
544 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
545 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
|
546 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
|
547 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
|
548 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
549 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
|
550 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
|
551 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
552 case "south" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
553 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
554 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
|
555 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
|
556 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
|
557 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
|
558 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
|
559 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
|
560 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
561 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
|
562 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
|
563 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
564 case "east" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
565 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
566 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
|
567 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
|
568 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
|
569 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
|
570 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
|
571 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
572 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
|
573 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
|
574 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
575 case "west" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
576 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
577 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
|
578 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
|
579 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
|
580 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
|
581 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
|
582 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
|
583 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
584 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
|
585 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
|
586 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
587 case "northeast" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
588 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
589 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
|
590 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
|
591 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
|
592 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
|
593 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
|
594 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
|
595 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
596 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
|
597 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
|
598 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
599 case "northwest" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
600 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
601 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
|
602 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
|
603 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
|
604 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
|
605 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
|
606 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
|
607 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
608 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
|
609 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
|
610 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
611 case "southeast" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
612 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
613 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
|
614 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
|
615 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
|
616 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
|
617 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
|
618 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
|
619 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
620 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
|
621 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
|
622 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
623 case "southwest" |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
624 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
625 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
|
626 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
|
627 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
|
628 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
|
629 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
|
630 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
631 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
|
632 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
633 endswitch |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
634 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
635 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
|
636 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
637 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
|
638 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
|
639 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
|
640 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
|
641 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
|
642 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
643 ## 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
|
644 xk = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
645 yk = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
646 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
|
647 hobjects = [hobjects, texthandle (k)]; |
11120
a44f979a35ce
style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents:
11033
diff
changeset
|
648 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
|
649 case "line" |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
650 color = get (hplots(k), "color"); |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
651 style = get (hplots(k), "linestyle"); |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
652 if (! strcmp (style, "none")) |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
653 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
|
654 "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
|
655 "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
|
656 "userdata", hplots (k)); |
10999
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
657 hobjects = [hobjects, l1]; |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
658 endif |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
659 marker = get (hplots(k), "marker"); |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
660 if (! strcmp (marker, "none")) |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
661 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
|
662 "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
|
663 "color", color, "linestyle", "none", "marker", marker, |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
11003
diff
changeset
|
664 "markeredgecolor", get (hplots (k), "markeredgecolor"), |
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
11003
diff
changeset
|
665 "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
|
666 "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
|
667 "userdata", hplots (k)); |
10999
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
668 hobjects = [hobjects, l1]; |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
669 endif |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
670 |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
671 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
|
672 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
|
673 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
|
674 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
|
675 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
|
676 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
|
677 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
|
678 case "patch" |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
679 case "surface" |
9f45b76c16e3
legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents:
10995
diff
changeset
|
680 endswitch |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
681 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
|
682 (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
|
683 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
|
684 yk++; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
685 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
|
686 yk = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
687 xk++; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
688 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
689 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
690 xk++; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
691 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
|
692 xk = 0; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
693 yk++; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
694 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
695 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
696 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
697 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
698 ## 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
|
699 ## 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
|
700 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
|
701 "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
|
702 "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
|
703 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
|
704 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
705 ## 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
|
706 ## 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
|
707 ## 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
|
708 ## 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
|
709 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
710 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
|
711 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
|
712 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
713 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
|
714 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
|
715 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
|
716 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
|
717 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
|
718 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
719 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
720 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
|
721 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
|
722 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
|
723 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
|
724 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
|
725 else |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
726 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
|
727 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
728 |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
729 if (addprops) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
730 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
|
731 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
|
732 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
|
733 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
|
734 "{vertical}|horizontal"); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
735 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
|
736 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
|
737 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
738 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
|
739 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
740 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
741 if (outside) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
742 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
|
743 "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
|
744 else |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
745 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
|
746 "textposition", textpos); |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
747 endif |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
748 if (addprops) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
749 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
|
750 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
|
751 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
|
752 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
|
753 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
|
754 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
|
755 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
|
756 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
757 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
|
758 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
|
759 end_unwind_protect |
6272 | 760 endif |
6147 | 761 endif |
762 | |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
763 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
|
764 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
|
765 hobjects2 = hobjects; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
766 hplot2 = hplots; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
767 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
|
768 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
769 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
770 endfunction |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
771 |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
772 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
|
773 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
|
774 if (! recursive) |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
775 recursive = true; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
776 [hplots, text_strings] = getlegenddata (h); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
777 h = legend (fliplr (hplots), get (h, "string")); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
778 recursive = false; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
779 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
780 endfunction |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
781 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
782 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
|
783 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
|
784 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
|
785 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
|
786 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
|
787 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
|
788 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
|
789 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
|
790 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
|
791 endwhile |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
792 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
|
793 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
|
794 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
|
795 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
796 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
797 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
798 endwhile |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
799 endfunction |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
800 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
801 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
|
802 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
|
803 if (! isvisible) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
804 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
|
805 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
|
806 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
|
807 isvisible = true; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
808 break; |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
809 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
810 endfor |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
811 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
812 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
813 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
|
814 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
|
815 && (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
|
816 && 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
|
817 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
|
818 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
819 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
|
820 if (isvisible) |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
821 set (ca(i), "position", pos2, "outerposition", outpos2); |
10990
529b36293297
Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents:
10989
diff
changeset
|
822 else |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
823 set (ca(i), "position", pos1, "outerposition", outpos1); |
10990
529b36293297
Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents:
10989
diff
changeset
|
824 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
825 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
|
826 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
|
827 end_unwind_protect |
10990
529b36293297
Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents:
10989
diff
changeset
|
828 endif |
529b36293297
Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents:
10989
diff
changeset
|
829 endfor |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
830 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
|
831 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
832 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
|
833 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
|
834 && (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
|
835 && 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
|
836 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
|
837 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
838 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
|
839 |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
840 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
|
841 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
|
842 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
|
843 && (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
|
844 && 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
|
845 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
|
846 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
|
847 unwind_protect |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
848 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
|
849 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
|
850 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
|
851 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
|
852 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
|
853 endif |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
854 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
855 endfor |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
856 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
|
857 delete (t1); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
858 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
|
859 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
|
860 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
|
861 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
|
862 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
|
863 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
|
864 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
|
865 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
|
866 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
|
867 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
868 endfor |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
869 endfunction |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
870 |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
871 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
|
872 lm = []; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
873 ll = []; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
874 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
|
875 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
|
876 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
|
877 && 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
|
878 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
|
879 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
|
880 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
881 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
|
882 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
883 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
884 endfor |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
885 |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
886 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
|
887 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
|
888 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
|
889 |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
890 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
|
891 || (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
|
892 && (! 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
|
893 ## 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
|
894 ## 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
|
895 [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
|
896 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
|
897 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
|
898 hplots(i) = []; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
899 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
|
900 break; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
901 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
902 endfor |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
903 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
|
904 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
|
905 && (! 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
|
906 && 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
|
907 ## 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
|
908 ## 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
|
909 [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
|
910 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
|
911 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
|
912 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
|
913 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
914 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
|
915 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
|
916 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
|
917 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
|
918 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
|
919 delete (ll); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
920 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
|
921 delete (lm); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
922 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
923 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
924 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
|
925 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
|
926 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
|
927 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
|
928 delete (lm); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
929 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
930 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
|
931 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
|
932 "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
|
933 "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
|
934 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
935 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
|
936 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
|
937 "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
|
938 "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
|
939 "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
|
940 "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
|
941 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
942 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
943 endfunction |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
944 |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
945 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
|
946 hplots = []; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
947 text_strings = {}; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
948 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
|
949 kids = []; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
950 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
|
951 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
|
952 endfor |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
953 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
|
954 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
|
955 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
|
956 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
|
957 && ! (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
|
958 || 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
|
959 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
|
960 endwhile |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
961 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
|
962 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
|
963 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
|
964 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
|
965 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
|
966 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
|
967 && ! 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
|
968 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
|
969 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
|
970 break; |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
971 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
972 endfor |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
973 else |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
974 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
|
975 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
|
976 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
|
977 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
978 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
979 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
|
980 break; |
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 endif |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
983 endwhile |
6146 | 984 endfunction |
985 | |
986 %!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
|
987 %! clf |
8343
9f34f7636fe0
legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents:
8291
diff
changeset
|
988 %! plot(1:10, 1:10, 1:10, fliplr(1:10)); |
9f34f7636fe0
legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents:
8291
diff
changeset
|
989 %! title("incline is blue and decline is green"); |
9f34f7636fe0
legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents:
8291
diff
changeset
|
990 %! legend({"I'm blue", "I'm green"}, "location", "east") |
9f34f7636fe0
legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents:
8291
diff
changeset
|
991 |
9f34f7636fe0
legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents:
8291
diff
changeset
|
992 %!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
|
993 %! clf |
9451 | 994 %! plot(1:10, 1:10, 1:10, fliplr(1:10)); |
995 %! title("incline is blue and decline is green"); | |
996 %! legend("I'm blue", "I'm green", "location", "east") | |
997 | |
998 %!demo | |
999 %! clf | |
6146 | 1000 %! plot(1:10, 1:10); |
1001 %! title("a very long label can sometimes cause problems"); | |
6977 | 1002 %! legend({"hello world"}, "location", "northeastoutside") |
6146 | 1003 |
1004 %!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
|
1005 %! clf |
9451 | 1006 %! plot(1:10, 1:10); |
1007 %! title("a very long label can sometimes cause problems"); | |
1008 %! legend("hello world", "location", "northeastoutside") | |
1009 | |
1010 %!demo | |
1011 %! clf | |
6146 | 1012 %! labels = {}; |
1013 %! for i = 1:5 | |
8915
485eabc0cfec
__go_draw_axes__.m: Preserve the order of axes' children when pruning the handles for the {x,y,z}labels and title.
Ben Abbott <bpabbott@mac.com>
parents:
8790
diff
changeset
|
1014 %! h = plot(1:100, i + rand(100,1)); hold on; |
485eabc0cfec
__go_draw_axes__.m: Preserve the order of axes' children when pruning the handles for the {x,y,z}labels and title.
Ben Abbott <bpabbott@mac.com>
parents:
8790
diff
changeset
|
1015 %! set (h, "color", get (gca, "colororder")(i,:)) |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7148
diff
changeset
|
1016 %! labels = {labels{:}, cstrcat("Signal ", num2str(i))}; |
6146 | 1017 %! endfor; hold off; |
1018 %! title("Signals with random offset and uniform noise") | |
1019 %! xlabel("Sample Nr [k]"); ylabel("Amplitude [V]"); | |
6977 | 1020 %! legend(labels, "location", "southoutside") |
6146 | 1021 %! legend("boxon") |
9451 | 1022 |
1023 %!demo | |
1024 %! clf | |
1025 %! labels = {}; | |
1026 %! for i = 1:5 | |
1027 %! h = plot(1:100, i + rand(100,1)); hold on; | |
1028 %! set (h, "color", get (gca, "colororder")(i,:)) | |
1029 %! labels = {labels{:}, cstrcat("Signal ", num2str(i))}; | |
1030 %! endfor; hold off; | |
1031 %! title("Signals with random offset and uniform noise") | |
1032 %! xlabel("Sample Nr [k]"); ylabel("Amplitude [V]"); | |
1033 %! legend(labels{:}, "location", "southoutside") | |
1034 %! legend("boxon") | |
1035 | |
1036 %!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
|
1037 %! clf |
9451 | 1038 %! x = linspace (0, 10); |
1039 %! plot (x, x); | |
1040 %! hold ("on"); | |
1041 %! stem (x, x.^2, 'g') | |
1042 %! legend ("linear"); | |
1043 %! hold ("off"); | |
1044 | |
1045 %!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
|
1046 %! clf |
9451 | 1047 %! x = linspace (0, 10); |
1048 %! plot (x, x, x, x.^2); | |
1049 %! legend ("linear"); | |
1050 | |
1051 %!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
|
1052 %! clf |
9451 | 1053 %! x = linspace (0, 10); |
1054 %! plot (x, x, x, x.^2); | |
1055 %! 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
|
1056 |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1057 %!demo |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1058 %! clf |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1059 %! bar (rand (2, 3)) |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1060 %! ylim ([0 1.2]) |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1061 %! legend ({"1st Bar", "2nd Bar", "3rd Bar"}) |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1062 |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1063 %!demo |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1064 %! clf |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1065 %! bar (rand (2, 3)) |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1066 %! ylim ([0 1.2]) |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1067 %! 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
|
1068 |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1069 %!demo |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1070 %! clf |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1071 %! x = 0:0.1:7; |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1072 %! h = plot (x, sin(x), x, cos(x), x, sin(x.^2/10), x, cos(x.^2/10)); |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1073 %! title ("Only the sin() objects have keylabels") |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1074 %! legend (h([1, 3]), {"sin(x)", "sin(x^2/10)"}, "location", "southwest") |