annotate scripts/plot/legend.m @ 17125:b5d6314314fc

Change various plot functions to take advantage of new isaxes() function. * scripts/geometry/voronoi.m, scripts/image/imagesc.m, scripts/plot/__plt_get_axis_arg__.m, scripts/plot/axes.m, scripts/plot/cla.m, scripts/plot/colorbar.m, scripts/plot/hold.m, scripts/plot/legend.m, scripts/plot/plotmatrix.m, scripts/plot/plotyy.m, scripts/plot/private/__errplot__.m, scripts/plot/private/__plt__.m, scripts/plot/view.m: Use new isaxes function to simplify code. * scripts/plot/shading.m: Use Octave convention for spacing of parentheses. * scripts/plot/zlabel.m: Correct %!test incorrectly calling plot3 with figure handle.
author Rik <rik@octave.org>
date Wed, 31 Jul 2013 16:27:49 -0700
parents eaab03308c0b
children c3c1ebfaa7dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13979
diff changeset
1 ## Copyright (C) 2010-2012 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 ##
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6395
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
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
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 ## 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
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6395
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6395
diff changeset
13 ## 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
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
17 ## <http://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 -*-
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
20 ## @deftypefn {Function File} {} legend (@var{str1}, @var{str2}, @dots{})
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
21 ## @deftypefnx {Function File} {} legend (@var{matstr})
14755
bf759828760c doc: Clarify input must be cellstr, not just cell, to legend().
Rik <octave@nomad.inbox5.com>
parents: 14747
diff changeset
22 ## @deftypefnx {Function File} {} legend (@var{cellstr})
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
23 ## @deftypefnx {Function File} {} legend (@dots{}, "location", @var{pos})
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
24 ## @deftypefnx {Function File} {} legend (@dots{}, "orientation", @var{orient})
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
25 ## @deftypefnx {Function File} {} legend (@var{hax}, @dots{})
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
26 ## @deftypefnx {Function File} {} legend (@var{hobjs}, @dots{})
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
27 ## @deftypefnx {Function File} {} legend (@var{hax}, @var{hobjs}, @dots{})
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
28 ## @deftypefnx {Function File} {} legend ("@var{option}")
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
29 ## @deftypefnx {Function File} {[@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
30 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
31 ## 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
32 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
33 ## Legend entries may be specified as individual character string arguments,
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
34 ## a character array, or a cell array of character strings.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
35 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
36 ## If the first argument @var{hax} is an axes handle, then plot into this axis,
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
37 ## rather than the current axes returned by @code{gca}. If the handles,
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
38 ## @var{hobjs}, are not specified then the legend's strings will be associated
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
39 ## with the axes' descendants. @code{legend} works on line graphs,
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
40 ## bar graphs, etc. A plot must exist before legend is called.
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
41 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
42 ## The optional parameter @var{pos} specifies the location of the legend
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
43 ## as follows:
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
44 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
45 ## @multitable @columnfractions 0.06 0.14 0.80
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
46 ##
13937
1ab3062df1ae Add headers to texinfo table for legend.m
Ben Abbott <bpabbott@mac.com>
parents: 13936
diff changeset
47 ## @headitem @tab @var{pos} @tab
1ab3062df1ae Add headers to texinfo table for legend.m
Ben Abbott <bpabbott@mac.com>
parents: 13936
diff changeset
48 ## location of the legend
1ab3062df1ae Add headers to texinfo table for legend.m
Ben Abbott <bpabbott@mac.com>
parents: 13936
diff changeset
49 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
50 ## @item @tab north @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
51 ## center top
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
52 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
53 ## @item @tab south @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
54 ## center bottom
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
55 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
56 ## @item @tab east @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
57 ## right center
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
58 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
59 ## @item @tab west @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
60 ## left center
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
61 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
62 ## @item @tab northeast @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
63 ## right top (default)
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
64 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
65 ## @item @tab northwest @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
66 ## left top
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
67 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
68 ## @item @tab southeast @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
69 ## right bottom
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
70 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
71 ## @item @tab southwest @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
72 ## left bottom
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
73 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
74 ## @item
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
75 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
76 ## @item @tab outside @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
77 ## can be appended to any location string
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
78 ## @end multitable
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
79 ##
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
80 ## The optional parameter @var{orient} determines if the key elements
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
81 ## are placed vertically or horizontally. The allowed values are
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
82 ## "vertical" (default) or "horizontal".
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
83 ##
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
84 ## The following customizations are available using @var{option}:
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
85 ##
7148
735086cfd405 [project @ 2007-11-09 18:01:44 by jwe]
jwe
parents: 7054
diff changeset
86 ## @table @asis
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
87 ## @item "show"
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
88 ## Show legend on the plot
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
89 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
90 ## @item "hide"
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
91 ## Hide legend on the plot
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
92 ##
16094
8899c785cc99 doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents: 16002
diff changeset
93 ## @item "toggle"
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
94 ## Toggles between "hide" and "show"
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
95 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
96 ## @item "boxon"
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
97 ## Show a box around legend
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
98 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
99 ## @item "boxoff"
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
100 ## Hide the box around legend
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
101 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
102 ## @item "left"
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
103 ## 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
104 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
105 ## @item "right"
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
106 ## Place label text to the right of the keys
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
107 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
108 ## @item "off"
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
109 ## Delete the legend object
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
110 ## @end table
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
111 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
112 ## 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
113 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
114 ## @table @var
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
115 ## @item hleg
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
116 ## 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
117 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
118 ## @item hleg_obj
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
119 ## Graphics handles to the text and line objects which make up the legend.
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
120 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
121 ## @item hplot
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
122 ## 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
123 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
124 ## @item labels
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
125 ## A cell array of strings of the labels in the legend.
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
126 ## @end table
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
127 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
128 ## The legend label text is either provided in the call to @code{legend} or
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
129 ## is taken from the DisplayName property of graphics objects. If no
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
130 ## labels or DisplayNames are available, then the label text is simply
16826
a4969508008e doc: Periodic spellcheck of the documentation.
Rik <rik@octave.org>
parents: 16805
diff changeset
131 ## "data1", "data2", @dots{}, @nospell{"dataN"}.
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
132 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
133 ## Implementation Note: A legend is implemented as an additional axes object
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
134 ## of the current figure with the "tag" set to "legend". Properties of the
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
135 ## legend object may be manipulated directly by using @code{set}.
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
136 ## @end deftypefn
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
137
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
138 function [hlegend2, hobjects2, hplot2, text_strings2] = legend (varargin)
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
139
11246
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
140 if (nargin > 0
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
141 && (! ishandle (varargin{1})
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
142 || (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
143 && ! 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
144 [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
145 if (isempty (ca))
991e8a386aa3 legend.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16973
diff changeset
146 ca = gca ();
991e8a386aa3 legend.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16973
diff changeset
147 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
148 fig = get (ca, "parent");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
149 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
150 fig = get (0, "currentfigure");
11246
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
151 if (isempty (fig))
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
152 fig = gcf ();
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
153 endif
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
154 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
155 endif
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
156
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
157 ## Special handling for plotyy which has two axes objects
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
158 if (ishandle (ca) && isprop (ca, "__plotyy_axes__"))
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
159 plty = get (ca, "__plotyy_axes__");
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
160 if (isscalar (plty) && ishandle (plty))
11199
91c606a68693 minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents: 11198
diff changeset
161 ca = [ca, plty];
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
162 elseif (iscell (plty))
11199
91c606a68693 minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents: 11198
diff changeset
163 ca = [ca, plty{:}];
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
164 elseif (all (ishandle (plty)))
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
165 ca = [ca, plty(:).'];
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
166 else
15202
f3b5cadfd6d5 fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents: 14868
diff changeset
167 error ("legend.m: This should not happen. File a bug report.");
11199
91c606a68693 minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents: 11198
diff changeset
168 endif
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
169 ## Remove duplicates while preserving order
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
170 [~, n] = unique (ca);
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
171 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
172 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
173
11246
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
174 if (nargin > 0 && all (ishandle (varargin{1})))
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
175 kids = flipud (varargin{1}(:));
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
176 varargin(1) = [];
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
177 else
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
178 kids = ca;
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
179 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
180 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
181 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
182 else
14207
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
183 kids = 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
184 endif
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
185 endif
11246
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
186 nargs = numel (varargin);
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
187 nkids = numel (kids);
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
188
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
189 orientation = "default";
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
190 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
191 show = "create";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
192 textpos = "default";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
193 box = "default";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
194
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
195 ## Process old way of specifying location with a number rather than a string.
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
196 if (nargs > 0)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
197 pos = varargin{nargs};
13279
984359717d71 Use common code idiom for checking whether a double value is an integer.
Rik <octave@nomad.inbox5.com>
parents: 13216
diff changeset
198 if (isnumeric (pos) && isscalar (pos) && pos == fix (pos))
6395
a8dd70bacc1e [project @ 2007-03-07 22:22:12 by jwe]
jwe
parents: 6272
diff changeset
199 if (pos >= -1 && pos <= 4)
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
200 location = [{"northeastoutside", "best", "northeast",
11003
b1cfff739af5 legend.m: Index location cellstr to obtain a string.
Ben Abbott <bpabbott@mac.com>
parents: 10999
diff changeset
201 "northwest", "southwest", "southeast"}] {pos + 2};
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
202 nargs--;
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
203 else
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
204 error ("legend: invalid location specified");
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
205 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
206 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
207 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
208
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
209 ## Find location and orientation property/value pairs
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
210 while (nargs > 1)
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
211 pos = varargin{nargs-1};
7054
1c5b2b5b58ba [project @ 2007-10-23 23:22:16 by jwe]
jwe
parents: 7017
diff changeset
212 str = varargin{nargs};
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
213 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
214 location = lower (str);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
215 nargs -= 2;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
216 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
217 orientation = lower (str);
10989
6ea65c5de87a Respect the units and paperunits figure properties and the units and fontunits axes properties
David Bateman <dbateman@free.fr>
parents: 10949
diff changeset
218 nargs -= 2;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
219 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
220 break;
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
221 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
222 endwhile
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
223
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
224 ## Validate the orientation
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
225 switch (orientation)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
226 case {"vertical", "horizontal", "default"}
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
227 ## These are all accepted orientations.
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
228 otherwise
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
229 error ("legend: unrecognized legend orientation");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
230 endswitch
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
231
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
232 ## 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
233 outside = false;
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
234 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
235 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
236 outside = true;
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
237 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
238 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
239 outside = false;
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
240 endif
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
241
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
242 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
243 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
244 "southeast", "southwest", "default"}
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
245 case "best"
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
246 warning ("legend: 'best' not yet implemented for location specifier\n");
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
247 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
248 otherwise
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
249 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
250 endswitch
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
251
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
252 ## Find any existing legend object on figure
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
253 hlegend = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
254 fkids = get (fig, "children");
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
255 for i = 1 : numel (fkids)
17125
b5d6314314fc Change various plot functions to take advantage of new isaxes() function.
Rik <rik@octave.org>
parents: 17122
diff changeset
256 if ( strcmp (get (fkids(i), "type"), "axes")
b5d6314314fc Change various plot functions to take advantage of new isaxes() function.
Rik <rik@octave.org>
parents: 17122
diff changeset
257 && strcmp (get (fkids(i), "tag"), "legend"))
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
258 udata = get (fkids(i), "userdata");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
259 if (! isempty (intersect (udata.handle, ca)))
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
260 hlegend = fkids(i);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
261 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
262 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
263 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
264 endfor
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
265
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
266 if (nargs == 1)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
267 arg = varargin{1};
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
268 if (ischar (arg))
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
269 if (rows (arg) == 1)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
270 str = tolower (strtrim (arg));
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
271 switch (str)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
272 case "off"
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
273 delete (hlegend);
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
274 return;
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
275 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
276 show = "off";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
277 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
278 case "show"
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
279 if (! isempty (hlegend))
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
280 show = "on";
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
281 else
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
282 show = "create";
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
283 textpos = "left";
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
284 endif
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
285 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
286 case "toggle"
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
287 if (isempty (hlegend))
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
288 show = "create";
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
289 textpos = "left";
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
290 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
291 show = "on";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
292 else
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
293 show = "off";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
294 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
295 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
296 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
297 box = "on";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
298 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
299 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
300 box = "off";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
301 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
302 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
303 textpos = "left";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
304 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
305 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
306 textpos = "right";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
307 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
308 endswitch
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
309 else
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
310 ## Character matrix of labels
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
311 varargin = cellstr (arg);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
312 nargs = numel (varargin);
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
313 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
314 elseif (iscellstr (arg))
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
315 ## 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
316 varargin = arg;
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
317 nargs = numel (varargin);
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
318 else
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
319 error ("legend: expecting argument to be a character string");
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
320 endif
14589
fd6e50e2eee6 legend() should accept labels being specified as both cellstrs and char.
Ben Abbott <bpabbott@mac.com>
parents: 14585
diff changeset
321 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
322 ## Cell array of labels followed by property/value pairs
14589
fd6e50e2eee6 legend() should accept labels being specified as both cellstrs and char.
Ben Abbott <bpabbott@mac.com>
parents: 14585
diff changeset
323 varargin = {varargin{1}{:}, varargin{2:end}};
fd6e50e2eee6 legend() should accept labels being specified as both cellstrs and char.
Ben Abbott <bpabbott@mac.com>
parents: 14585
diff changeset
324 nargs = numel (varargin);
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
325 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
326
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
327 have_labels = (nargs > 0);
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
328
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
329 if (strcmp (show, "off"))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
330 if (! isempty (hlegend))
14578
f579a94aacaa Preserve legend handle when changing properties (Bug # 36259).
Carnë Draug <carandraug+dev@gmail.com>
parents: 14552
diff changeset
331 set (findobj (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
332 hlegend = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
333 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
334 hobjects = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
335 hplots = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
336 text_strings = {};
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
337 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
338 if (! isempty (hlegend))
14578
f579a94aacaa Preserve legend handle when changing properties (Bug # 36259).
Carnë Draug <carandraug+dev@gmail.com>
parents: 14552
diff changeset
339 set (findobj (hlegend), "visible", "on");
14585
c38a253723d3 Syncrhonize legend's "visible" and "box" properties. (Bug # 36136)
Ben Abbott <bpabbott@mac.com>
parents: 14581
diff changeset
340 ## NOTE - Matlab sets both "visible", and "box" to "on"
c38a253723d3 Syncrhonize legend's "visible" and "box" properties. (Bug # 36136)
Ben Abbott <bpabbott@mac.com>
parents: 14581
diff changeset
341 set (hlegend, "visible", get (hlegend, "box"));
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
342 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
343 hobjects = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
344 hplots = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
345 text_strings = {};
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
346 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
347 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
348 if (! isempty (hlegend))
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
349 set (hlegend, "box", "on", "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
350 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
351 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
352 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
353 set (hlegend, "box", "off", "visible", "off");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
354 endif
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
355 elseif (! have_labels && !(strcmp (location, "default") &&
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
356 strcmp (orientation, "default")))
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
357 ## Changing location or orientation of existing legend
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
358 if (! isempty (hlegend))
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
359 hax = getfield (get (hlegend, "userdata"), "handle");
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
360 [hplots, text_strings] = __getlegenddata__ (hlegend);
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
361
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
362 if (strcmp (location, "default"))
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
363 h = legend (hax, hplots, text_strings, "orientation", orientation);
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
364 elseif (strcmp (orientation, "default"))
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
365 if (outside)
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12440
diff changeset
366 h = legend (hax, hplots, text_strings, "location",
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
367 strcat (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
368 else
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
369 h = legend (hax, hplots, text_strings, "location", location);
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
370 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
371 else
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
372 if (outside)
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12440
diff changeset
373 h = legend (hax, hplots, text_strings, "location",
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
374 strcat (location, "outside"), "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
375 else
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
376 h = legend (hax, hplots, text_strings, "location", location,
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
377 "orientation", orientation);
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
378 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
379 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
380 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
381 else
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
382 ## Create new legend
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
383 hobjects = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
384 hplots = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
385 text_strings = {};
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
386
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
387 if (have_labels)
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
388 ## 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
389 have_data = false;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
390 have_dname = false;
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
391 for k = 1 : nkids
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
392 typ = get (kids(k), "type");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
393 if (strcmp (typ, "line") || strcmp (typ, "surface")
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
394 || strcmp (typ, "patch") || strcmp (typ, "hggroup"))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
395 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
396 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
397 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
398 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
399
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
400 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
401 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
402 endif
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
403 else
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
404 ## 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
405 have_dname = false;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
406 for k = 1 : nkids
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
407 hkid = kids(k);
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
408 typ = get (hkid, "type");
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
409 if (strcmp (typ, "line") || strcmp (typ, "surface")
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
410 || strcmp (typ, "patch"))
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
411 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
412 have_dname = true;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
413 break;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
414 endif
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
415 elseif (strcmp (typ, "hggroup"))
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
416 hgkids = get (hkid, "children");
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
417 for j = 1 : length (hgkids)
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
418 hgobj = get (hgkids(j));
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
419 if (isfield (hgobj, "displayname") && ! isempty (hgobj.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; # break from j-loop over hgkids
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
422 endif
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
423 endfor
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
424 if (have_dname)
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
425 break; # break from k loop over nkids
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
426 endif
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
427 endif # elseif hggroup
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
428 endfor # for loop k = 1 : nkids
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
429 endif # else branch of if (have_labels)
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
430
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
431 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
432 k = nkids;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
433 if (! have_labels)
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
434 varargin = arrayfun (@(x) sprintf ("data%d", x), [1:nkids]',
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
435 "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
436 have_labels = true;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
437 nargs = nkids;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
438 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
439 for i = 1 : nargs
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
440 arg = varargin{i};
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
441 if (ischar (arg))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
442 typ = get (kids(k), "type");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
443 while (k > 0
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
444 && ! (strcmp (typ, "line") || strcmp (typ, "surface")
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
445 || strcmp (typ, "patch") || strcmp (typ, "hggroup")))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
446 typ = get (kids(--k), "type");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
447 endwhile
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
448 if (k > 0)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
449 if (strcmp (get (kids(k), "type"), "hggroup"))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
450 hgkids = get (kids(k), "children");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
451 for j = 1 : length (hgkids)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
452 hgobj = get (hgkids(j));
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
453 if (isfield (hgobj, "displayname"))
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
454 if (have_labels)
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
455 set (hgkids(j), "displayname", arg);
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
456 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
457 hplots = [hplots, hgkids(j)];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
458 text_strings = {text_strings{:}, arg};
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
459 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
460 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
461 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
462 else
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
463 if (have_labels)
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
464 set (kids(k), "displayname", arg);
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
465 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
466 hplots = [hplots, kids(k)];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
467 text_strings = {text_strings{:}, arg};
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
468 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
469
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
470 if (--k == 0)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
471 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
472 endif
15441
e5a07d7aafcc legend.m: Remove unused warning variable and associated code.
Rik <rik@octave.org>
parents: 15440
diff changeset
473 else
e5a07d7aafcc legend.m: Remove unused warning variable and associated code.
Rik <rik@octave.org>
parents: 15440
diff changeset
474 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
475 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
476 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
477 error ("legend: expecting argument to be a character string");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
478 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
479 endfor
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
480 if (have_labels && i < nargs)
13979
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
481 warning ("legend: ignoring extra labels");
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
482 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
483 else
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
484 ## 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
485 k = nkids;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
486 while (k > 0)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
487 typ = get (kids(k), "type");
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
488 while (k > 1
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
489 && ! (strcmp (typ, "line") || strcmp (typ, "surface")
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
490 || strcmp (typ, "patch") || strcmp (typ, "hggroup")))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
491 typ = get (kids(--k), "type");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
492 endwhile
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
493 if (! (strcmp (typ, "line") || strcmp (typ, "surface")
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
494 || strcmp (typ, "patch") || strcmp (typ, "hggroup")))
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
495 break;
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
496 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
497 if (k > 0)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
498 if (strcmp (get (kids(k), "type"), "hggroup"))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
499 hgkids = get (kids(k), "children");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
500 for j = 1 : length (hgkids)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
501 hgobj = get (hgkids(j));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
502 if (isfield (hgobj, "displayname")
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
503 && ! isempty (hgobj.displayname))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
504 hplots = [hplots, hgkids(j)];
13936
bfaacd5e7379 Bug fix (#34901). Allow legend options to be specified. Modify demo.
Ben Abbott <bpabbott@mac.com>
parents: 13279
diff changeset
505 text_strings = {text_strings{:}, hgobj.displayname};
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
506 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
507 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
508 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
509 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
510 if (! isempty (get (kids(k), "displayname")))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
511 hplots = [hplots, kids(k)];
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
512 text_strings = {text_strings{:}, get(kids(k), "displayname")};
10995
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 (--k == 0)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
516 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
517 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
518 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
519 endwhile
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
520 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
521
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
522 if (isempty (hplots))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
523 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
524 fkids = get (fig, "children");
16800
56102c33122d Fix problems with changeset 286904321282.
Ben Abbott <bpabbott@mac.com>
parents: 16799
diff changeset
525 delete (fkids(fkids == hlegend));
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
526 hlegend = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
527 hobjects = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
528 hplots = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
529 text_strings = {};
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
530 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
531 else
14578
f579a94aacaa Preserve legend handle when changing properties (Bug # 36259).
Carnë Draug <carandraug+dev@gmail.com>
parents: 14552
diff changeset
532 ## 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
533 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
534 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
535 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
536 endif
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
537 if (strcmp (location, "default"))
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
538 location = get (hlegend, "location");
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
539 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
540 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
541 outside = true;
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
542 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
543 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
544 outside = false;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
545 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
546 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
547 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
548 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
549 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
550 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
551 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
552 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
553 textpos = "left";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
554 endif
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
555 if (strcmp (location, "default"))
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
556 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
557 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
558 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
559 orientation = "vertical";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
560 endif
14529
aabdc8f281f1 legend.m: Change default to boxon for Matlab compatibility (bug #36105).
Rik <octave@nomad.inbox5.com>
parents: 14375
diff changeset
561 box = "on";
6272
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
562 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
563
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
564 ## Get axis size and fontsize in points.
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
565 ## Rely on listener to handle coversion.
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
566 units = get (ca(1), "units");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
567 fontunits = get (ca(1), "fontunits");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
568 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
569 set (ca(1), "units", "points");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
570 set (ca(1), "fontunits", "points");
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
571 if (isempty (hlegend) || ! isprop (hlegend, "unmodified_axes_position"))
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
572 unmodified_axes_position = get (ca(1), "position");
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
573 unmodified_axes_outerposition = get (ca(1), "outerposition");
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
574 else
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
575 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
576 unmodified_axes_outerposition = get (hlegend, ...
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
577 "unmodified_axes_outerposition");
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
578 endif
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
579 ca_pos = unmodified_axes_position;
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
580 ca_outpos = unmodified_axes_outerposition;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
581 ca_fontsize = get (ca(1), "fontsize");
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
582 tightinset = get (ca(1), "tightinset");
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
583 for i = 2 : numel (ca)
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
584 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
585 endfor
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
586 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
587 set (ca(1), "units", units);
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
588 set (ca(1), "fontunits", fontunits);
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
589 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
590
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
591 ## Padding between legend entries horizontally and vertically
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
592 xpad = 2;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
593 ypad = 2;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
594
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
595 linelength = 15;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
596
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
597 ## Create the axis first
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
598 ## FIXME hlegend should inherit properties from "ca"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
599 curaxes = get (fig, "currentaxes");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
600 unwind_protect
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
601 ud = ancestor (hplots, "axes");
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
602 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
603 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
604 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
605 if (isempty (hlegend))
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
606 addprops = true;
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
607 hlegend = axes ("tag", "legend", "userdata", struct ("handle", ud),
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
608 "box", box,
14529
aabdc8f281f1 legend.m: Change default to boxon for Matlab compatibility (bug #36105).
Rik <octave@nomad.inbox5.com>
parents: 14375
diff changeset
609 "xtick", [], "ytick", [],
aabdc8f281f1 legend.m: Change default to boxon for Matlab compatibility (bug #36105).
Rik <octave@nomad.inbox5.com>
parents: 14375
diff changeset
610 "xticklabel", "", "yticklabel", "", "zticklabel", "",
14578
f579a94aacaa Preserve legend handle when changing properties (Bug # 36259).
Carnë Draug <carandraug+dev@gmail.com>
parents: 14552
diff changeset
611 "xlim", [0, 1], "ylim", [0, 1],
f579a94aacaa Preserve legend handle when changing properties (Bug # 36259).
Carnë Draug <carandraug+dev@gmail.com>
parents: 14552
diff changeset
612 "visible", ifelse (strcmp (box, "on"), "on", "off"),
14746
3ddb62bd67c5 legend.m: Inherit font size from axes.
Konstantinos Poulios <logari81@gmail.com>
parents: 14589
diff changeset
613 "activepositionproperty", "position",
3ddb62bd67c5 legend.m: Inherit font size from axes.
Konstantinos Poulios <logari81@gmail.com>
parents: 14589
diff changeset
614 "fontsize", ca_fontsize);
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
615 else
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"));
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
619 endif
16728
5cf7369a74cb Update legend box when the fontsize changes.
Ben Abbott <bpabbott@mac.com>
parents: 16094
diff changeset
620 fontsize = get (hlegend, "fontsize");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
621 ## Add text label to the axis first, checking their extents
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
622 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
623 texthandle = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
624 maxwidth = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
625 maxheight = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
626 for k = 1 : nentries
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
627 if (strcmp (textpos, "right"))
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
628 texthandle = [texthandle, text(0, 0, text_strings{k},
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
629 "horizontalalignment", "left",
14746
3ddb62bd67c5 legend.m: Inherit font size from axes.
Konstantinos Poulios <logari81@gmail.com>
parents: 14589
diff changeset
630 "userdata", hplots(k),
16728
5cf7369a74cb Update legend box when the fontsize changes.
Ben Abbott <bpabbott@mac.com>
parents: 16094
diff changeset
631 "fontsize", fontsize)];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
632 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
633 texthandle = [texthandle, text(0, 0, text_strings{k},
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
634 "horizontalalignment", "right",
14746
3ddb62bd67c5 legend.m: Inherit font size from axes.
Konstantinos Poulios <logari81@gmail.com>
parents: 14589
diff changeset
635 "userdata", hplots(k),
16728
5cf7369a74cb Update legend box when the fontsize changes.
Ben Abbott <bpabbott@mac.com>
parents: 16094
diff changeset
636 "fontsize", fontsize)];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
637 endif
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
638 units = get (texthandle(end), "units");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
639 unwind_protect
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
640 set (texthandle(end), "units", "points");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
641 extents = get (texthandle(end), "extent");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
642 maxwidth = max (maxwidth, extents(3));
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
643 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
644 unwind_protect_cleanup
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
645 set (texthandle(end), "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
646 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
647 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
648
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
649 num1 = nentries;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
650 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
651 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
652 if (outside)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
653 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
654 ## 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
655 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
656 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
657 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
658 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
659 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
660 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
661 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
662 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
663 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
664 if (outside)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
665 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
666 ## 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
667 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
668 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
669 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
670 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
671 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
672 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
673 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
674 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
675 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
676
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
677 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
678 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
679 xoffset = xpad;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
680 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
681 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
682 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
683 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
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 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
686 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
687
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
688 ## 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
689 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
690 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
691 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
692 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
693 endif
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
694
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
695 gnuplot = strcmp (get (fig, "__graphics_toolkit__"), "gnuplot");
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
696 if (gnuplot)
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
697 ## Gnuplot places the key (legend) at edge of the figure window.
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
698 ## 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
699 ## position.
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
700 if (isempty (strfind (location, "east")))
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
701 gnuplot_offset = unmodified_axes_outerposition(1) ...
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
702 + unmodified_axes_outerposition(3) ...
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
703 - unmodified_axes_position(1) ...
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
704 - unmodified_axes_position(3);
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
705 else
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
706 gnuplot_offset = unmodified_axes_position(1) ...
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
707 - unmodified_axes_outerposition(1);
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
708 endif
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
709 ## FIXME - the "fontsize" is added to match the behavior of OpenGL.
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
710 ## 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
711 ## 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
712 ## key in the absence of any subplots.
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
713 gnuplot_offset = gnuplot_offset - 2 * fontsize;
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
714 else
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
715 gnuplot_offset = 0;
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
716 endif
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
717
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
718 ## For legend's outside the associated axes postion, align their edge
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
719 ## to the unmodified_axes_outerpostion, and adjust the axes postion
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
720 ## accordingly.
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
721 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
722 case "north"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
723 if (outside)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
724 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ...
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
725 ca_outpos(2) + ca_outpos(4) - lpos(4) - ypad, lpos(3), ...
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
726 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
727
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
728 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
729 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
730 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ...
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
731 ca_pos(2) + ca_pos(4) - lpos(4) - ypad, lpos(3), lpos(4)];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
732 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
733 case "south"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
734 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
735 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ...
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
736 ca_outpos(2) + ypad, lpos(3), lpos(4)];
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
737 new_pos = [ca_pos(1), lpos(2) + lpos(4) + 2 * ypad ...
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
738 + tightinset(2), 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
739 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
740 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
741 lpos = [ca_pos(1) + (ca_pos(3) - lpos(3)) / 2, ...
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
742 ca_pos(2) + ypad, lpos(3), lpos(4)];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
743 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
744 case "east"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
745 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
746 lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3) - ypad, ...
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
747 ca_pos(2) + (ca_pos(4) - lpos(4)) / 2, lpos(3), lpos(4)];
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
748 new_pos = [ca_pos(1), ca_pos(2), ...
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
749 lpos(1) - 2 * xpad - ca_pos(1) - tightinset(3), ...
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
750 ca_pos(4)];
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
751 new_pos(3) = 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
752 else
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) - ypad, ...
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
754 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
755 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
756 case "west"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
757 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
758 lpos = [ca_outpos(1) + ypad, ...
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
759 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
760 lpos(3), lpos(4)];
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
761 new_pos = [lpos(1) + lpos(3) + 2 * xpad + tightinset(1), ...
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
762 ca_pos(2), ca_pos(3) - lpos(3) - 2 * xpad, ca_pos(4)];
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
763 new_pos(1) = new_pos(1) - gnuplot_offset;
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
764 new_pos(3) = 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
765 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
766 lpos = [ca_pos(1) + ypad, ...
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
767 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
768 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
769 case "northeast"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
770 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
771 lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3) - ypad, ...
12395
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
772 ca_pos(2) + ca_pos(4) - lpos(4), lpos(3), lpos(4)];
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
773 new_pos = [ca_pos(1), ca_pos(2), ...
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
774 lpos(1) - 2 * xpad - tightinset(3) - ca_pos(1), ...
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
775 ca_pos(4)];
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
776 new_pos(3) = 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
777 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
778 lpos = [ca_pos(1) + ca_pos(3) - lpos(3) - ypad, ...
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
779 ca_pos(2) + ca_pos(4) - lpos(4) - ypad, lpos(3), lpos(4)];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
780 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
781 case "northwest"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
782 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
783 lpos = [ca_outpos(1) + ypad , 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
784 lpos(3), lpos(4)];
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
785 new_pos = [lpos(1) + lpos(3) + 2 * xpad + tightinset(1), ...
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
786 ca_pos(2), ca_pos(3) - lpos(3) - 2 * xpad, ca_pos(4)];
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
787 new_pos(1) = new_pos(1) - gnuplot_offset;
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
788 new_pos(3) = 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
789 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
790 lpos = [ca_pos(1) + ypad, ...
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
791 ca_pos(2) + ca_pos(4) - lpos(4) - ypad, lpos(3), lpos(4)];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
792 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
793 case "southeast"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
794 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
795 lpos = [ca_outpos(1) + ca_outpos(3) - lpos(3) - ypad, ...
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
796 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
797 new_pos = [ca_pos(1), ca_pos(2), ...
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
798 lpos(1) - 2 * xpad - ca_pos(1) - tightinset(3), ...
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
799 ca_pos(4)];
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
800 new_pos(3) = 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
801 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
802 lpos = [ca_pos(1) + ca_pos(3) - lpos(3) - ypad, ...
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
803 ca_pos(2) + ypad, lpos(3), lpos(4)];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
804 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
805 case "southwest"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
806 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
807 lpos = [ca_outpos(1) + ypad, ca_pos(2), lpos(3), lpos(4)];
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
808 new_pos = [lpos(1) + lpos(3) + 2 * xpad + tightinset(1), ...
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
809 ca_pos(2), ca_pos(3) - lpos(3) - 2 * xpad, ca_pos(4)];
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
810 new_pos(1) = new_pos(1) - gnuplot_offset;
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
811 new_pos(3) = 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
812 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
813 lpos = [ca_pos(1) + ypad, ca_pos(2) + ypad, lpos(3), lpos(4)];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
814 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
815 endswitch
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
816
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
817 units = get (hlegend, "units");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
818 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
819 set (hlegend, "units", "points");
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
820 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
821 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
822 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
823 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
824
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
825 ## Now write the line segments and place the text objects correctly
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
826 xk = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
827 yk = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
828 for k = 1 : numel (hplots)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
829 hobjects = [hobjects, texthandle(k)];
11120
a44f979a35ce style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents: 11033
diff changeset
830 switch (get (hplots(k), "type"))
10999
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
831 case "line"
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
832 color = get (hplots(k), "color");
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
833 style = get (hplots(k), "linestyle");
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
834 if (! strcmp (style, "none"))
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
835 l1 = line ("xdata", ([xoffset, xoffset + linelength] + xk * xstep) / lpos(3),
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
836 "ydata", [1, 1] .* (lpos(4) - yoffset - yk * ystep) / lpos(4),
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
837 "color", color, "linestyle", style, "marker", "none",
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
838 "userdata", hplots (k));
10999
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
839 hobjects = [hobjects, l1];
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
840 endif
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
841 marker = get (hplots(k), "marker");
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
842 if (! strcmp (marker, "none"))
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
843 l1 = line ("xdata", (xoffset + 0.5 * linelength + xk * xstep) / lpos(3),
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
844 "ydata", (lpos(4) - yoffset - yk * ystep) / lpos(4),
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
845 "color", color, "linestyle", "none", "marker", marker,
11033
d9c8916bb9dd Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents: 11003
diff changeset
846 "markeredgecolor", get (hplots (k), "markeredgecolor"),
d9c8916bb9dd Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents: 11003
diff changeset
847 "markerfacecolor", get (hplots (k), "markerfacecolor"),
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
848 "markersize", get (hplots (k), "markersize"),
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
849 "userdata", hplots (k));
10999
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
850 hobjects = [hobjects, l1];
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
851 endif
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
852
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
853 addlistener (hplots(k), "color",
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
854 {@updateline, hlegend, linelength});
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
855 addlistener (hplots(k), "linestyle",
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
856 {@updateline, hlegend, linelength});
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
857 addlistener (hplots(k), "marker",
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
858 {@updateline, hlegend, linelength});
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
859 addlistener (hplots(k), "markeredgecolor",
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
860 {@updateline, hlegend, linelength});
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
861 addlistener (hplots(k), "markerfacecolor",
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
862 {@updateline, hlegend, linelength});
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
863 addlistener (hplots(k), "markersize",
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
864 {@updateline, hlegend, linelength});
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
865 addlistener (hplots(k), "displayname",
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
866 {@updateline, hlegend, linelength});
10999
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
867 case "patch"
14747
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
868 facecolor = get (hplots(k), "facecolor");
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
869 edgecolor = get (hplots(k), "edgecolor");
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
870 cdata = get (hplots(k), "cdata");
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
871 if (! strcmp (facecolor, "none") || ! strcmp (edgecolor, "none"))
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
872 p1 = patch ("xdata", ([0, linelength, linelength, 0] +
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
873 xoffset + xk * xstep) / lpos(3),
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
874 "ydata", (lpos(4) - yoffset -
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
875 [yk-0.3, yk-0.3, yk+0.3, yk+0.3] .* ystep) / lpos(4),
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
876 "facecolor", facecolor, "edgecolor", edgecolor,
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
877 "cdata", cdata, "userdata", hplots(k));
14747
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
878 hobjects = [hobjects, p1];
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
879 endif
10999
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
880 case "surface"
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
881 endswitch
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
882 set (texthandle (k), "position", [(txoffset + xk * xstep) / lpos(3), ...
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
883 (lpos(4) - yoffset - yk * ystep) / lpos(4)]);
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
884 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
885 yk++;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
886 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
887 yk = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
888 xk++;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
889 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
890 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
891 xk++;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
892 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
893 xk = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
894 yk++;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
895 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
896 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
897 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
898
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
899 ## Add an invisible text object to original axis
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
900 ## that when it is destroyed will remove the legend
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
901 props = {"parent", ca(1), "tag", "legend", ...
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
902 "handlevisibility", "off", "visible", "off", ...
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
903 "xliminclude", "off", "yliminclude", "off"};
16800
56102c33122d Fix problems with changeset 286904321282.
Ben Abbott <bpabbott@mac.com>
parents: 16799
diff changeset
904 t1 = findall (ca(1), props{3:4}, "type", "text");
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
905 if (isempty (t1))
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
906 t1 = text (0, 0, "", props{:});
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
907 set (t1, "deletefcn", {@deletelegend1, hlegend});
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
908 endif
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
909 if (isprop (hlegend, "unmodified_axes_position"))
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
910 set (hlegend, "unmodified_axes_position", unmodified_axes_position);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
911 set (hlegend, "unmodified_axes_outerposition",
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
912 unmodified_axes_outerposition);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
913 else
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
914 addproperty ("unmodified_axes_position", hlegend,
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
915 "data", unmodified_axes_position);
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
916 addproperty ("unmodified_axes_outerposition", hlegend,
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
917 "data", unmodified_axes_outerposition);
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
918 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
919
15441
e5a07d7aafcc legend.m: Remove unused warning variable and associated code.
Rik <rik@octave.org>
parents: 15440
diff changeset
920 ## Resize the axis that the legend is attached to if the
e5a07d7aafcc legend.m: Remove unused warning variable and associated code.
Rik <rik@octave.org>
parents: 15440
diff changeset
921 ## legend is "outside" the plot and create a listener to
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
922 ## resize axis to original size if the legend is deleted,
15441
e5a07d7aafcc legend.m: Remove unused warning variable and associated code.
Rik <rik@octave.org>
parents: 15440
diff changeset
923 ## 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
924 if (outside)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
925 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
926 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
927 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
928 set (ca(i), "units", "points");
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
929 if (gnuplot && numel (ca) == 1)
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
930 ## Let Gnuplot handle the positioning of the keybox.
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
931 ## This violates strict Matlab compatibility, but reliably
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
932 ## renders an esthetic result.
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
933 set (ca(i), "position", unmodified_axes_position);
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
934 set (ca(i), "activepositionproperty", "outerposition")
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
935 else
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
936 ## 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
937 set (ca(i), "position", new_pos);
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
938 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
939 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
940 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
941 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
942 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
943
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
944 set (hlegend, "deletefcn", {@deletelegend2, ca, ...
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
945 unmodified_axes_position, ...
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
946 unmodified_axes_outerposition, ...
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
947 t1, hplots});
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
948 addlistener (hlegend, "visible", {@hideshowlegend, ca, ...
16909
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
949 unmodified_axes_position, ...
8f9ed9d8a478 Allow gnuplot to handle keybox and axes positioning.
Ben Abbott <bpabbott@mac.com>
parents: 16908
diff changeset
950 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
951 else
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
952 set (hlegend, "deletefcn", {@deletelegend2, ca, [], [], t1, hplots});
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
953 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
954
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
955 if (addprops)
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
956 addproperty ("edgecolor", hlegend, "color", [0, 0, 0]);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
957 addproperty ("textcolor", hlegend, "color", [0, 0, 0]);
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
958 locations = {"north", "south", "east", "west", ...
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
959 "northeast", "southeast", "northwest", "southwest", ...
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
960 "northoutside", "southoutside", ...
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
961 "eastoutside", "westoutside", ...
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
962 "northeastoutside", "southeastoutside", ...
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
963 "northwestoutside", "southwestoutside"};
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
964 addproperty ("location", hlegend, "radio", strjoin (locations, "|"));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
965 addproperty ("orientation", hlegend, "radio",
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
966 "{vertical}|horizontal");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
967 addproperty ("string", hlegend, "any", text_strings);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
968 addproperty ("textposition", hlegend, "radio", "{left}|right");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
969 else
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
970 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
971 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
972
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
973 if (outside)
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
974 set (hlegend, "location", strcat (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
975 "orientation", orientation, "textposition", textpos);
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
976 else
16796
519343308ab1 Rename "position" variable to "location" in legend.m
Ben Abbott <bpabbott@mac.com>
parents: 16795
diff changeset
977 set (hlegend, "location", location, "orientation", orientation,
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
978 "textposition", textpos);
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
979 endif
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
980 if (addprops)
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
981 addlistener (hlegend, "edgecolor", @updatelegendtext);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
982 addlistener (hlegend, "textcolor", @updatelegendtext);
16885
fb80e1891cf9 Change to legend fontsize should trigger updatelegendtext.
Ben Abbott <bpabbott@mac.com>
parents: 16826
diff changeset
983 addlistener (hlegend, "fontsize", @updatelegendtext);
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
984 addlistener (hlegend, "interpreter", @updatelegendtext);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
985 addlistener (hlegend, "location", @updatelegend);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
986 addlistener (hlegend, "orientation", @updatelegend);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
987 addlistener (hlegend, "string", @updatelegend);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
988 addlistener (hlegend, "textposition", @updatelegend);
16910
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
989 ## TODO - need to add listeners for tighinset and position
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
990 ## addlistener (ca, "tightinset", @update????);
8a4e53cf79c9 Modify the plotbox position relative to the keybox position.
Ben Abbott <bpabbott@mac.com>
parents: 16909
diff changeset
991 ## addlistener (ca, "position", @update????);
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
992 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
993 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
994 set (fig, "currentaxes", curaxes);
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
995 end_unwind_protect
6272
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
996 endif
6147
e14b0e9b7bf7 [project @ 2006-11-09 03:28:01 by jwe]
jwe
parents: 6146
diff changeset
997 endif
e14b0e9b7bf7 [project @ 2006-11-09 03:28:01 by jwe]
jwe
parents: 6146
diff changeset
998
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
999 if (nargout > 0)
11134
7c045d801702 legend.m: Trivial fix to allow legend handle to be returned.
Ben Abbott <bpabbott@mac.com>
parents: 11120
diff changeset
1000 hlegend2 = hlegend;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1001 hobjects2 = hobjects;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1002 hplot2 = hplots;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1003 text_strings2 = text_strings;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1004 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1005
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1006 endfunction
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1007
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1008 function updatelegend (h, d)
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1009 persistent recursive = false;
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1010
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1011 if (! recursive)
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1012 recursive = true;
12339
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1013 unwind_protect
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1014 hax = getfield (get (h, "userdata"), "handle");
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1015 [hplots, text_strings] = __getlegenddata__ (h);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1016 position = get (h, "unmodified_axes_position");
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1017 outerposition = get (h, "unmodified_axes_outerposition");
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1018 units = get (hax, "units");
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1019 set (hax, "units", "points");
16933
e39f00a32dc7 maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents: 16921
diff changeset
1020 switch (get (hax, "activepositionproperty"))
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1021 case "position"
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1022 set (hax, "outerposition", outerposition);
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1023 set (hax, "position", position);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1024 case "outerposition"
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1025 set (hax, "position", position);
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1026 set (hax, "outerposition", outerposition);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1027 endswitch
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1028 set (hax, "units", units);
12339
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1029 h = legend (hax, hplots, get (h, "string"));
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1030 unwind_protect_cleanup
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1031 recursive = false;
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1032 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
1033 endif
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1034
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1035 endfunction
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1036
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1037 function updatelegendtext (h, d)
13979
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1038 hax = get (h, "userdata").handle;
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1039 kids = get (h, "children");
13979
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1040 text_kids = findobj (kids, "-property", "interpreter", "type", "text");
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1041 interpreter = get (h, "interpreter");
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1042 textcolor = get (h, "textcolor");
16002
cddf9103a566 Fix legend bugs (#38263, #38265).
Ben Abbott <bpabbott@mac.com>
parents: 15570
diff changeset
1043 fontsize = get (h, "fontsize");
cddf9103a566 Fix legend bugs (#38263, #38265).
Ben Abbott <bpabbott@mac.com>
parents: 15570
diff changeset
1044 set (text_kids, "interpreter", interpreter,
cddf9103a566 Fix legend bugs (#38263, #38265).
Ben Abbott <bpabbott@mac.com>
parents: 15570
diff changeset
1045 "fontsize", fontsize,
cddf9103a566 Fix legend bugs (#38263, #38265).
Ben Abbott <bpabbott@mac.com>
parents: 15570
diff changeset
1046 "color", textcolor);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1047 endfunction
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1048
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
1049 function hideshowlegend (h, d, ca, pos1, pos2)
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1050 isvisible = strcmp (get (h, "visible"), "off");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1051 if (! isvisible)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1052 kids = get (h, "children");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1053 for i = 1 : numel (kids)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1054 if (! strcmp (get (kids(i), "visible"), "off"))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1055 isvisible = true;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1056 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1057 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1058 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1059 endif
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 for i = 1 : numel (ca)
17125
b5d6314314fc Change various plot functions to take advantage of new isaxes() function.
Rik <rik@octave.org>
parents: 17122
diff changeset
1062 if (isaxes (ca(i))
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14755
diff changeset
1063 && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"),"off"))
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11134
diff changeset
1064 && strcmp (get (ca(i), "beingdeleted"), "off"))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1065 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
1066 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1067 set (ca(i), "units", "points");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1068 if (isvisible)
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
1069 set (ca(i), "position", pos2);
10990
529b36293297 Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents: 10989
diff changeset
1070 else
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
1071 set (ca(i), "position", pos1);
10990
529b36293297 Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents: 10989
diff changeset
1072 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1073 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
1074 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
1075 end_unwind_protect
10990
529b36293297 Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents: 10989
diff changeset
1076 endif
529b36293297 Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents: 10989
diff changeset
1077 endfor
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1078 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
1079
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1080 function deletelegend1 (h, d, ca)
17125
b5d6314314fc Change various plot functions to take advantage of new isaxes() function.
Rik <rik@octave.org>
parents: 17122
diff changeset
1081 if (isaxes (ca)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1082 && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off"))
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11134
diff changeset
1083 && strcmp (get (ca, "beingdeleted"), "off"))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1084 delete (ca);
10989
6ea65c5de87a Respect the units and paperunits figure properties and the units and fontunits axes properties
David Bateman <dbateman@free.fr>
parents: 10949
diff changeset
1085 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1086 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
1087
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1088 function deletelegend2 (h, d, ca, pos, outpos, t1, hplots)
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1089 for i = 1 : numel (ca)
17125
b5d6314314fc Change various plot functions to take advantage of new isaxes() function.
Rik <rik@octave.org>
parents: 17122
diff changeset
1090 if (isaxes (ca(i))
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1091 && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off"))
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11134
diff changeset
1092 && strcmp (get (ca(i), "beingdeleted"), "off"))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1093 if (!isempty (pos) && !isempty(outpos))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1094 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
1095 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1096 set (ca(i), "units", "points");
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
1097 set (ca(i), "position", pos, "deletefcn", "");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1098 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
1099 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
1100 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
1101 endif
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
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1103 endfor
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1104 set (t1, "deletefcn", "");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1105 delete (t1);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1106 for i = 1 : numel (hplots)
15569
3649a6012eaa legend.m: Fix segmentation fault when deleting legend where plot has already been removed (Bug #37640)
Rik <rik@octave.org>
parents: 14138
diff changeset
1107 if (ishandle (hplots(i)) && strcmp (get (hplots (i), "type"), "line"))
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1108 dellistener (hplots(i), "color");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1109 dellistener (hplots(i), "linestyle");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1110 dellistener (hplots(i), "marker");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1111 dellistener (hplots(i), "markeredgecolor");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1112 dellistener (hplots(i), "markerfacecolor");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1113 dellistener (hplots(i), "markersize");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1114 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
1115 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1116 endfor
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1117 endfunction
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1118
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1119 function updateline (h, d, hlegend, linelength)
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1120 lm = [];
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1121 ll = [];
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1122 kids = get (hlegend, "children");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1123 for i = 1 : numel (kids)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1124 if (get (kids(i), "userdata") == h
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1125 && strcmp (get (kids(i), "type"), "line"))
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1126 if (strcmp (get (kids (i), "marker"), "none"))
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1127 ll = kids(i);
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1128 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1129 lm = kids(i);
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1130 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1131 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1132 endfor
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1133
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1134 linestyle = get (h, "linestyle");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1135 marker = get (h, "marker");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1136 displayname = get (h, "displayname");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1137
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
1138 if ((isempty (displayname)
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1139 || (strcmp (marker, "none") && strcmp (linestyle, "none")))
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1140 && (! isempty (lm) || isempty (ll)))
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1141 ## An element was removed from the legend. Need to recall the
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1142 ## legend function to recreate a new legend
12339
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1143 [hplots, text_strings] = __getlegenddata__ (hlegend);
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1144 for i = 1 : numel (hplots)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1145 if (hplots(i) == h)
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1146 hplots(i) = [];
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1147 text_strings(i) = [];
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1148 break;
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1149 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1150 endfor
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1151 legend (hplots, text_strings);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
1152 elseif ((!isempty (displayname)
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1153 && (! strcmp (marker, "none") || ! strcmp (linestyle, "none")))
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1154 && isempty (lm) && isempty (ll))
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1155 ## An element was added to the legend. Need to re-call the
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1156 ## legend function to recreate a new legend.
12339
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1157 [hplots, text_strings] = __getlegenddata__ (hlegend);
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1158 hplots = [hplots, h];
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1159 text_strings = {text_strings{:}, displayname};
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1160 legend (hplots, text_strings);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1161 else
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1162 if (! isempty (ll))
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1163 ypos1 = get (ll,"ydata");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1164 xpos1 = get (ll,"xdata");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1165 ypos2 = ypos1(1);
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1166 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
1167 delete (ll);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1168 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
1169 delete (lm);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1170 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1171 else
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1172 ypos2 = get (lm,"ydata");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1173 xpos2 = get (lm,"xdata");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1174 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
1175 xpos1 = xpos2 + [-0.5, 0.5] * linelength;
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1176 delete (lm);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1177 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1178 if (! strcmp (linestyle, "none"))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
1179 line ("xdata", xpos1, "ydata", ypos1, "color", get (h, "color"),
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1180 "linestyle", get (h, "linestyle"), "marker", "none",
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1181 "userdata", h, "parent", hlegend);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1182 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1183 if (! strcmp (marker, "none"))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
1184 line ("xdata", xpos2, "ydata", ypos2, "color", get (h, "color"),
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1185 "marker", marker, "markeredgecolor", get (h, "markeredgecolor"),
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1186 "markerfacecolor", get (h, "markerfacecolor"),
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1187 "markersize", get (h, "markersize"), "linestyle", "none",
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1188 "userdata", h, "parent", hlegend);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1189 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1190 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1191 endfunction
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1192
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1193
11418
a140991387fb legend.m: Add demo to legend for inline key.
Ben Abbott <bpabbott@mac.com>
parents: 11363
diff changeset
1194 %!demo
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1195 %! clf;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1196 %! plot (rand (2));
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1197 %! title ('legend called with cellstr and string inputs for labels');
16728
5cf7369a74cb Update legend box when the fontsize changes.
Ben Abbott <bpabbott@mac.com>
parents: 16094
diff changeset
1198 %! h = legend ({'foo'}, 'bar');
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1199 %! legend location northeastoutside
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1200 %! 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
1201
aed2c50c3082 legend.m: legend with more than two inline keys (bug 31991). Add/modifyy demos.
Ben Abbott <bpabbott@mac.com>
parents: 11434
diff changeset
1202 %!demo
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1203 %! clf;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1204 %! plot (rand (3));
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1205 %! title ('legend() without inputs creates default labels');
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1206 %! h = legend ();
14236
35903f035390 Escaping strings for legend entries are handled by __go_draw_axes__.
Ben Abbott <bpabbott@mac.com>
parents: 14214
diff changeset
1207
35903f035390 Escaping strings for legend entries are handled by __go_draw_axes__.
Ben Abbott <bpabbott@mac.com>
parents: 14214
diff changeset
1208 %!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
1209 %! clf;
11418
a140991387fb legend.m: Add demo to legend for inline key.
Ben Abbott <bpabbott@mac.com>
parents: 11363
diff changeset
1210 %! x = 0:1;
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1211 %! plot (x,x,';I am Blue;', x,2*x, x,3*x,';I am Red;');
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1212 %! legend location northeastoutside
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1213 %! ## Placing legend inside should return axes to original size
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1214 %! legend location northeast
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1215 %! title ('Blue and Red keys, with Green missing');
8343
9f34f7636fe0 legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents: 8291
diff changeset
1216
9f34f7636fe0 legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents: 8291
diff changeset
1217 %!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
1218 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1219 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1220 %! title ('incline is blue and decline is green');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1221 %! legend ({'I am blue', 'I am green'}, 'location', 'east');
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1222 %! legend hide
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1223 %! legend show
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1224
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1225 %!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
1226 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1227 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1228 %! title ('Legend with keys in horizontal orientation');
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1229 %! legend ({'I am blue', 'I am green'}, ...
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1230 %! 'location', 'east', 'orientation', 'horizontal');
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1231 %! legend boxoff
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1232 %! 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
1233
aed2c50c3082 legend.m: legend with more than two inline keys (bug 31991). Add/modifyy demos.
Ben Abbott <bpabbott@mac.com>
parents: 11434
diff changeset
1234 %!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
1235 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1236 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
14529
aabdc8f281f1 legend.m: Change default to boxon for Matlab compatibility (bug #36105).
Rik <octave@nomad.inbox5.com>
parents: 14375
diff changeset
1237 %! title ('Legend with box off');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1238 %! legend ({'I am blue', 'I am green'}, 'location', 'east');
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1239 %! legend boxoff
11434
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1240
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1241 %!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
1242 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1243 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1244 %! title ('Legend with text to the right of key');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1245 %! legend ({'I am blue', 'I am green'}, 'location', 'east');
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1246 %! legend right
8343
9f34f7636fe0 legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents: 8291
diff changeset
1247
9f34f7636fe0 legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents: 8291
diff changeset
1248 %!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
1249 %! clf;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1250 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1251 %! title ({'Use properties to place legend text to the right of key', ...
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1252 %! 'Legend text color is magenta'});
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1253 %! h = legend ({'I am blue', 'I am green'}, 'location', 'east');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1254 %! legend ('left');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1255 %! set (h, 'textposition', 'right');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1256 %! set (h, 'textcolor', [1 0 1]);
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1257
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1258 %!demo
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1259 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1260 %! plot (1:10, 1:10, 1:10, fliplr (1:10));
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1261 %! title ('Legend is hidden')
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1262 %! legend ({'I am blue', 'I am green'}, 'location', 'east');
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1263 %! legend hide
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1264
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1265 %!demo
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1266 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1267 %! x = 0:1;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1268 %! plot (x,x,';I am Blue;', x,2*x,';I am Green;', x,3*x,';I am Red;');
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1269 %! title ({'Labels are embedded in call to plot', ...
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1270 %! '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
1271 %! legend boxon
11434
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1272 %! legend hide
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1273 %! legend show
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1274
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1275 %!demo
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1276 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1277 %! x = 0:1;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1278 %! plot (x, x, ';\alpha;', ...
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1279 %! x, 2*x, ';\beta=2\alpha;', ...
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1280 %! x, 3*x, ';\gamma=3\alpha;');
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1281 %! title ('Labels with interpreted Greek text');
11434
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1282
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1283 %!demo
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1284 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1285 %! plot (rand (2));
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1286 %! title ('Labels with TeX interpreter turned off');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1287 %! h = legend ('Hello_World', 'foo^bar');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1288 %! set (h, 'interpreter', 'none');
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1289
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1290 %!demo
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1291 %! clf;
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1292 %! plot (1:10, 1:10);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1293 %! title ('a very long label can sometimes cause problems');
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1294 %! legend ('hello very big world', 'location', 'northeastoutside');
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1295
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1296 %!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
1297 %! clf;
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
1298 %! labels = {};
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1299 %! colororder = get (gca, 'colororder');
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
1300 %! 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
1301 %! h = plot (1:100, i + rand (100,1)); hold on;
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1302 %! set (h, 'color', colororder(i,:));
14252
4e6436a60b62 Changes to allow plot demos to be run under Matlab.
Ben Abbott <bpabbott@mac.com>
parents: 14245
diff changeset
1303 %! labels = {labels{:}, ['Signal ', num2str(i)]};
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1304 %! end
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1305 %! hold off;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1306 %! title ({'Signals with random offset and uniform noise';
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1307 %! 'Legend shown below and outside of plot'});
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1308 %! xlabel ('Sample Nr [k]'); ylabel ('Amplitude [V]');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1309 %! legend (labels, 'location', 'southoutside');
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1310
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1311 %!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
1312 %! clf;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1313 %! x = linspace (0, 10);
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1314 %! 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
1315 %! hold on;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1316 %! stem (x, x.^2, 'g');
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1317 %! title ('First created object gets first label');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1318 %! 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
1319 %! hold off;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1320
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1321 %!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
1322 %! clf;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1323 %! x = linspace (0, 10);
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1324 %! plot (x, x, x, x.^2);
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1325 %! title ('First created object gets first label');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1326 %! legend ('linear');
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1327
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1328 %!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
1329 %! clf;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1330 %! x = linspace (0, 10);
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1331 %! plot (x, x, x, x.^2);
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1332 %! title ('Labels are applied in order of object creation');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1333 %! 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
1334
f9fb8c1a8e45 legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents: 9451
diff changeset
1335 %!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
1336 %! clf;
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1337 %! 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
1338 %! 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
1339 %! ylim ([0 1.0]);
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1340 %! title ('legend() works for bar graphs (hgobjects)');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1341 %! legend ({'1st Bar', '2nd Bar', '3rd Bar'});
9457
f9fb8c1a8e45 legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents: 9451
diff changeset
1342
f9fb8c1a8e45 legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents: 9451
diff changeset
1343 %!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
1344 %! clf;
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1345 %! 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
1346 %! bar (rand_2x3_data2);
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1347 %! ylim ([0 1.2]);
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1348 %! title ('legend() works for bar graphs (hgobjects)');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1349 %! legend ('1st Bar', '2nd Bar', '3rd Bar');
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1350 %! legend right;
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
1351
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
1352 %!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
1353 %! clf;
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
1354 %! 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
1355 %! h = plot (x,sin(x), x,cos(x), x,sin(x.^2/10), x,cos(x.^2/10));
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1356 %! title ('Only the sin() objects have keylabels');
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1357 %! 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
1358
12340
d63007ac067a legend.m: Add demo for inline keys created by two plot commands.
Ben Abbott <bpabbott@mac.com>
parents: 12339
diff changeset
1359 %!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
1360 %! clf;
12340
d63007ac067a legend.m: Add demo for inline keys created by two plot commands.
Ben Abbott <bpabbott@mac.com>
parents: 12339
diff changeset
1361 %! x = 0:0.1:10;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1362 %! plot (x, sin (x), ';sin (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
1363 %! hold all;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1364 %! 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
1365 %! hold off;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1366 %! 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
1367
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1368 %!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
1369 %! clf;
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1370 %! x = 0:0.1:10;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1371 %! plot (x, sin (x), ';sin (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
1372 %! hold all;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1373 %! 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
1374 %! hold off;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1375 %! title ('Specified label text overrides previous labels');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1376 %! legend ({'Sine', 'Cosine'}, 'location', 'northeastoutside');
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1377
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
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;
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
1380 %! x = 0:10;
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
1381 %! plot (x, rand (11));
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1382 %! xlabel ('Indices');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1383 %! ylabel ('Random Values');
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1384 %! title ('Legend ''off'' deletes the legend');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1385 %! legend (cellstr (num2str ((1:10)')), 'location', 'northeastoutside');
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1386 %! legend off;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1387 %! axis ([0, 10, 0 1]);
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1388
12395
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
1389 %!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
1390 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1391 %! x = (1:5)';
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1392 %! 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
1393 %! plot (x, rand (numel (x)));
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1394 %! 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
1395 %! 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
1396 %! plot (x, rand (numel (x)));
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1397 %! 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
1398 %! 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
1399 %! plot (x, rand (numel (x)));
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1400 %! 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
1401 %! 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
1402 %! plot (x, rand (numel (x)));
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1403 %! legend (cellstr (num2str (x)), 'location', 'southeastoutside');
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1404
12395
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
1405 %!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
1406 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1407 %! plot (rand (2));
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1408 %! title ('legend() will warn if extra labels are specified');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1409 %! 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
1410
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1411 %!demo
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1412 %! clf;
14207
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1413 %! x = 0:10;
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1414 %! y1 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1415 %! y2 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1416 %! [ax, h1, h2] = plotyy (x, y1, x, y2);
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1417 %! title ('plotyy legend test #1: Blue and Green labels');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1418 %! legend ([h1, h2], {'Blue', 'Green'}, 'location', 'south');
12395
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
1419
13979
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1420 %!demo
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1421 %! clf;
14207
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1422 %! x = 0:10;
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1423 %! y1 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1424 %! y2 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1425 %! [ax, h1, h2] = plotyy (x, y1, x, y2);
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1426 %! title ('plotyy legend test #2: Blue and Green labels');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1427 %! legend ({'Blue', 'Green'}, 'location', 'south');
13979
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1428
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1429 %!demo
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1430 %! clf;
14207
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1431 %! x = 0:10;
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1432 %! y1 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1433 %! y2 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1434 %! [ax, h1, h2] = plotyy (x, y1, x, y2);
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1435 %! title ('plotyy legend test #3: Blue and Green labels');
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1436 %! legend ('Blue', 'Green', 'location', 'south');
13979
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1437
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1438 %!demo % bug 36408
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1439 %! clf;
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1440 %! option = 'right';
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1441 %! 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
1442 %! 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
1443 %! 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
1444 %! ylabel ylabel;
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1445 %! title ('Subplots should adjust to the legend placed outside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1446 %! legend ({'1'}, 'location', 'northeastoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1447 %! legend (option);
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1448 %! 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
1449 %! 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
1450 %! 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
1451 %! ylabel ylabel;
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1452 %! legend ({'1234567890'}, 'location', 'eastoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1453 %! legend (option);
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1454 %! 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
1455 %! 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
1456 %! 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
1457 %! ylabel ylabel;
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1458 %! legend ({'12345678901234567890'}, 'location', 'southeastoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1459 %! legend (option);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1460
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1461 %!demo % bug 36408
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1462 %! clf;
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1463 %! 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
1464 %! 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
1465 %! 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
1466 %! title ('Subplots should adjust to the legend placed outside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1467 %! legend ({'1'}, 'location', 'northwestoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1468 %! legend (option);
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1469 %! 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
1470 %! 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
1471 %! legend ({'1234567890'}, 'location', 'westoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1472 %! legend (option);
16805
2281d957cde6 legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents: 16800
diff changeset
1473 %! 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
1474 %! 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
1475 %! legend ({'12345678901234567890'}, 'location', 'southwestoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1476 %! legend (option);
16799
286904321282 Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents: 16796
diff changeset
1477
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1478 %!demo % bug 36408
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1479 %! clf;
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1480 %! option = 'right';
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1481 %! 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
1482 %! 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
1483 %! set (gca (), 'yaxislocation', 'right');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1484 %! 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
1485 %! ylabel ('ylabel');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1486 %! title ('Subplots should adjust to the legend placed outside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1487 %! legend ({'1'}, 'location', 'northeastoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1488 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1489 %! 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
1490 %! 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
1491 %! set (gca (), 'yaxislocation', 'right');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1492 %! 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
1493 %! ylabel ('ylabel');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1494 %! legend ({'1234567890'}, 'location', 'eastoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1495 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1496 %! 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
1497 %! 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
1498 %! set (gca (), 'yaxislocation', 'right');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1499 %! 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
1500 %! ylabel ('ylabel');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1501 %! legend ({'12345678901234567890'}, 'location', 'southeastoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1502 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1503
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1504 %!demo % bug 36408
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1505 %! clf;
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1506 %! 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
1507 %! 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
1508 %! 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
1509 %! set (gca (), 'yaxislocation', 'right');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1510 %! 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
1511 %! ylabel ('ylabel');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1512 %! title ('Subplots should adjust to the legend placed outside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1513 %! legend ({'1'}, 'location', 'northwestoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1514 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1515 %! 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
1516 %! 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
1517 %! set (gca (), 'yaxislocation', 'right');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1518 %! 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
1519 %! ylabel ('ylabel');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1520 %! legend ({'1234567890'}, 'location', 'westoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1521 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1522 %! 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
1523 %! 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
1524 %! set (gca (), 'yaxislocation', 'right');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1525 %! 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
1526 %! ylabel ('ylabel');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1527 %! legend ({'12345678901234567890'}, 'location', 'southwestoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1528 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1529
16921
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1530 %!demo % bug 36408;
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1531 %! clf;
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1532 %! 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
1533 %! 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
1534 %! 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
1535 %! set (gca (), 'xaxislocation', 'top');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1536 %! 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
1537 %! ylabel ('ylabel');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1538 %! title ('Subplots should adjust to the legend placed outside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1539 %! legend ({'1'}, 'location', 'northwestoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1540 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1541 %! 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
1542 %! 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
1543 %! set (gca (), 'xaxislocation', 'top');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1544 %! 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
1545 %! ylabel ('ylabel');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1546 %! legend ({'1234567890'}, 'location', 'westoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1547 %! legend (option);
16908
1c4be5dcacd5 Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents: 16885
diff changeset
1548 %! 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
1549 %! 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
1550 %! set (gca (), 'xaxislocation', 'top');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1551 %! 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
1552 %! ylabel ('ylabel');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1553 %! legend ({'12345678901234567890'}, 'location', 'southwestoutside');
9a316ec12b5f legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents: 16910
diff changeset
1554 %! 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
1555
16973
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1556 %!test
17107
dbd64c9a16da Restore graphics toolkit after %!tests that alter it.
Rik <rik@octave.org>
parents: 17065
diff changeset
1557 %! 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
1558 %! 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
1559 %! unwind_protect
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1560 %! position = get (h, "position");
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1561 %! plot (rand (3));
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1562 %! legend ();
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1563 %! filename = sprintf ("%s.eps", tmpnam ());
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1564 %! print (filename);
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1565 %! unlink (filename);
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1566 %! 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
1567 %! unwind_protect_cleanup
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1568 %! close (h);
17107
dbd64c9a16da Restore graphics toolkit after %!tests that alter it.
Rik <rik@octave.org>
parents: 17065
diff changeset
1569 %! graphics_toolkit (toolkit);
16973
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1570 %! end_unwind_protect
d429a05dc11c legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents: 16933
diff changeset
1571