File: Object-Groups.html

package info (click to toggle)
octave3.2 3.2.4-8
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 62,936 kB
  • ctags: 37,353
  • sloc: cpp: 219,497; fortran: 116,336; ansic: 10,264; sh: 5,508; makefile: 4,245; lex: 3,573; yacc: 3,062; objc: 2,042; lisp: 1,692; awk: 860; perl: 844
file content (290 lines) | stat: -rw-r--r-- 13,641 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<html lang="en">
<head>
<title>Object Groups - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Advanced-Plotting.html#Advanced-Plotting" title="Advanced Plotting">
<link rel="prev" href="Callbacks.html#Callbacks" title="Callbacks">
<link rel="next" href="Graphics-backends.html#Graphics-backends" title="Graphics backends">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Object-Groups"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="Graphics-backends.html#Graphics-backends">Graphics backends</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Callbacks.html#Callbacks">Callbacks</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Advanced-Plotting.html#Advanced-Plotting">Advanced Plotting</a>
<hr>
</div>

<h4 class="subsection">15.2.8 Object Groups</h4>

<p><a name="index-object-groups-1220"></a>
A number of Octave high level plot functions return groups of other
graphics objects or they return graphics objects that are have their
properties linked in such a way that changes to one of the properties
results in changes in the others.  A graphic object that groups other
objects is an <code>hggroup</code>

<!-- ./plot/hggroup.m -->
   <p><a name="doc_002dhggroup"></a>

<div class="defun">
&mdash; Function File:  <b>hggroup</b> ()<var><a name="index-hggroup-1221"></a></var><br>
&mdash; Function File:  <b>hggroup</b> (<var>h</var>)<var><a name="index-hggroup-1222"></a></var><br>
&mdash; Function File:  <b>hggroup</b> (<var><small class="dots">...</small>, property, value, <small class="dots">...</small></var>)<var><a name="index-hggroup-1223"></a></var><br>
<blockquote><p>Create group object with parent <var>h</var>.  If no parent is specified,
the group is created in the current axes.  Return the handle of the
group object created.

        <p>Multiple property-value pairs may be specified for the group, but they
must appear in pairs. 
</p></blockquote></div>

   <p>For example a simple use of a <code>hggroup</code> might be

<pre class="example">     x = 0:0.1:10;
     hg = hggroup ();
     plot (x, sin (x), "color", [1, 0, 0], "parent", hg);
     hold on
     plot (x, cos (x), "color", [0, 1, 0], "parent", hg);
     set (hg, "visible", "off");
</pre>
   <p class="noindent">which groups the two plots into a single object and controls their
visibility directly.  The default properties of an <code>hggroup</code> are
the same as the set of common properties for the other graphics
objects.  Additional properties can be added with the <code>addproperty</code>
function.

<!-- graphics.cc -->
   <p><a name="doc_002daddproperty"></a>

<div class="defun">
&mdash; Built-in Function:  <b>addproperty</b> (<var>name, h, type, </var>[<var>arg, <small class="dots">...</small></var>])<var><a name="index-addproperty-1224"></a></var><br>
<blockquote><p>Create a new property named <var>name</var> in graphics object <var>h</var>. 
<var>type</var> determines the type of the property to create.  <var>args</var>
usually contains the default value of the property, but additional
arguments might be given, depending on the type of the property.

        <p>The supported property types are:

          <dl>
<dt><code>string</code><dd>A string property.  <var>arg</var> contains the default string value. 
<br><dt><code>any</code><dd>An un-typed property.  This kind of property can hold any octave
value.  <var>args</var> contains the default value. 
<br><dt><code>radio</code><dd>A string property with a limited set of accepted values.  The first
argument must be a string with all accepted values separated by
a vertical bar ('|').  The default value can be marked by enclosing
it with a '{' '}' pair.  The default value may also be given as
an optional second string argument. 
<br><dt><code>boolean</code><dd>A boolean property.  This property type is equivalent to a radio
property with "on|off" as accepted values.  <var>arg</var> contains
the default property value. 
<br><dt><code>double</code><dd>A scalar double property.  <var>arg</var> contains the default value. 
<br><dt><code>handle</code><dd>A handle property.  This kind of property holds the handle of a
graphics object.  <var>arg</var> contains the default handle value. 
When no default value is given, the property is initialized to
the empty matrix. 
<br><dt><code>data</code><dd>A data (matrix) property.  <var>arg</var> contains the default data
value.  When no default value is given, the data is initialized to
the empty matrix. 
<br><dt><code>color</code><dd>A color property.  <var>arg</var> contains the default color value. 
When no default color is given, the property is set to black. 
An optional second string argument may be given to specify an
additional set of accepted string values (like a radio property). 
</dl>

        <p><var>type</var> may also be the concatenation of a core object type and
