annotate scripts/plot/legend.m @ 16728:5cf7369a74cb

Update legend box when the fontsize changes. * scripts/plot/legend.m: Use the legend fontsize property when creating text objects. Update the legend when the fontsize property changes. Modify demo. Bug # 38265.
author Ben Abbott <bpabbott@mac.com>
date Thu, 06 Jun 2013 12:59:41 +0800
parents 8899c785cc99
children 38c1a421f082
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 ##
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
31 ## Display a legend for the axes with handle @var{hax}, or the current axes,
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
32 ## using the specified strings as labels. Legend entries may be specified
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
33 ## as individual character string arguments, a character array, or a cell
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
34 ## array of character strings. If the handles, @var{hobjs}, are not specified
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
35 ## then the legend's strings will be associated with the axes' descendants.
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
36 ## @code{legend} works on line graphs, bar graphs, etc.
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
37 ## A plot must exist before legend is called.
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
38 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
39 ## 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
40 ## as follows:
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
41 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
42 ## @multitable @columnfractions 0.06 0.14 0.80
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
43 ##
13937
1ab3062df1ae Add headers to texinfo table for legend.m
Ben Abbott <bpabbott@mac.com>
parents: 13936
diff changeset
44 ## @headitem @tab @var{pos} @tab
1ab3062df1ae Add headers to texinfo table for legend.m
Ben Abbott <bpabbott@mac.com>
parents: 13936
diff changeset
45 ## location of the legend
1ab3062df1ae Add headers to texinfo table for legend.m
Ben Abbott <bpabbott@mac.com>
parents: 13936
diff changeset
46 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
47 ## @item @tab north @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
48 ## center top
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
49 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
50 ## @item @tab south @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
51 ## center bottom
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 east @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
54 ## right center
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 west @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
57 ## left 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 northeast @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
60 ## right top (default)
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 northwest @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
63 ## left top
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 southeast @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
66 ## right bottom
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 southwest @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
69 ## left bottom
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
70 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
71 ## @item
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
72 ##
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
73 ## @item @tab outside @tab
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
74 ## can be appended to any location string
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
75 ## @end multitable
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
76 ##
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
77 ## 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
78 ## 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
79 ## "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
80 ##
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
81 ## The following customizations are available using @var{option}:
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
82 ##
7148
735086cfd405 [project @ 2007-11-09 18:01:44 by jwe]
jwe
parents: 7054
diff changeset
83 ## @table @asis
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
84 ## @item "show"
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
85 ## Show legend on the plot
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
86 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
87 ## @item "hide"
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
88 ## Hide legend on the plot
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
89 ##
16094
8899c785cc99 doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents: 16002
diff changeset
90 ## @item "toggle"
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
91 ## Toggles between "hide" and "show"
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
92 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
93 ## @item "boxon"
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
94 ## Show a box around legend
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10666
diff changeset
95 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
96 ## @item "boxoff"
10666
7a43499f074a legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents: 10662
diff changeset
97 ## Hide the 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 "left"
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
100 ## 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
101 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6740
diff changeset
102 ## @item "right"
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 right of the keys
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
104 ##
16094
8899c785cc99 doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents: 16002
diff changeset
105 ## @item "off"
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
106 ## Delete the legend object
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
107 ## @end table
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
108 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
109 ## 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
110 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
111 ## @table @var
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
112 ## @item hleg
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
113 ## 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
114 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
115 ## @item hleg_obj
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
116 ## Graphics handles to the 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
117 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
118 ## @item hplot
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 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
120 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
121 ## @item labels
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
122 ## 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
123 ## @end table
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
124 ##
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
125 ## 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
126 ## 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
127 ## labels or DisplayNames are available, then the label text is simply
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
128 ## "data1", "data2", @dots{}, "dataN".
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
129 ## @end deftypefn
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
130
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
131 function [hlegend2, hobjects2, hplot2, text_strings2] = legend (varargin)
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
132
11246
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
133 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
134 && (! 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
135 || (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
136 && ! strcmp (get (varargin{1}, "tag"), "legend"))))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
137 [ca, varargin, nargs] = __plt_get_axis_arg__ ("legend", varargin{:});
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
138 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
139 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
140 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
141 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
142 fig = gcf ();
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
143 endif
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
144 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
145 endif
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
146
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
147 ## Special handling for plotyy which has two axes objects
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
148 if (ishandle (ca) && isprop (ca, "__plotyy_axes__"))
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
149 plty = get (ca, "__plotyy_axes__");
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
150 if (isscalar (plty) && ishandle (plty))
11199
91c606a68693 minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents: 11198
diff changeset
151 ca = [ca, plty];
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
152 elseif (iscell (plty))
11199
91c606a68693 minor fix to previous changeset
David Bateman <dbateman@free.fr>
parents: 11198
diff changeset
153 ca = [ca, plty{:}];
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
154 elseif (all (ishandle (plty)))
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
155 ca = [ca, plty(:).'];
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
156 else
15202
f3b5cadfd6d5 fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents: 14868
diff changeset
157 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
158 endif
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
159 ## Remove duplicates while preserving order
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13141
diff changeset
160 [~, n] = unique (ca);
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
161 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
162 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
163
11246
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
164 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
165 kids = flipud (varargin{1}(:));
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
166 varargin(1) = [];
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
167 else
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
168 kids = ca;
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
169 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
170 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
171 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
172 else
14207
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
173 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
174 endif
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
175 endif
11246
c463aed850b0 allow legend and gcf to work when no figure is present
John W. Eaton <jwe@octave.org>
parents: 11200
diff changeset
176 nargs = numel (varargin);
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
177 nkids = numel (kids);
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
178
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
179 orientation = "default";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
180 position = "default";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
181 show = "create";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
182 textpos = "default";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
183 box = "default";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
184
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
185 ## Process old way of specifying position with a number rather than a string.
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
186 if (nargs > 0)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
187 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
188 if (isnumeric (pos) && isscalar (pos) && pos == fix (pos))
6395
a8dd70bacc1e [project @ 2007-03-07 22:22:12 by jwe]
jwe
parents: 6272
diff changeset
189 if (pos >= -1 && pos <= 4)
11003
b1cfff739af5 legend.m: Index location cellstr to obtain a string.
Ben Abbott <bpabbott@mac.com>
parents: 10999
diff changeset
190 position = [{"northeastoutside", "best", "northeast",
b1cfff739af5 legend.m: Index location cellstr to obtain a string.
Ben Abbott <bpabbott@mac.com>
parents: 10999
diff changeset
191 "northwest", "southwest", "southeast"}] {pos + 2};
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
192 nargs--;
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
193 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
194 error ("legend: invalid position specified");
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
195 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
196 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
197 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
198
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
199 ## Find position 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
200 while (nargs > 1)
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
201 pos = varargin{nargs-1};
7054
1c5b2b5b58ba [project @ 2007-10-23 23:22:16 by jwe]
jwe
parents: 7017
diff changeset
202 str = varargin{nargs};
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
203 if (strcmpi (pos, "location") && ischar (str))
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
204 position = lower (str);
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
205 nargs -= 2;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
206 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
207 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
208 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
209 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
210 break;
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
211 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
212 endwhile
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
213
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
214 ## 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
215 switch (orientation)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
216 case {"vertical", "horizontal", "default"}
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
217 otherwise
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
218 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
219 endswitch
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
220
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
221 ## Validate the position type
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
222 outside = false;
14214
2fe0f5fa8cc3 Replace to-be-deprecated findstr occurrences with strfind.
Rik <octave@nomad.inbox5.com>
parents: 14207
diff changeset
223 inout = strfind (position, "outside");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
224 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
225 outside = true;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
226 position = position(1:inout-1);
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
227 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
228 outside = false;
6977
e78e31f0a236 [project @ 2007-10-08 19:09:32 by jwe]
jwe
parents: 6895
diff changeset
229 endif
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
230
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
231 switch (position)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
232 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
233 "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
234 case "best"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
235 warning ("legend: 'Best' not yet implemented for location specifier\n");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
236 position = "northeast";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
237 otherwise
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
238 error ("legend: unrecognized legend position");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
239 endswitch
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
240
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
241 ## 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
242 hlegend = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
243 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
244 for i = 1 : numel (fkids)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
245 if (ishandle (fkids(i)) && strcmp (get (fkids(i), "type"), "axes")
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
246 && (strcmp (get (fkids(i), "tag"), "legend")))
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
247 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
248 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
249 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
250 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
251 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
252 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
253 endfor
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6163
diff changeset
254
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
255 if (nargs == 1)
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
256 arg = varargin{1};
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
257 if (ischar (arg))
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
258 if (rows (arg) == 1)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
259 str = tolower (strtrim (arg));
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
260 switch (str)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
261 case "off"
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
262 delete (hlegend);
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
263 return;
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
264 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
265 show = "off";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
266 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
267 case "show"
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
268 if (! isempty (hlegend))
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
269 show = "on";
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
270 else
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
271 show = "create";
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
272 textpos = "left";
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
273 endif
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
274 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
275 case "toggle"
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
276 if (isempty (hlegend))
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
277 show = "create";
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
278 textpos = "left";
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
279 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
280 show = "on";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
281 else
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
282 show = "off";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
283 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
284 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
285 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
286 box = "on";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
287 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
288 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
289 box = "off";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
290 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
291 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
292 textpos = "left";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
293 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
294 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
295 textpos = "right";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
296 nargs--;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
297 endswitch
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
298 else
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
299 ## Character matrix of labels
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
300 varargin = cellstr (arg);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9457
diff changeset
301 nargs = numel (varargin);
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
302 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
303 elseif (iscellstr (arg))
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
304 ## 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
305 varargin = arg;
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
306 nargs = numel (varargin);
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
307 else
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
308 error ("legend: expecting argument to be a character string");
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
309 endif
14589
fd6e50e2eee6 legend() should accept labels being specified as both cellstrs and char.
Ben Abbott <bpabbott@mac.com>
parents: 14585
diff changeset
310 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
311 ## 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
312 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
313 nargs = numel (varargin);
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
314 endif
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
315
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
316 have_labels = (nargs > 0);
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
317
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
318 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
319 if (! isempty (hlegend))
14578
f579a94aacaa Preserve legend handle when changing properties (Bug # 36259).
Carnë Draug <carandraug+dev@gmail.com>
parents: 14552
diff changeset
320 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
321 hlegend = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
322 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
323 hobjects = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
324 hplots = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
325 text_strings = {};
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
326 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
327 if (! isempty (hlegend))
14578
f579a94aacaa Preserve legend handle when changing properties (Bug # 36259).
Carnë Draug <carandraug+dev@gmail.com>
parents: 14552
diff changeset
328 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
329 ## 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
330 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
331 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
332 hobjects = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
333 hplots = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
334 text_strings = {};
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
335 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
336 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
337 if (! isempty (hlegend))
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
338 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
339 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
340 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
341 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
342 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
343 endif
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
344 elseif (! have_labels && !(strcmp (position, "default") &&
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
345 strcmp (orientation, "default")))
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
346 ## 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
347 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
348 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
349 [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
350
14552
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14529
diff changeset
351 if (strcmp (position, "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
352 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
353 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
354 if (outside)
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12440
diff changeset
355 h = legend (hax, hplots, text_strings, "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
356 strcat (position, "outside"));
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
357 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
358 h = legend (hax, hplots, text_strings, "location", position);
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 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
360 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
361 if (outside)
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 12440
diff changeset
362 h = legend (hax, hplots, text_strings, "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
363 strcat (position, "outside"), "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 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
365 h = legend (hax, hplots, text_strings, "location", position,
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
366 "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
367 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
368 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
369 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
370 else
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
371 ## 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
372 hobjects = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
373 hplots = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
374 text_strings = {};
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
375
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
376 if (have_labels)
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
377 ## 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
378 have_data = false;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
379 have_dname = false;
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
380 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
381 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
382 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
383 || 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
384 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
385 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
386 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
387 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
388
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
389 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
390 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
391 endif
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
392 else
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
393 ## 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
394 have_dname = false;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
395 for k = 1 : nkids
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
396 hkid = kids(k);
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
397 typ = get (hkid, "type");
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
398 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
399 || strcmp (typ, "patch"))
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
400 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
401 have_dname = true;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
402 break;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
403 endif
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
404 elseif (strcmp (typ, "hggroup"))
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
405 hgkids = get (hkid, "children");
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
406 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
407 hgobj = get (hgkids(j));
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
408 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
409 have_dname = true;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
410 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
411 endif
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
412 endfor
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
413 if (have_dname)
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
414 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
415 endif
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
416 endif # elseif hggroup
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
417 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
418 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
419
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
420 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
421 k = nkids;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
422 if (! have_labels)
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
423 varargin = arrayfun (@(x) sprintf ("data%d", x), [1:nkids]', "uniformoutput", false);
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
424 nargs = nkids;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
425 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
426 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
427 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
428 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
429 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
430 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
431 && ! (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
432 || 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
433 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
434 endwhile
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
435 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
436 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
437 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
438 for j = 1 : length (hgkids)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
439 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
440 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
441 if (have_labels)
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
442 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
443 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
444 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
445 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
446 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
447 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
448 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
449 else
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
450 if (have_labels)
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
451 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
452 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
453 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
454 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
455 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
456
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
457 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
458 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
459 endif
15441
e5a07d7aafcc legend.m: Remove unused warning variable and associated code.
Rik <rik@octave.org>
parents: 15440
diff changeset
460 else
e5a07d7aafcc legend.m: Remove unused warning variable and associated code.
Rik <rik@octave.org>
parents: 15440
diff changeset
461 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
462 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
463 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
464 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
465 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
466 endfor
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
467 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
468 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
469 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
470 else
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
471 ## 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
472 k = nkids;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
473 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
474 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
475 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
476 && ! (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
477 || 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
478 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
479 endwhile
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
480 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
481 || strcmp (typ, "patch") || strcmp (typ, "hggroup")))
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
482 break
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
483 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
484 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
485 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
486 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
487 for j = 1 : length (hgkids)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
488 hgobj = get (hgkids(j));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
489 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
490 && ! 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
491 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
492 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
493 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
494 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
495 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
496 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
497 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
498 hplots = [hplots, kids(k)];
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
499 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
500 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
501 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
502 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
503 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
504 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
505 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
506 endwhile
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
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
509 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
510 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
511 fkids = get (fig, "children");
15441
e5a07d7aafcc legend.m: Remove unused warning variable and associated code.
Rik <rik@octave.org>
parents: 15440
diff changeset
512 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
513 hlegend = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
514 hobjects = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
515 hplots = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
516 text_strings = {};
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 else
14578
f579a94aacaa Preserve legend handle when changing properties (Bug # 36259).
Carnë Draug <carandraug+dev@gmail.com>
parents: 14552
diff changeset
519 ## 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
520 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
521 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
522 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
523 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
524 if (strcmp (position, "default"))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
525 position = get (hlegend, "location");
14214
2fe0f5fa8cc3 Replace to-be-deprecated findstr occurrences with strfind.
Rik <octave@nomad.inbox5.com>
parents: 14207
diff changeset
526 inout = strfind (position, "outside");
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
527 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
528 outside = true;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
529 position = position(1:inout-1);
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
530 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
531 outside = false;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
532 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
533 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
534 if (strcmp (orientation, "default"))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
535 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
536 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
537 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
538 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
539 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
540 textpos = "left";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
541 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
542 if (strcmp (position, "default"))
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
543 position = "northeast";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
544 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
545 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
546 orientation = "vertical";
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
547 endif
14529
aabdc8f281f1 legend.m: Change default to boxon for Matlab compatibility (bug #36105).
Rik <octave@nomad.inbox5.com>
parents: 14375
diff changeset
548 box = "on";
6272
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
549 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
550
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
551 ## 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
552 ## 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
553 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
554 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
555 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
556 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
557 set (ca(1), "fontunits", "points");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
558 ca_pos = get (ca(1), "position");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
559 ca_outpos = get (ca(1), "outerposition");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
560 ca_fontsize = get (ca(1), "fontsize");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
561 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
562 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
563 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
564 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
565
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
566 ## 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
567 xpad = 2;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
568 ypad = 2;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
569
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
570 ## Length of line segments in the legend in points
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
571 linelength = 15;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
572
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
573 ## 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
574 ## 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
575 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
576 unwind_protect
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
577 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
578 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
579 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
580 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
581 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
582 addprops = true;
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
583 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
584 "box", box,
14529
aabdc8f281f1 legend.m: Change default to boxon for Matlab compatibility (bug #36105).
Rik <octave@nomad.inbox5.com>
parents: 14375
diff changeset
585 "xtick", [], "ytick", [],
aabdc8f281f1 legend.m: Change default to boxon for Matlab compatibility (bug #36105).
Rik <octave@nomad.inbox5.com>
parents: 14375
diff changeset
586 "xticklabel", "", "yticklabel", "", "zticklabel", "",
14578
f579a94aacaa Preserve legend handle when changing properties (Bug # 36259).
Carnë Draug <carandraug+dev@gmail.com>
parents: 14552
diff changeset
587 "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
588 "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
589 "activepositionproperty", "position",
3ddb62bd67c5 legend.m: Inherit font size from axes.
Konstantinos Poulios <logari81@gmail.com>
parents: 14589
diff changeset
590 "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
591 else
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
592 addprops = false;
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
593 axes (hlegend);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
594 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
595 endif
16728
5cf7369a74cb Update legend box when the fontsize changes.
Ben Abbott <bpabbott@mac.com>
parents: 16094
diff changeset
596 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
597 ## 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
598 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
599 texthandle = [];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
600 maxwidth = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
601 maxheight = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
602 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
603 if (strcmp (textpos, "right"))
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
604 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
605 "horizontalalignment", "left",
14746
3ddb62bd67c5 legend.m: Inherit font size from axes.
Konstantinos Poulios <logari81@gmail.com>
parents: 14589
diff changeset
606 "userdata", hplots(k),
16728
5cf7369a74cb Update legend box when the fontsize changes.
Ben Abbott <bpabbott@mac.com>
parents: 16094
diff changeset
607 "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
608 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
609 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
610 "horizontalalignment", "right",
14746
3ddb62bd67c5 legend.m: Inherit font size from axes.
Konstantinos Poulios <logari81@gmail.com>
parents: 14589
diff changeset
611 "userdata", hplots(k),
16728
5cf7369a74cb Update legend box when the fontsize changes.
Ben Abbott <bpabbott@mac.com>
parents: 16094
diff changeset
612 "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
613 endif
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
614 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
615 unwind_protect
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
616 set (texthandle(end), "units", "points");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
617 extents = get (texthandle(end), "extent");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
618 maxwidth = max (maxwidth, extents(3));
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
619 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
620 unwind_protect_cleanup
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
621 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
622 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
623 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
624
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
625 num1 = nentries;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
626 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
627 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
628 if (outside)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
629 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
630 ## 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
631 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
632 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
633 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
634 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
635 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
636 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
637 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
638 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
639 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
640 if (outside)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
641 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
642 ## 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
643 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
644 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
645 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
646 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
647 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
648 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
649 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
650 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
651 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
652
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
653 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
654 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
655 xoffset = xpad;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
656 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
657 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
658 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
659 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
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 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
662 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
663
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
664 ## Place the legend in the desired position
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
665 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
666 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
667 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
668 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
669 endif
11120
a44f979a35ce style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents: 11033
diff changeset
670 switch (position)
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
671 case "north"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
672 if (outside)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
673 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
674 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
675 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
676
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
677 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
678 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
679 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
680 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
681 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
682 case "south"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
683 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
684 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
685 ca_outpos(2) + ypad, lpos(3), lpos(4)];
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
686 new_pos = [ca_pos(1), ca_pos(2) + lpos(4), ca_pos(3), ...
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
687 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
688 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
689 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
690 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
691 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
692 case "east"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
693 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
694 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
695 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
696 new_pos = [ca_pos(1), ca_pos(2), ca_pos(3) - lpos(3), ca_pos(4)];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
697 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
698 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
699 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
700 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
701 case "west"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
702 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
703 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
704 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
705 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
706 new_pos = [ca_pos(1) + lpos(3), ca_pos(2), ...
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
707 ca_pos(3) - lpos(3), ca_pos(4)];
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
708 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
709 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
710 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
711 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
712 case "northeast"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
713 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
714 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
715 ca_pos(2) + ca_pos(4) - lpos(4), lpos(3), lpos(4)];
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
716 new_pos = [ca_pos(1), ca_pos(2), ca_pos(3) - lpos(3), 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
717 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
718 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
719 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
720 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
721 case "northwest"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
722 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
723 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
724 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
725 new_pos = [ca_pos(1) + lpos(3), ca_pos(2), ...
12395
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
726 ca_pos(3) - lpos(3), 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
727 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
728 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
729 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
730 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
731 case "southeast"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
732 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
733 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
734 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
735 new_pos = [ca_pos(1), ca_pos(2), ...
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
736 ca_pos(3) - lpos(3), 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
737 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
738 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
739 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
740 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
741 case "southwest"
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
742 if (outside)
12396
6ba430a75553 Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
David Bateman <dbateman@free.fr>
parents: 12395
diff changeset
743 lpos = [ca_outpos(1) + ypad, 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
744 new_pos = [ca_pos(1) + lpos(3), ca_pos(2), ...
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
745 ca_pos(3) - lpos(3), 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
746 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
747 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
748 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
749 endswitch
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
750
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
751 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
752 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
753 set (hlegend, "units", "points");
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
754 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
755 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
756 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
757 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
758
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
759 ## 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
760 xk = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
761 yk = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
762 for k = 1 : numel (hplots)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
763 hobjects = [hobjects, texthandle(k)];
11120
a44f979a35ce style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents: 11033
diff changeset
764 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
765 case "line"
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
766 color = get (hplots(k), "color");
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
767 style = get (hplots(k), "linestyle");
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
768 if (! strcmp (style, "none"))
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
769 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
770 "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
771 "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
772 "userdata", hplots (k));
10999
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
773 hobjects = [hobjects, l1];
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
774 endif
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
775 marker = get (hplots(k), "marker");
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
776 if (! strcmp (marker, "none"))
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
777 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
778 "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
779 "color", color, "linestyle", "none", "marker", marker,
11033
d9c8916bb9dd Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents: 11003
diff changeset
780 "markeredgecolor", get (hplots (k), "markeredgecolor"),
d9c8916bb9dd Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents: 11003
diff changeset
781 "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
782 "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
783 "userdata", hplots (k));
10999
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
784 hobjects = [hobjects, l1];
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
785 endif
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
786
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
787 addlistener (hplots(k), "color", {@updateline, hlegend, linelength});
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
788 addlistener (hplots(k), "linestyle", {@updateline, hlegend, linelength});
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
789 addlistener (hplots(k), "marker", {@updateline, hlegend, linelength});
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
790 addlistener (hplots(k), "markeredgecolor", {@updateline, hlegend, linelength});
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
791 addlistener (hplots(k), "markerfacecolor", {@updateline, hlegend, linelength});
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
792 addlistener (hplots(k), "markersize", {@updateline, hlegend, linelength});
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
793 addlistener (hplots(k), "displayname", {@updateline, hlegend, linelength});
10999
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
794 case "patch"
14747
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
795 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
796 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
797 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
798 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
799 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
800 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
801 "ydata", (lpos(4) - yoffset -
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
802 [yk-0.3, yk-0.3, yk+0.3, yk+0.3] .* ystep) / lpos(4),
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
803 "facecolor", facecolor, "edgecolor", edgecolor, "cdata", cdata,
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
804 "userdata", hplots(k));
14747
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
805 hobjects = [hobjects, p1];
daad312c8af0 legend.m: Add support for patches (Bugs #33463, #34881, #35260).
Konstantinos Poulios <logari81@gmail.com>
parents: 14746
diff changeset
806 endif
10999
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
807 case "surface"
9f45b76c16e3 legend.m: Treat line, patch, and surface objects differetly.
Ben Abbott <bpabbott@mac.com>
parents: 10995
diff changeset
808 endswitch
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
809 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
810 (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
811 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
812 yk++;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
813 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
814 yk = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
815 xk++;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
816 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
817 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
818 xk++;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
819 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
820 xk = 0;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
821 yk++;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
822 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
823 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
824 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
825
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
826 ## 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
827 ## that when it is destroyed will remove the legend
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
828 t1 = text (0, 0, "", "parent", ca(1), "tag", "legend",
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
829 "handlevisibility", "off", "visible", "off",
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
830 "xliminclude", "off", "yliminclude", "off");
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
831 set (t1, "deletefcn", {@deletelegend1, hlegend});
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
832
15441
e5a07d7aafcc legend.m: Remove unused warning variable and associated code.
Rik <rik@octave.org>
parents: 15440
diff changeset
833 ## 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
834 ## 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
835 ## 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
836 ## 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
837 if (outside)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
838 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
839 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
840 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
841 set (ca(i), "units", "points");
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
842 set (ca(i), "position", 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
843 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
844 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
845 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
846 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
847
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
848 set (hlegend, "deletefcn", {@deletelegend2, ca, ...
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
849 ca_pos, ca_outpos, t1, hplots});
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
850 addlistener (hlegend, "visible", {@hideshowlegend, ca, ...
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
851 ca_pos, 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
852 else
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
853 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
854 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
855
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
856 if (addprops)
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
857 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
858 addproperty ("textcolor", hlegend, "color", [0, 0, 0]);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
859 addproperty ("location", hlegend, "radio", "north|south|east|west|{northeast}|southeast|northwest|southwest|northoutside|southoutside|eastoutside|westoutside|northeastoutside|southeastoutside|northwestoutside|southwestoutside");
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
860 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
861 "{vertical}|horizontal");
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
862 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
863 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
864 else
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
865 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
866 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
867
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
868 if (outside)
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
869 set (hlegend, "location", strcat (position, "outside"),
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
870 "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
871 else
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
872 set (hlegend, "location", position, "orientation", orientation,
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
873 "textposition", textpos);
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
874 endif
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
875 if (addprops)
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
876 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
877 addlistener (hlegend, "textcolor", @updatelegendtext);
16728
5cf7369a74cb Update legend box when the fontsize changes.
Ben Abbott <bpabbott@mac.com>
parents: 16094
diff changeset
878 addlistener (hlegend, "fontsize", @updatelegend);
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
879 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
880 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
881 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
882 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
883 addlistener (hlegend, "textposition", @updatelegend);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
884 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
885 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
886 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
887 end_unwind_protect
6272
a1f3d3b7ee5c [project @ 2007-02-06 02:09:48 by jwe]
jwe
parents: 6257
diff changeset
888 endif
6147
e14b0e9b7bf7 [project @ 2006-11-09 03:28:01 by jwe]
jwe
parents: 6146
diff changeset
889 endif
e14b0e9b7bf7 [project @ 2006-11-09 03:28:01 by jwe]
jwe
parents: 6146
diff changeset
890
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
891 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
892 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
893 hobjects2 = hobjects;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
894 hplot2 = hplots;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
895 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
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
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
898 endfunction
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
899
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
900 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
901 persistent recursive = false;
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
902 if (! recursive)
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
903 recursive = true;
12339
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
904 unwind_protect
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
905 hax = getfield (get (h, "userdata"), "handle");
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
906 [hplots, text_strings] = __getlegenddata__ (h);
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
907 h = legend (hax, hplots, get (h, "string"));
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
908 unwind_protect_cleanup
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
909 recursive = false;
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
910 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
911 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
912 endfunction
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
913
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
914 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
915 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
916 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
917 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
918 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
919 textcolor = get (h, "textcolor");
16002
cddf9103a566 Fix legend bugs (#38263, #38265).
Ben Abbott <bpabbott@mac.com>
parents: 15570
diff changeset
920 fontsize = get (h, "fontsize");
cddf9103a566 Fix legend bugs (#38263, #38265).
Ben Abbott <bpabbott@mac.com>
parents: 15570
diff changeset
921 set (text_kids, "interpreter", interpreter,
cddf9103a566 Fix legend bugs (#38263, #38265).
Ben Abbott <bpabbott@mac.com>
parents: 15570
diff changeset
922 "fontsize", fontsize,
cddf9103a566 Fix legend bugs (#38263, #38265).
Ben Abbott <bpabbott@mac.com>
parents: 15570
diff changeset
923 "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
924 endfunction
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
925
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
926 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
927 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
928 if (! isvisible)
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
929 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
930 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
931 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
932 isvisible = true;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
933 break;
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
934 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
935 endfor
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
936 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
937
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
938 for i = 1 : numel (ca)
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11134
diff changeset
939 if (ishandle (ca(i)) && strcmp (get (ca(i), "type"), "axes")
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
940 && (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
941 && 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
942 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
943 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
944 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
945 if (isvisible)
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
946 set (ca(i), "position", pos2);
10990
529b36293297 Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents: 10989
diff changeset
947 else
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
948 set (ca(i), "position", pos1);
10990
529b36293297 Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents: 10989
diff changeset
949 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
950 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
951 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
952 end_unwind_protect
10990
529b36293297 Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents: 10989
diff changeset
953 endif
529b36293297 Backed out changeset 6ea65c5de87a
David Bateman <dbateman@free.fr>
parents: 10989
diff changeset
954 endfor
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
955 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
956
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
957 function deletelegend1 (h, d, ca)
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11134
diff changeset
958 if (ishandle (ca) && strcmp (get (ca, "type"), "axes")
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
959 && (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
960 && 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
961 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
962 endif
10995
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
963 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
964
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
965 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
966 for i = 1 : numel (ca)
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11134
diff changeset
967 if (ishandle (ca(i)) && strcmp (get (ca(i), "type"), "axes")
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
968 && (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
969 && 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
970 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
971 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
972 unwind_protect
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
973 set (ca(i), "units", "points");
12440
2ed62b9f949e synchronization of axes position and outerposition
Konstantinos Poulios <logari81@googlemail.com>
parents: 12437
diff changeset
974 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
975 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
976 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
977 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
978 endif
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
979 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
980 endfor
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
981 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
982 delete (t1);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
983 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
984 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
985 dellistener (hplots(i), "color");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
986 dellistener (hplots(i), "linestyle");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
987 dellistener (hplots(i), "marker");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
988 dellistener (hplots(i), "markeredgecolor");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
989 dellistener (hplots(i), "markerfacecolor");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
990 dellistener (hplots(i), "markersize");
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
991 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
992 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
993 endfor
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
994 endfunction
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
995
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
996 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
997 lm = [];
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
998 ll = [];
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
999 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
1000 for i = 1 : numel (kids)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1001 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
1002 && 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
1003 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
1004 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
1005 else
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1006 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
1007 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1008 endif
e81914f3921f Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents: 10990
diff changeset
1009 endfor
11198
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1010
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1011 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
1012 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
1013 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
1014
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
1015 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
1016 || (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
1017 && (! 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
1018 ## 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
1019 ## legend function to recreate a new legend
12339
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1020 [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
1021 for i = 1 : numel (hplots)
15440
1db706430c96 Fix legend ('show') to work with DisplayName (bug #33757)
Rik <rik@octave.org>
parents: 15202
diff changeset
1022 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
1023 hplots(i) = [];
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1024 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
1025 break;
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1026 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1027 endfor
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1028 legend (hplots, text_strings);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
1029 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
1030 && (! 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
1031 && 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
1032 ## An element was added to the legend. Need to recall the
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1033 ## legend function to recreate a new legend
12339
eda5eabd5d0b Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents: 11587
diff changeset
1034 [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
1035 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
1036 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
1037 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
1038 else
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1039 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
1040 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
1041 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
1042 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
1043 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
1044 delete (ll);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1045 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
1046 delete (lm);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1047 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1048 else
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1049 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
1050 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
1051 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
1052 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
1053 delete (lm);
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1054 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1055 if (! strcmp (linestyle, "none"))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
1056 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
1057 "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
1058 "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
1059 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1060 if (! strcmp (marker, "none"))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
1061 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
1062 "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
1063 "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
1064 "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
1065 "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
1066 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1067 endif
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1068 endfunction
9f080d23396f Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents: 11149
diff changeset
1069
11418
a140991387fb legend.m: Add demo to legend for inline key.
Ben Abbott <bpabbott@mac.com>
parents: 11363
diff changeset
1070 %!demo
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1071 %! plot (rand (2));
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1072 %! 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
1073 %! h = legend ({'foo'}, 'bar');
5cf7369a74cb Update legend box when the fontsize changes.
Ben Abbott <bpabbott@mac.com>
parents: 16094
diff changeset
1074 %! 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
1075
aed2c50c3082 legend.m: legend with more than two inline keys (bug 31991). Add/modifyy demos.
Ben Abbott <bpabbott@mac.com>
parents: 11434
diff changeset
1076 %!demo
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1077 %! plot (rand (3));
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1078 %! title ('legend() without inputs creates default labels');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1079 %! legend ();
14236
35903f035390 Escaping strings for legend entries are handled by __go_draw_axes__.
Ben Abbott <bpabbott@mac.com>
parents: 14214
diff changeset
1080
35903f035390 Escaping strings for legend entries are handled by __go_draw_axes__.
Ben Abbott <bpabbott@mac.com>
parents: 14214
diff changeset
1081 %!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
1082 %! clf;
11418
a140991387fb legend.m: Add demo to legend for inline key.
Ben Abbott <bpabbott@mac.com>
parents: 11363
diff changeset
1083 %! x = 0:1;
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1084 %! plot (x,x,';I am Blue;', x,2*x, x,3*x,';I am Red;');
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1085 %! 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
1086
9f34f7636fe0 legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents: 8291
diff changeset
1087 %!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
1088 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1089 %! 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
1090 %! 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
1091 %! legend ({'I am blue', 'I am green'}, 'location', 'east');
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1092
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1093 %!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
1094 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1095 %! 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
1096 %! title ('Legend with keys in horizontal orientation');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1097 %! legend ({'I am blue', 'I am green'}, 'location', 'east', 'orientation', 'horizontal');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1098 %! legend boxoff;
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
1099
aed2c50c3082 legend.m: legend with more than two inline keys (bug 31991). Add/modifyy demos.
Ben Abbott <bpabbott@mac.com>
parents: 11434
diff changeset
1100 %!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
1101 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1102 %! 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
1103 %! 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
1104 %! legend ({'I am blue', 'I am green'}, 'location', 'east');
14529
aabdc8f281f1 legend.m: Change default to boxon for Matlab compatibility (bug #36105).
Rik <octave@nomad.inbox5.com>
parents: 14375
diff changeset
1105 %! legend boxoff;
11434
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1106
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1107 %!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
1108 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1109 %! 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
1110 %! 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
1111 %! legend ({'I am blue', 'I am green'}, 'location', 'east');
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1112 %! legend right;
8343
9f34f7636fe0 legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents: 8291
diff changeset
1113
9f34f7636fe0 legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents: 8291
diff changeset
1114 %!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
1115 %! clf;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1116 %! 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
1117 %! title ('Using properties to have legend text shown to the right of key');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1118 %! 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
1119 %! legend ('left');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1120 %! set (h, 'textposition', 'right');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1121 %! 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
1122
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1123 %!demo
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1124 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1125 %! 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
1126 %! title ('Legend is hidden')
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1127 %! 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
1128 %! legend hide;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1129
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1130 %!demo
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1131 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1132 %! x = 0:1;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1133 %! plot (x,x,';I am Blue;', x,2*x,';I am Green;', x,3*x,';I am Red;');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1134 %! title ('labels embedded in call to plot');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1135 %! legend boxon
11434
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1136 %! legend hide
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1137 %! legend show
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1138
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1139 %!demo
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1140 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1141 %! x = 0:1;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1142 %! plot (x, x, ';\alpha;', ...
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1143 %! 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
1144 %! x, 3*x, ';\gamma=3\alpha;');
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1145 %! 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
1146
1f54ee6760b5 legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents: 11418
diff changeset
1147 %!demo
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1148 %! clf;
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1149 %! plot (rand (2));
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1150 %! 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
1151 %! 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
1152 %! set (h, 'interpreter', 'none');
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1153
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1154 %!demo
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1155 %! 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
1156 %! 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
1157 %! 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
1158 %! legend ('hello very big world', 'location', 'northeastoutside');
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1159
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1160 %!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
1161 %! clf;
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
1162 %! labels = {};
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1163 %! colororder = get (gca, 'colororder');
6146
1a6d826e92b5 [project @ 2006-11-09 03:13:11 by jwe]
jwe
parents:
diff changeset
1164 %! 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
1165 %! 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
1166 %! 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
1167 %! 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
1168 %! end
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1169 %! hold off;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1170 %! 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
1171 %! '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
1172 %! 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
1173 %! legend (labels, 'location', 'southoutside');
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1174
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1175 %!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
1176 %! clf;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1177 %! x = linspace (0, 10);
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1178 %! 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
1179 %! 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
1180 %! 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
1181 %! 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
1182 %! 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
1183 %! hold off;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1184
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1185 %!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
1186 %! clf;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1187 %! x = linspace (0, 10);
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1188 %! 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
1189 %! 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
1190 %! legend ('linear');
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1191
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1192 %!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
1193 %! clf;
9451
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1194 %! x = linspace (0, 10);
350148cc0774 legend.m: fix legend order
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
1195 %! 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
1196 %! 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
1197 %! 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
1198
f9fb8c1a8e45 legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents: 9451
diff changeset
1199 %!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
1200 %! clf;
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1201 %! 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
1202 %! 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
1203 %! 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
1204 %! 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
1205 %! 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
1206
f9fb8c1a8e45 legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents: 9451
diff changeset
1207 %!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
1208 %! clf;
11363
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1209 %! 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
1210 %! bar (rand_2x3_data2);
a0dfd7e8e3e2 Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents: 11246
diff changeset
1211 %! 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
1212 %! 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
1213 %! 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
1214 %! legend right;
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
1215
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
1216 %!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
1217 %! clf;
10662
3afcd24ced61 legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
1218 %! 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
1219 %! 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
1220 %! 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
1221 %! 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
1222
12340
d63007ac067a legend.m: Add demo for inline keys created by two plot commands.
Ben Abbott <bpabbott@mac.com>
parents: 12339
diff changeset
1223 %!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
1224 %! clf;
12340
d63007ac067a legend.m: Add demo for inline keys created by two plot commands.
Ben Abbott <bpabbott@mac.com>
parents: 12339
diff changeset
1225 %! 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
1226 %! 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
1227 %! hold all;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1228 %! 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
1229 %! hold off;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1230 %! 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
1231
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1232 %!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
1233 %! clf;
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1234 %! 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
1235 %! 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
1236 %! hold all;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1237 %! 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
1238 %! hold off;
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1239 %! 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
1240 %! legend ({'Sine', 'Cosine'}, 'location', 'northeastoutside');
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1241
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
1242 %!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
1243 %! clf;
12394
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
1244 %! x = 0:10;
c2e1973d870b legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents: 12388
diff changeset
1245 %! plot (x, rand (11));
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1246 %! xlabel ('Indices');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
1247 %! ylabel ('Random Values');
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1248 %! 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
1249 %! 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
1250 %! 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
1251 %! axis ([0, 10, 0 1]);
12387
5fb6ea1bff65 legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents: 12340
diff changeset
1252
12395
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
1253 %!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
1254 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1255 %! x = (1:5)';
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14252
diff changeset
1256 %! 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
1257 %! 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
1258 %! 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
1259 %! 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
1260 %! 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
1261 %! 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
1262 %! 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
1263 %! 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
1264 %! 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
1265 %! 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
1266 %! 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
1267 %! 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
1268
12395
4d30b4136a3e legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents: 12394
diff changeset
1269 %!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
1270 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14236
diff changeset
1271 %! plot (rand (2));
15442
015cc3d1f389 legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents: 15441
diff changeset
1272 %! 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
1273 %! 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
1274
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1275 %!demo
14207
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1276 %! x = 0:10;
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1277 %! y1 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1278 %! y2 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1279 %! [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
1280 %! 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
1281 %! 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
1282
13979
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1283 %!demo
14207
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1284 %! x = 0:10;
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1285 %! y1 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1286 %! y2 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1287 %! [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
1288 %! 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
1289 %! 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
1290
f35b593688a5 Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents: 13937
diff changeset
1291 %!demo
14207
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1292 %! x = 0:10;
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1293 %! y1 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1294 %! y2 = rand (size (x));
57e3490094e1 Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents: 14138
diff changeset
1295 %! [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
1296 %! 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
1297 %! 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
1298