annotate scripts/plot/appearance/legend.m @ 26815:45270d3aa861

legend.m: Allow "location" specifier in any input position (bug #55800). * legend.m: Redo while loop and search through all input arguments for "location" and "orientation" specifiers.
author Rik <rik@octave.org>
date Sat, 02 Mar 2019 11:08:53 -0800
parents 4eed5ba2586a
children ca40628fff39
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26341
diff changeset
1 ## Copyright (C) 2010-2019 David Bateman
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
2 ##
6440
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6395
diff changeset
3 ## This file is part of Octave.
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6395
diff changeset
4 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24498
diff changeset
5 ## Octave is free software: you can redistribute it and/or modify it
6440
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6395
diff changeset
6 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24498
diff changeset
7 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22631
diff changeset
8 ## (at your option) any later version.
6440
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6395
diff changeset
9 ##
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6395
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6395
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22631
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22631
diff changeset
13 ## GNU General Public License for more details.
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
14 ##
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24498
diff changeset
17 ## <https://www.gnu.org/licenses/>.
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
18
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
20 ## @deftypefn {} {} legend ()
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
21 ## @deftypefnx {} {} legend (@var{str1}, @var{str2}, @dots{})
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
22 ## @deftypefnx {} {} legend (@var{charmat})
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
23 ## @deftypefnx {} {} legend (@{@var{cellstr}@})
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20781
diff changeset
24 ## @deftypefnx {} {} legend (@dots{}, "location", @var{pos})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20781
diff changeset
25 ## @deftypefnx {} {} legend (@dots{}, "orientation", @var{orient})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20781
diff changeset
26 ## @deftypefnx {} {} legend (@var{hax}, @dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20781
diff changeset
27 ## @deftypefnx {} {} legend (@var{hobjs}, @dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20781
diff changeset
28 ## @deftypefnx {} {} legend (@var{hax}, @var{hobjs}, @dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20781
diff changeset
29 ## @deftypefnx {} {} legend ("@var{option}")
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
30 ## @deftypefnx {} {} legend (@dots{}, @{@var{cellstr}@}, @var{property}, @var{value}, @dots{})
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20781
diff changeset
31 ## @deftypefnx {} {[@var{hleg}, @var{hleg_obj}, @var{hplot}, @var{labels}] =} legend (@dots{})
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
32 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
33 ## Display a legend for the current axes using the specified strings as labels.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
34 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
35 ## Legend entries may be specified as individual character string arguments,
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
36 ## a character array, or a cell array of character strings. When label names
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
37 ## might be confused with options to @code{legend}, the labels should be
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
38 ## protected by specifying them as a cell array of strings.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
39 ##
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
40 ## If the first argument @var{hax} is an axes handle, then add a legend to this
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
41 ## axes, rather than the current axes returned by @code{gca}.
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
42 ##
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
43 ## Legend labels are associated with the axes' children; The first label is
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
44 ## assigned to the first object that was plotted in the axes, the second label
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
45 ## to the next object plotted, etc. To label specific data objects, without
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
46 ## labeling all objects, provide their graphic handles in the input
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
47 ## @var{hobjs}.
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
48 ##
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
49 ## The optional parameter @var{pos} specifies the location of the legend as
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
50 ## follows:
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
51 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
52 ## @multitable @columnfractions 0.06 0.14 0.80
17204
d87179b38bcf doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents: 17190
diff changeset
53 ## @headitem @tab pos @tab location of the legend
d87179b38bcf doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents: 17190
diff changeset
54 ## @item @tab north @tab center top
d87179b38bcf doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents: 17190
diff changeset
55 ## @item @tab south @tab center bottom
d87179b38bcf doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents: 17190
diff changeset
56 ## @item @tab east @tab right center
d87179b38bcf doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents: 17190
diff changeset
57 ## @item @tab west @tab left center
d87179b38bcf doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents: 17190
diff changeset
58 ## @item @tab northeast @tab right top (default)
d87179b38bcf doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents: 17190
diff changeset
59 ## @item @tab northwest @tab left top
d87179b38bcf doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents: 17190
diff changeset
60 ## @item @tab southeast @tab right bottom
d87179b38bcf doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents: 17190
diff changeset
61 ## @item @tab southwest @tab left bottom
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
62 ## @sp 1
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
63 ## @item @tab outside @tab can be appended to any location string @*
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
64 ## @item @tab @tab which will place the legend outside the axes
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
65 ## @end multitable
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
66 ##
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
67 ## The optional parameter @var{orient} determines if the legend elements are
20173
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19880
diff changeset
68 ## placed vertically or horizontally. The allowed values are
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17204
diff changeset
69 ## @qcode{"vertical"} (default) or @qcode{"horizontal"}.
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
70 ##
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
71 ## The following customizations are available using @var{option}:
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
72 ##
7148
735086cfd405 [project @ 2007-11-09 18:01:44 by jwe]
jwe
parents: 7054
diff changeset
73 ## @table @asis
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17204
diff changeset
74 ## @item @qcode{"show"}
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
75 ## Show legend on the plot
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
76 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17204
diff changeset
77 ## @item @qcode{"hide"}
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
78 ## Hide legend on the plot
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
79 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17204
diff changeset
80 ## @item @qcode{"toggle"}
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
81 ## Toggle between @qcode{"hide"} and @qcode{"show"}
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
82 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17204
diff changeset
83 ## @item @qcode{"boxon"}
17532
492d609d2d75 legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents: 17530
diff changeset
84 ## Show a box around legend (default)
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
85 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17204
diff changeset
86 ## @item @qcode{"boxoff"}
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
87 ## Hide the box around legend
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
88 ##
17532
492d609d2d75 legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents: 17530
diff changeset
89 ## @item @qcode{"right"}
492d609d2d75 legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents: 17530
diff changeset
90 ## Place label text to the right of the keys (default)
492d609d2d75 legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents: 17530
diff changeset
91 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17204
diff changeset
92 ## @item @qcode{"left"}
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
93 ## Place label text to the left of the keys
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
94 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17204
diff changeset
95 ## @item @qcode{"off"}
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
96 ## Delete the legend object
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
97 ## @end table
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
98 ##
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
99 ## The @code{legend} function creates a graphics object which has various
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
100 ## properties that can be manipulated with @code{get}/@code{set}.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
101 ## Alternatively, properties can be set directly when calling @code{legend} by
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
102 ## including @var{property}/@var{value} pairs. If using this calling form, the
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
103 ## labels must be specified as a cell array of strings.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
104 ##
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
105 ## The optional output values are
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
106 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
107 ## @table @var
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
108 ## @item hleg
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
109 ## The graphics handle of the legend object.
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
110 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
111 ## @item hleg_obj
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
112 ## Graphics handles to the text, patch, and line objects which form the
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
113 ## legend.
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
114 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
115 ## @item hplot
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
116 ## Graphics handles to the plot objects which were used in making the legend.
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
117 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
118 ## @item labels
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
119 ## A cell array of strings of the labels in the legend.
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
120 ## @end table
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
121 ##
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
122 ## Implementation Note: The legend label text is either provided in the call to
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
123 ## @code{legend} or is taken from the @code{DisplayName} property of the
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
124 ## graphics objects. Only data objects, such as line, patch, and surface, have
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
125 ## this property whereas axes, figures, etc.@: do not so they are never present
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
126 ## in a legend. If no labels or @code{DisplayName} properties are available,
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
127 ## then the label text is simply @qcode{"data1"}, @qcode{"data2"}, @dots{},
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
128 ## @nospell{@qcode{"dataN"}}. No more than 20 data labels will be
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
129 ## automatically generated. To label more, call @code{legend} explicitly and
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
130 ## provide all labels.
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
131 ##
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
132 ## The legend @code{FontSize} property is initially set to 90% of the axes
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
133 ## @code{FontSize} to which it is attached. Use @code{set} to override this
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
134 ## if necessary.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
135 ##
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
136 ## A legend is implemented as an additional axes object with the @code{tag}
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
137 ## property set to @qcode{"legend"}. Properties of the legend object may be
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
138 ## manipulated directly by using @code{set}.
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
139 ## @end deftypefn
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
140
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
141 function [hleg, hleg_obj, hplot, labels] = legend (varargin)
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
142
11246
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
143 if (nargin > 0
24423
1d52db450db4 Change ishandle to return true for Java objects for Matlab compatibility.
Rik <rik@octave.org>
parents: 24403
diff changeset
144 && (! ishghandle (varargin{1})
11246
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
145 || (strcmp (get (varargin{1}, "type"), "axes")
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
146 && ! strcmp (get (varargin{1}, "tag"), "legend"))))
17065
991e8a386aa3 legend.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16973
diff changeset
147 [ca, varargin, nargin] = __plt_get_axis_arg__ ("legend", varargin{:});
991e8a386aa3 legend.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16973
diff changeset
148 if (isempty (ca))
991e8a386aa3 legend.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16973
diff changeset
149 ca = gca ();
991e8a386aa3 legend.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16973
diff changeset
150 endif
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
151 hfig = ancestor (ca, "figure");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
152 else
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
153 hfig = get (0, "currentfigure");
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
154 if (isempty (hfig))
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
155 hfig = gcf ();
11246
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
156 endif
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
157 ca = gca ();
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
158 endif
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
159
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
160 ## Special handling for plotyy which has two axes objects
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
161 if (isprop (ca, "__plotyy_axes__"))
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
162 plty = get (ca, "__plotyy_axes__");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
163 ca = [ca, plty.'];
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
164 ## Remove duplicates while preserving order
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
165 [~, n] = unique (ca, "first");
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
166 ca = ca(sort (n));
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
167 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
168
24423
1d52db450db4 Change ishandle to return true for Java objects for Matlab compatibility.
Rik <rik@octave.org>
parents: 24403
diff changeset
169 if (nargin > 0 && all (ishghandle (varargin{1})))
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
170 ## List of plot objects to label given as first argument
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
171 kids = flipud (varargin{1}(:));
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
172 varargin(1) = [];
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
173 else
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
174 ## Find list of plot objects from axes "children"
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
175 kids = ca;
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
176 kids(strcmp (get (ca, "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
177 if (isscalar (kids))
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
178 kids = get (kids, "children")(:);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
179 else
23257
61ec2557eece Fix order of legend labels with plotyy axes (bug #50497)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 23253
diff changeset
180 kids = vertcat (flipud (get (kids, "children")){:});
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
181 endif
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
182 endif
11246
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
183 nargs = numel (varargin);
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
184 nkids = numel (kids);
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
185
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
186 ## Find any existing legend object associated with axes
18734
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
187 hlegend = [];
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
188 for hax = ca
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
189 try
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
190 hlegend = get (hax, "__legend_handle__");
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
191 if (! isempty (hlegend))
18734
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
192 break;
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
193 endif
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
194 end_try_catch
18734
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
195 endfor
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
196
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
197 orientation = "default";
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
198 location = "default";
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
199 show = "create";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
200 textpos = "default";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
201 box = "default";
18734
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
202 delete_leg = false;
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
203 find_leg_hdl = (nargs == 0); # possibly overridden
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
204 propvals = {};
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
205
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
206 ## Find "location" and "orientation" property/value pairs
26815
45270d3aa861 legend.m: Allow "location" specifier in any input position (bug #55800).
Rik <rik@octave.org>
parents: 26814
diff changeset
207 i = nargs - 1;
45270d3aa861 legend.m: Allow "location" specifier in any input position (bug #55800).
Rik <rik@octave.org>
parents: 26814
diff changeset
208 while (i > 0)
45270d3aa861 legend.m: Allow "location" specifier in any input position (bug #55800).
Rik <rik@octave.org>
parents: 26814
diff changeset
209 pos = varargin{i};
45270d3aa861 legend.m: Allow "location" specifier in any input position (bug #55800).
Rik <rik@octave.org>
parents: 26814
diff changeset
210 str = varargin{i+1};
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
211 if (strcmpi (pos, "location") && ischar (str))
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
212 location = lower (str);
26815
45270d3aa861 legend.m: Allow "location" specifier in any input position (bug #55800).
Rik <rik@octave.org>
parents: 26814
diff changeset
213 varargin(i:i+1) = [];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
214 nargs -= 2;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
215 elseif (strcmpi (pos, "orientation") && 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
216 orientation = lower (str);
26815
45270d3aa861 legend.m: Allow "location" specifier in any input position (bug #55800).
Rik <rik@octave.org>
parents: 26814
diff changeset
217 varargin(i:i+1) = [];
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
218 nargs -= 2;
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
219 endif
26815
45270d3aa861 legend.m: Allow "location" specifier in any input position (bug #55800).
Rik <rik@octave.org>
parents: 26814
diff changeset
220 i -= 2;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
221 endwhile
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
222
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
223 ## Validate the orientation
26239
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
224 if (! any (strcmp (orientation, {"vertical", "horizontal", "default"})))
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
225 error ("legend: unrecognized legend orientation");
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
226 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
227
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
228 ## Validate the location type
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
229 outside = false;
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
230 inout = strfind (location, "outside");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
231 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
232 outside = true;
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
233 location = location(1:inout-1);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
234 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
235 outside = false;
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
236 endif
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
237
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
238 switch (location)
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
239 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
240 "southeast", "southwest", "default"}
26239
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
241 ## These are all valid locations, do nothing.
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
242
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
243 case "best"
26239
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
244 if (outside)
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
245 if (strcmp (orientation, "horizontal"))
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
246 location = "south";
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
247 else
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
248 location = "northeast";
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
249 endif
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
250 else
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
251 warning ("legend: 'best' not yet implemented for location specifier, using 'northeast' instead\n");
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
252 location = "northeast";
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
253 endif
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
254
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
255 case "none"
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
256 ## FIXME: Should there be any more error checking on this?
26239
64061eace057 legend.m: Implement "bestoutside" location.
Rik <rik@octave.org>
parents: 26230
diff changeset
257
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
258 otherwise
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
259 error ("legend: unrecognized legend location");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
260 endswitch
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
261
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
262 ## Finish input processing based on number of inputs
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
263 if (nargs == 0)
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
264 ## No labels given, create a new legend or return existing one
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
265 if (isempty (hlegend))
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
266 show = "create";
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
267 textpos = "right";
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
268 find_leg_hdl = false;
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
269 endif
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
270
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
271 elseif (nargs == 1)
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
272 ## Either OPTION value, single string label, or cellstr of labels.
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
273 arg = varargin{1};
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
274 if (ischar (arg))
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
275 if (rows (arg) == 1)
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
276 str = lower (strtrim (arg));
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
277 switch (str)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
278 case "off"
18734
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
279 delete_leg = true;
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
280 case "hide"
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
281 show = "off";
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20711
diff changeset
282 nargs -= 1;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
283 case "show"
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
284 if (! isempty (hlegend))
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
285 show = "on";
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
286 else
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
287 show = "create";
17532
492d609d2d75 legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents: 17530
diff changeset
288 textpos = "right";
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
289 endif
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20711
diff changeset
290 nargs -= 1;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
291 case "toggle"
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
292 if (isempty (hlegend))
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
293 show = "create";
17532
492d609d2d75 legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents: 17530
diff changeset
294 textpos = "right";
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
295 elseif (strcmp (get (hlegend, "visible"), "off"))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
296 show = "on";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
297 else
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
298 show = "off";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
299 endif
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20711
diff changeset
300 nargs -= 1;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
301 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
302 box = "on";
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20711
diff changeset
303 nargs -= 1;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
304 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
305 box = "off";
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20711
diff changeset
306 nargs -= 1;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
307 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
308 textpos = "left";
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20711
diff changeset
309 nargs -= 1;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
310 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
311 textpos = "right";
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20711
diff changeset
312 nargs -= 1;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
313 endswitch
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
314 else
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
315 ## Character matrix of labels
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
316 varargin = cellstr (arg);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
317 nargs = numel (varargin);
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
318 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
319 elseif (iscellstr (arg))
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
320 ## Cell array of labels
8529
774b44619c5c Fix legend order for both horizontal and vertical string cell.
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 8343
diff changeset
321 varargin = arg;
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
322 nargs = numel (varargin);
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
323 else
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20408
diff changeset
324 error ("legend: single argument must be a string or cellstr");
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
325 endif
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
326
14589
fd6e50e2eee6 legend() should accept labels being specified as both cellstrs and char.
Ben Abbott <bpabbott@mac.com>
parents: 14585
diff changeset
327 elseif (nargs > 1 && iscellstr (varargin{1}))
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
328 ## Cell array of labels followed by property/value pairs
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
329 propvals = varargin(2:end);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
330 if (rem (numel (propvals), 2) != 0)
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
331 error ("legend: PROPERTY/VALUE arguments must occur in pairs");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
332 endif
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
333 varargin = {varargin{1}{:}};
14589
fd6e50e2eee6 legend() should accept labels being specified as both cellstrs and char.
Ben Abbott <bpabbott@mac.com>
parents: 14585
diff changeset
334 nargs = numel (varargin);
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
335 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
336
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
337 have_labels = (nargs > 0);
18734
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
338 hobjects = [];
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
339 hplots = [];
18734
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
340 text_strings = {};
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
341
18734
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
342 if (delete_leg)
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
343 delete (hlegend);
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
344 hlegend = [];
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
345 elseif (find_leg_hdl)
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
346 ## Don't change anything about legend.
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
347 ## hleg output will be assigned hlegend value at end of function.
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
348 elseif (strcmp (show, "off"))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
349 if (! isempty (hlegend))
21898
b5313b6cbe72 Simplify handling of 'box' property for legend axes objects.
Rik <rik@octave.org>
parents: 21758
diff changeset
350 set (hlegend, "visible", "off");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
351 hlegend = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
352 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
353 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
354 if (! isempty (hlegend))
21898
b5313b6cbe72 Simplify handling of 'box' property for legend axes objects.
Rik <rik@octave.org>
parents: 21758
diff changeset
355 set (hlegend, "visible", "on");
b5313b6cbe72 Simplify handling of 'box' property for legend axes objects.
Rik <rik@octave.org>
parents: 21758
diff changeset
356 ## NOTE: Matlab sets both "visible" and "box" to "on" for "show on"
b5313b6cbe72 Simplify handling of 'box' property for legend axes objects.
Rik <rik@octave.org>
parents: 21758
diff changeset
357 ## set (hlegend, "box", "on");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
358 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
359 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
360 if (! isempty (hlegend))
21898
b5313b6cbe72 Simplify handling of 'box' property for legend axes objects.
Rik <rik@octave.org>
parents: 21758
diff changeset
361 set (hlegend, "box", "on");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
362 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
363 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
364 if (! isempty (hlegend))
21898
b5313b6cbe72 Simplify handling of 'box' property for legend axes objects.
Rik <rik@octave.org>
parents: 21758
diff changeset
365 set (hlegend, "box", "off");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
366 endif
18734
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
367 elseif (! have_labels && ! isempty (hlegend)
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
368 && ! (strcmp (location, "default")
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
369 && strcmp (orientation, "default")))
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
370 ## Changing location or orientation of existing legend
18734
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
371 if (strcmp (location, "default"))
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
372 set (hlegend, "orientation", orientation);
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
373 elseif (strcmp (orientation, "default"))
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
374 if (outside)
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
375 set (hlegend, "location", [location "outside"]);
12398
735e43b75e45 Allow the legend location and orientation to be set without modifying the legend keys (#32374)
David Bateman <dbateman@free.fr>
parents: 12396
diff changeset
376 else
18734
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
377 set (hlegend, "location", location);
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
378 endif
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
379 else
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
380 if (outside)
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
381 set (hlegend, "location", [location "outside"],
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
382 "orientation", orientation);
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
383 else
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
384 set (hlegend, "location", location,
adb948d7fae4 legend.m: Don't create legend for some inputs for Matlab compatibility (bug #42034)
Rik <rik@octave.org>
parents: 18647
diff changeset
385 "orientation", orientation);
12398
735e43b75e45 Allow the legend location and orientation to be set without modifying the legend keys (#32374)
David Bateman <dbateman@free.fr>
parents: 12396
diff changeset
386 endif
735e43b75e45 Allow the legend location and orientation to be set without modifying the legend keys (#32374)
David Bateman <dbateman@free.fr>
parents: 12396
diff changeset
387 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
388 else
24403
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
389 ## Create or modify legend object
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
390
24403
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
391 if (! isempty (hlegend))
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
392 ## Disable callbacks while modifying an existing legend
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
393 setappdata (hlegend, "nocallbacks", true);
24403
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
394 endif
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
395
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
396 if (have_labels)
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
397 ## Check for valid data that can be labeled.
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
398 have_data = false;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
399 have_dname = false;
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
400 for hkid = kids.'
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
401 typ = get (hkid, "type");
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
402 if (any (strcmp (typ, {"line", "patch", "surface", "hggroup"})))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
403 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
404 break;
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 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
407
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
408 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
409 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
410 endif
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
411 else
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
412 ## No labels. Search for DisplayName property.
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
413 have_dname = false;
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
414 n_dname = 0;
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
415 for hkid = kids.'
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
416 typ = get (hkid, "type");
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
417 if (any (strcmp (typ, {"line", "patch", "surface", "hggroup"})))
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
418 n_dname += 1; # count of objects which could be labeled
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
419 if (! isempty (get (hkid, "displayname")))
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
420 have_dname = true;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
421 break;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
422 endif
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
423 endif
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
424 endfor
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
425 have_data = n_dname > 0;
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
426 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
427
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
428 if (have_labels || ! have_dname)
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
429 k = nkids;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
430 if (! have_labels)
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
431 ## No labels or DisplayName. Create set of "dataX" labels.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
432 if (n_dname > 20)
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
433 warning ("legend: labeling only first 20 data objects");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
434 n_dname = 20;
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
435 endif
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
436 nargs = n_dname;
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
437 varargin = arrayfun (@(x) sprintf ("data%d", x), [1:nargs]',
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
438 "uniformoutput", false);
16795
38c1a421f082 When no keys are specified and defaults are populated, set have_labels = true.
Ben Abbott <bpabbott@mac.com>
parents: 16728
diff changeset
439 have_labels = true;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
440 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
441 for i = 1 : nargs
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
442 label = varargin{i};
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
443 if (! ischar (label))
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
444 error ("legend: expecting label to be a string");
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
445 endif
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
446 ## Locate an object which can be labeled
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
447 while (k > 0)
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
448 typ = get (kids(k), "type");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
449 if (any (strcmp (typ, {"line","patch","surface","hggroup"})))
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
450 break;
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
451 endif
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
452 k--;
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
453 endwhile
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
454 if (k > 0)
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
455 set (kids(k), "displayname", label);
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
456 hplots(end+1) = kids(k);
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
457 text_strings(end+1) = label;
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
458 k--;
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
459 else
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
460 if (have_data)
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
461 warning ("legend: ignoring extra labels");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
462 endif
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
463 break; # k = 0, no further handles to process
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
464 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
465 endfor
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
466
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
467 else
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
468 ## No labels specified but objects have DisplayName property set.
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
469 k = nkids;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
470 while (k > 0)
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
471 ## Locate object to label
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
472 while (k > 0)
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
473 typ = get (kids(k), "type");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
474 if (any (strcmp (typ, {"line","patch","surface","hggroup"})))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
475 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
476 endif
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
477 k--;
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
478 endwhile
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
479 if (k > 0)
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
480 dname = get (kids(k), "displayname");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
481 if (! isempty (dname))
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
482 hplots(end+1) = kids(k);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
483 text_strings(end+1) = dname;
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
484 endif
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
485 k--;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
486 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
487 endwhile
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
488 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
489
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
490 if (isempty (hplots))
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
491 ## Nothing to label
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
492 if (! isempty (hlegend))
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
493 delete (hlegend);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
494 hlegend = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
495 hobjects = [];
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
496 hplots = [];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
497 text_strings = {};
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
498 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
499 else
14578
f579a94aacaa Preserve legend handle when changing properties (Bug # 36259).
Carnë Draug <carandraug+dev@gmail.com>
parents: 14552
diff changeset
500 ## Preserve the old legend if it exists
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
501 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
502 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
503 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
504 endif
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
505 if (strcmp (location, "default"))
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
506 location = get (hlegend, "location");
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
507 inout = strfind (location, "outside");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
508 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
509 outside = true;
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
510 location = location(1:inout-1);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
511 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
512 outside = false;
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 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
515 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
516 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
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 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
519 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
520 if (strcmp (textpos, "default"))
17532
492d609d2d75 legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents: 17530
diff changeset
521 textpos = "right";
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
522 endif
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
523 if (strcmp (location, "default"))
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
524 location = "northeast";
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
525 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
526 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
527 orientation = "vertical";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
528 endif
14529
aabdc8f281f1 legend.m: Change default to boxon for Matlab compatibility (bug #36105).
Rik <octave@nomad.inbox5.com>
parents: 14375
diff changeset
529 box = "on";
6272
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
530 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
531
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
532 ## Use axis which is appropriate for legend location.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
533 ## This is only necessary for plotyy figures where there are two axes.
24335
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
534 if (numel (ca) == 1)
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
535 cax = ca(1);
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
536 elseif (strfind (location, "east"))
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
537 cax = ca(2);
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
538 else
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
539 cax = ca(1);
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
540 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
541 ## Get axis size and fontsize in points.
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
542 ## Rely on listener to handle conversion.
24335
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
543 units = get (cax, "units");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
544 unwind_protect
24335
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
545 set (cax, "units", "points");
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
546 set (cax, "fontunits", "points");
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
547 if (isempty (hlegend) || ! isprop (hlegend, "unmodified_axes_position"))
24335
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
548 unmodified_axes_position = get (cax, "position");
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
549 unmodified_axes_outerposition = get (cax, "outerposition");
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
550 else
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
551 unmodified_axes_position = get (hlegend, "unmodified_axes_position");
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
552 unmodified_axes_outerposition = get (hlegend, ...
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
553 "unmodified_axes_outerposition");
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
554 endif
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
555 ca_pos = unmodified_axes_position;
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
556 ca_outpos = unmodified_axes_outerposition;
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
557 tightinset = get (ca(1), "tightinset");
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
558 for i = 2 : numel (ca)
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
559 tightinset = max (tightinset, get (ca(i), "tightinset"));
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
560 endfor
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
561 unwind_protect_cleanup
24335
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
562 set (cax, "units", units);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
563 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
564
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
565 ## Padding between legend entries horizontally and vertically
26228
4f044bc43f07 legend.m: Space out legend objects 1/3 of a point more in x-direction (bug #55189).
Rik <rik@octave.org>
parents: 26217
diff changeset
566 ## measured in points.
4f044bc43f07 legend.m: Space out legend objects 1/3 of a point more in x-direction (bug #55189).
Rik <rik@octave.org>
parents: 26217
diff changeset
567 ## FIXME: 3*xpad must be integer or strange off-by-1 pixel issues
4f044bc43f07 legend.m: Space out legend objects 1/3 of a point more in x-direction (bug #55189).
Rik <rik@octave.org>
parents: 26217
diff changeset
568 ## with lines in OpenGL.
4f044bc43f07 legend.m: Space out legend objects 1/3 of a point more in x-direction (bug #55189).
Rik <rik@octave.org>
parents: 26217
diff changeset
569 xpad = 2 + 1/3;
26189
05e8cc761c14 legend.m: Increase spacing between multiple labels (bug #55189).
Rik <rik@octave.org>
parents: 25949
diff changeset
570 ypad = 4;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
571
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
572 bpad = 8; # padding of legend box from surrounding axes
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
573
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
574 linelength = 15;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
575
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
576 ## Preamble code to restore figure and axes after legend creation
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
577 origfig = get (0, "currentfigure");
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
578 if (origfig != hfig)
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
579 set (0, "currentfigure", hfig);
18647
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
580 else
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
581 origfig = [];
18647
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
582 endif
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
583 origaxes = get (hfig, "currentaxes");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
584 unwind_protect
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
585 ud = ancestor (hplots, "axes");
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
586 if (! isscalar (ud))
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
587 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
588 endif
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
589 hpar = get (ud(1), "parent");
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
590
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
591 if (isempty (hlegend))
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
592 ## Create a legend object (axes + new properties)
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
593 addprops = true;
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
594 hlegend = axes ("parent", hpar, "tag", "legend",
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
595 "box", box,
14529
aabdc8f281f1 legend.m: Change default to boxon for Matlab compatibility (bug #36105).
Rik <octave@nomad.inbox5.com>
parents: 14375
diff changeset
596 "xtick", [], "ytick", [],
14578
f579a94aacaa Preserve legend handle when changing properties (Bug # 36259).
Carnë Draug <carandraug+dev@gmail.com>
parents: 14552
diff changeset
597 "xlim", [0, 1], "ylim", [0, 1],
20286
42b7d7758c4a Remove axes "interpreter" property (bug #45388)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20231
diff changeset
598 "activepositionproperty", "position");
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
599 setappdata (hlegend, "__axes_handle__", ud);
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
600 try
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
601 addproperty ("__legend_handle__", ud(1), "handle", hlegend);
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
602 catch
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
603 set (ud(1), "__legend_handle__", hlegend);
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
604 end_try_catch
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
605
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
606 ## Inherit fontsize from current axis
24335
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
607 ## "fontunits" should be first because it affects interpretation
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
608 ## of "fontsize" property.
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
609 [fontunits, fontsz] = get (ca(1), {"fontunits", "fontsize"}){:};
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
610 fontsz *= 0.90; # Reduce legend fontsize to 90% of axes fontsize
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
611 set (hlegend, {"fontunits", "fontsize"}, {fontunits, fontsz});
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
612 set (hlegend, "fontunits", "points"); # legend always works in pts.
20408
71bd638e0ef6 legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents: 20286
diff changeset
613 old_hplots = [];
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
614 else
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
615 ## Re-use existing legend.
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
616 addprops = false;
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
617 axes (hlegend);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
618 delete (get (hlegend, "children"));
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
619 ## Hack: get list of hplots for which addlistener has been called.
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
620 old_hplots = get (hlegend, "deletefcn"){6};
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
621 endif
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
622
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
623 if (addprops)
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
624 ## Only required for a newly created legend object
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
625 ## FIXME: "autoupdate" is not implemented.
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
626 addproperty ("autoupdate", hlegend, "radio", "{on}|off");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
627 addproperty ("edgecolor", hlegend, "color", [0.15, 0.15, 0.15]);
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
628 addproperty ("textcolor", hlegend, "color", [0, 0, 0]);
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
629 locations = {"north", "south", "east", "west", ...
17536
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
630 "{northeast}", "southeast", "northwest", "southwest", ...
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
631 "northoutside", "southoutside", ...
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
632 "eastoutside", "westoutside", ...
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
633 "northeastoutside", "southeastoutside", ...
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
634 "northwestoutside", "southwestoutside", "best", ...
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
635 "bestoutside", "none"};
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
636 addproperty ("location", hlegend, "radio", strjoin (locations, "|"));
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
637 addproperty ("orientation", hlegend, "radio",
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
638 "{vertical}|horizontal");
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
639 addproperty ("string", hlegend, "any", text_strings);
20286
42b7d7758c4a Remove axes "interpreter" property (bug #45388)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20231
diff changeset
640 addproperty ("interpreter", hlegend, "textinterpreter");
17536
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
641 addproperty ("textposition", hlegend, "radio", "left|{right}");
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
642 endif
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
643
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
644 ## Apply any PROPERTY/VALUE pairs given as arguments
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
645 if (! isempty (propvals))
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
646 set (hlegend, propvals{:});
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
647 endif
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
648
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
649 ## Text objects in key inherit visual properties from legend object
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
650 legprops = { "fontunits", "fontangle", "fontname", "fontsize", ...
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
651 "fontweight", "interpreter", "textcolor" };
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
652
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
653 txtprops = { "fontunits", [], "fontangle", [] "fontname", [], ...
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
654 "fontsize", [], "fontweight", [] "interpreter", [], ...
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
655 "color", [] };
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
656 propvals = get (hlegend, legprops);
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
657 txtprops(2:2:end) = propvals;
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
658
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
659 ## Add text labels to the axes first and check their extents
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
660 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
661 texthandle = [];
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
662 maxwidth = maxheight = 0;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
663 for k = 1 : nentries
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
664 halign = ifelse (strcmp (textpos, "right"), "left", "right");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
665 texthandle(k) = text (0, 0, text_strings{k},
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
666 "units", "points",
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
667 "horizontalalignment", halign,
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
668 txtprops{:});
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
669 setappdata (texthandle(k), "handle", hplots(k));
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
670 extents = get (texthandle(k), "extent");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
671 maxwidth = max (maxwidth, extents(3));
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
672 maxheight = max (maxheight, extents(4));
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
673 endfor
26189
05e8cc761c14 legend.m: Increase spacing between multiple labels (bug #55189).
Rik <rik@octave.org>
parents: 25949
diff changeset
674 ## Restore units which were forced to points
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
675 set (texthandle, "units", get (0, "DefaultTextUnits"));
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
676
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
677 num1 = nentries;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
678 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
679 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
680 if (outside)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
681 if (height > ca_pos(4))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
682 ## 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
683 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
684 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
685 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
686 if (height > 0.9 * ca_pos(4))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
687 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
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 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
690 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
691 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
692 if (outside)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
693 if (width > ca_pos(3))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
694 ## 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
695 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
696 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
697 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
698 if (width > 0.9 * ca_pos(3))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
699 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
700 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
701 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
702 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
703 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
704
26228
4f044bc43f07 legend.m: Space out legend objects 1/3 of a point more in x-direction (bug #55189).
Rik <rik@octave.org>
parents: 26217
diff changeset
705 ## Layout is [xpad, linelength, xpad, maxwidth, xpad]
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
706 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
707 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
708 xoffset = xpad;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
709 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
710 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
711 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
712 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
713 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
714 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
715 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
716
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
717 ## Place the legend in the desired location
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
718 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
719 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
720 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
721 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
722 endif
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
723
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
724 gnuplot = strcmp (get (hfig, "__graphics_toolkit__"), "gnuplot");
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
725 if (gnuplot)
24335
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
726 ## gnuplot places the key (legend) at edge of the figure window.
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
727 ## OpenGL places the legend box at edge of the unmodified axes
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
728 ## position.
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
729 if (isempty (strfind (location, "east")))
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
730 gnuplot_offset = unmodified_axes_outerposition(1) ...
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
731 + unmodified_axes_outerposition(3) ...
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
732 - unmodified_axes_position(1) ...
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
733 - unmodified_axes_position(3);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
734 else
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
735 gnuplot_offset = unmodified_axes_position(1) ...
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
736 - unmodified_axes_outerposition(1);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
737 endif
17179
828e8852efa9 legend.m: Add %!demo block showing bug #39697.
Rik <rik@octave.org>
parents: 17174
diff changeset
738 ## FIXME: The "fontsize" is added to match the behavior of OpenGL.
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
739 ## This implies that a change in fontsize should trigger a listener
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
740 ## to update the legend. The "2" was determined using a long legend
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
741 ## key in the absence of any subplots.
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
742 gnuplot_offset -= 2 * get (hlegend, "fontsize");
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
743 else
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
744 gnuplot_offset = 0;
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
745 endif
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
746
24335
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
747 ## For legend's outside the associated axes position,
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
748 ## align their edge to the unmodified_axes_outerposition,
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
749 ## and adjust the axes position accordingly.
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
750 switch (location)
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
751 case "north"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
752 if (outside)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
753 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ...
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
754 ca_outpos(2) + ca_outpos(4) - lpos(4) - bpad/2, ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
755 lpos(3), lpos(4)];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
756
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
757 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
758 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
759 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ...
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
760 ca_pos(2) + ca_pos(4) - lpos(4) - bpad, ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
761 lpos(3), lpos(4)];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
762 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
763 case "south"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
764 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
765 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ...
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
766 ca_outpos(2) + bpad/2, lpos(3), lpos(4)];
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
767 new_pos = [ca_pos(1), ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
768 lpos(2) + lpos(4) + bpad/2 + tightinset(2), ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
769 ca_pos(3), ca_pos(4) - lpos(4)];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
770 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
771 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ...
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
772 ca_pos(2) + bpad, lpos(3), lpos(4)];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
773 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
774 case "east"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
775 if (outside)
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
776 lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3) - bpad/2, ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
777 ca_pos(2) + (ca_pos(4) - lpos(4)) / 2, ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
778 lpos(3), lpos(4)];
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
779 new_pos = [ca_pos(1), ca_pos(2), ...
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
780 lpos(1) - bpad - tightinset(3) - ca_pos(1), ...
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
781 ca_pos(4)];
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
782 new_pos(3) += gnuplot_offset;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
783 else
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
784 lpos = [ca_pos(1) + ca_pos(3) - lpos(3) - bpad, ...
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
785 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
786 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
787 case "west"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
788 if (outside)
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
789 lpos = [ca_outpos(1) + bpad/2, ...
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
790 ca_pos(2) + (ca_pos(4) - lpos(4)) / 2, ...
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
791 lpos(3), lpos(4)];
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
792 new_pos = [lpos(1) + lpos(3) + bpad/2 + tightinset(1), ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
793 ca_pos(2), ca_pos(3) - lpos(3) - bpad/2, ca_pos(4)];
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
794 new_pos([1, 3]) += [-gnuplot_offset, gnuplot_offset];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
795 else
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
796 lpos = [ca_pos(1) + bpad, ...
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
797 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
798 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
799 case "northeast"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
800 if (outside)
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
801 lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3) - bpad/2, ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
802 ca_pos(2) + ca_pos(4) - lpos(4), ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
803 lpos(3), lpos(4)];
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
804 new_pos = [ca_pos(1), ca_pos(2), ...
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
805 lpos(1) - bpad - tightinset(3) - ca_pos(1), ...
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
806 ca_pos(4)];
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
807 new_pos(3) += gnuplot_offset;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
808 else
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
809 lpos = [ca_pos(1) + ca_pos(3) - lpos(3) - bpad, ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
810 ca_pos(2) + ca_pos(4) - lpos(4) - bpad, ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
811 lpos(3), lpos(4)];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
812 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
813 case "northwest"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
814 if (outside)
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
815 lpos = [ca_outpos(1) + bpad/2, ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
816 ca_pos(2) + ca_pos(4) - lpos(4), ...
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
817 lpos(3), lpos(4)];
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
818 new_pos = [lpos(1) + lpos(3) + bpad/2 + tightinset(1), ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
819 ca_pos(2), ca_pos(3) - lpos(3) - bpad/2, ca_pos(4)];
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
820 new_pos([1, 3]) += [-gnuplot_offset, gnuplot_offset];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
821 else
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
822 lpos = [ca_pos(1) + bpad, ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
823 ca_pos(2) + ca_pos(4) - lpos(4) - bpad, ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
824 lpos(3), lpos(4)];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
825 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
826 case "southeast"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
827 if (outside)
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
828 lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3) - bpad/2, ...
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
829 ca_pos(2), lpos(3), lpos(4)];
12395
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
830 new_pos = [ca_pos(1), ca_pos(2), ...
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
831 lpos(1) - bpad - ca_pos(1) - tightinset(3), ...
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
832 ca_pos(4)];
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
833 new_pos(3) += gnuplot_offset;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
834 else
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
835 lpos = [ca_pos(1) + ca_pos(3) - lpos(3) - bpad, ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
836 ca_pos(2) + bpad, lpos(3), lpos(4)];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
837 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
838 case "southwest"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
839 if (outside)
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
840 lpos = [ca_outpos(1) + bpad/2, ca_pos(2), lpos(3), lpos(4)];
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
841 new_pos = [lpos(1) + lpos(3) + bpad/2 + tightinset(1), ...
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
842 ca_pos(2), ca_pos(3) - lpos(3) - bpad/2, ca_pos(4)];
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
843 new_pos([1, 3]) += [-gnuplot_offset, gnuplot_offset];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
844 else
26243
b22a2aa820e6 legend.m: Implement new placement algorithm with larger spacing from axes.
Rik <rik@octave.org>
parents: 26239
diff changeset
845 lpos = [ca_pos(1) + bpad, ca_pos(2) + bpad, lpos(3), lpos(4)];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
846 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
847 endswitch
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
848
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
849 units = get (hlegend, "units");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
850 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
851 set (hlegend, "units", "points");
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
852 set (hlegend, "position", lpos);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
853 unwind_protect_cleanup
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
854 set (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
855 end_unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
856
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
857 ## Now write the line segments and place the text objects correctly
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
858 xk = yk = 0;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
859 for k = 1 : numel (hplots)
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
860 hobjects(end+1) = texthandle(k);
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
861 hplt = hplots(k);
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
862 typ = get (hplt, "type");
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
863 ## For an hggroup, find an underlying primitive object
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
864 if (strcmp (typ, "hggroup"))
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
865 for hgkid = get (hplt, "children").'
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
866 hgkid_type = get (hgkid, "type");
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
867 if (any (strcmp (hgkid_type, {"line","patch","surface"})))
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
868 typ = hgkid_type;
21937
55f7de37b618 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 21904
diff changeset
869 hplt = hgkid;
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
870 break;
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
871 endif
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
872 endfor
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
873 endif
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
874
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
875 switch (typ)
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
876
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
877 case "line"
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
878 color = get (hplt, "color");
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
879 style = get (hplt, "linestyle");
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
880 lwidth = min (get (hplt, "linewidth"), 5);
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
881 if (! strcmp (style, "none"))
26217
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
882 l1 = __go_line__ (hlegend, ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
883 "xdata", ([xoffset, xoffset + linelength] + xk * xstep) / lpos(3), ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
884 "ydata", [1, 1] .* (lpos(4) - yoffset - yk * ystep) / lpos(4), ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
885 "color", color, "linestyle", style, ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
886 "linewidth", lwidth, "marker", "none");
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
887 setappdata (l1, "handle", hplt);
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
888 hobjects(end+1) = l1;
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
889 endif
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
890 marker = get (hplt, "marker");
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
891 if (! strcmp (marker, "none"))
26217
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
892 l1 = __go_line__ (hlegend, ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
893 "xdata", (xoffset + 0.5 * linelength + xk * xstep) / lpos(3), ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
894 "ydata", (lpos(4) - yoffset - yk * ystep) / lpos(4), ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
895 "color", color, "linestyle", "none", ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
896 "linewidth", lwidth, "marker", marker, ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
897 "markeredgecolor", get (hplt, "markeredgecolor"), ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
898 "markerfacecolor", get (hplt, "markerfacecolor"), ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
899 "markersize", min (get (hplt, "markersize"),10));
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
900 setappdata (l1, "handle", hplt);
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
901 hobjects(end+1) = l1;
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
902 endif
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
903
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
904 ## Newly labeled objects have listeners added
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
905 if (! any (hplt == old_hplots))
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
906 addlistener (hplt, "color",
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
907 {@cb_line_listener, hlegend, linelength, false});
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
908 addlistener (hplt, "linestyle",
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
909 {@cb_line_listener, hlegend, linelength, false});
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
910 addlistener (hplt, "linewidth",
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
911 {@cb_line_listener, hlegend, linelength, false});
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
912 addlistener (hplt, "marker",
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
913 {@cb_line_listener, hlegend, linelength, false});
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
914 addlistener (hplt, "markeredgecolor",
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
915 {@cb_line_listener, hlegend, linelength, false});
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
916 addlistener (hplt, "markerfacecolor",
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
917 {@cb_line_listener, hlegend, linelength, false});
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
918 addlistener (hplt, "markersize",
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
919 {@cb_line_listener, hlegend, linelength, false});
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
920 addlistener (hplt, "displayname",
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
921 {@cb_line_listener, hlegend, linelength, true});
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
922 endif
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
923
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
924 case "patch"
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
925 facecolor = get (hplt, "facecolor");
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
926 edgecolor = get (hplt, "edgecolor");
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
927 cdata = get (hplt, "cdata");
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
928 if (! strcmp (facecolor, "none") || ! strcmp (edgecolor, "none"))
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
929 p1 = patch ("xdata", ([0, linelength, linelength, 0] +
17536
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
930 xoffset + xk * xstep) / lpos(3),
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
931 "ydata", (lpos(4) - yoffset -
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
932 [yk-0.3, yk-0.3, yk+0.3, yk+0.3] .* ystep) / lpos(4),
18564
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
933 "facecolor", facecolor, "edgecolor", edgecolor,
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
934 "cdata", cdata);
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
935 setappdata (p1, "handle", hplt);
18564
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
936 else
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
937 ## non-standard patch only making use of marker styles
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
938 ## such as scatter plot.
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
939 p1 = patch ("xdata", (xoffset + 0.5 * linelength + xk * xstep) / lpos(3),
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
940 "ydata", (lpos(4) - yoffset - yk * ystep) / lpos(4),
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
941 "marker", get (hplt, "marker"),
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
942 "markeredgecolor",get (hplt,"markeredgecolor"),
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
943 "markerfacecolor",get (hplt,"markerfacecolor"),
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
944 "markersize", min (get (hplt,"markersize"),10),
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
945 "cdata", cdata);
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
946 setappdata (p1, "handle", hplt);
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
947 endif
18564
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
948 hobjects(end+1) = p1;
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
949 ## Copy clim from axes so that colors work out.
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
950 set (hlegend, "clim", get (ca(1), "clim"));
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
951
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
952 ## FIXME: Need listeners, as for line objects.
17730
580990c2ce04 legend.m: Fix legend color for bar graphs (bug #40327)
Rik <rik@octave.org>
parents: 17677
diff changeset
953 ## Changing clim, for example, won't update colors
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
954
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
955 case "surface"
21904
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
956 facecolor = get (hplt, "facecolor");
7aa8d9c28d2b legend.m: Return the correct third argument (h_plots) when plot has hggroups (bug #48210).
Rik <rik@octave.org>
parents: 21898
diff changeset
957 edgecolor = get (hplt, "edgecolor");
17560
225ec9a0222a legend.m: Use axis that legend refers to when calculating color for surface patch label.
Rik <rik@octave.org>
parents: 17540
diff changeset
958 cdata = sum (get (ca(1), "clim")) / 2;
17540
b7aa1d726bcc legend.m: Add support for surface objects.
Rik <rik@octave.org>
parents: 17538
diff changeset
959 if (! strcmp (facecolor, "none") || ! strcmp (edgecolor, "none"))
b7aa1d726bcc legend.m: Add support for surface objects.
Rik <rik@octave.org>
parents: 17538
diff changeset
960 p1 = patch ("xdata", ([0, linelength, linelength, 0] +
b7aa1d726bcc legend.m: Add support for surface objects.
Rik <rik@octave.org>
parents: 17538
diff changeset
961 xoffset + xk * xstep) / lpos(3),
b7aa1d726bcc legend.m: Add support for surface objects.
Rik <rik@octave.org>
parents: 17538
diff changeset
962 "ydata", (lpos(4) - yoffset -
b7aa1d726bcc legend.m: Add support for surface objects.
Rik <rik@octave.org>
parents: 17538
diff changeset
963 [yk-0.3, yk-0.3, yk+0.3, yk+0.3] .* ystep) / lpos(4),
18564
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
964 "facecolor", facecolor, "edgecolor", edgecolor,
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
965 "cdata", cdata);
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
966 setappdata (p1, "handle", hplt);
17540
b7aa1d726bcc legend.m: Add support for surface objects.
Rik <rik@octave.org>
parents: 17538
diff changeset
967 hobjects(end+1) = p1;
b7aa1d726bcc legend.m: Add support for surface objects.
Rik <rik@octave.org>
parents: 17538
diff changeset
968 endif
18564
3a1a4d587c4e legend.m: Correctly create legend for scatter plots (bug #33463).
Rik <rik@octave.org>
parents: 18423
diff changeset
969 ## FIXME: Need listeners, as for line objects.
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
970
10999
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
971 endswitch
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
972
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
973 set (texthandle(k), "position",
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
974 [(txoffset + xk * xstep) / lpos(3), ...
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
975 (lpos(4) - yoffset - yk * ystep) / lpos(4)]);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
976 if (strcmp (orientation, "vertical"))
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20711
diff changeset
977 yk += 1;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
978 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
979 yk = 0;
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20711
diff changeset
980 xk += 1;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
981 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
982 else
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20711
diff changeset
983 xk += 1;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
984 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
985 xk = 0;
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20711
diff changeset
986 yk += 1;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
987 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
988 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
989 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
990
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
991 ## Add an invisible text object to original axis
24335
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
992 ## that, when it is destroyed, will remove the legend.
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
993 htdel = findall (ca(1), "-depth", 1, "tag", "deletelegend",
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
994 "type", "text");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
995 if (isempty (htdel))
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
996 htdel = text (0, 0, "", "parent", ca(1), "tag", "deletelegend",
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
997 "visible", "off", "handlevisibility", "off",
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
998 "xliminclude", "off", "yliminclude", "off",
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
999 "zliminclude", "off");
24482
b4e371b5f6b5 Fix shrinking plots when colorbar or legend in "outside" location (bug #52732).
Rik <rik@octave.org>
parents: 24478
diff changeset
1000 set (htdel, "deletefcn", {@cb_axes_deleted, ca, hlegend});
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1001 endif
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1002 if (isprop (hlegend, "unmodified_axes_position"))
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1003 set (hlegend, "unmodified_axes_position",
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1004 unmodified_axes_position,
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1005 "unmodified_axes_outerposition",
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1006 unmodified_axes_outerposition);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1007 else
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1008 addproperty ("unmodified_axes_position", hlegend,
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1009 "data", unmodified_axes_position);
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1010 addproperty ("unmodified_axes_outerposition", hlegend,
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1011 "data", unmodified_axes_outerposition);
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1012 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1013
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1014 ## Resize the axis that the legend is attached to if the legend is
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1015 ## "outside" the plot and create a listener to resize axis to original
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1016 ## size if the legend is deleted, hidden, or shown.
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1017 if (outside)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1018 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
1019 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
1020 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1021 set (ca(i), "units", "points");
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
1022 if (gnuplot && numel (ca) == 1)
24335
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
1023 ## Let gnuplot handle the positioning of the keybox.
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
1024 ## This violates strict Matlab compatibility, but reliably
24335
8edaf9c80779 Fix legend placement for plotyy figures (bug #52547).
Rik <rik@octave.org>
parents: 23573
diff changeset
1025 ## renders an aesthetic result.
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
1026 set (ca(i), "position", unmodified_axes_position);
21385
89fa0694aa2e Fix check-missing-semicolon QA target (bug #47277).
Rik <rik@octave.org>
parents: 20852
diff changeset
1027 set (ca(i), "activepositionproperty", "outerposition");
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
1028 else
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
1029 ## numel (ca) > 1 for axes overlays (like plotyy)
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
1030 set (ca(i), "position", new_pos);
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
1031 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1032 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
1033 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
1034 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
1035 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1036
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1037 set (hlegend, "deletefcn", {@cb_restore_axes, ca, ...
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1038 unmodified_axes_position, ...
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
1039 unmodified_axes_outerposition, ...
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1040 htdel, hplots});
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1041 addlistener (hlegend, "visible", {@cb_legend_hideshow, ca, ...
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
1042 unmodified_axes_position, ...
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
1043 new_pos});
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1044 else
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1045 set (hlegend, "deletefcn", {@cb_restore_axes, ca, [], [], ...
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1046 htdel, hplots});
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1047 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1048
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
1049 if (! addprops)
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1050 ## Remove listeners on existing legend temporarily to stop recursion.
17536
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1051 dellistener (hlegend, "location");
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1052 dellistener (hlegend, "orientation");
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1053 dellistener (hlegend, "string");
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1054 dellistener (hlegend, "textposition");
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1055 endif
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1056
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1057 if (! addprops)
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1058 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
1059 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1060
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1061 if (outside)
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
1062 set (hlegend, "location", [location "outside"],
17536
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1063 "orientation", orientation, "textposition", textpos);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1064 else
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
1065 set (hlegend, "location", location, "orientation", orientation,
17536
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1066 "textposition", textpos);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1067 endif
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1068
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1069 if (addprops)
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1070 addlistener (hlegend, "edgecolor", @cb_legend_text_update);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1071 addlistener (hlegend, "fontangle", @cb_legend_text_update);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1072 addlistener (hlegend, "fontname", @cb_legend_text_update);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1073 addlistener (hlegend, "fontweight", @cb_legend_text_update);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1074 addlistener (hlegend, "textcolor", @cb_legend_text_update);
17536
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1075 ## Properties which could change size of box, such as fontsize,
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1076 ## require legend to be redrawn.
17885
1d109119ac71 legend.m: Don't add listener for 'fontsize' if using gnuplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
1077 ## FIXME: fontsize is changed by print.m function during the
1d109119ac71 legend.m: Don't add listener for 'fontsize' if using gnuplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
1078 ## production of a plot for output. This screws things up
1d109119ac71 legend.m: Don't add listener for 'fontsize' if using gnuplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
1079 ## because legend tries to return the axes size to what it
1d109119ac71 legend.m: Don't add listener for 'fontsize' if using gnuplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
1080 ## was when the figure was created, versus what it is now
1d109119ac71 legend.m: Don't add listener for 'fontsize' if using gnuplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
1081 ## when the figure is being printed. Temporary hack is
1d109119ac71 legend.m: Don't add listener for 'fontsize' if using gnuplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
1082 ## good enough for generating the Octave manual which still
1d109119ac71 legend.m: Don't add listener for 'fontsize' if using gnuplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
1083 ## relies on gnuplot for generating images. See bug #40333.
1d109119ac71 legend.m: Don't add listener for 'fontsize' if using gnuplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
1084 if (! gnuplot)
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1085 addlistener (hlegend, "fontsize", @cb_legend_update);
17885
1d109119ac71 legend.m: Don't add listener for 'fontsize' if using gnuplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
1086 endif
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1087 addlistener (hlegend, "fontunits", @cb_legend_update);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1088 addlistener (hlegend, "interpreter", @cb_legend_update);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1089 addlistener (hlegend, "location", @cb_legend_location);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1090 addlistener (hlegend, "orientation", @cb_legend_update);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1091 addlistener (hlegend, "string", @cb_legend_update);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1092 addlistener (hlegend, "textposition", @cb_legend_update);
17536
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1093 ## FIXME: need to add listeners for tightinset and position
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
1094 ## addlistener (ca, "tightinset", @update????);
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
1095 ## addlistener (ca, "position", @update????);
17536
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1096 else
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1097 ## Restore listeners temporarily disabled during reconstruction.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1098 addlistener (hlegend, "location", @cb_legend_update);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1099 addlistener (hlegend, "orientation", @cb_legend_update);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1100 addlistener (hlegend, "string", @cb_legend_update);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1101 addlistener (hlegend, "textposition", @cb_legend_update);
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1102 endif
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1103
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1104 unwind_protect_cleanup
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1105 set (hfig, "currentaxes", origaxes);
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1106 if (! isempty (origfig))
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1107 set (0, "currentfigure", origfig);
18647
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1108 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1109 end_unwind_protect
6272
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
1110 endif
6147
e14b0e9b7bf7 [project @ 2006-11-09 03:28:01 by jwe]
jwe
parents: 6146
diff changeset
1111 endif
e14b0e9b7bf7 [project @ 2006-11-09 03:28:01 by jwe]
jwe
parents: 6146
diff changeset
1112
24403
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
1113 ## Restore operation of callbacks
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
1114 setappdata (hlegend, "nocallbacks", false);
24403
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
1115
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1116 if (nargout > 0)
17503
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
1117 hleg = hlegend;
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
1118 hleg_obj = hobjects;
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
1119 hplot = hplots;
d99785217634 legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents: 17281
diff changeset
1120 labels = text_strings;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1121 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1122
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1123 endfunction
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1124
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1125 ## A non-text property of legend has changed requiring an update.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1126 function cb_legend_update (hleg, ~)
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1127 persistent recursive = false;
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1128
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1129 if (! recursive)
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1130 recursive = true;
12339
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1131 unwind_protect
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1132 hax = getappdata (hleg, "__axes_handle__");
24464
359596cc55dd Fix ordering of legend objects when updated via callback (bug #46835).
Rik <rik@octave.org>
parents: 24434
diff changeset
1133 ## Hack. Maybe store this somewhere else such as appdata.
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1134 hplots = get (hleg, "deletefcn"){6};
24464
359596cc55dd Fix ordering of legend objects when updated via callback (bug #46835).
Rik <rik@octave.org>
parents: 24434
diff changeset
1135 text_strings = get (hleg, "string");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1136 position = get (hleg, "unmodified_axes_position");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1137 outerposition = get (hleg, "unmodified_axes_outerposition");
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1138 units = get (hax, "units");
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1139 set (hax, "units", "points");
16933
e39f00a32dc7 maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents: 16921
diff changeset
1140 switch (get (hax, "activepositionproperty"))
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
1141 case "position"
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
1142 set (hax, "outerposition", outerposition);
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
1143 set (hax, "position", position);
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
1144 case "outerposition"
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
1145 set (hax, "position", position);
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17125
diff changeset
1146 set (hax, "outerposition", outerposition);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1147 endswitch
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1148 if (isscalar (hax))
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1149 set (hax, "units", units);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1150 else
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1151 set (hax, {"units"}, units);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1152 endif
18644
8c0646dd9e5a legend.m: Fix bug updating plotyy figures (bug #41970).
Rik <rik@octave.org>
parents: 18564
diff changeset
1153
24464
359596cc55dd Fix ordering of legend objects when updated via callback (bug #46835).
Rik <rik@octave.org>
parents: 24434
diff changeset
1154 hleg = legend (hax(1), hplots, text_strings);
12339
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1155 unwind_protect_cleanup
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1156 recursive = false;
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1157 end_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
1158 endif
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1159
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1160 endfunction
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1161
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1162 ## A text property of legend, such as fontname, has changed.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1163 function cb_legend_text_update (hleg, ~)
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
1164
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1165 kids = get (hleg, "children");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1166 htext = kids(strcmp (get (kids, "type"), "text"));
17533
bb7756dff055 legend.m: Add listeners for all font properties to update text labels.
Rik <rik@octave.org>
parents: 17532
diff changeset
1167
17536
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1168 tprops = {"fontangle", "fontname", "fontweight", "color"};
8a186cd5b9a6 legend.m: Updating of font properties which affect box size, now redraws correctly sized legend.
Rik <rik@octave.org>
parents: 17535
diff changeset
1169 lprops = {"fontangle", "fontname", "fontweight", "textcolor"};
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1170 set (htext, tprops, get (hleg, lprops));
17535
5eae41c8c07f legend.m: Add support for "edgecolor" property.
Rik <rik@octave.org>
parents: 17534
diff changeset
1171
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1172 ec = get (hleg, "edgecolor");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1173 set (hleg, "xcolor", ec, "ycolor", ec);
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
1174
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1175 endfunction
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1176
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1177 ## The legend "visible" property has changed.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1178 function cb_legend_hideshow (hleg, ~, ca, orig_pos, new_pos)
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
1179
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1180 isvisible = strcmp (get (hleg, "visible"), "on");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1181
24426
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1182 ## FIXME: Can't use a single set() call because of linked axes and
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1183 ## listeners on plotyy graphs.
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1184 ca = ca(isaxes (ca));
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1185 for cax = ca(:).'
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1186 units = get (cax, "units");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1187 unwind_protect
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1188 set (cax, "units", "points");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1189 if (isvisible)
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1190 set (cax, "position", new_pos);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1191 else
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1192 set (cax, "position", orig_pos);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1193 endif
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1194 unwind_protect_cleanup
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1195 set (cax, "units", units);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1196 end_unwind_protect
10990
529b36293297 Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents: 10989
diff changeset
1197 endfor
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
1198
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1199 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
1200
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1201 ## The legend "location" property has changed.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1202 function cb_legend_location (hleg, d)
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1203
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1204 ## If it isn't "none", which means manual positioning, then rebuild .
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1205 if (! strcmp (get (hleg, "location"), "none"))
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1206 cb_legend_update (hleg, d);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1207 endif
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1208
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1209 endfunction
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1210
24482
b4e371b5f6b5 Fix shrinking plots when colorbar or legend in "outside" location (bug #52732).
Rik <rik@octave.org>
parents: 24478
diff changeset
1211 ## Axes to which legend was attached is being deleted/reset. Delete legend.
b4e371b5f6b5 Fix shrinking plots when colorbar or legend in "outside" location (bug #52732).
Rik <rik@octave.org>
parents: 24478
diff changeset
1212 function cb_axes_deleted (~, ~, ca, hlegend)
24426
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1213 if (isaxes (hlegend))
24482
b4e371b5f6b5 Fix shrinking plots when colorbar or legend in "outside" location (bug #52732).
Rik <rik@octave.org>
parents: 24478
diff changeset
1214 if (strcmp (get (ca(1), "beingdeleted"), "on"))
b4e371b5f6b5 Fix shrinking plots when colorbar or legend in "outside" location (bug #52732).
Rik <rik@octave.org>
parents: 24478
diff changeset
1215 ## Axes are being deleted. Disable call to cb_restore_axes.
b4e371b5f6b5 Fix shrinking plots when colorbar or legend in "outside" location (bug #52732).
Rik <rik@octave.org>
parents: 24478
diff changeset
1216 set (hlegend, "deletefcn", []);
b4e371b5f6b5 Fix shrinking plots when colorbar or legend in "outside" location (bug #52732).
Rik <rik@octave.org>
parents: 24478
diff changeset
1217 endif
21652
2e07dcdc6139 legend.m: Check handle is valid before delete (partial fix bug #47699).
Rik <rik@octave.org>
parents: 21580
diff changeset
1218 delete (hlegend);
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
1219 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1220 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
1221
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1222 ## Restore position of axes object when legend is deleted.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1223 function cb_restore_axes (~, ~, ca, pos, outpos, htdel, hplots)
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
1224
24426
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1225 hf = ancestor (ca(1), "figure");
25949
c2bf210ac94f style fixes
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
1226 if (strcmp (get (hf, "beingdeleted"), "on")
c2bf210ac94f style fixes
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
1227 || strcmp (get (ca(1), "beingdeleted"), "on"))
24426
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1228 ## Skip restoring axes if entire figure or axes is being destroyed.
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1229 return;
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1230 endif
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1231
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1232 ## Remove text object used to trigger legend delete when axes is deleted
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1233 if (ishghandle (htdel))
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1234 set (htdel, "deletefcn", []);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1235 delete (htdel);
24426
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1236 endif
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1237
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1238 ## Restore original axes positions
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1239 if (! isempty (pos))
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1240 ## FIXME: can't use single call to set() because of weirdness w/plotyy
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1241 for cax = ca(:).'
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1242 if (isaxes (cax))
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1243 units = get (cax, "units");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1244 unwind_protect
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1245 set (cax, "units", "points");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1246 set (cax, "position", pos);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1247 unwind_protect_cleanup
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1248 set (cax, "units", units);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1249 end_unwind_protect
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1250 endif
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1251 endfor
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1252 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
1253
24426
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1254 ## Remove listeners from plot objects
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1255 for i = 1 : numel (hplots)
24426
a51497205f4c Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents: 24423
diff changeset
1256 if (isgraphics (hplots(i), "line"))
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1257 dellistener (hplots(i), "color");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1258 dellistener (hplots(i), "linestyle");
18422
be3702a2eb8a legend.m: use linewidth from plot object in drawing legend (bug #41283)
Joachim Wiesemann <gnu@jwiesemann.com>
parents: 17885
diff changeset
1259 dellistener (hplots(i), "linewidth");
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1260 dellistener (hplots(i), "marker");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1261 dellistener (hplots(i), "markeredgecolor");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1262 dellistener (hplots(i), "markerfacecolor");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1263 dellistener (hplots(i), "markersize");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1264 dellistener (hplots(i), "displayname");
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1265 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1266 endfor
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
1267
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1268 ## Nullify legend link (can't delete properties yet)
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1269 set (ca(1), "__legend_handle__", []);
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1270
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1271 endfunction
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1272
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1273 ## Update legend item because underlying plot line object has changed.
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1274 function cb_line_listener (h, ~, hlegend, linelength, update_name)
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1275
24403
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
1276 ## Don't execute callbacks when legend is under construction
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
1277 legdata = getappdata (hlegend);
24403
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
1278 if (legdata.nocallbacks)
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
1279 return;
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
1280 endif
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
1281
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1282 if (update_name)
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1283 ## When string changes, have to rebuild legend completely
12339
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1284 [hplots, text_strings] = __getlegenddata__ (hlegend);
24403
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
1285 if (isempty (hplots))
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
1286 delete (hlegend);
b9462090773a legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents: 24399
diff changeset
1287 else
24464
359596cc55dd Fix ordering of legend objects when updated via callback (bug #46835).
Rik <rik@octave.org>
parents: 24434
diff changeset
1288 legend (legdata.handle(1), hplots, text_strings);
24398
a7dfb685d261 legend.m: Fix callback error when changing a legend string to "".
Rik <rik@octave.org>
parents: 23257
diff changeset
1289 endif
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1290 else
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1291 kids = get (hlegend, "children");
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
1292 kids = kids([getappdata(kids, "handle"){:}] == h);
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1293 kids = kids(strcmp (get (kids, "type"), "line"));
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1294 idx = strcmp (get (kids, "marker"), "none");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1295 ll = kids (idx);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1296 lm = kids (! idx);
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1297
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1298 [linestyle, marker, displayname] = ...
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1299 get (h, {"linestyle", "marker", "displayname"}){:};
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1300
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1301 if (! isempty (ll))
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1302 [xpos1, ypos1] = get (ll, {"xdata", "ydata"}){:};
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1303 xpos2 = sum (xpos1) / 2;
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1304 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
1305 delete (ll);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1306 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
1307 delete (lm);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1308 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1309 else
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1310 [xpos2, ypos2] = get (lm, {"xdata", "ydata"}){:};
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1311 xpos1 = xpos2 + [-0.5, 0.5] * linelength;
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1312 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
1313 delete (lm);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1314 endif
17537
4f57d4de0383 legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents: 17536
diff changeset
1315
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1316 if (! strcmp (linestyle, "none"))
26217
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1317 hl = __go_line__ (hlegend, "xdata", xpos1, "ydata", ypos1,
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1318 "color", get (h, "color"),
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1319 "linestyle", get (h, "linestyle"),
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1320 "linewidth", min (get (h, "linewidth"), 5),
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1321 "marker", "none");
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
1322 setappdata (hl, "handle", h);
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1323 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1324 if (! strcmp (marker, "none"))
26217
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1325 hl = __go_line__ (hlegend, "xdata", xpos2, "ydata", ypos2, ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1326 "color", get (h, "color"), ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1327 "marker", marker, "markeredgecolor", get (h, "markeredgecolor"), ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1328 "markerfacecolor", get (h, "markerfacecolor"), ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1329 "markersize", min (get (h, "markersize"), 10), ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1330 "linestyle", "none", ...
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 26189
diff changeset
1331 "linewidth", min (get (h, "linewidth"), 5));
24472
19d63669d174 Don't use "userdata" property internally for legend private data.
Rik <rik@octave.org>
parents: 24464
diff changeset
1332 setappdata (hl, "handle", h);
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1333 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1334 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21751
diff changeset
1335
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1336 endfunction
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1337
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1338
11418
a140991387fb legend.m: Add demo to legend for inline key.
Ben Abbott <bpabbott@mac.com>
parents: 11363
diff changeset
1339 %!demo
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1340 %! clf;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1341 %! plot (rand (2));
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1342 %! title ("legend called with string inputs for labels");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1343 %! h = legend ("foo", "bar");
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1344 %! legend (h, "location", "northeastoutside");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1345 %! set (h, "fontsize", 20);
11462
aed2c50c3082 legend.m: legend with more than two inline keys (bug 31991). Add/modifyy demos.
Ben Abbott <bpabbott@mac.com>
parents: 11434
diff changeset
1346
aed2c50c3082 legend.m: legend with more than two inline keys (bug 31991). Add/modifyy demos.
Ben Abbott <bpabbott@mac.com>
parents: 11434
diff changeset
1347 %!demo
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1348 %! clf;
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1349 %! plot (rand (2));
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1350 %! title ("legend called with cell array of strings");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1351 %! h = legend ({"cellfoo", "cellbar"});
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1352 %! legend (h, "location", "northeast");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1353 %! set (h, "fontsize", 20);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1354
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1355 %!demo
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1356 %! clf;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1357 %! plot (rand (3));
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1358 %! title ("legend () without inputs creates default labels");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1359 %! h = legend ();
14236
35903f035390 Escaping strings for legend entries are handled by __go_draw_axes__.
Ben Abbott <bpabbott@mac.com>
parents: 14214
diff changeset
1360
35903f035390 Escaping strings for legend entries are handled by __go_draw_axes__.
Ben Abbott <bpabbott@mac.com>
parents: 14214
diff changeset
1361 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1362 %! clf;
11418
a140991387fb legend.m: Add demo to legend for inline key.
Ben Abbott <bpabbott@mac.com>
parents: 11363
diff changeset
1363 %! x = 0:1;
22800
5de8670d10a6 Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents: 22624
diff changeset
1364 %! plot (x,x,";I am Blue;", x,2*x, x,3*x,";I am yellow;");
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1365 %! h = legend ("location", "northeastoutside");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1366 %! ## Placing legend inside returns axes to original size
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1367 %! legend (h, "location", "northeast");
22800
5de8670d10a6 Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents: 22624
diff changeset
1368 %! title ("Blue and Yellow keys, with Orange missing");
8343
9f34f7636fe0 legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents: 8291
diff changeset
1369
9f34f7636fe0 legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents: 8291
diff changeset
1370 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1371 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1372 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
22800
5de8670d10a6 Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents: 22624
diff changeset
1373 %! title ("incline is blue and decline is orange");
5de8670d10a6 Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents: 22624
diff changeset
1374 %! legend ({"I am blue", "I am orange"}, "location", "east");
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1375 %! legend hide
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1376 %! legend show
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1377
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1378 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1379 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1380 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1381 %! title ("Legend with keys in horizontal orientation");
22800
5de8670d10a6 Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents: 22624
diff changeset
1382 %! legend ({"I am blue", "I am orange"}, ...
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1383 %! "location", "east", "orientation", "horizontal");
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1384 %! legend boxoff
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1385 %! legend boxon
11462
aed2c50c3082 legend.m: legend with more than two inline keys (bug 31991). Add/modifyy demos.
Ben Abbott <bpabbott@mac.com>
parents: 11434
diff changeset
1386
aed2c50c3082 legend.m: legend with more than two inline keys (bug 31991). Add/modifyy demos.
Ben Abbott <bpabbott@mac.com>
parents: 11434
diff changeset
1387 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1388 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1389 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1390 %! title ("Legend with box off");
22800
5de8670d10a6 Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents: 22624
diff changeset
1391 %! legend ({"I am blue", "I am orange"}, "location", "east");
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1392 %! legend boxoff
11434
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1393
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1394 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1395 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1396 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1397 %! title ("Legend with text to the left of key");
22800
5de8670d10a6 Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents: 22624
diff changeset
1398 %! legend ({"I am blue", "I am orange"}, "location", "east");
17532
492d609d2d75 legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents: 17530
diff changeset
1399 %! legend left
8343
9f34f7636fe0 legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents: 8291
diff changeset
1400
9f34f7636fe0 legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents: 8291
diff changeset
1401 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1402 %! clf;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1403 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1404 %! title ({"Use properties to place legend text to the left of key", ...
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1405 %! "Legend text color is magenta"});
22800
5de8670d10a6 Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents: 22624
diff changeset
1406 %! h = legend ({"I am blue", "I am orange"}, "location", "east");
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1407 %! legend ("right");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1408 %! set (h, "textposition", "left");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1409 %! set (h, "textcolor", [1 0 1]);
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1410
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1411 %!demo
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1412 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1413 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1414 %! title ("Legend is hidden");
22800
5de8670d10a6 Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents: 22624
diff changeset
1415 %! legend ({"I am blue", "I am orange"}, "location", "east");
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1416 %! legend hide
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1417
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1418 %!demo
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1419 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1420 %! x = 0:1;
22800
5de8670d10a6 Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents: 22624
diff changeset
1421 %! plot (x,x,";I am Blue;", x,2*x,";I am Orange;", x,3*x,";I am Yellow;");
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1422 %! title ({"Labels are embedded in call to plot", ...
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1423 %! "Legend is hidden and then shown"});
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1424 %! legend boxon
11434
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1425 %! legend hide
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1426 %! legend show
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1427
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1428 %!demo
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1429 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1430 %! x = 0:1;
22151
283d8dfcad37 Make demos Matlab compatible for comparison with dump_demos script.
Rik <rik@octave.org>
parents: 22069
diff changeset
1431 %! plot (x,x, x,2*x, x,3*x);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1432 %! title ("Labels with interpreted Greek text");
22151
283d8dfcad37 Make demos Matlab compatible for comparison with dump_demos script.
Rik <rik@octave.org>
parents: 22069
diff changeset
1433 %! h = legend ('\alpha', '\beta=2\alpha', '\gamma=3\alpha');
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1434 %! set (h, "interpreter", "tex");
11434
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1435
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1436 %!demo
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1437 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1438 %! plot (rand (2));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1439 %! title ("Labels with TeX interpreter turned off");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1440 %! h = legend ("Hello_World", "foo^bar");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1441 %! set (h, "interpreter", "none");
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1442
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1443 %!demo
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1444 %! clf;
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
1445 %! labels = {};
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1446 %! colororder = get (gca, "colororder");
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
1447 %! for i = 1:5
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1448 %! h = plot (1:100, i + rand (100,1)); hold on;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1449 %! set (h, "color", colororder(i,:));
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1450 %! labels = {labels{:}, ["Signal ", num2str(i)]};
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1451 %! endfor
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1452 %! hold off;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1453 %! title ({"Signals with random offset and uniform noise";
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1454 %! "Legend shown below and outside of plot"});
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1455 %! xlabel ("Sample Nr [k]"); ylabel ("Amplitude [V]");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1456 %! legend (labels, "location", "southoutside");
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1457
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1458 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1459 %! clf;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1460 %! x = linspace (0, 10);
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1461 %! plot (x, x);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1462 %! hold on;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1463 %! stem (x, x.^2, "g");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1464 %! title ("First created object gets first label");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1465 %! legend ("linear");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1466 %! hold off;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1467
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1468 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1469 %! clf;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1470 %! x = linspace (0, 10);
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1471 %! plot (x, x, x, x.^2);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1472 %! title ("First created object gets first label");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1473 %! legend ("linear");
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1474
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1475 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1476 %! clf;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1477 %! x = linspace (0, 10);
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1478 %! plot (x, x, x, x.^2);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1479 %! title ("Labels are applied in order of object creation");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1480 %! 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
1481
f9fb8c1a8e45 legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents: 9451
diff changeset
1482 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1483 %! clf;
22629
4bd7bab38f39 Add stem example to the hggroup type of legend (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 22489
diff changeset
1484 %! subplot (2,1,1);
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1485 %! rand_2x3_data1 = [0.341447, 0.171220, 0.284370; 0.039773, 0.731725, 0.779382];
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1486 %! bar (rand_2x3_data1);
13936
bfaacd5e7379 Bug fix (#34901). Allow legend options to be specified. Modify demo.
Ben Abbott <bpabbott@mac.com>
parents: 13279
diff changeset
1487 %! ylim ([0 1.0]);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1488 %! title ("legend() works for bar graphs (hggroups)");
22629
4bd7bab38f39 Add stem example to the hggroup type of legend (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 22489
diff changeset
1489 %! legend ({"1st Bar", "2nd Bar", "3rd Bar"}, "location", "northwest");
4bd7bab38f39 Add stem example to the hggroup type of legend (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 22489
diff changeset
1490 %! subplot (2,1,2);
23253
8a1ba13e9914 Correct hggroup plot legends for gnuplot toolkit, add legend demo 17 items (bug #49341)
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23219
diff changeset
1491 %! x = linspace (0, 10, 20);
8a1ba13e9914 Correct hggroup plot legends for gnuplot toolkit, add legend demo 17 items (bug #49341)
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23219
diff changeset
1492 %! stem (x, 0.5+x.*rand (size (x))/max (x), "markeredgecolor", [0 0.7 0]);
8a1ba13e9914 Correct hggroup plot legends for gnuplot toolkit, add legend demo 17 items (bug #49341)
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23219
diff changeset
1493 %! hold on;
8a1ba13e9914 Correct hggroup plot legends for gnuplot toolkit, add legend demo 17 items (bug #49341)
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23219
diff changeset
1494 %! stem (x+10/(2*20), x.*(1.0+rand (size (x)))/max (x));
8a1ba13e9914 Correct hggroup plot legends for gnuplot toolkit, add legend demo 17 items (bug #49341)
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23219
diff changeset
1495 %! xlim ([0 10+10/(2*20)]);
22629
4bd7bab38f39 Add stem example to the hggroup type of legend (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 22489
diff changeset
1496 %! title ("legend() works for stem plots (hggroups)");
23253
8a1ba13e9914 Correct hggroup plot legends for gnuplot toolkit, add legend demo 17 items (bug #49341)
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 23219
diff changeset
1497 %! legend ({"Multicolor", "Unicolor"}, "location", "northwest");
9457
f9fb8c1a8e45 legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents: 9451
diff changeset
1498
f9fb8c1a8e45 legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents: 9451
diff changeset
1499 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1500 %! clf;
20408
71bd638e0ef6 legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents: 20286
diff changeset
1501 %! colormap (cool (64));
71bd638e0ef6 legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents: 20286
diff changeset
1502 %! surf (peaks ());
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1503 %! legend ("peaks()");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1504 %! title ("legend() works for surface objects too");
20408
71bd638e0ef6 legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents: 20286
diff changeset
1505
71bd638e0ef6 legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents: 20286
diff changeset
1506 %!demo
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1507 %! clf reset; # needed to undo colormap assignment in previous demo
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1508 %! rand_2x3_data2 = [0.44804, 0.84368, 0.23012; 0.72311, 0.58335, 0.90531];
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1509 %! bar (rand_2x3_data2);
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1510 %! ylim ([0 1.2]);
22151
283d8dfcad37 Make demos Matlab compatible for comparison with dump_demos script.
Rik <rik@octave.org>
parents: 22069
diff changeset
1511 %! title ('"left" option places colors to the left of text label');
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1512 %! legend ("1st Bar", "2nd Bar", "3rd Bar");
18888
962db83e36c3 legend.m: Update demo 19 with more descriptive title.
Rik <rik@octave.org>
parents: 18753
diff changeset
1513 %! legend left;
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
1514
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
1515 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1516 %! clf;
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
1517 %! x = 0:0.1:7;
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1518 %! h = plot (x,sin(x), x,cos(x), x,sin(x.^2/10), x,cos(x.^2/10));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1519 %! title ("Only the sin() objects have keylabels");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1520 %! legend (h([1, 3]), {"sin (x)", "sin (x^2/10)"}, "location", "southwest");
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1521
12340
d63007ac067a legend.m: Add demo for inline keys created by two plot commands.
Ben Abbott <bpabbott@mac.com>
parents: 12339
diff changeset
1522 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1523 %! clf;
12340
d63007ac067a legend.m: Add demo for inline keys created by two plot commands.
Ben Abbott <bpabbott@mac.com>
parents: 12339
diff changeset
1524 %! x = 0:0.1:10;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1525 %! plot (x, sin (x), ";sin (x);");
22069
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 22054
diff changeset
1526 %! hold on;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1527 %! plot (x, cos (x), ";cos (x);");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1528 %! hold off;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1529 %! title ("legend constructed from multiple plot calls");
12340
d63007ac067a legend.m: Add demo for inline keys created by two plot commands.
Ben Abbott <bpabbott@mac.com>
parents: 12339
diff changeset
1530
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1531 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1532 %! clf;
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1533 %! x = 0:0.1:10;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1534 %! plot (x, sin (x), ";sin (x);");
22069
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 22054
diff changeset
1535 %! hold on;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1536 %! plot (x, cos (x), ";cos (x);");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1537 %! hold off;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1538 %! title ("Specified label text overrides previous labels");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1539 %! legend ({"Sine", "Cosine"}, "location", "northeastoutside");
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1540
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
1541 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1542 %! clf;
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
1543 %! x = 0:10;
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
1544 %! plot (x, rand (11));
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1545 %! axis ([0, 10, 0, 1]);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1546 %! xlabel ("Indices");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1547 %! ylabel ("Random Values");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1548 %! title ('Legend "off" deletes the legend');
22624
37b7b86f62f2 Fix legend.m typo in demo example 23 (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 22489
diff changeset
1549 %! legend (cellstr (num2str ((0:10)')), "location", "northeastoutside");
37b7b86f62f2 Fix legend.m typo in demo example 23 (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 22489
diff changeset
1550 %! pause (1);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1551 %! legend off;
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1552
12395
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
1553 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1554 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1555 %! x = (1:5)';
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1556 %! subplot (2,2,1);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1557 %! plot (x, rand (numel (x)));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1558 %! legend (cellstr (num2str (x)), "location", "northwestoutside");
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1559 %! subplot (2,2,2);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1560 %! plot (x, rand (numel (x)));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1561 %! legend (cellstr (num2str (x)), "location", "northeastoutside");
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1562 %! subplot (2,2,3);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1563 %! plot (x, rand (numel (x)));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1564 %! legend (cellstr (num2str (x)), "location", "southwestoutside");
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1565 %! subplot (2,2,4);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1566 %! plot (x, rand (numel (x)));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1567 %! legend (cellstr (num2str (x)), "location", "southeastoutside");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1568 %! ## Legend works on a per axes basis for each subplot
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1569
12395
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
1570 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1571 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1572 %! plot (rand (2));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1573 %! title ("legend() will warn if extra labels are specified");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1574 %! legend ("Hello", "World", "interpreter", "foobar");
13979
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1575
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1576 %!demo
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1577 %! clf;
14207
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1578 %! x = 0:10;
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1579 %! y1 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1580 %! y2 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1581 %! [ax, h1, h2] = plotyy (x, y1, x, y2);
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1582 %! title ({"plotyy legend test #1", "Blue label to left axis, Orange label to right axis"});
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1583 %! drawnow ();
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1584 %! legend ("Blue", "Orange", "location", "south");
12395
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
1585
13979
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1586 %!demo
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1587 %! clf;
14207
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1588 %! x = 0:10;
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1589 %! y1 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1590 %! y2 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1591 %! [ax, h1, h2] = plotyy (x, y1, x, y2);
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1592 %! ylabel (ax(1), {"Blue", "Y", "Axis"});
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1593 %! title ('plotyy legend test #2: "westoutside" adjusts to ylabel');
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1594 %! drawnow ();
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1595 %! legend ([h1, h2], {"Blue", "Orange"}, "location", "westoutside");
13979
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1596
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1597 %!demo
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1598 %! clf;
14207
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1599 %! x = 0:10;
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1600 %! y1 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1601 %! y2 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1602 %! [ax, h1, h2] = plotyy (x, y1, x, y2);
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1603 %! ylabel (ax(2), {"Orange", "Y", "Axis"});
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1604 %! title ('plotyy legend test #3: "eastoutside" adjusts to ylabel');
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1605 %! drawnow ();
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1606 %! legend ([h1, h2], {"Blue", "Orange"}, "location", "eastoutside");
13979
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1607
20408
71bd638e0ef6 legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents: 20286
diff changeset
1608 %!demo
71bd638e0ef6 legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents: 20286
diff changeset
1609 %! clf;
71bd638e0ef6 legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents: 20286
diff changeset
1610 %! plot (1:10, 1:10);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1611 %! title ("a very long label can sometimes cause problems");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1612 %! legend ("hello very big world", "location", "northeastoutside");
20408
71bd638e0ef6 legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents: 20286
diff changeset
1613
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1614 %!demo # bug 36408
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1615 %! clf;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1616 %! option = "right";
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1617 %! subplot (3,1,1);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1618 %! plot (rand (1,4));
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1619 %! xlabel xlabel;
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1620 %! ylabel ylabel;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1621 %! title ("Subplots adjust to the legend placed outside");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1622 %! legend ({"1"}, "location", "northeastoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1623 %! legend (option);
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1624 %! subplot (3,1,2);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1625 %! plot (rand (1,4));
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1626 %! xlabel xlabel;
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1627 %! ylabel ylabel;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1628 %! legend ({"1234567890"}, "location", "eastoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1629 %! legend (option);
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1630 %! subplot (3,1,3);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1631 %! plot (rand (1,4));
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1632 %! xlabel xlabel;
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1633 %! ylabel ylabel;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1634 %! legend ({"12345678901234567890"}, "location", "southeastoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1635 %! legend (option);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1636
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1637 %!demo # bug 36408
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1638 %! clf;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1639 %! option = "right";
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1640 %! subplot (3,1,1);
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1641 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1642 %! title ("Subplots adjust to the legend placed outside");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1643 %! legend ({"1"}, "location", "northwestoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1644 %! legend (option);
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1645 %! subplot (3,1,2);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1646 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1647 %! legend ({"1234567890"}, "location", "westoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1648 %! legend (option);
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1649 %! subplot (3,1,3);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1650 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1651 %! legend ({"12345678901234567890"}, "location", "southwestoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1652 %! legend (option);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1653
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1654 %!demo # bug 36408
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1655 %! clf;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1656 %! option = "right";
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1657 %! subplot (3,1,1);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1658 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1659 %! set (gca (), "yaxislocation", "right");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1660 %! xlabel ("xlabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1661 %! ylabel ("ylabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1662 %! title ("Subplots adjust to the legend placed outside");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1663 %! legend ({"1"}, "location", "northeastoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1664 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1665 %! subplot (3,1,2);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1666 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1667 %! set (gca (), "yaxislocation", "right");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1668 %! xlabel ("xlabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1669 %! ylabel ("ylabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1670 %! legend ({"1234567890"}, "location", "eastoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1671 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1672 %! subplot (3,1,3);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1673 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1674 %! set (gca (), "yaxislocation", "right");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1675 %! xlabel ("xlabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1676 %! ylabel ("ylabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1677 %! legend ({"12345678901234567890"}, "location", "southeastoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1678 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1679
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1680 %!demo # bug 36408
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1681 %! clf;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1682 %! option = "right";
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1683 %! subplot (3,1,1);
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1684 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1685 %! set (gca (), "yaxislocation", "right");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1686 %! xlabel ("xlabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1687 %! ylabel ("ylabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1688 %! title ("Subplots adjust to the legend placed outside");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1689 %! legend ({"1"}, "location", "northwestoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1690 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1691 %! subplot (3,1,2);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1692 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1693 %! set (gca (), "yaxislocation", "right");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1694 %! xlabel ("xlabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1695 %! ylabel ("ylabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1696 %! legend ({"1234567890"}, "location", "westoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1697 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1698 %! subplot (3,1,3);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1699 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1700 %! set (gca (), "yaxislocation", "right");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1701 %! xlabel ("xlabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1702 %! ylabel ("ylabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1703 %! legend ({"12345678901234567890"}, "location", "southwestoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1704 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1705
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1706 %!demo # bug 36408;
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1707 %! clf;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1708 %! option = "right";
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1709 %! subplot (3,1,1);
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1710 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1711 %! set (gca (), "xaxislocation", "top");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1712 %! xlabel ("xlabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1713 %! ylabel ("ylabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1714 %! title ("Subplots adjust to the legend placed outside");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1715 %! legend ({"1"}, "location", "northwestoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1716 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1717 %! subplot (3,1,2);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1718 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1719 %! set (gca (), "xaxislocation", "top");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1720 %! xlabel ("xlabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1721 %! ylabel ("ylabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1722 %! legend ({"1234567890"}, "location", "westoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1723 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1724 %! subplot (3,1,3);
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1725 %! plot (rand (1,4));
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1726 %! set (gca (), "xaxislocation", "top");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1727 %! xlabel ("xlabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1728 %! ylabel ("ylabel");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1729 %! legend ({"12345678901234567890"}, "location", "southwestoutside");
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1730 %! legend (option);
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1731
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1732 %!demo # bug 39697
17190
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17179
diff changeset
1733 %! clf;
17179
828e8852efa9 legend.m: Add %!demo block showing bug #39697.
Rik <rik@octave.org>
parents: 17174
diff changeset
1734 %! plot (1:10);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1735 %! legend ("Legend Text");
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 22151
diff changeset
1736 %! title ({"Multi-line", "titles", "are a", "problem", "See bug #39697"});
17179
828e8852efa9 legend.m: Add %!demo block showing bug #39697.
Rik <rik@octave.org>
parents: 17174
diff changeset
1737
23508
4b38c9687331 Skip tests that require gnuplot when gnuplot is not installed (bug #36983)
Mike Miller <mtmiller@octave.org>
parents: 23263
diff changeset
1738 %!testif ; any (strcmp ("gnuplot", available_graphics_toolkits ()))
17107
dbd64c9a16da Restore graphics toolkit after %!tests that alter it.
Rik <rik@octave.org>
parents: 17065
diff changeset
1739 %! toolkit = graphics_toolkit ("gnuplot");
17119
bd50e0660545 test: Add missing semicolons to suppress output in some plot %!tests.
Rik <rik@octave.org>
parents: 17107
diff changeset
1740 %! h = figure ("visible", "off");
16973
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1741 %! unwind_protect
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1742 %! position = get (h, "position");
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1743 %! plot (rand (3));
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1744 %! legend ();
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 18937
diff changeset
1745 %! filename = sprintf ("%s.eps", tempname ());
16973
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1746 %! print (filename);
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1747 %! unlink (filename);
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1748 %! assert (get (h, "position"), position);
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1749 %! unwind_protect_cleanup
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1750 %! close (h);
17107
dbd64c9a16da Restore graphics toolkit after %!tests that alter it.
Rik <rik@octave.org>
parents: 17065
diff changeset
1751 %! graphics_toolkit (toolkit);
16973
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1752 %! end_unwind_protect
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1753
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
1754 %!test <*42035>
18647
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1755 %! h = figure ("visible", "off");
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1756 %! unwind_protect
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1757 %! hax1 = subplot (1,2,1);
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1758 %! plot (1:10);
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1759 %! hax2 = subplot (1,2,2);
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1760 %! plot (1:10);
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1761 %! hleg1 = legend (hax1, "foo");
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1762 %! assert (getappdata (hleg1, "__axes_handle__"), hax1);
18647
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1763 %! assert (gca (), hax2);
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1764 %! hleg2 = legend ("bar");
24498
5865d2fef424 legend.m: Clean up implementation.
Rik <rik@octave.org>
parents: 24482
diff changeset
1765 %! assert (getappdata (hleg2, "__axes_handle__"), gca ());
18647
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1766 %! unwind_protect_cleanup
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1767 %! close (h);
ce36233e4849 legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents: 18644
diff changeset
1768 %! end_unwind_protect
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1769
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1770 %!test
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1771 %! ## Difficult example from plotyy demo #1
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1772 %! hf = figure ("visible", "off");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1773 %! unwind_protect
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1774 %! x = 0:0.1:2*pi;
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1775 %! y1 = sin (x);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1776 %! y2 = exp (x - 1);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1777 %! hax = plotyy (x,y1, x-1,y2, @plot, @semilogy);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1778 %! text (0.5, 0.5, "Left Axis", "parent", hax(1));
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1779 %! text (4.5, 80, "Right Axis", "parent", hax(2));
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1780 %! hleg = legend ("show");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1781 %! assert (get (hleg, "string"), {"data1", "data2"});
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1782 %! fail ("legend ('foo', 'bar', 'baz')", "warning", "ignoring extra labels");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1783 %! unwind_protect_cleanup
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1784 %! close (hf);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1785 %! end_unwind_protect
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1786
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1787 %!test
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1788 %! ## Test warnings about objects to label
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1789 %! hf = figure ("visible", "off");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1790 %! unwind_protect
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1791 %! hax = gca ();
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1792 %! fail ("legend ('foobar')", "warning", "plot data is empty");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1793 %! ht = text (0.5, 0.5, "Hello World");
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1794 %! fail ("legend ('foobar')", "warning", "plot data is empty");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1795 %! lastwarn (""); # clear warning
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1796 %! hleg = legend ();
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1797 %! assert (isempty (hleg) && isempty (lastwarn ()));
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1798 %! fail ("legend ('foobar')", "warning", "plot data is empty");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1799 %! hln = line ([0 1], [0 1]);
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1800 %! fail ("legend ('foo', 'bar')", "warning", "ignoring extra labels");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1801 %! plot (rand (2, 21));
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1802 %! fail ("legend ()", "warning", "labeling only first 20 data objects");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1803 %! unwind_protect_cleanup
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1804 %! close (hf);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1805 %! end_unwind_protect
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1806
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1807 %!test
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1808 %! ## Test warnings about unsupported features
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1809 %! hf = figure ("visible", "off");
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1810 %! unwind_protect
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1811 %! plot (1:10);
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1812 %! fail ("legend ('location','best')", "warning", "'best' not yet implemented");
24434
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1813 %! unwind_protect_cleanup
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1814 %! close (hf);
436deae9f9ab legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents: 24432
diff changeset
1815 %! end_unwind_protect