a valid property name for that object type.  The property created
then has the same characteristics as the referenced property (type,
possible values, hidden state<small class="dots">...</small>).  This allows to clone an existing
property into the graphics object <var>h</var>.

        <p>Examples:

     <pre class="example">          addproperty ("my_property", gcf, "string", "a string value");
          addproperty ("my_radio", gcf, "radio", "val_1|val_2|{val_3}");
          addproperty ("my_style", gcf, "linelinestyle", "--");
</pre>
        </blockquote></div>

   <p>Once a property in added to an <code>hggroup</code>, it is not linked to any
other property of either the children of the group, or any other
graphics object.  Add so to control the way in which this newly added
property is used, the <code>addlistener</code> function is used to define a
callback function that is executed when the property is altered.

<!-- graphics.cc -->
   <p><a name="doc_002daddlistener"></a>

<div class="defun">
&mdash; Built-in Function:  <b>addlistener</b> (<var>h, prop, fcn</var>)<var><a name="index-addlistener-1225"></a></var><br>
<blockquote><p>Register <var>fcn</var> as listener for the property <var>prop</var> of the graphics
object <var>h</var>.  Property listeners are executed (in order of registration)
when the property is set.  The new value is already available when the
listeners are executed.

        <p><var>prop</var> must be a string naming a valid property in <var>h</var>.

        <p><var>fcn</var> can be a function handle, a string or a cell array whose first
element is a function handle.  If <var>fcn</var> is a function handle, the
corresponding function should accept at least 2 arguments, that will be
set to the object handle and the empty matrix respectively.  If <var>fcn</var>
is a string, it must be any valid octave expression.  If <var>fcn</var> is a cell
array, the first element must be a function handle with the same signature
as described above.  The next elements of the cell array are passed
as additional arguments to the function.

        <p>Example:

     <pre class="example">          function my_listener (h, dummy, p1)
            fprintf ("my_listener called with p1=%s\n", p1);
          endfunction
          
          addlistener (gcf, "position", {@my_listener, "my string"})
</pre>
        </blockquote></div>

<!-- graphics.cc -->
   <p><a name="doc_002ddellistener"></a>

<div class="defun">
&mdash; Built-in Function:  <b>dellistener</b> (<var>h, prop, fcn</var>)<var><a name="index-dellistener-1226"></a></var><br>
<blockquote><p>Remove the registration of <var>fcn</var> as a listener for the property
<var>prop</var> of the graphics object <var>h</var>.  The function <var>fcn</var> must
be the same variable (not just the same value), as was passed to the
original call to <code>addlistener</code>.

        <p>If <var>fcn</var> is not defined then all listener functions of <var>prop</var>
are removed.

        <p>Example:

     <pre class="example">          function my_listener (h, dummy, p1)
            fprintf ("my_listener called with p1=%s\n", p1);
          endfunction
          
          c = {@my_listener, "my string"};
          addlistener (gcf, "position", c);
          dellistener (gcf, "position", c);
</pre>
        </blockquote></div>

   <p>An example of the use of these two functions might be

<pre class="example">     x = 0:0.1:10;
     hg = hggroup ();
     h = plot (x, sin (x), "color", [1, 0, 0], "parent", hg);
     addproperty ("linestyle", hg, "linelinestyle", get (h, "linestyle"));
     addlistener (hg, "linestyle", @update_props);
     hold on
     plot (x, cos (x), "color", [0, 1, 0], "parent", hg);
     
     function update_props (h, d)
       set (get (h, "children"), "linestyle", get (h, "linestyle"));
     endfunction
