Mercurial > octave
annotate scripts/plot/appearance/legend.m @ 27790:0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
* __contour__.m, __scatter__.m, __stem__.m, __quiver__.m, __errplot__.m:
Set "__creator__" appdata.
* legend.m: Use "icon" rather than "item" to name the icon objects
(textitem_objects): Rename "texticon_objects". Use the new "create_icon"
function to create objects. Use the icon object's appdata to store the
creator for further triage.
(create_icon): Decide what objects to create using the "__creator__" appdata
of hggroups. Add listener to delete all legend objects for an item which has
its peer objects deleted.
(textitem_data): Rename "update_texticon_data". Call "update_icon_position"
rather than returning an array of data
(update_icon_position): New function that is aware of how to compute the
position of the the icon object depending on the hggroup creator.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Sun, 08 Dec 2019 17:52:18 +0100 |
parents | b70da79e4ed9 |
children | d68ae60f1557 |
rev | line source |
---|---|
27719
88350aacd800
legend.m: Tweaks to cset 39ac47fdcda2.
Rik <rik@octave.org>
parents:
27718
diff
changeset
|
1 ## Copyright (C) 2010-2019 David Bateman |
6146 | 2 ## |
6440 | 3 ## This file is part of Octave. |
4 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24498
diff
changeset
|
5 ## Octave is free software: you can redistribute it and/or modify it |
6440 | 6 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24498
diff
changeset
|
7 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22631
diff
changeset
|
8 ## (at your option) any later version. |
6440 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22631
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22631
diff
changeset
|
13 ## GNU General Public License for more details. |
6146 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24498
diff
changeset
|
17 ## <https://www.gnu.org/licenses/>. |
6146 | 18 |
19 ## -*- texinfo -*- | |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
20 ## @deftypefn {} {} legend () |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
21 ## @deftypefnx {} {} legend @var{command} |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
22 ## @deftypefnx {} {} legend (@var{str1}, @var{str2}, @dots{}) |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
23 ## @deftypefnx {} {} legend (@var{charmat}) |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
24 ## @deftypefnx {} {} legend (@{@var{cellstr}@}) |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
25 ## @deftypefnx {} {} legend (@dots{}, @var{property}, @var{value}, @dots{}) |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20781
diff
changeset
|
26 ## @deftypefnx {} {} legend (@var{hobjs}, @dots{}) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
27 ## @deftypefnx {} {} legend ("@var{command}") |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
28 ## @deftypefnx {} {} legend (@var{hax}, @dots{}) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
29 ## @deftypefnx {} {@var{hleg, hplt} =} legend (@dots{}) |
6146 | 30 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17119
diff
changeset
|
31 ## Display a legend for the current axes using the specified strings as labels. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17119
diff
changeset
|
32 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17119
diff
changeset
|
33 ## Legend entries may be specified as individual character string arguments, |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
34 ## a character array, or a cell array of character strings. When label names |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
35 ## might be confused with legend properties, or @var{command} arguments, |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
36 ## the labels should be protected by specifying them as a cell array of |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
37 ## strings. |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
38 ## |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
39 ## If the first argument @var{hax} is an axes handle, then add a legend to this |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
40 ## axes, rather than the current axes returned by @code{gca}. |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17119
diff
changeset
|
41 ## |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
42 ## Legend labels are associated with the axes' children; The first label is |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
43 ## assigned to the first object that was plotted in the axes, the second label |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
44 ## to the next object plotted, etc. To label specific data objects, without |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
45 ## labeling all objects, provide their graphic handles in the input |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
46 ## @var{hobjs}. |
6146 | 47 ## |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
48 ## The optional parameter @var{loc} specifies the location of the legend as |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
49 ## follows: |
6146 | 50 ## |
6977 | 51 ## @multitable @columnfractions 0.06 0.14 0.80 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
52 ## @headitem @tab loc @tab location of the legend |
17204
d87179b38bcf
doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
53 ## @item @tab north @tab center top |
d87179b38bcf
doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
54 ## @item @tab south @tab center bottom |
d87179b38bcf
doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
55 ## @item @tab east @tab right center |
d87179b38bcf
doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
56 ## @item @tab west @tab left center |
d87179b38bcf
doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
57 ## @item @tab northeast @tab right top (default) |
d87179b38bcf
doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
58 ## @item @tab northwest @tab left top |
d87179b38bcf
doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
59 ## @item @tab southeast @tab right bottom |
d87179b38bcf
doc: Touch up alignment of @multitables in plot, legend, newplot.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
60 ## @item @tab southwest @tab left bottom |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
61 ## @sp 1 |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
62 ## @item @tab outside @tab can be appended to any location string @* |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
63 ## @item @tab @tab which will place the legend outside the axes |
6146 | 64 ## @end multitable |
65 ## | |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
66 ## The following customizations are available using @var{command}: |
6146 | 67 ## |
7148 | 68 ## @table @asis |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17204
diff
changeset
|
69 ## @item @qcode{"show"} |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
70 ## Show legend on the plot |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
71 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17204
diff
changeset
|
72 ## @item @qcode{"hide"} |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
73 ## Hide legend on the plot |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
74 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17204
diff
changeset
|
75 ## @item @qcode{"toggle"} |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
76 ## Toggle between @qcode{"hide"} and @qcode{"show"} |
12394
c2e1973d870b
legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents:
12388
diff
changeset
|
77 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17204
diff
changeset
|
78 ## @item @qcode{"boxon"} |
17532
492d609d2d75
legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents:
17530
diff
changeset
|
79 ## Show a box around legend (default) |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
80 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17204
diff
changeset
|
81 ## @item @qcode{"boxoff"} |
10666
7a43499f074a
legend.m: Improve documentation string
Rik <octave@nomad.inbox5.com>
parents:
10662
diff
changeset
|
82 ## Hide the box around legend |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10666
diff
changeset
|
83 ## |
17532
492d609d2d75
legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents:
17530
diff
changeset
|
84 ## @item @qcode{"right"} |
492d609d2d75
legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents:
17530
diff
changeset
|
85 ## Place label text to the right of the keys (default) |
492d609d2d75
legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents:
17530
diff
changeset
|
86 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17204
diff
changeset
|
87 ## @item @qcode{"left"} |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
88 ## 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
|
89 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17204
diff
changeset
|
90 ## @item @qcode{"off"} |
12394
c2e1973d870b
legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents:
12388
diff
changeset
|
91 ## Delete the legend object |
6146 | 92 ## @end table |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
93 ## |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
94 ## The @code{legend} function creates a graphics object which has various |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
95 ## properties that can be manipulated with @code{get}/@code{set}. |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
96 ## Alternatively, properties can be set directly when calling @code{legend} by |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
97 ## including @var{property}/@var{value} pairs. If using this calling form, the |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
98 ## labels must be specified as a cell array of strings. |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
99 ## |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
100 ## The optional output value @var{hleg} is a handle to the legend object. |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
101 ## |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
102 ## Implementation Note: The legend label text is either provided in the call to |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
103 ## @code{legend} or is taken from the @code{DisplayName} property of the |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
104 ## graphics objects. Only data objects, such as line, patch, and surface, have |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
105 ## this property whereas axes, figures, etc.@: do not so they are never present |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
106 ## in a legend. If no labels or @code{DisplayName} properties are available, |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
107 ## then the label text is simply @qcode{"data1"}, @qcode{"data2"}, @dots{}, |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
108 ## @nospell{@qcode{"dataN"}}. |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17119
diff
changeset
|
109 ## |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
110 ## The legend @code{FontSize} property is initially set to 90% of the axes |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
111 ## @code{FontSize} to which it is attached. Use @code{set} to override this |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
112 ## if necessary. |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
113 ## |
24498 | 114 ## A legend is implemented as an additional axes object with the @code{tag} |
115 ## property set to @qcode{"legend"}. Properties of the legend object may be | |
116 ## manipulated directly by using @code{set}. | |
6146 | 117 ## @end deftypefn |
118 | |
17503
d99785217634
legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
119 function [hleg, hleg_obj, hplot, labels] = legend (varargin) |
6146 | 120 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
121 ## Use the old legend code to handle gnuplot toolkit |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
122 if (strcmp (graphics_toolkit (), "gnuplot")) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
123 [hleg, hleg_obj, hplot, labels] = __gnuplot_legend__ (varargin{:}); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
124 return; |
6146 | 125 endif |
126 | |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
127 opts = parse_opts (varargin{:}); |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
128 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
129 hl = opts.legend_handle; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
130 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
131 ## Fix property/value pairs |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
132 pval = opts.propval(:)'; |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
133 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
134 if (! isempty (opts.action)) |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
135 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
136 do_set_box = isempty (hl); |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
137 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
138 switch (opts.action) |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
139 case "boxoff" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
140 tmp_pval = {"box", "off"}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
141 do_set_box = false; |
24403
b9462090773a
legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents:
24399
diff
changeset
|
142 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
143 case "boxon" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
144 tmp_pval = {"box", "on"}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
145 do_set_box = false; |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
146 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
147 case "hide" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
148 tmp_pval = {"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
|
149 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
150 case "show" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
151 tmp_pval = {"visible", "on"}; |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
152 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
153 case "toggle" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
154 if (! isempty (hl)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
155 if (strcmp (get (hl, "visible"), "on")) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
156 tmp_pval = {"visible", "off"}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
157 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
158 tmp_pval = {"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
|
159 endif |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
160 endif |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
161 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
162 case "left" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
163 tmp_pval = {"textposition", "left"}; |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
164 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
165 case "right" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
166 tmp_pval = {"textposition", "right"}; |
16799
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
167 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
168 case "off" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
169 if (! isempty (hl)) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
170 delete (hl); |
16799
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
171 endif |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
172 return; |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
173 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
174 endswitch |
17503
d99785217634
legend.m: Text objects should inherit textcolor, interpreter properties from legend (bug #40064).
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
175 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
176 pval = [tmp_pval, pval]; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
177 if (do_set_box) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
178 pval = [pval, "box", "on"]; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
179 endif |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
180 |
6147 | 181 endif |
182 | |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
183 if (isempty (hl)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
184 |
27747
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
185 hl = axes ("parent", get (opts.axes_handles(1), "parent"), ... |
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
186 "tag", "legend", "handlevisibility", "off", ... |
27716
790038c12003
legend.m: handle non default colormap (bug #54757)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27715
diff
changeset
|
187 "ydir", "reverse", "position", [.5 .5 .3 .3], ... |
790038c12003
legend.m: handle non default colormap (bug #54757)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27715
diff
changeset
|
188 "fontsize", 0.9 * get (opts.axes_handles(1), "fontsize"), ... |
27717
842d4221ac6c
legend.m: also inherit "clim" property from peer axes (bug #57258)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27716
diff
changeset
|
189 "clim", get (opts.axes_handles(1), "clim"), ... |
27716
790038c12003
legend.m: handle non default colormap (bug #54757)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27715
diff
changeset
|
190 "colormap", get (opts.axes_handles(1), "colormap"), ... |
790038c12003
legend.m: handle non default colormap (bug #54757)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27715
diff
changeset
|
191 "xtick", [], "ytick", [], "box", "on"); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
192 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
193 ## FIXME: Use the axes appdata to store its peer legend handle |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
194 ## rather that adding a public property and change all uses. |
27715
95cc1f535ba8
legend.m: handle plotyy with ones axes already legend aware (bug #57257)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27714
diff
changeset
|
195 for htmp = opts.axes_handles |
95cc1f535ba8
legend.m: handle plotyy with ones axes already legend aware (bug #57257)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27714
diff
changeset
|
196 try |
95cc1f535ba8
legend.m: handle plotyy with ones axes already legend aware (bug #57257)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27714
diff
changeset
|
197 addproperty ("__legend_handle__", htmp, "handle", hl); |
95cc1f535ba8
legend.m: handle plotyy with ones axes already legend aware (bug #57257)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27714
diff
changeset
|
198 catch |
95cc1f535ba8
legend.m: handle plotyy with ones axes already legend aware (bug #57257)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27714
diff
changeset
|
199 set (htmp, "__legend_handle__", hl); |
95cc1f535ba8
legend.m: handle plotyy with ones axes already legend aware (bug #57257)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27714
diff
changeset
|
200 end_try_catch |
95cc1f535ba8
legend.m: handle plotyy with ones axes already legend aware (bug #57257)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27714
diff
changeset
|
201 endfor |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
202 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
203 ## Add and update legend specific properties |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
204 addproperties (hl); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
205 try |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
206 set (hl, "string", opts.obj_labels, pval{:}); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
207 catch ee |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
208 delete (hl); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
209 set (opts.axes_handles, "__legend_handle__", []); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
210 rethrow (ee); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
211 end_try_catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
212 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
213 ## Update legend layout |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
214 setappdata (hl, "__axes_handle__", opts.axes_handles, |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
215 "__next_label_index__", opts.next_idx, |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
216 "__peer_objects__", opts.obj_handles); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
217 update_location_cb (hl, [], false); |
27718
39ac47fdcda2
legend.m: handle "edgecolor" passed at legend creation (bug #56968)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27717
diff
changeset
|
218 update_edgecolor_cb (hl); |
39ac47fdcda2
legend.m: handle "edgecolor" passed at legend creation (bug #56968)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27717
diff
changeset
|
219 update_numchild_cb (hl); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
220 update_layout_cb (hl, [], true); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
221 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
222 ## Dummy invisible object that deletes the legend when "newplot" is called |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
223 ht = __go_text__ (opts.axes_handles(1), "tag", "__legend_watcher__", |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
224 "visible", "off", "handlevisibility", "off", |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
225 "deletefcn", {@reset_cb, hl}); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
226 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
227 ## Listeners to foreign objects properties are stored for later |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
228 ## deletion in "delfunction" |
27747
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
229 hax = opts.axes_handles(1); |
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
230 hf = ancestor (hax, "figure"); |
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
231 |
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
232 add_safe_listener (hl, hf, "colormap", ... |
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
233 @() set (hl, "colormap", get (hax, "colormap"))); |
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
234 add_safe_listener (hl, hf, "position", {@maybe_update_layout_cb, hl}); |
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
235 |
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
236 add_safe_listener (hl, hax, "position", {@maybe_update_layout_cb, hl}); |
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
237 add_safe_listener (hl, hax, "tightinset", ... |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
238 @(h) update_layout_cb (get (h, "__legend_handle__"))); |
27747
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
239 add_safe_listener (hl, hax, "clim", ... |
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
240 @(hax) set (hl, "clim", get (hax, "clim"))); |
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
241 add_safe_listener (hl, hax, "colormap", ... |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
242 @(hax) set (hl, "colormap", get (hax, "colormap"))); |
27747
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
243 add_safe_listener (hl, hax, "fontsize", ... |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
244 @(hax) set (hl, "fontsize", 0.9*get (hax, "fontsize"))); |
27747
7ae72862b542
legend.m: handle colormap also for non figure parent (bug #57303)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27740
diff
changeset
|
245 add_safe_listener (hl, hax, "children", {@legend_autoupdate_cb, hl}); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
246 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
247 ## Listeners to legend properties |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
248 props = {"fontsize", "fontweight", "fontname", "interpreter", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
249 "textposition", "numcolumnsmode", "numcolumns", "orientation"}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
250 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
251 for ii = 1:numel (props) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
252 addlistener (hl, props{ii}, {@update_layout_cb, true}); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
253 endfor |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
254 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
255 addlistener (hl, "autoupdate", @update_numchild_cb); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
256 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
257 addlistener (hl, "beingdeleted", @delete_legend_cb); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
258 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
259 addlistener (hl, "box", @update_box_cb); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
260 |
27718
39ac47fdcda2
legend.m: handle "edgecolor" passed at legend creation (bug #56968)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27717
diff
changeset
|
261 addlistener (hl, "edgecolor", @update_edgecolor_cb); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
262 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
263 addlistener (hl, "location", @update_location_cb); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
264 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
265 addlistener (hl, "position", @update_position_cb); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
266 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
267 addlistener (hl, "string", @update_string_cb); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
268 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
269 addlistener (hl, "textcolor", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
270 @(h) set (findobj (h, "type", "text"), ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
271 "color", get (hl, "textcolor"))); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
272 |
27740
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
273 addlistener (hl, "visible", @update_visible_cb); |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
274 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
275 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
276 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
277 ## FIXME: This will trigger the execution of update_layout_cb for each |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
278 ## watched property. Should we suspend its execution with yet another |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
279 ## appdata bool property for performance? |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
280 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
281 ## Update properties |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
282 setappdata (hl, "__peer_objects__", opts.obj_handles); |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
283 if (! isempty (opts.obj_labels)) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
284 set (hl ,"string", opts.obj_labels, pval{:}) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
285 elseif (! isempty (pval)) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
286 set (hl, pval{:}); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
287 endif |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
288 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
289 endif |
24403
b9462090773a
legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents:
24399
diff
changeset
|
290 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
291 if (nargout > 0) |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
292 hleg = hl; |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
293 ## These ones are needed for backward compatibility |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
294 hleg_obj = get (hl, "children"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
295 hplot = getappdata (hl, "__peer_objects__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
296 labels = get (hl, "string"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
297 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
298 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
299 set (hl, "handlevisibility", "on"); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
300 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
301 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
302 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
303 function update_box_cb (hl) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
304 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
305 if (strcmp (get (hl, "box"), "on")) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
306 if (strcmp (get (hl, "color"), "none")) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
307 set (hl, "color", "w"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
308 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
309 else |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
310 set (hl, "color", "none"); |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
311 endif |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
312 |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
313 endfunction |
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
314 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
315 function update_location_cb (hl, ~, do_layout = true) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
316 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
317 if (strcmp (get (hl, "location"), "best")) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
318 warning ("Octave:legend:unimplemented-location", |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
319 ["legend: 'best' not yet implemented for location ", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
320 "specifier, using 'northeast' instead\n"]); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
321 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
322 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
323 if (do_layout) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
324 update_layout_cb (hl); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
325 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
326 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
327 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
328 |
27718
39ac47fdcda2
legend.m: handle "edgecolor" passed at legend creation (bug #56968)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27717
diff
changeset
|
329 function update_edgecolor_cb (hl) |
39ac47fdcda2
legend.m: handle "edgecolor" passed at legend creation (bug #56968)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27717
diff
changeset
|
330 |
27719
88350aacd800
legend.m: Tweaks to cset 39ac47fdcda2.
Rik <rik@octave.org>
parents:
27718
diff
changeset
|
331 ecolor = get (hl, "edgecolor"); |
88350aacd800
legend.m: Tweaks to cset 39ac47fdcda2.
Rik <rik@octave.org>
parents:
27718
diff
changeset
|
332 set (hl, "xcolor", ecolor, "ycolor", ecolor); |
27718
39ac47fdcda2
legend.m: handle "edgecolor" passed at legend creation (bug #56968)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27717
diff
changeset
|
333 |
39ac47fdcda2
legend.m: handle "edgecolor" passed at legend creation (bug #56968)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27717
diff
changeset
|
334 endfunction |
39ac47fdcda2
legend.m: handle "edgecolor" passed at legend creation (bug #56968)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27717
diff
changeset
|
335 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
336 function update_position_cb (hl) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
337 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
338 updating = getappdata (hl, "__updating_layout__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
339 if (isempty (updating) || ! updating) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
340 set (hl, "location", "none"); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
341 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
342 |
26832
ca40628fff39
legend.m: Update legend when target axes colormap changes (bug #54757).
Rik <rik@octave.org>
parents:
26815
diff
changeset
|
343 endfunction |
ca40628fff39
legend.m: Update legend when target axes colormap changes (bug #54757).
Rik <rik@octave.org>
parents:
26815
diff
changeset
|
344 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
345 function update_string_cb (hl) |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
346 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
347 ## Check that the number of legend item and the number of labels match |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
348 ## before calling update_layout_cb. |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
349 persistent updating = false; |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
350 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
351 if (! updating) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
352 updating = true; |
12339
eda5eabd5d0b
Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents:
11587
diff
changeset
|
353 unwind_protect |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
354 str = get (hl, "string"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
355 nstr = numel (str); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
356 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
357 obj = getappdata (hl, "__peer_objects__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
358 nobj = numel (obj); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
359 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
360 if (ischar (str) && nobj != 1) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
361 setappdata (hl, "__peer_objects__", obj(1)); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
362 elseif (iscellstr (str) && nobj != nstr) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
363 if (nobj > nstr) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
364 setappdata (hl, "__peer_objects__", obj(1:nstr)); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
365 elseif (nobj == 1) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
366 set (hl, "string", str{1}); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
367 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
368 set (hl, "string", str(1:nobj)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
369 endif |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
370 endif |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
371 update_layout_cb (hl, [], true); |
12339
eda5eabd5d0b
Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents:
11587
diff
changeset
|
372 unwind_protect_cleanup |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
373 updating = false; |
12339
eda5eabd5d0b
Fix for inline legends (#32022, #32343)
David Bateman <dbateman@free.fr>
parents:
11587
diff
changeset
|
374 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
|
375 endif |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
376 |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
377 endfunction |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
378 |
27740
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
379 function update_visible_cb (hl) |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
380 |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
381 location = get (hl, "location"); |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
382 if (strcmp (location(end:-1:end-3), "edis")) |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
383 update_layout_cb (hl); |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
384 endif |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
385 |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
386 endfunction |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
387 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
388 function reset_cb (ht, evt, hl, deletelegend = true) |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
389 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
390 if (ishghandle (hl)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
391 listeners = getappdata (hl, "__listeners__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
392 for ii = 1:numel (listeners) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
393 dellistener (listeners{ii}{:}); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
394 endfor |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
395 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
396 if (deletelegend) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
397 delete (hl); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
398 endif |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
399 endif |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
400 |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
401 endfunction |
24498 | 402 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
403 function delete_legend_cb (hl) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
404 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
405 reset_cb ([], [], hl, false); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
406 |
27751
8ac3222bf951
legend.m: reset both plotyy axes data when legend is deleted (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27749
diff
changeset
|
407 hax = getappdata (hl, "__axes_handle__"); |
8ac3222bf951
legend.m: reset both plotyy axes data when legend is deleted (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27749
diff
changeset
|
408 for h = hax(:)' |
8ac3222bf951
legend.m: reset both plotyy axes data when legend is deleted (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27749
diff
changeset
|
409 units = get (h, "units"); |
8ac3222bf951
legend.m: reset both plotyy axes data when legend is deleted (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27749
diff
changeset
|
410 set (h, "units", getappdata (hl, "__original_units__"), ... |
8ac3222bf951
legend.m: reset both plotyy axes data when legend is deleted (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27749
diff
changeset
|
411 "looseinset", getappdata (hl, "__original_looseinset__"), ... |
8ac3222bf951
legend.m: reset both plotyy axes data when legend is deleted (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27749
diff
changeset
|
412 "units", units, "__legend_handle__", []); |
8ac3222bf951
legend.m: reset both plotyy axes data when legend is deleted (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27749
diff
changeset
|
413 endfor |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
414 |
10995
e81914f3921f
Update legend code to support fltk (fixes #29348 and partially fixes #30461)
David Bateman <dbateman@free.fr>
parents:
10990
diff
changeset
|
415 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
|
416 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
417 function add_safe_listener (hl, varargin) |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
418 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
419 addlistener (varargin{:}); |
24426
a51497205f4c
Change uses of gcbf after Matlab compatibility change in bug #52621.
Rik <rik@octave.org>
parents:
24423
diff
changeset
|
420 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
421 lsn = getappdata (hl, "__listeners__"); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
422 lsn = [lsn, {varargin}]; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
423 setappdata (hl, "__listeners__", lsn); |
24498 | 424 |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
425 endfunction |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
426 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
427 function addproperties (hl) |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
428 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
429 persistent default = {"north", "northoutside", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
430 "south", "southoutside", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
431 "east", "eastoutside", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
432 "west", "westoutside", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
433 "{northeast}", "northeastoutside", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
434 "northwest", "northwestoutside", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
435 "southeast", "southeastoutside", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
436 "southwest", "southwestoutside", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
437 "best", "bestoutside", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
438 "none"}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
439 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
440 addproperty ("location", hl, "radio", strjoin (default(:), "|")); |
24403
b9462090773a
legend.m: Setting DisplayName to "" should delete legend (bug #52641).
Rik <rik@octave.org>
parents:
24399
diff
changeset
|
441 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
442 addproperty ("orientation", hl, "radio", "{vertical}|horizontal"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
443 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
444 addproperty ("numcolumns", hl, "double", 1); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
445 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
446 addproperty ("numcolumnsmode", hl, "radio", "{auto}|manual"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
447 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
448 addlistener (hl, "numcolumns", @(h) set (h, "numcolumnsmode", "manual")); |
17537
4f57d4de0383
legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents:
17536
diff
changeset
|
449 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
450 addproperty ("autoupdate", hl, "radio", "{on}|off"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
451 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
452 addproperty ("string", hl, "textstring", {}); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
453 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
454 addproperty ("interpreter", hl, "textinterpreter"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
455 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
456 addproperty ("edgecolor", hl, "color", [.15 .15 .15]); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
457 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
458 addproperty ("textcolor", hl, "color", "k"); |
17537
4f57d4de0383
legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents:
17536
diff
changeset
|
459 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
460 addproperty ("textposition", hl, "radio", "left|{right}"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
461 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
462 addproperty ("itemhitfcn", hl, "axesbuttondownfcn"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
463 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
464 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
465 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
466 function pos = get_position_points (h) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
467 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
468 units = get (h, "units"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
469 unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
470 set (h, "units", "points"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
471 pos = get (h, "position"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
472 unwind_protect_cleanup |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
473 set (h, "units", units); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
474 end_unwind_protect |
17537
4f57d4de0383
legend.m: Implement correct listener for DisplayName on line objects.
Rik <rik@octave.org>
parents:
17536
diff
changeset
|
475 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
476 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
477 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
478 function maybe_update_layout_cb (h, d, hl) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
479 |
27721
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
480 persistent updating = false; |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
481 |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
482 if (! updating) |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
483 |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
484 unwind_protect |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
485 updating = true; |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
486 if (isaxes (h)) |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
487 pos = get_position_points (h); |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
488 old_pos = getappdata (hl, "__peer_axes_position__"); |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
489 if (! all (pos == old_pos)) |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
490 update_layout_cb (hl); |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
491 setappdata (hl, "__peer_axes_position__", pos); |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
492 endif |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
493 elseif (isfigure (h)) |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
494 pos = get_position_points (h)(3:4); |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
495 old_pos = getappdata (hl, "__peer_figure_position__"); |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
496 if (isempty (old_pos) || ! all (pos == old_pos)) |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
497 update_layout_cb (hl); |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
498 setappdata (hl, "__peer_figure_position__", pos); |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
499 endif |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
500 endif |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
501 unwind_protect_cleanup |
27754
0a9213395844
legend.m: prevent infinite listener execution with uipanel parent (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27751
diff
changeset
|
502 ## FIXME: If the parent is an uipanel, asynchronous events that affect |
0a9213395844
legend.m: prevent infinite listener execution with uipanel parent (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27751
diff
changeset
|
503 ## the "position" and "tightinset" properties are emitted. |
0a9213395844
legend.m: prevent infinite listener execution with uipanel parent (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27751
diff
changeset
|
504 ## Since those events are asynchronous, there is no recursion (which we |
0a9213395844
legend.m: prevent infinite listener execution with uipanel parent (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27751
diff
changeset
|
505 ## can stop using the "updating" variable) and this leeds to an infinite |
0a9213395844
legend.m: prevent infinite listener execution with uipanel parent (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27751
diff
changeset
|
506 ## execution of listeners. Porcessing graphics events here seems to fix |
0a9213395844
legend.m: prevent infinite listener execution with uipanel parent (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27751
diff
changeset
|
507 ## the issue but is this reliable? |
0a9213395844
legend.m: prevent infinite listener execution with uipanel parent (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27751
diff
changeset
|
508 if (strcmp (get (get (hl, "parent"), "type"), "uipanel")) |
0a9213395844
legend.m: prevent infinite listener execution with uipanel parent (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27751
diff
changeset
|
509 pause (0.01); |
0a9213395844
legend.m: prevent infinite listener execution with uipanel parent (bug #57319)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27751
diff
changeset
|
510 endif |
27721
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
511 updating = false; |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
512 end_unwind_protect |
6eb7491a8794
legend.m: fix max recursion error with fltk (bug #52752)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27719
diff
changeset
|
513 |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
514 endif |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
515 |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
516 endfunction |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11149
diff
changeset
|
517 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
518 function update_numchild_cb (hl) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
519 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
520 if (strcmp (get (hl, "autoupdate"), "on")) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
521 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
522 hax = getappdata (hl, "__axes_handle__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
523 kids = get (hax, "children"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
524 if (iscell (kids)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
525 nkids = numel (cell2mat (get (hax, "children"))); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
526 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
527 nkids = numel (get (hax, "children")); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
528 endif |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
529 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
530 setappdata (hl, "__total_num_children__", nkids); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
531 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
532 endif |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
533 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
534 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
535 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
536 function legend_autoupdate_cb (hax, d, hl) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
537 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
538 ## Get all current children including eventual peer plotyy axes children |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
539 try |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
540 hax = get (hax, "__plotyy_axes__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
541 kids = cell2mat (get (hax, "children")); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
542 catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
543 kids = get (hax, "children"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
544 end_try_catch |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
545 |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
546 is_deletion = (getappdata (hl, "__total_num_children__") > numel (kids)); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
547 setappdata (hl, "__total_num_children__", numel (kids)); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
548 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
549 ## Remove item for deleted object |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
550 current_obj = getappdata (hl, "__peer_objects__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
551 [~, iold, inew] = setxor (current_obj, kids); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
552 current_obj(iold) = []; |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
553 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
554 if (isempty (current_obj)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
555 delete (hl); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
556 return; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
557 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
558 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
559 if (! is_deletion && strcmp (get (hl, "autoupdate"), "on")) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
560 |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
561 ## We only expect 1 new child |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
562 kids = kids(min (inew)); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
563 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
564 ## FIXME: if the latest child is an hggroup, we cannot label it since this |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
565 ## function is called before the hggroup has been properly populated. |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
566 persistent valid_types = {"line", "patch", "surface"}; |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
567 if (! any (strcmp (get (kids, "type"), valid_types))) |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
568 kids = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
569 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
570 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
571 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
572 kids = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
573 endif |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
574 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
575 if (any (iold) || any (kids)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
576 setappdata (hl, "__peer_objects__", [current_obj; kids]); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
577 set (hl, "string", displayname_or_default ([current_obj; kids], hl)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
578 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
579 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
580 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
581 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
582 function opts = parse_opts (varargin) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
583 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
584 action = ""; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
585 legend_handle = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
586 axes_handles = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
587 obj_handles = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
588 obj_labels = {}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
589 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
590 nargs = numel (varargin); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
591 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
592 ## Find peer axes |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
593 if (nargs > 0 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
594 && (! ishghandle (varargin{1}) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
595 || (strcmp (get (varargin{1}, "type"), "axes") |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
596 && ! strcmp (get (varargin{1}, "tag"), "legend")))) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
597 [axes_handles, varargin, nargs] = __plt_get_axis_arg__ ("legend", |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
598 varargin{:}); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
599 if (isempty (axes_handles)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
600 axes_handles = gca (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
601 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
602 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
603 axes_handles = gca (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
604 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
605 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
606 ## Special handling for plotyy which has two axes objects |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
607 if (isprop (axes_handles, "__plotyy_axes__")) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
608 axes_handles = [axes_handles get(axes_handles, "__plotyy_axes__").']; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
609 ## Remove duplicates while preserving order |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
610 [~, n] = unique (axes_handles, "first"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
611 axes_handles = axes_handles(sort (n)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
612 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
613 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
614 ## Find any existing legend object associated with axes |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
615 try |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
616 legend_handle = get (axes_handles, "__legend_handle__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
617 if (iscell (legend_handle)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
618 legend_handle = unique (cell2mat (legend_handle)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
619 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
620 catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
621 end_try_catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
622 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
623 ## Legend actions |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
624 actions = {"show", "hide", "toggle", "boxon", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
625 "boxoff", "right", "left", "off"}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
626 if (nargs > 0 && ischar (varargin{1}) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
627 && any (strcmp (varargin{1}, actions))) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
628 action = varargin{1}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
629 if (nargs > 1) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
630 warning ("Octave:legend:ignoring-extra-argument", |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
631 'legend: ignoring extra arguments after "%s"', action); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
632 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
633 nargs = 0; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
634 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
635 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
636 ## Now remove property-value pairs for compatibility. |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
637 propval = {}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
638 warn_propval = ""; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
639 persistent legend_props = {"location", "orientation", "numcolumns", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
640 "numcolumnsmode", "textposition", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
641 "position", "units", "autoupdate", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
642 "string", "title", "interpreter", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
643 "fontname", "fontsize", "fontweight", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
644 "fontangle", "textcolor", "color", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
645 "edgecolor", "box", "linewidth", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
646 "visible", "uicontextmenu", "selected", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
647 "selectionhighlight", "itemhitfcn", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
648 "buttondownfcn", "createfcn", "deletefcn" ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
649 "interruptible", "busyaction", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
650 "pickableparts", "hittest", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
651 "beingdeleted", "parent", "children", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
652 "handlevisibility", "tag", "type", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
653 "userdata"}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
654 isprp = @(prop) (ischar (prop) && any (strcmpi (legend_props, prop))); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
655 idx = find (cellfun (isprp, varargin)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
656 if (! isempty (idx)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
657 idx = idx(1); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
658 propval = varargin(idx:end); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
659 warn_propval = varargin{idx}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
660 varargin(idx:end) = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
661 nargs = idx-1; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
662 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
663 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
664 ## List plot objects that can be handled |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
665 warn_extra_obj = false; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
666 persistent valid_types = {"line", "patch", "surface", "hggroup"}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
667 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
668 if (nargs > 0 && all (ishghandle (varargin{1}))) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
669 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
670 ## List of plot objects to label given as first argument |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
671 obj_handles = varargin{1}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
672 types = get (obj_handles, "type"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
673 if (! iscell (types)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
674 types = {types}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
675 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
676 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
677 idx = cellfun (@(s) any (strcmp (s, valid_types)), types); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
678 if (! all (idx)) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
679 error ("Octave:legend:bad-object", |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
680 "legend: objects of type \"%s\" can't be labeled", |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
681 types(! idx){1}); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
682 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
683 varargin(1) = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
684 nargs--; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
685 warn_extra_obj = true; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
686 |
27739
f18f85ec4b96
legend.m: New labels on existing legend to redefine labeled objects.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27738
diff
changeset
|
687 elseif (nargs > 0 || isempty (legend_handle)) |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
688 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
689 ## Find list of plot objects from axes "children" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
690 if (isscalar (axes_handles)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
691 obj_handles = flipud (get (axes_handles, "children")(:)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
692 else |
27713
e297d20e2d4f
legend.m: fix regression with plotyy item order (bug #50497)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27711
diff
changeset
|
693 tmp = get (axes_handles(:), "children"); |
e297d20e2d4f
legend.m: fix regression with plotyy item order (bug #50497)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27711
diff
changeset
|
694 obj_handles = [flipud(tmp{1}); flipud(tmp{2})]; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
695 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
696 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
697 if (isempty (obj_handles)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
698 error ("Octave:legend:no-object", "legend: no valid object to label"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
699 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
700 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
701 idx = arrayfun (@(h) any (strcmp (get (h, "type"), valid_types)), ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
702 obj_handles); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
703 obj_handles(! idx) = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
704 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
705 if (isempty (obj_handles)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
706 error ("Octave:legend:no-object", "legend: no valid object to label"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
707 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
708 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
709 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
710 obj_handles = getappdata (legend_handle, "__peer_objects__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
711 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
712 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
713 nobj = numel (obj_handles); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
714 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
715 ## List labels |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
716 next_idx = 1; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
717 if (nargs > 0) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
718 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
719 if (iscellstr (varargin{1})) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
720 obj_labels = varargin{1}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
721 varargin(1) = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
722 nargs--; |
27722
62a57f086bf9
legend.m: fix argument parsing when empty string present (bug #52641)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27721
diff
changeset
|
723 elseif (ischar (varargin{1}) && rows (varargin{1}) > 1) |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
724 obj_labels = cellstr (varargin{1}); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
725 varargin(1) = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
726 nargs--; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
727 elseif (all (cellfun (@ischar, varargin))) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
728 obj_labels = varargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
729 varargin = {}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
730 nargs = 0; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
731 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
732 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
733 if (nargs > 0) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
734 print_usage ("legend"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
735 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
736 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
737 nlab = numel (obj_labels); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
738 if (nlab != nobj) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
739 if (nobj > nlab) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
740 obj_handles = obj_handles(1:nlab); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
741 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
742 msg = "legend: ignoring extra objects."; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
743 if (! isempty (warn_propval)) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
744 msg = [msg ' "' warn_propval '" interpreted as a property ' , ... |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
745 "name. Use a cell array of strings to specify labels ", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
746 "that match a legend property name."]; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
747 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
748 if (warn_extra_obj) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
749 warning ("Octave:legend:object-label-mismatch", msg); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
750 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
751 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
752 obj_labels = obj_labels(1:nobj); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
753 warning ("Octave:legend:object-label-mismatch", |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
754 "legend: ignoring extra labels."); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
755 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
756 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
757 else |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
758 [tmp_labels, next_idx] = displayname_or_default (obj_handles, |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
759 legend_handle); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
760 if (isempty (legend_handle) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
761 || ! isequal (tmp_labels, get (legend_handle, "string"))) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
762 obj_labels = tmp_labels; |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
763 endif |
27740
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
764 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
765 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
766 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
767 opts.action = action; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
768 opts.axes_handles = axes_handles; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
769 opts.obj_handles = obj_handles; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
770 opts.obj_labels = obj_labels; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
771 opts.legend_handle = legend_handle; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
772 opts.propval = propval; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
773 opts.next_idx = next_idx; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
774 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
775 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
776 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
777 function [labels, next_idx] = displayname_or_default (hplots, hl = []) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
778 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
779 next_idx = 1; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
780 if (! isempty (hl)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
781 next_idx = getappdata (hl, "__next_label_index__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
782 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
783 |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
784 ## Use the displayname property |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
785 labels = get (hplots, "displayname"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
786 if (! iscell (labels)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
787 labels = {labels}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
788 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
789 |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
790 ## Fallback to automatic names for empty labels |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
791 empty_label_idx = cellfun (@isempty, labels); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
792 |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
793 if (any (empty_label_idx) && ! isempty (hl)) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
794 ## Empty strings must not be blindly replaced by data%d. If there exist |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
795 ## an old text object that was affected an empty string, keep it as is. |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
796 kids = get (hl, "children"); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
797 htext = kids(strcmp (get (kids, "type"), "text")); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
798 old_objects = get (htext, "peer_object"); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
799 if (iscell (old_objects)) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
800 old_objects = cell2mat (old_objects); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
801 endif |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
802 |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
803 for h = hplots(empty_label_idx).' |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
804 idx = (h == old_objects); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
805 if (any (idx)) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
806 labels(hplots == h) = get (htext(idx), "string"); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
807 empty_label_idx(hplots == h) = false; |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
808 endif |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
809 endfor |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
810 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
811 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
812 |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
813 if (any (empty_label_idx)) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
814 default = arrayfun (@(ii) sprintf ("data%d", ii), ... |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
815 [next_idx:(next_idx + sum (empty_label_idx) - 1)], ... |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
816 "uniformoutput", false)(:); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
817 labels(empty_label_idx) = default; |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
818 endif |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
819 |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
820 next_idx += sum (empty_label_idx); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
821 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
822 if (! isempty (hl)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
823 setappdata (hl, "__next_label_index__", next_idx); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
824 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
825 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
826 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
827 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
828 function update_layout_cb (hl, ~, update_item = false) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
829 updating = getappdata (hl, "__updating_layout__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
830 if (! isempty (updating) && updating) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
831 return; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
832 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
833 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
834 setappdata(hl, "__updating_layout__", true); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
835 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
836 ## Scale limits so that item positions are expressed in points, from |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
837 ## top to bottom and from left to right or reverse depending on textposition |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
838 units = get (hl, "units"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
839 set (hl, "units", "points"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
840 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
841 unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
842 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
843 if (update_item) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
844 pos = get (hl, "position")(3:4); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
845 set (hl, "xlim", [0, pos(1)], "ylim", [0, pos(2)]); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
846 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
847 textright = strcmp (get (hl, "textposition"), "right"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
848 set (hl, "ydir", "reverse", ... |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
849 "xdir", ifelse (textright, "normal", "reverse")); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
850 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
851 ## Create or reuse text and icon graphics objects |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
852 objlist = texticon_objects (hl, textright); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
853 nitem = rows (objlist); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
854 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
855 ## Prepare the array of text/icon pairs and update their position |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
856 sz = update_texticon_position (hl, objlist); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
857 else |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
858 sz = [diff(get (hl, "xlim")), diff(get (hl, "ylim"))]; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
859 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
860 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
861 ## Place the legend |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
862 update_legend_position (hl, sz); |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
863 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
864 unwind_protect_cleanup |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
865 set (hl, "units", units); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
866 setappdata(hl, "__updating_layout__", false); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
867 end_unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
868 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
869 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
870 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
871 function objlist = texticon_objects (hl, textright) |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
872 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
873 ## Delete or set invisible obsolete or unused text/icon objects. |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
874 old_kids = get (hl, "children")(:).'; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
875 old_peer_objects = cell2mat (get (old_kids, "peer_object"))(:).'; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
876 unused = ! ishghandle (old_peer_objects); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
877 delete (old_kids(unused)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
878 old_kids(unused) = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
879 old_peer_objects(unused) = []; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
880 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
881 new_peer_objects = getappdata (hl, "__peer_objects__")(:).'; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
882 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
883 unused = arrayfun (@(h) ! any (h == new_peer_objects), old_peer_objects); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
884 set (old_kids(unused), "visible", "off"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
885 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
886 ## Text properties |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
887 string = get (hl , "string"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
888 if (! iscell (string)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
889 string = {string}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
890 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
891 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
892 txtprops = {"textcolor", "fontsize", "fontweight", "fontname", ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
893 "interpreter"}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
894 txtvals = get (hl, txtprops); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
895 txtprops{1} = "color"; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
896 txtprops = [txtprops, "horizontalalignment"]; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
897 txtvals = [txtvals, ifelse(textright, "left", "right")]; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
898 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
899 ## Create or reuse text/icon objects as needed |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
900 nitem = numel (new_peer_objects); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
901 objlist = NaN (nitem, 2); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
902 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
903 for ii = 1:nitem |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
904 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
905 str = string{ii}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
906 hplt = new_peer_objects(ii); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
907 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
908 idx = (old_peer_objects == hplt); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
909 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
910 if (any (idx)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
911 tmp = old_kids(idx); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
912 idx = strcmp (get (tmp, "type"), "text"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
913 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
914 htxt = tmp(idx); |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
915 hicon = tmp(! idx); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
916 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
917 set (htxt, "visible", "on", "string", str, ... |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
918 [txtprops(:)'; txtvals(:)']{:}); |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
919 set (hicon, "visible", "on"); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
920 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
921 else |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
922 [htxt, hicon] = create_item (hl, str, [txtprops(:)'; txtvals(:)'], hplt); |
27755
b70da79e4ed9
legend.m: Fix storage of listeners for displayname property
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27754
diff
changeset
|
923 add_safe_listener (hl, hplt, "displayname", {@update_displayname_cb, hl}); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
924 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
925 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
926 set (hplt, "displayname", str); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
927 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
928 objlist(ii,:) = [htxt, hicon]; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
929 endfor |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
930 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
931 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
932 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
933 function [htxt, hicon] = create_item (hl, str, txtpval, hplt) |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
934 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
935 typ = get (hplt, "type"); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
936 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
937 ## For unknown hggroups use the first child that can be labeled |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
938 persistent known_creators = {"__contour__", "__errplot__", "__quiver__", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
939 "__scatter__", "__stem__"}; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
940 base_hplt = hplt; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
941 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
942 if (strcmp (typ, "hggroup")) |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
943 creator = getappdata (hplt, "__creator__"); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
944 kids = get (hplt, "children"); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
945 if (any (strcmp (known_creators, creator))) |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
946 typ = creator; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
947 switch (creator) |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
948 case "__contour__" |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
949 hplt = [kids(1), kids(end)]; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
950 case {"__errplot__", "__quiver__", "__stem__"} |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
951 hplt = kids(2:-1:1); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
952 otherwise |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
953 hplt = kids(1); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
954 endswitch |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
955 else |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
956 types = get (kids, "type"); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
957 if (! iscell (types)) |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
958 types = {types}; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
959 endif |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
960 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
961 idx = cellfun (@(s) any (strcmp (s, {"line", "patch", "surface"})), ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
962 types); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
963 hplt = kids(idx)(1); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
964 typ = types(idx){1}; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
965 endif |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
966 endif |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
967 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
968 persistent lprops = {"color", "linestyle", "linewidth"}; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
969 persistent mprops = {"color", "marker", "markeredgecolor", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
970 "markerfacecolor", "markersize"}; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
971 persistent pprops = {"edgecolor", "facecolor", "cdata", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
972 "linestyle", "linewidth", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
973 "marker", "markeredgecolor", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
974 "markerfacecolor", "markersize"}; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
975 switch (typ) |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
976 case {"line", "__errplot__", "__quiver__", "__stem__"} |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
977 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
978 ## Main line |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
979 vals = get (hplt(1), lprops); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
980 hicon = __go_line__ (hl, [lprops; vals]{:}); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
981 addproperty ("markerxdata", hicon, "double", 0); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
982 addproperty ("markerydata", hicon, "double", 0); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
983 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
984 ## Additional line for the marker |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
985 vals = get (hplt(end), mprops); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
986 hmarker = __go_line__ (hl, "handlevisibility", "off", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
987 "xdata", 0, "ydata", 0, [mprops; vals]{:}); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
988 update_marker_cb (hmarker); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
989 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
990 setappdata (hplt(1), "__icon_link__", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
991 linkprop ([hplt(1), hicon], lprops)); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
992 setappdata (hplt(end), "__marker_link__", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
993 linkprop ([hplt(end) hmarker], mprops)); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
994 addlistener (hicon, "ydata", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
995 @(h) set (hmarker, "ydata", get (h, "markerydata"))); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
996 addlistener (hicon, "xdata", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
997 @(h) set (hmarker, "xdata", get (h, "markerxdata"))); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
998 addlistener (hmarker, "markersize", @update_marker_cb); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
999 add_safe_listener (hl, hplt(1), "beingdeleted", |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1000 @() delete ([hicon hmarker])) |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1001 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1002 case {"patch", "surface", "__scatter__"} |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1003 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1004 vals = get (hplt, pprops); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1005 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1006 hicon = __go_patch__ (hl, [pprops; vals]{:}); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1007 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1008 setappdata (hplt, "__icon_link__", linkprop ([hplt, hicon], pprops)); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1009 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1010 case "__contour__" |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1011 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1012 ## Main patch |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1013 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1014 vals = get (hplt(1), pprops); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1015 hicon = __go_patch__ (hl, [pprops; vals]{:}); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1016 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1017 addproperty ("innerxdata", hicon, "any", 0); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1018 addproperty ("innerydata", hicon, "any", 0); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1019 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1020 ## Additional patch for the inner contour |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1021 vals = get (hplt(end), pprops); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1022 htmp = __go_patch__ (hl, "handlevisibility", "off", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1023 "xdata", 0, "ydata", 0, [pprops; vals]{:}); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1024 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1025 setappdata (hplt(1), "__icon_link__", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1026 linkprop ([hplt(1), hicon], pprops)); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1027 setappdata (hplt(end), "__icon_link__", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1028 linkprop ([hplt(end) htmp], pprops)); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1029 addlistener (hicon, "ydata", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1030 @(h) set (htmp, "ydata", get (h, "innerydata"))); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1031 addlistener (hicon, "xdata", ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1032 @(h) set (htmp, "xdata", get (h, "innerxdata"))); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1033 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1034 add_safe_listener (hl, hplt(1), "beingdeleted", |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1035 @() delete ([hicon htmp])) |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1036 endswitch |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1037 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1038 htxt = __go_text__ (hl, "string", str, txtpval{:}); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1039 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1040 addproperty ("peer_object", htxt, "double", base_hplt); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1041 addproperty ("peer_object", hicon, "double", base_hplt); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1042 setappdata (hicon, "__creator__", typ); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1043 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1044 endfunction |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1045 |
27738
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1046 function update_displayname_cb (h, ~, hl) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1047 |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1048 updating = getappdata (hl, "__updating_layout__"); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1049 if (! isempty (updating) && updating) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1050 return; |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1051 endif |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1052 |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1053 str = get (hl, "string"); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1054 if (! iscell (str)) |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1055 str = {str}; |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1056 endif |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1057 |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1058 str{h == getappdata (hl, "__peer_objects__")} = get (h, "displayname"); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1059 |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1060 set (hl ,"string", str); |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1061 |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1062 endfunction |
7fff532afcb1
legend.m: Fix handling of empty strings and displayname (bug #57271)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27723
diff
changeset
|
1063 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1064 function update_marker_cb (h) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1065 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1066 if (get (h, "markersize") > 3) |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1067 set (h, "markersize", 3); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1068 endif |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1069 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1070 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1071 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1072 function sz = update_texticon_position (hl, objlist) |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1073 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1074 ## margins in points |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1075 persistent hmargin = 3; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1076 persistent vmargin = 3; |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1077 persistent icon_width = 15; |
27749
b3ad1b9417c0
legend.m: Make icon height depend on the fontsize (bug #57269)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27747
diff
changeset
|
1078 |
b3ad1b9417c0
legend.m: Make icon height depend on the fontsize (bug #57269)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27747
diff
changeset
|
1079 units = get (hl, "fontunits"); |
b3ad1b9417c0
legend.m: Make icon height depend on the fontsize (bug #57269)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27747
diff
changeset
|
1080 set (hl, "fontunits", "points"); |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1081 icon_height = 0.7 * get (hl, "fontsize"); |
27749
b3ad1b9417c0
legend.m: Make icon height depend on the fontsize (bug #57269)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27747
diff
changeset
|
1082 set (hl, "fontunits", units); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1083 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1084 ext = get (objlist(:,1), "extent"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1085 markers = get (objlist(:,2), "marker"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1086 markersz = get (objlist(:,2), "markersize"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1087 types = get (objlist(:,2), "type"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1088 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1089 ## Simple case of 1 text/icon pair |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1090 nitem = rows (objlist); |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1091 txticon = zeros (nitem, 4); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1092 if (nitem == 1) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1093 ext = abs (ext(:,3:4)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1094 types = {types}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1095 markers = {markers}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1096 markersz = {markersz}; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1097 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1098 ext = abs (cell2mat (ext)(:,3:4)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1099 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1100 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1101 ## Maximum allowable size for the legend |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1102 hax = getappdata (hl, "__axes_handle__")(1); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1103 units = get (hax, "units"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1104 unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1105 set (hax, "units", "points"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1106 max_size = get (hax, "position")(3:4); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1107 unwind_protect_cleanup |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1108 set (hax, "units", units); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1109 end_unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1110 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1111 location = get (hl, "location"); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1112 outside = strcmp (location(end-3:end), "side"); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1113 if (! outside) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1114 max_size *= .90; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1115 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1116 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1117 autolayout = strcmp (get (hl, "numcolumnsmode"), "auto"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1118 xmax = ymax = 0; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1119 iter = 1; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1120 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1121 if (strcmp (get (hl, "orientation"), "vertical")) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1122 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1123 if (autolayout) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1124 if (any (strcmpi (location, {"north", "northoutside", |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1125 "south", "southoutside"}))) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1126 ##FIXME: handle autolayout for these in a better fashion |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1127 nrow = 1; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1128 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1129 nrow = max (find ((cumsum (ext(:,2) + vmargin) + vmargin) ... |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1130 < max_size(2))); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1131 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1132 ncol = ceil (nitem / nrow); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1133 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1134 ncol = min (nitem, get (hl, "numcolumns")); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1135 nrow = ceil (nitem / ncol); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1136 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1137 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1138 rowheights = arrayfun (@(idx) max([icon_height; ext(idx:nrow:end, 2)]), ... |
27723
a0143104b224
legend.m: fix icon height for patch and surface objects (bug #57269)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27722
diff
changeset
|
1139 1:nrow); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1140 x = hmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1141 for ii = 1:ncol |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1142 y = vmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1143 for jj = 1:nrow |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1144 if (iter > nitem) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1145 continue; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1146 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1147 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1148 hg = rowheights(jj); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1149 dx = 0; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1150 if (! strcmp (markers{iter}, "none")) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1151 dx = markersz{iter}/2; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1152 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1153 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1154 ybase = y + hg / 2; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1155 y0 = y + hg/2 - icon_height/2 + dx; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1156 y1 = y + hg/2 + icon_height/2 - dx; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1157 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1158 update_icon_position (objlist(iter,2), [x+dx, x+icon_width-dx], ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1159 [y0, y1]); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1160 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1161 set (objlist(iter,1), "position", [x+icon_width+hmargin, ybase, 0]); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1162 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1163 xmax = max ([xmax, x+icon_width+2*hmargin+ext(iter,1)]); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1164 y += (vmargin + hg); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1165 iter++; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1166 endfor |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1167 ymax = max ([ymax, y]); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1168 x = xmax + 2*hmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1169 endfor |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1170 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1171 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1172 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1173 if (autolayout) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1174 if (any (strcmpi (location, {"north", "northoutside", |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1175 "south", "southoutside"}))) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1176 ##FIXME: handle autolayout for these in a better fashion |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1177 ncol = nitem; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1178 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1179 ncol = max (find ((cumsum (ext(:,1) + 2*hmargin ... |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1180 + icon_width) + hmargin) ... |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1181 < max_size(1))); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1182 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1183 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1184 ncol = min (nitem, get (hl, "numcolumns")); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1185 nrow = ceil (nitem / ncol); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1186 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1187 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1188 nrow = ceil (nitem / ncol); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1189 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1190 colwidth = arrayfun (@(idx) max(ext(idx:ncol:end, 1)), |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1191 1:ncol); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1192 y = vmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1193 for ii = 1:nrow |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1194 x = hmargin; |
27714
a984e6722601
legend.m: better vertical alignment for horizontal orientation (bug #57264)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27713
diff
changeset
|
1195 |
a984e6722601
legend.m: better vertical alignment for horizontal orientation (bug #57264)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27713
diff
changeset
|
1196 endidx = min (iter+ncol-1, nitem); |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1197 hg = max ([icon_height; ext(iter:endidx,2)]); |
27714
a984e6722601
legend.m: better vertical alignment for horizontal orientation (bug #57264)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27713
diff
changeset
|
1198 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1199 for jj = 1:ncol |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1200 if (iter > nitem) |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1201 continue; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1202 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1203 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1204 wd = colwidth(jj); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1205 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1206 dx = 0; |
27714
a984e6722601
legend.m: better vertical alignment for horizontal orientation (bug #57264)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27713
diff
changeset
|
1207 if (! strcmp (markers{iter}, "none")) |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1208 dx = markersz{iter}/2; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1209 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1210 |
27714
a984e6722601
legend.m: better vertical alignment for horizontal orientation (bug #57264)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27713
diff
changeset
|
1211 ybase = y + hg / 2; |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1212 y0 = y + hg/2 - icon_height/2 + dx; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1213 y1 = y + hg/2 + icon_height/2 - dx; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1214 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1215 update_icon_position (objlist(iter,2), [x+dx, x+icon_width-dx], ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1216 [y0, y1]); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1217 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1218 set (objlist(iter,1), "position", [x+icon_width+hmargin, ybase, 0]); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1219 |
27714
a984e6722601
legend.m: better vertical alignment for horizontal orientation (bug #57264)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27713
diff
changeset
|
1220 ymax = max ([ymax, ybase+hg/2+vmargin]); |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1221 x += (3*hmargin + icon_width + wd); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1222 iter++; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1223 endfor |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1224 xmax = max ([xmax, x-hmargin]); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1225 y = ymax + vmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1226 endfor |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1227 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1228 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1229 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1230 sz = [xmax, ymax]; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1231 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1232 endfunction |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1233 |
27790
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1234 function update_icon_position (hicon, xdata, ydata) |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1235 creator = getappdata (hicon, "__creator__"); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1236 switch (creator) |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1237 case {"line", "__stem__"} |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1238 set (hicon, "markerxdata", mean (xdata), "markerydata", mean (ydata), ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1239 "xdata", xdata, "ydata", [mean(ydata), mean(ydata)]); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1240 case {"patch", "surface"} |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1241 set (hicon, ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1242 "xdata", [xdata, fliplr(xdata)], ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1243 "ydata", [ydata; ydata](:).'); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1244 case "__contour__" |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1245 ## Draw two patches |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1246 x0 = xdata(1); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1247 x1 = xdata(2); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1248 xm = mean (xdata); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1249 y0 = ydata(1); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1250 y1 = ydata(2); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1251 ym = mean (ydata); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1252 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1253 xdata = [x0, x1, x1, x0]; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1254 ydata = [y0, y0, y1, y1]; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1255 set (hicon, ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1256 "innerxdata", (xdata-xm) * 0.6 + xm, ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1257 "innerydata", (ydata-ym) * 0.6 + ym, ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1258 "xdata", xdata, "ydata", ydata); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1259 case "__errplot__" |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1260 ## Draw a double arrow |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1261 x0 = xdata(1); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1262 x1 = xdata(2); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1263 xm = mean (xdata); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1264 y0 = ydata(1); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1265 y1 = ydata(2); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1266 ym = mean (ydata); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1267 |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1268 xdata = [x0, x0, x0, x1, x1, x1, x1, ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1269 xm, xm, xm-2, xm+2, xm, xm, xm-2, xm+2]; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1270 ydata = [ym+2, ym-2, ym, ym, ym+2, ym-2, ym, ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1271 ym, y0, y0, y0, y0, y1, y1, y1]; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1272 set (hicon, "markerxdata", xm, "markerydata", ym, ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1273 "xdata", xdata, "ydata", ydata); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1274 case "__quiver__" |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1275 ## Draw an arrow |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1276 x0 = xdata(1); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1277 x1 = xdata(2); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1278 y0 = mean (ydata); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1279 xdata = [x0, x1, x1-2, x1, x1-2]; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1280 ydata = [y0, y0, y0+2, y0, y0-2]; |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1281 set (hicon, "markerxdata", x0, "markerydata", y0, ... |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1282 "xdata", xdata, "ydata", ydata); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1283 case "__scatter__" |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1284 set (hicon, "xdata", mean(xdata), "ydata", mean(ydata)); |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1285 endswitch |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1286 endfunction |
0157c4d4792e
legend.m: Handle builtin hggroup-based objects (bug #57260)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27755
diff
changeset
|
1287 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1288 function update_legend_position (hl, sz) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1289 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1290 persistent hmargin = 6; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1291 persistent vmargin = 6; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1292 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1293 location = get (hl, "location"); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1294 outside = strcmp (location(end-3:end), "side"); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1295 if (outside) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1296 location = location(1:end-7); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1297 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1298 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1299 if (strcmp (location, "best")) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1300 orientation = get (hl, "orientation"); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1301 if (outside) |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1302 if (strcmp (orientation, "vertical")) |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1303 location = "northeast"; |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1304 else |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1305 location = "south"; |
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1306 endif |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1307 else |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1308 ## FIXME: implement "best" inside properly |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1309 location = "northeast"; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1310 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1311 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1312 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1313 haxes = getappdata (hl, "__axes_handle__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1314 hax = haxes(end); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1315 units = get (hax, "units"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1316 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1317 unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1318 ## Restore the original looseinset first and set units to points. |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1319 li = getappdata (hl, "__original_looseinset__"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1320 if (isempty (li)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1321 li = get (hax, "looseinset"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1322 setappdata (hl, "__original_looseinset__", li); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1323 setappdata (hl, "__original_units__", units); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1324 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1325 |
27740
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
1326 if (strcmp (get (hl, "visible"), "on")) |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
1327 set (hax, "units", getappdata (hl, "__original_units__"), |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
1328 "looseinset", li, |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
1329 "units", "points"); |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
1330 else |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
1331 ## Return early for invible legends |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
1332 set (hax, "units", getappdata (hl, "__original_units__"), |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
1333 "looseinset", li, |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
1334 "units", units); |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
1335 return; |
3d5f00d4c847
legend.m: Restore original axes looseinset when the legend is hidden.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27739
diff
changeset
|
1336 endif |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1337 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1338 [li, axpos] = get (hax, {"looseinset", "position"}){:}; |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1339 lpos = [get(hl, "position")(1:2), sz]; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1340 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1341 if (! outside) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1342 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1343 switch (location) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1344 case "southwest" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1345 lpos(1) = axpos(1) + hmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1346 lpos(2) = axpos(2) + vmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1347 case "west" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1348 lpos(1) = axpos(1) + hmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1349 lpos(2) = axpos(2) + axpos(4)/2 - lpos(4)/2; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1350 case "northwest" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1351 lpos(1) = axpos(1) + hmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1352 lpos(2) = axpos(2) + axpos(4) - lpos(4) - vmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1353 case "north" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1354 lpos(1) = axpos(1) + axpos(3)/2 - lpos(3)/2; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1355 lpos(2) = axpos(2) + axpos(4) - lpos(4) - vmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1356 case "northeast" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1357 lpos(1) = axpos(1) + axpos(3) - lpos(3) - hmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1358 lpos(2) = axpos(2) + axpos(4) - lpos(4) - vmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1359 case "east" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1360 lpos(1) = axpos(1) + axpos(3) - lpos(3) - hmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1361 lpos(2) = axpos(2) + axpos(4)/2 - lpos(4)/2; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1362 case "southeast" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1363 lpos(1) = axpos(1) + axpos(3) - lpos(3) - hmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1364 lpos(2) = axpos(2) + vmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1365 case "south" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1366 lpos(1) = axpos(1) + axpos(3)/2 - lpos(3)/2; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1367 lpos(2) = axpos(2) + vmargin; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1368 endswitch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1369 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1370 else |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1371 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1372 ti = get (haxes, "tightinset"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1373 if (iscell (ti)) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1374 ti = max (cell2mat (ti)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1375 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1376 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1377 switch (location) |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1378 case "southwest" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1379 dx = lpos(3) + hmargin + ti(1); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1380 if (axpos(1) < (dx + hmargin)) |
27711
63a03d2a20e6
legend.m: don't set too large looseinset for outside legends (bug #50094)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27710
diff
changeset
|
1381 li(1) = min (dx + hmargin, 0.95 * (axpos(1) + axpos(3))); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1382 set (hax, "looseinset", li); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1383 axpos = get (hax, "position"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1384 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1385 lpos(1) = axpos(1) - dx; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1386 lpos(2) = axpos(2); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1387 case "west" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1388 dx = lpos(3) + hmargin + ti(1); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1389 if (axpos(1) < (dx + hmargin)) |
27711
63a03d2a20e6
legend.m: don't set too large looseinset for outside legends (bug #50094)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27710
diff
changeset
|
1390 li(1) = min (dx + hmargin, 0.95 * (axpos(1) + axpos(3))); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1391 set (hax, "looseinset", li); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1392 axpos = get (hax, "position"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1393 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1394 lpos(1) = axpos(1) - dx; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1395 lpos(2) = axpos(2) + axpos(4)/2 - lpos(4)/2; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1396 case "northwest" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1397 dx = lpos(3) + hmargin + ti(1); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1398 if (axpos(1) < (dx + hmargin)) |
27711
63a03d2a20e6
legend.m: don't set too large looseinset for outside legends (bug #50094)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27710
diff
changeset
|
1399 li(1) = min (dx + hmargin, 0.95 * (axpos(1) + axpos(3))); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1400 set (hax, "looseinset", li); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1401 axpos = get (hax, "position"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1402 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1403 lpos(1) = axpos(1) - dx; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1404 lpos(2) = axpos(2) + axpos(4) - lpos(4); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1405 case "north" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1406 dy = lpos(4) + vmargin + ti(4); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1407 if (li(4) < (dy + vmargin)) |
27711
63a03d2a20e6
legend.m: don't set too large looseinset for outside legends (bug #50094)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27710
diff
changeset
|
1408 li(4) = min (dy + vmargin, axpos(4)); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1409 set (hax, "looseinset", li); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1410 axpos = get (hax, "position"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1411 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1412 lpos(1) = axpos(1) + axpos(3)/2 - lpos(3)/2; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1413 lpos(2) = axpos(2) + axpos(4) + vmargin + ti(4); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1414 case "northeast" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1415 dx = lpos(3) + hmargin + ti(3); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1416 if (li(3) < (dx + hmargin)) |
27711
63a03d2a20e6
legend.m: don't set too large looseinset for outside legends (bug #50094)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27710
diff
changeset
|
1417 li(3) = min (dx + hmargin, axpos(3)); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1418 set (hax, "looseinset", li); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1419 axpos = get (hax, "position"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1420 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1421 lpos(1) = axpos(1) + axpos(3) + hmargin + ti(3); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1422 lpos(2) = axpos(2) + axpos(4) - lpos(4); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1423 case "east" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1424 dx = lpos(3) + hmargin + ti(3); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1425 if (li(3) < (dx + hmargin)) |
27711
63a03d2a20e6
legend.m: don't set too large looseinset for outside legends (bug #50094)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27710
diff
changeset
|
1426 li(3) = min (dx + hmargin, axpos(3)); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1427 set (hax, "looseinset", li); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1428 axpos = get (hax, "position"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1429 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1430 lpos(1) = axpos(1) + axpos(3) + hmargin + ti(3); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1431 lpos(2) = axpos(2) + axpos(4)/2 - lpos(4)/2; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1432 case "southeast" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1433 dx = lpos(3) + hmargin + ti(3); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1434 if (li(3) < (dx + hmargin)) |
27711
63a03d2a20e6
legend.m: don't set too large looseinset for outside legends (bug #50094)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27710
diff
changeset
|
1435 li(3) = min (dx + hmargin, axpos(3)); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1436 set (hax, "looseinset", li); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1437 axpos = get (hax, "position"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1438 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1439 lpos(1) = axpos(1) + axpos(3) + hmargin + ti(3); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1440 lpos(2) = axpos(2); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1441 case "south" |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1442 dy = lpos(4) + vmargin + ti(2); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1443 if (li(2) < (dy + vmargin)) |
27711
63a03d2a20e6
legend.m: don't set too large looseinset for outside legends (bug #50094)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27710
diff
changeset
|
1444 li(2) = min (dy + vmargin, 0.95 * (axpos(2) + axpos(4))); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1445 set (hax, "looseinset", li); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1446 axpos = get (hax, "position"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1447 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1448 lpos(1) = axpos(1) + axpos(3)/2 - lpos(3)/2; |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1449 lpos(2) = axpos(2) - lpos(4) - vmargin - ti(2); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1450 endswitch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1451 endif |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1452 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1453 set (hl, "xlim", [0, sz(1)], "ylim", [0, sz(2)], ... |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1454 "position", lpos); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1455 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1456 setappdata (hl, "__peer_axes_position__", axpos); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1457 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1458 unwind_protect_cleanup |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1459 set (hax, "units", units); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1460 end_unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1461 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1462 endfunction |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
1463 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1464 |
11418
a140991387fb
legend.m: Add demo to legend for inline key.
Ben Abbott <bpabbott@mac.com>
parents:
11363
diff
changeset
|
1465 %!demo |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
1466 %! clf; |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1467 %! plot (rand (2)); |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1468 %! title ("legend called with string inputs for labels"); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1469 %! h = legend ("foo", "bar"); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1470 %! set (h, "fontsize", 20, "location", "northeastoutside"); |
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
|
1471 |
aed2c50c3082
legend.m: legend with more than two inline keys (bug 31991). Add/modifyy demos.
Ben Abbott <bpabbott@mac.com>
parents:
11434
diff
changeset
|
1472 %!demo |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
1473 %! clf; |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1474 %! plot (rand (2)); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1475 %! title ("legend called with cell array of strings"); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1476 %! h = legend ({"cellfoo", "cellbar"}); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1477 %! set (h, "fontsize", 20, "location", "northeast"); |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1478 |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1479 %!demo |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1480 %! clf; |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1481 %! plot (rand (3)); |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1482 %! title ("legend () without inputs creates default labels"); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1483 %! h = legend (); |
14236
35903f035390
Escaping strings for legend entries are handled by __go_draw_axes__.
Ben Abbott <bpabbott@mac.com>
parents:
14214
diff
changeset
|
1484 |
35903f035390
Escaping strings for legend entries are handled by __go_draw_axes__.
Ben Abbott <bpabbott@mac.com>
parents:
14214
diff
changeset
|
1485 %!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
|
1486 %! clf; |
11418
a140991387fb
legend.m: Add demo to legend for inline key.
Ben Abbott <bpabbott@mac.com>
parents:
11363
diff
changeset
|
1487 %! x = 0:1; |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1488 %! hline = plot (x,x,";I am Blue;", x,2*x, x,3*x,";I am yellow;"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1489 %! h = legend (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1490 %! set (h, "location", "northeastoutside"); |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1491 %! ## Placing legend inside returns axes to original size |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1492 %! set (h, "location", "northeast"); |
22800
5de8670d10a6
Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents:
22624
diff
changeset
|
1493 %! title ("Blue and Yellow keys, with Orange missing"); |
8343
9f34f7636fe0
legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents:
8291
diff
changeset
|
1494 |
9f34f7636fe0
legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents:
8291
diff
changeset
|
1495 %!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
|
1496 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14236
diff
changeset
|
1497 %! plot (1:10, 1:10, 1:10, fliplr (1:10)); |
22800
5de8670d10a6
Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents:
22624
diff
changeset
|
1498 %! title ("incline is blue and decline is orange"); |
5de8670d10a6
Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents:
22624
diff
changeset
|
1499 %! legend ({"I am blue", "I am orange"}, "location", "east"); |
16799
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
1500 %! legend hide |
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
1501 %! legend show |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1502 |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1503 %!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
|
1504 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14236
diff
changeset
|
1505 %! plot (1:10, 1:10, 1:10, fliplr (1:10)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1506 %! title ("Legend with keys in horizontal orientation"); |
22800
5de8670d10a6
Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents:
22624
diff
changeset
|
1507 %! legend ({"I am blue", "I am orange"}, ... |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1508 %! "location", "east", "orientation", "horizontal"); |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
1509 %! legend boxoff |
16799
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
1510 %! legend boxon |
11462
aed2c50c3082
legend.m: legend with more than two inline keys (bug 31991). Add/modifyy demos.
Ben Abbott <bpabbott@mac.com>
parents:
11434
diff
changeset
|
1511 |
aed2c50c3082
legend.m: legend with more than two inline keys (bug 31991). Add/modifyy demos.
Ben Abbott <bpabbott@mac.com>
parents:
11434
diff
changeset
|
1512 %!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
|
1513 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14236
diff
changeset
|
1514 %! plot (1:10, 1:10, 1:10, fliplr (1:10)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1515 %! title ("Legend with box off"); |
22800
5de8670d10a6
Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents:
22624
diff
changeset
|
1516 %! legend ({"I am blue", "I am orange"}, "location", "east"); |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
1517 %! legend boxoff |
11434
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1518 |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1519 %!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
|
1520 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14236
diff
changeset
|
1521 %! plot (1:10, 1:10, 1:10, fliplr (1:10)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1522 %! title ("Legend with text to the left of key"); |
22800
5de8670d10a6
Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents:
22624
diff
changeset
|
1523 %! legend ({"I am blue", "I am orange"}, "location", "east"); |
17532
492d609d2d75
legend.m: Default text labels to "right" alignment for Matlab compatibility.
Rik <rik@octave.org>
parents:
17530
diff
changeset
|
1524 %! legend left |
8343
9f34f7636fe0
legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents:
8291
diff
changeset
|
1525 |
9f34f7636fe0
legend.m: Correct ording of legend labels.
Ben Abbott <bpabbott@mac.com>
parents:
8291
diff
changeset
|
1526 %!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
|
1527 %! clf; |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1528 %! plot (1:10, 1:10, 1:10, fliplr (1:10)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1529 %! title ({"Use properties to place legend text to the left of key", ... |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1530 %! "Legend text color is magenta"}); |
22800
5de8670d10a6
Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents:
22624
diff
changeset
|
1531 %! h = legend ({"I am blue", "I am orange"}, "location", "east"); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1532 %! legend ("right"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1533 %! set (h, "textposition", "left"); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1534 %! set (h, "textcolor", [1, 0, 1]); |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1535 |
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1536 %!demo |
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1537 %! clf; |
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1538 %! plot (1:10, 1:10, 1:10, fliplr (1:10)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1539 %! title ("Legend is hidden"); |
22800
5de8670d10a6
Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents:
22624
diff
changeset
|
1540 %! legend ({"I am blue", "I am orange"}, "location", "east"); |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
1541 %! legend hide |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1542 |
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1543 %!demo |
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1544 %! clf; |
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1545 %! x = 0:1; |
22800
5de8670d10a6
Change text describing demo plots to reflect new ColorOrder (bug #49288).
Rik <rik@octave.org>
parents:
22624
diff
changeset
|
1546 %! plot (x,x,";I am Blue;", x,2*x,";I am Orange;", x,3*x,";I am Yellow;"); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1547 %! title ({"Labels are embedded in call to plot", ... |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1548 %! "Legend is hidden and then shown"}); |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1549 %! legend boxon |
11434
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1550 %! legend hide |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1551 %! legend show |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1552 |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1553 %!demo |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1554 %! clf; |
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1555 %! x = 0:1; |
22151
283d8dfcad37
Make demos Matlab compatible for comparison with dump_demos script.
Rik <rik@octave.org>
parents:
22069
diff
changeset
|
1556 %! plot (x,x, x,2*x, x,3*x); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1557 %! title ("Labels with interpreted Greek text"); |
22151
283d8dfcad37
Make demos Matlab compatible for comparison with dump_demos script.
Rik <rik@octave.org>
parents:
22069
diff
changeset
|
1558 %! h = legend ('\alpha', '\beta=2\alpha', '\gamma=3\alpha'); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1559 %! set (h, "interpreter", "tex"); |
11434
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1560 |
1f54ee6760b5
legend.m: Only one legend per axes (bug 32022)
Ben Abbott <bpabbott@mac.com>
parents:
11418
diff
changeset
|
1561 %!demo |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1562 %! clf; |
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1563 %! plot (rand (2)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1564 %! title ("Labels with TeX interpreter turned off"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1565 %! h = legend ("Hello_World", "foo^bar"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1566 %! set (h, "interpreter", "none"); |
9451 | 1567 |
1568 %!demo | |
15442
015cc3d1f389
legend.m: Overhaul function and add support for automatic data labels.
Rik <rik@octave.org>
parents:
15441
diff
changeset
|
1569 %! clf; |
6146 | 1570 %! labels = {}; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1571 %! colororder = get (gca, "colororder"); |
6146 | 1572 %! 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
|
1573 %! h = plot (1:100, i + rand (100,1)); hold on; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1574 %! set (h, "color", colororder(i,:)); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1575 %! labels = {labels{:}, ["Signal ", num2str(i)]}; |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1576 %! endfor |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1577 %! hold off; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1578 %! title ({"Signals with random offset and uniform noise"; |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1579 %! "Legend shown below and outside of plot"}); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1580 %! xlabel ("Sample Nr [k]"); ylabel ("Amplitude [V]"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1581 %! legend (labels, "location", "southoutside"); |
9451 | 1582 |
1583 %!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
|
1584 %! clf; |
9451 | 1585 %! x = linspace (0, 10); |
1586 %! 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
|
1587 %! hold on; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1588 %! stem (x, x.^2, "g"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1589 %! title ("First created object gets first label"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1590 %! 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
|
1591 %! hold off; |
9451 | 1592 |
1593 %!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
|
1594 %! clf; |
9451 | 1595 %! x = linspace (0, 10); |
1596 %! plot (x, x, x, x.^2); | |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1597 %! title ("First created object gets first label"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1598 %! legend ("linear"); |
9451 | 1599 |
1600 %!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
|
1601 %! clf; |
9451 | 1602 %! x = linspace (0, 10); |
1603 %! plot (x, x, x, x.^2); | |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1604 %! title ("Labels are applied in order of object creation"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1605 %! 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
|
1606 |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1607 %!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
|
1608 %! clf; |
22629
4bd7bab38f39
Add stem example to the hggroup type of legend (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
22489
diff
changeset
|
1609 %! subplot (2,1,1); |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1610 %! 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
|
1611 %! bar (rand_2x3_data1); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1612 %! ylim ([0, 1.0]); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1613 %! title ("legend() works for bar graphs (hggroups)"); |
22629
4bd7bab38f39
Add stem example to the hggroup type of legend (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
22489
diff
changeset
|
1614 %! legend ({"1st Bar", "2nd Bar", "3rd Bar"}, "location", "northwest"); |
4bd7bab38f39
Add stem example to the hggroup type of legend (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
22489
diff
changeset
|
1615 %! subplot (2,1,2); |
23253
8a1ba13e9914
Correct hggroup plot legends for gnuplot toolkit, add legend demo 17 items (bug #49341)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
1616 %! x = linspace (0, 10, 20); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1617 %! stem (x, 0.5+x.*rand (size (x))/max (x), "markeredgecolor", [0, 0.7, 0]); |
23253
8a1ba13e9914
Correct hggroup plot legends for gnuplot toolkit, add legend demo 17 items (bug #49341)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
1618 %! hold on; |
8a1ba13e9914
Correct hggroup plot legends for gnuplot toolkit, add legend demo 17 items (bug #49341)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
1619 %! stem (x+10/(2*20), x.*(1.0+rand (size (x)))/max (x)); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1620 %! xlim ([0, 10+10/(2*20)]); |
22629
4bd7bab38f39
Add stem example to the hggroup type of legend (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
22489
diff
changeset
|
1621 %! title ("legend() works for stem plots (hggroups)"); |
23253
8a1ba13e9914
Correct hggroup plot legends for gnuplot toolkit, add legend demo 17 items (bug #49341)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
1622 %! legend ({"Multicolor", "Unicolor"}, "location", "northwest"); |
9457
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1623 |
f9fb8c1a8e45
legend.m: Add an hggroup demo using bar(). Include clf() in each demo.
Ben Abbott <bpabbott@mac.com>
parents:
9451
diff
changeset
|
1624 %!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
|
1625 %! clf; |
20408
71bd638e0ef6
legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
1626 %! colormap (cool (64)); |
71bd638e0ef6
legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
1627 %! surf (peaks ()); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1628 %! legend ("peaks()"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1629 %! title ("legend() works for surface objects too"); |
20408
71bd638e0ef6
legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
1630 |
71bd638e0ef6
legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
1631 %!demo |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1632 %! clf reset; # needed to undo colormap assignment in previous demo |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
11246
diff
changeset
|
1633 %! 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
|
1634 %! bar (rand_2x3_data2); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1635 %! ylim ([0, 1.2]); |
22151
283d8dfcad37
Make demos Matlab compatible for comparison with dump_demos script.
Rik <rik@octave.org>
parents:
22069
diff
changeset
|
1636 %! title ('"left" option places colors to the left of text label'); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1637 %! legend ("1st Bar", "2nd Bar", "3rd Bar"); |
18888
962db83e36c3
legend.m: Update demo 19 with more descriptive title.
Rik <rik@octave.org>
parents:
18753
diff
changeset
|
1638 %! legend left; |
10662
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1639 |
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1640 %!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
|
1641 %! clf; |
10662
3afcd24ced61
legend.m: Key labels for specified objects.
Ben Abbott <bpabbott@mac.com>
parents:
10549
diff
changeset
|
1642 %! 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
|
1643 %! h = plot (x,sin(x), x,cos(x), x,sin(x.^2/10), x,cos(x.^2/10)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1644 %! title ("Only the sin() objects have keylabels"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1645 %! 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
|
1646 |
12340
d63007ac067a
legend.m: Add demo for inline keys created by two plot commands.
Ben Abbott <bpabbott@mac.com>
parents:
12339
diff
changeset
|
1647 %!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
|
1648 %! clf; |
12340
d63007ac067a
legend.m: Add demo for inline keys created by two plot commands.
Ben Abbott <bpabbott@mac.com>
parents:
12339
diff
changeset
|
1649 %! x = 0:0.1:10; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1650 %! plot (x, sin (x), ";sin (x);"); |
22069
9121d6584f6a
Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents:
22054
diff
changeset
|
1651 %! hold on; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1652 %! 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
|
1653 %! hold off; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1654 %! 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
|
1655 |
12387
5fb6ea1bff65
legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents:
12340
diff
changeset
|
1656 %!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
|
1657 %! clf; |
12387
5fb6ea1bff65
legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents:
12340
diff
changeset
|
1658 %! x = 0:0.1:10; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1659 %! plot (x, sin (x), ";sin (x);"); |
22069
9121d6584f6a
Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents:
22054
diff
changeset
|
1660 %! hold on; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1661 %! 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
|
1662 %! hold off; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1663 %! title ("Specified label text overrides previous labels"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1664 %! legend ({"Sine", "Cosine"}, "location", "northeastoutside"); |
12387
5fb6ea1bff65
legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents:
12340
diff
changeset
|
1665 |
12394
c2e1973d870b
legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents:
12388
diff
changeset
|
1666 %!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
|
1667 %! clf; |
12394
c2e1973d870b
legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents:
12388
diff
changeset
|
1668 %! x = 0:10; |
c2e1973d870b
legend.m: "legend off" should delete the legend object.
Ben Abbott <bpabbott@mac.com>
parents:
12388
diff
changeset
|
1669 %! plot (x, rand (11)); |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1670 %! axis ([0, 10, 0, 1]); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1671 %! xlabel ("Indices"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1672 %! ylabel ("Random Values"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1673 %! title ('Legend "off" deletes the legend'); |
22624
37b7b86f62f2
Fix legend.m typo in demo example 23 (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
22489
diff
changeset
|
1674 %! legend (cellstr (num2str ((0:10)')), "location", "northeastoutside"); |
37b7b86f62f2
Fix legend.m typo in demo example 23 (bug #49341).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
22489
diff
changeset
|
1675 %! pause (1); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14236
diff
changeset
|
1676 %! legend off; |
12387
5fb6ea1bff65
legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents:
12340
diff
changeset
|
1677 |
12395
4d30b4136a3e
legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents:
12394
diff
changeset
|
1678 %!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
|
1679 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14236
diff
changeset
|
1680 %! x = (1:5)'; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14252
diff
changeset
|
1681 %! 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
|
1682 %! plot (x, rand (numel (x))); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1683 %! 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
|
1684 %! 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
|
1685 %! plot (x, rand (numel (x))); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1686 %! 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
|
1687 %! 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
|
1688 %! plot (x, rand (numel (x))); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1689 %! 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
|
1690 %! 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
|
1691 %! plot (x, rand (numel (x))); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1692 %! legend (cellstr (num2str (x)), "location", "southeastoutside"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1693 %! ## Legend works on a per axes basis for each subplot |
12387
5fb6ea1bff65
legend.m: Add demo for replacing existing legend.
Ben Abbott <bpabbott@mac.com>
parents:
12340
diff
changeset
|
1694 |
12395
4d30b4136a3e
legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents:
12394
diff
changeset
|
1695 %!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
|
1696 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14236
diff
changeset
|
1697 %! plot (rand (2)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1698 %! title ("legend() will warn if extra labels are specified"); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1699 %! legend ("Hello", "World", "foo", "bar"); |
13979
f35b593688a5
Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents:
13937
diff
changeset
|
1700 |
f35b593688a5
Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents:
13937
diff
changeset
|
1701 %!demo |
16799
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
1702 %! clf; |
14207
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1703 %! x = 0:10; |
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1704 %! y1 = rand (size (x)); |
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1705 %! y2 = rand (size (x)); |
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1706 %! [ax, h1, h2] = plotyy (x, y1, x, y2); |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1707 %! title ({"plotyy legend test #1", "Blue label to left axis, Orange label to right axis"}); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1708 %! drawnow (); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1709 %! legend ("Blue", "Orange", "location", "south"); |
12395
4d30b4136a3e
legend.m: Align legends to plot box, add demo. Bug 32373.
Ben Abbott <bpabbott@mac.com>
parents:
12394
diff
changeset
|
1710 |
13979
f35b593688a5
Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents:
13937
diff
changeset
|
1711 %!demo |
16799
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
1712 %! clf; |
14207
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1713 %! x = 0:10; |
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1714 %! y1 = rand (size (x)); |
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1715 %! y2 = rand (size (x)); |
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1716 %! [ax, h1, h2] = plotyy (x, y1, x, y2); |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1717 %! ylabel (ax(1), {"Blue", "Y", "Axis"}); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1718 %! title ('plotyy legend test #2: "westoutside" adjusts to ylabel'); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1719 %! drawnow (); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1720 %! legend ([h1, h2], {"Blue", "Orange"}, "location", "westoutside"); |
13979
f35b593688a5
Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents:
13937
diff
changeset
|
1721 |
f35b593688a5
Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents:
13937
diff
changeset
|
1722 %!demo |
16799
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
1723 %! clf; |
14207
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1724 %! x = 0:10; |
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1725 %! y1 = rand (size (x)); |
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1726 %! y2 = rand (size (x)); |
57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
Ben Abbott <bpabbott@mac.com>
parents:
14138
diff
changeset
|
1727 %! [ax, h1, h2] = plotyy (x, y1, x, y2); |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1728 %! ylabel (ax(2), {"Orange", "Y", "Axis"}); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1729 %! title ('plotyy legend test #3: "eastoutside" adjusts to ylabel'); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1730 %! drawnow (); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1731 %! legend ([h1, h2], {"Blue", "Orange"}, "location", "eastoutside"); |
13979
f35b593688a5
Changing the legend's interpreter property should be inherited by the
Ben Abbott <bpabbott@mac.com>
parents:
13937
diff
changeset
|
1732 |
20408
71bd638e0ef6
legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
1733 %!demo |
71bd638e0ef6
legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
1734 %! clf; |
71bd638e0ef6
legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
1735 %! plot (1:10, 1:10); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1736 %! title ("a very long label can sometimes cause problems"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1737 %! legend ("hello very big world", "location", "northeastoutside"); |
20408
71bd638e0ef6
legend.m: Fix listeners on legend line objects (bug #45563).
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
1738 |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1739 %!demo # bug 36408 |
16799
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
1740 %! clf; |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
1741 %! subplot (3,1,1); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1742 %! plot (rand (1,4)); |
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1743 %! xlabel xlabel; |
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1744 %! ylabel ylabel; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1745 %! title ("Subplots adjust to the legend placed outside"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1746 %! legend ({"1"}, "location", "northeastoutside"); |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
1747 %! subplot (3,1,2); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1748 %! plot (rand (1,4)); |
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1749 %! xlabel xlabel; |
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1750 %! ylabel ylabel; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1751 %! legend ({"1234567890"}, "location", "eastoutside"); |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
1752 %! subplot (3,1,3); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1753 %! plot (rand (1,4)); |
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1754 %! xlabel xlabel; |
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1755 %! ylabel ylabel; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1756 %! legend ({"12345678901234567890"}, "location", "southeastoutside"); |
16799
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
1757 |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1758 %!demo # bug 36408 |
16799
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
1759 %! clf; |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1760 %! subplot (3,1,1); |
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1761 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1762 %! title ("Subplots adjust to the legend placed outside"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1763 %! legend ({"1"}, "location", "northwestoutside"); |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
1764 %! subplot (3,1,2); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1765 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1766 %! legend ({"1234567890"}, "location", "westoutside"); |
16805
2281d957cde6
legend.m: Tweak code for Octave coding conventions.
Rik <rik@octave.org>
parents:
16800
diff
changeset
|
1767 %! subplot (3,1,3); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1768 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1769 %! legend ({"12345678901234567890"}, "location", "southwestoutside"); |
16799
286904321282
Use unmodified axes "position" and "outerposition" properties for legend().
Ben Abbott <bpabbott@mac.com>
parents:
16796
diff
changeset
|
1770 |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1771 %!demo # bug 36408 |
16908
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1772 %! clf; |
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1773 %! subplot (3,1,1); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1774 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1775 %! set (gca (), "yaxislocation", "right"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1776 %! xlabel ("xlabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1777 %! ylabel ("ylabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1778 %! title ("Subplots adjust to the legend placed outside"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1779 %! legend ({"1"}, "location", "northeastoutside"); |
16908
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1780 %! subplot (3,1,2); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1781 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1782 %! set (gca (), "yaxislocation", "right"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1783 %! xlabel ("xlabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1784 %! ylabel ("ylabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1785 %! legend ({"1234567890"}, "location", "eastoutside"); |
16908
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1786 %! subplot (3,1,3); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1787 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1788 %! set (gca (), "yaxislocation", "right"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1789 %! xlabel ("xlabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1790 %! ylabel ("ylabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1791 %! legend ({"12345678901234567890"}, "location", "southeastoutside"); |
16908
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1792 |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1793 %!demo # bug 36408 |
16908
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1794 %! clf; |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1795 %! subplot (3,1,1); |
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1796 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1797 %! set (gca (), "yaxislocation", "right"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1798 %! xlabel ("xlabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1799 %! ylabel ("ylabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1800 %! title ("Subplots adjust to the legend placed outside"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1801 %! legend ({"1"}, "location", "northwestoutside"); |
16908
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1802 %! subplot (3,1,2); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1803 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1804 %! set (gca (), "yaxislocation", "right"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1805 %! xlabel ("xlabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1806 %! ylabel ("ylabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1807 %! legend ({"1234567890"}, "location", "westoutside"); |
16908
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1808 %! subplot (3,1,3); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1809 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1810 %! set (gca (), "yaxislocation", "right"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1811 %! xlabel ("xlabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1812 %! ylabel ("ylabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1813 %! legend ({"12345678901234567890"}, "location", "southwestoutside"); |
16908
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1814 |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1815 %!demo # bug 36408; |
16908
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1816 %! clf; |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1817 %! subplot (3,1,1); |
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1818 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1819 %! set (gca (), "xaxislocation", "top"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1820 %! xlabel ("xlabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1821 %! ylabel ("ylabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1822 %! title ("Subplots adjust to the legend placed outside"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1823 %! legend ({"1"}, "location", "northwestoutside"); |
16908
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1824 %! subplot (3,1,2); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1825 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1826 %! set (gca (), "xaxislocation", "top"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1827 %! xlabel ("xlabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1828 %! ylabel ("ylabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1829 %! legend ({"1234567890"}, "location", "westoutside"); |
16908
1c4be5dcacd5
Add demos to legend.m using subplots.
Ben Abbott <bpabbott@mac.com>
parents:
16885
diff
changeset
|
1830 %! subplot (3,1,3); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1831 %! plot (rand (1,4)); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1832 %! set (gca (), "xaxislocation", "top"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1833 %! xlabel ("xlabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1834 %! ylabel ("ylabel"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1835 %! legend ({"12345678901234567890"}, "location", "southwestoutside"); |
16921
9a316ec12b5f
legend.m: Use Matlab coding conventions in %!demo blocks so comparison script can run.
Rik <rik@octave.org>
parents:
16910
diff
changeset
|
1836 |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1837 %!demo # bug 39697 |
17190
df4c4b7708a4
Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents:
17179
diff
changeset
|
1838 %! clf; |
17179
828e8852efa9
legend.m: Add %!demo block showing bug #39697.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
1839 %! plot (1:10); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22151
diff
changeset
|
1840 %! legend ("Legend Text"); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1841 %! title ({"Multi-line", "titles", "are *not* a", "problem"}); |
17179
828e8852efa9
legend.m: Add %!demo block showing bug #39697.
Rik <rik@octave.org>
parents:
17174
diff
changeset
|
1842 |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1843 ## Test input validation |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1844 %!test |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1845 %! hf = figure ("visible", "off"); |
16973
d429a05dc11c
legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
1846 %! unwind_protect |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1847 %! try |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1848 %! legend (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1849 %! catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1850 %! [~, id] = lasterr (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1851 %! assert (id, "Octave:legend:no-object"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1852 %! end_try_catch |
16973
d429a05dc11c
legend.m: Move %!test block below %!demo blocks per standard usage.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
1853 %! unwind_protect_cleanup |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1854 %! close (hf); |
18647
ce36233e4849
legend.m: Correctly handle axis handle as first argument (bug #42035).
Rik <rik@octave.org>
parents:
18644
diff
changeset
|
1855 %! end_unwind_protect |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1856 |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1857 %!test |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1858 %! hf = figure ("visible", "off"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1859 %! unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1860 %! axes (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1861 %! try |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1862 %! legend (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1863 %! catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1864 %! [~, id] = lasterr (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1865 %! assert (id, "Octave:legend:no-object"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1866 %! end_try_catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1867 %! unwind_protect_cleanup |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1868 %! close (hf); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1869 %! end_unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1870 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1871 %!test |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1872 %! hf = figure ("visible", "off"); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1873 %! unwind_protect |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1874 %! axes (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1875 %! light (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1876 %! try |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1877 %! legend (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1878 %! catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1879 %! [~, id] = lasterr (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1880 %! assert (id, "Octave:legend:no-object"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1881 %! end_try_catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1882 %! unwind_protect_cleanup |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1883 %! close (hf); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1884 %! end_unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1885 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1886 %!test |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1887 %! hf = figure ("visible", "off"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1888 %! unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1889 %! axes (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1890 %! hli = light (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1891 %! try |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1892 %! legend (hli); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1893 %! catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1894 %! [~, id] = lasterr (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1895 %! assert (id, "Octave:legend:bad-object"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1896 %! end_try_catch |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1897 %! unwind_protect_cleanup |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1898 %! close (hf); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1899 %! end_unwind_protect |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1900 |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1901 %!test |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1902 %! hf = figure ("visible", "off"); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1903 %! unwind_protect |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1904 %! axes (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1905 %! hplot = plot (rand (3)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1906 %! try |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1907 %! legend (hplot, struct); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1908 %! catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1909 %! [~, id] = lasterr (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1910 %! assert (id, "Octave:invalid-fun-call"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1911 %! end_try_catch |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1912 %! unwind_protect_cleanup |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1913 %! close (hf); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1914 %! end_unwind_protect |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1915 |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1916 %!test |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1917 %! hf = figure ("visible", "off"); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1918 %! unwind_protect |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1919 %! axes (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1920 %! hplot = plot (rand (3)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1921 %! try |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1922 %! legend ("a", "b", "c", hplot); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1923 %! catch |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1924 %! [~, id] = lasterr (); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1925 %! assert (id, "Octave:invalid-fun-call"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1926 %! end_try_catch |
24434
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1927 %! unwind_protect_cleanup |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1928 %! close (hf); |
436deae9f9ab
legend.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
1929 %! end_unwind_protect |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1930 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1931 ## Test bugs in previous implementation |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1932 %!test <39697> |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1933 %! hf = figure ("visible", "off"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1934 %! unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1935 %! axes ("units", "normalized"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1936 %! plot (1:10); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1937 %! hl = legend ("Legend Text", "units", "normalized"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1938 %! title ({'Multi-line', 'titles', 'are a', 'problem'}); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1939 %! pos = get (gca, 'position'); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1940 %! axtop = sum (pos(2:2:4)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1941 %! pos = get (hl, 'position'); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1942 %! legtop = sum (pos(2:2:4)); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1943 %! assert (legtop < axtop); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1944 %! unwind_protect_cleanup |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1945 %! close (hf); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1946 %! end_unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1947 |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1948 %!test <40333> |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1949 %! hf = figure ("visible", "off"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1950 %! unwind_protect |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1951 %! axes ("units", "normalized"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1952 %! plot (1:10); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1953 %! hl = legend ("Legend Text", "units", "normalized"); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1954 %! pos = get (gca, 'position'); |
27710
9fd8534d3607
legend.m: Code cleanup for cset c66467f74278.
Rik <rik@octave.org>
parents:
27708
diff
changeset
|
1955 %! set (hf, 'position', [0, 0, 200, 200]); |
27708
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1956 %! set (hl, 'fontsize', 20); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1957 %! assert (get (gca, 'position'), pos, 2*eps); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1958 %! unwind_protect_cleanup |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1959 %! close (hf); |
c66467f74278
Rewrite legend (task #14243)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
27465
diff
changeset
|
1960 %! end_unwind_protect |