</pre>
   <p class="noindent">that adds a <code>linestyle</code> property to the <code>hggroup</code> and
propagating any changes its value to the children of the group.  The
<code>linkprop</code> function can be used to simplify the above to be

<pre class="example">     x = 0:0.1:10;
     hg = hggroup ();
     h1 = plot (x, sin (x), "color", [1, 0, 0], "parent", hg);
     addproperty ("linestyle", hg, "linelinestyle", get (h, "linestyle"));
     hold on
     h2 = plot (x, cos (x), "color", [0, 1, 0], "parent", hg);
     hlink = linkprop ([hg, h1, h2], "color");
</pre>
   <!-- ./plot/linkprop.m -->
   <p><a name="doc_002dlinkprop"></a>

<div class="defun">
&mdash; Function File: <var>hlink</var> = <b>linkprop</b> (<var>h, prop</var>)<var><a name="index-linkprop-1227"></a></var><br>
<blockquote><p>Links graphics object properties, such that a change in one is
propagated to the others.  The properties to link are given as a
string of cell string array by <var>prop</var> and the objects containing
these properties by the handle array <var>h</var>.

        <p>An example of the use of linkprops is

     <pre class="example">          x = 0:0.1:10;
          subplot (1, 2, 1);
          h1 = plot (x, sin (x));
          subplot (1, 2, 2);
          h2 = plot (x, cos (x));
          hlink = linkprop ([h1, h2], {"color","linestyle"});
          set (h1, "color", "green");
          set (h2, "linestyle", "--");
</pre>
        </blockquote></div>

   <p>These capabilities are used in a number of basic graphics objects. 
The <code>hggroup</code> objects created by the functions of Octave contain
one or more graphics object and are used to:

     <ul>
<li>group together multiple graphics objects,
<li>create linked properties between different graphics objects, and
<li>to hide the nominal user data, from the actual data of the objects. 
</ul>

<p class="noindent">For example the <code>stem</code> function creates a stem series where each
<code>hggroup</code> of the stem series contains two line objects representing
the body and head of the stem.  The <code>ydata</code> property of the
<code>hggroup</code> of the stem series represents the head of the stem,
whereas the body of the stem is between the baseline and this value.  For
example

<pre class="example">     h = stem (1:4)
     get (h, "xdata")
      [  1   2   3   4]'
     get (get (h, "children")(1), "xdata")
      [  1   1 NaN   2   2 NaN   3   3 NaN   4   4 NaN]'
</pre>
   <p class="noindent">shows the difference between the <code>xdata</code> of the <code>hggroup</code>
of a stem series object and the underlying line.

   <p>The basic properties of such group objects is that they consist of one
or more linked <code>hggroup</code>, and that changes in certain properties of
these groups are propagated to other members of the group.  Whereas,
certain properties of the members of the group only apply to the current
member.

   <p>In addition the members of the group can also be linked to other
graphics objects through callback functions.  For example the baseline of
the <code>bar</code> or <code>stem</code> functions is a line object, whose length
and position are automatically adjusted, based on changes to the
corresponding hggroup elements.

<ul class="menu">
<li><a accesskey="1" href="Data-sources-in-object-groups.html#Data-sources-in-object-groups">Data sources in object groups</a>
<li><a accesskey="2" href="Area-series.html#Area-series">Area series</a>
<li><a accesskey="3" href="Bar-series.html#Bar-series">Bar series</a>
<li><a accesskey="4" href="Contour-groups.html#Contour-groups">Contour groups</a>
<li><a accesskey="5" href="Error-bar-series.html#Error-bar-series">Error bar series</a>
<li><a accesskey="6" href="Line-series.html#Line-series">Line series</a>
<li><a accesskey="7" href="Quiver-group.html#Quiver-group">Quiver group</a>
<li><a accesskey="8" href="Scatter-group.html#Scatter-group">Scatter group</a>
<li><a accesskey="9" href="Stair-group.html#Stair-group">Stair group</a>
<li><a href="Stem-Series.html#Stem-Series">Stem Series</a>
<li><a href="Surface-group.html#Surface-group">Surface group</a>
</ul>

   </body></html>