-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpanel.m
5086 lines (4038 loc) · 127 KB
/
panel.m
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% Panel is an alternative to Matlab's "subplot" function.
%
% INSTALLATION. To install panel, place the file "panel.m"
% on your Matlab path.
%
% DOCUMENTATION. Scan the introductory information in the
% folder "docs". Learn to use panel by working through the
% demonstration scripts in the folder "demo" (list the demos
% by typing "help panel/demo"). Reference information is
% available through "doc panel" or "help panel". For the
% change log, use "edit panel" to view the file "panel.m".
% CHANGE LOG
%
% ############################################################
% 22/05/2011
% First Public Release Version 2.0
% ############################################################
%
% 23/05/2011
% Incorporated an LP solver, since the one we were using
% "linprog()" is not available to users who do not have the
% Optimisation Toolbox installed.
%
% 21/06/2011
% Added -opdf option, and changed PageSize to be equal to
% PaperPosition.
%
% 12/07/2011
% Made some linprog optimisations, inspired by "Ian" on
% Matlab central. Tested against subplot using
% demopanel2(N=9). Subplot is faster, by about 20%, but
% panel is better :). For my money, 20% isn't much of a hit
% for the extra functionality. NB: Using Jeff Stuart's
% linprog (unoptimised), panel is much slower (especially
% for large N problems); we will probably have to offer a
% faster solver at some point (optimise Jeff's?).
%
% NOTES: You will see a noticeable delay, also, on resize.
% That's the price of using physical units for the layout,
% because we have to recalculate everything when the
% physical canvas size changes. I suppose in the future, we
% could offer an option so that physical units are only used
% during export; that would make resizes fast, and the user
% may not care so much about layout on screen, if they are
% aiming for print figures. Or, you could have the ability
% to turn off auto-refresh on resize().
%
% ############################################################
% 20/07/2011
% Release Version 2.1
% ############################################################
%
% 05/10/2011
% Tidied in-file documentation (panel.m).
%
% 11/12/2011
% Added flag "no-manage-font" to constructor, as requested
% by Matlab Central user Mukhtar Ullah.
%
% ############################################################
% 13/12/2011
% Release Version 2.2
% ############################################################
%
% 21/01/2012
% Fixed bug in explicit height export option "-hX" which
% wasn't working right at all.
%
% 25/01/12
% Fixed bug in tick label display during print. _Think_ I've
% got it right, this time! Some notes below, search for
% "25/01/12".
%
% 25/01/12
% Fixed DPI bug in smoothed export figures. Bug was flagged
% up by Jesper at Matlab Central.
%
% ############################################################
% 26/01/2012
% Release Version 2.3
% ############################################################
%
% 09/03/12
% Fixed bug whereby re-positioning never got done if only
% one panel was created in an existing figure window.
%
% ############################################################
% 13/03/2012
% Release Version 2.4
% ############################################################
%
% 15/03/12
% NB: On 2008b, and possibly later versions, the fact that
% the resizeCallback() and closeCallback() are private makes
% things not work. You can fix this by removing the "Access
% = Private" modifier on that section of "methods". It works
% fine in later versions, they must have changed the access
% rules I guess.
%
% 19/07/12
% Modified so that more than one object can be managed by
% one axis. Just use p.select([h1 h2 ...]). Added function
% "getAllManagedAxes()" which returns only objects from the
% "object list" (h_object), as it now is, which represent
% axes. Suggested by Brendan Sullivan @ Matlab Central.
%
% 19/07/12
% Added support for zlabel() call (not applicable to parent
% panels, since they are implicitly 2D for axis labelling).
%
% 19/07/12
% Fixed another export bug - how did this one not get
% noticed? XLimMode (etc.) was not getting locked during
% export, so that axes without manual limits might get
% re-dimensioned during export, which is bad news. Added
% locking of limits as well as ticks, in storeAxisState().
% Hope this has no side effects!
%
% ############################################################
% 19/07/12
% Release Version 2.5
%
% NB: Owing to the introduction of management of multiple
% objects by each panel, this release should be considered
% possibly flaky. Revert to 2.4 if you have problems with
% 2.5.
% ############################################################
%
% 23/07/12
% Improved documentation for figure export in demopanelA.
%
% 24/07/12
% Added support for export to SVG, using "plot2svg" (Matlab
% Central File Exchange) as the renderer. Along the way,
% tidied the behaviour of export() a little, and improved
% reporting to the user. Changed default DPI for EPS to 600,
% since otherwise the output files are pretty shoddy, and
% the filesize is relatively unaffected.
%
% 24/07/12
% Updated documentation, particularly HTML pages and
% associated figures. Bit nicer, now.
%
% ############################################################
% 24/07/12
% Release Version 2.6
% ############################################################
%
% 22/09/12
% Added demopanelH, which illustrates how to do insets. Kudos
% to Ann Hickox for the idea.
%
% 20/03/13
% Added panel.plot() to work around poor rendering of dashed
% lines, etc. Added demopanelI to illustrate its use.
%
% 20/03/13
% Renamed setCallback to addCallback, so we can have more
% than one. Added "userdata" argument to addCallback(), and
% "event" field (and "userdata" field) to "data" passed when
% callback is fired.
%
% ############################################################
% 21/03/13
% Release Version 2.7
% ############################################################
%
% 21/03/13
% Fixed bug in panel.plot() which did not handle solid lines
% correctly.
%
% 12/04/13
% Added back setCallback() with appropriate semantics, for
% the use of legacy code (or, really, future code, these
% semantics might be useful to someone). Also added the
% function clearCallbacks().
%
% 12/04/13
% Removed panel.plot() because it just seemed to be too hard
% to manage. Instead, we'll let the user plot things in the
% usual way, but during export (when things are well under
% our control), we'll fix up any dashed lines that the user
% has requested using the call fixdash(). Thus, we apply the
% fix only where it's needed, when printing to an image
% file, and save all the faffing with resize callbacks.
%
% ############################################################
% 12/04/13
% Release Version 2.8
% ############################################################
%
% 13/04/13
% Changed panel.export() to infer image format from file
% extension, in the case that it is not explicitly specified
% and the passed filename has an extension.
%
% 03/05/13
% Changed term "render", where misused, to "layout", so as
% not to confuse users of the help/docs. Changed name of
% callback event from "render-complete" to "layout-updated",
% is the only functional effect.
%
% 03/05/13
% Added argument to panel constructor so that units can be
% set there, rather than through a separate call to the
% "units" property.
%
% 03/05/13
% Added set descriptor "family" to go with "children" and
% "descendants". This one should be of particular use for
% the construct p.fa.margin = 0.
%
% 03/05/13
% Updated demopanel9 to be a walkthrough of how to set
% margins. Will be useful to point users at this if they ask
% "how do I do margins?".
%
% 03/05/13
% Added panel.version().
%
% 03/05/13
% Added page size "LNCS" to export.
%
% ############################################################
% 03/05/13
% Release Version 2.9
% ############################################################
%
% 10/05/13
% Removed linprog solution in favour of recursive
% computation. This should speed things up for people who
% don't have the optimisation toolbox.
%
% 10/05/13
% Added support for panels of fixed physical size. See new
% documentation for panel/pack().
%
% 10/05/13
% Added support for packing into panels packed in absolute
% mode, which wasn't previously possible.
%
% 10/05/13
% Removed advertisement for 'defer' flag, since I suspect
% it's no longer needed now we've moved away from LP. There
% may be some optimisation required before this is true -
% defer still functions as before, it's just not advertised.
%
% ############################################################
% 10/05/13
% Release Version 2.10
% ############################################################
%
% 14/05/13
% Some minor optimisations, so now panel is not slower than
% subplot (see demopanelK).
%
% 14/01/15
% Various fixes to work correctly under R2014b. Essentially,
% checked the demos, added retirement notes to fixdash(), and
% added function "fignum()".
%
% ############################################################
% 14/01/15
% Release Version 2.11
% ############################################################
%
% 28/03/15
% Changed export() logic slightly so that if either -h or -w option is
% specified, direct sizing model is selected (and, therefore, /all/
% options from the paper sizing model are ignored). Thus, either -w or
% -h can be specified, with -a, and intuitively-correct behaviour
% results.
%
% 02/04/15
% Changed functions x/y/zlabel and title to return a handle to the
% referenced object so that caller can access its properties.
%
% ############################################################
% 02/04/15
% Release Version 2.12
% ############################################################
classdef (Sealed = true) panel < handle
%% ---- PROPERTIES ----
properties (Constant = true, Hidden = true)
PANEL_TYPE_UNCOMMITTED = 0;
PANEL_TYPE_PARENT = 1;
PANEL_TYPE_OBJECT = 2;
end
properties (Constant = true)
LAYOUT_MODE_NORMAL = 0;
LAYOUT_MODE_PREPRINT = 1;
LAYOUT_MODE_POSTPRINT = 2;
end
properties
% these properties are only here for documentation. they
% are actually stored in "prop". it's just some subsref
% madness.
% font name to use for axis text (inherited)
%
% access: read/write
% default: normal
fontname
% font size to use for axis text (inherited)
%
% access: read/write
% default: normal
fontsize
% font weight to use for axis text (inherited)
%
% access: read/write
% default: normal
fontweight
% the units that are used when reading/writing margins
%
% units can be set to any of 'mm', 'cm', 'in' or 'pt'.
% it only affects the read/write interface; values
% stored already are not re-interpreted.
%
% access: read/write
% default: mm
units
% the panel's margin vector in the form [left bottom right top]
%
% the margin is key to the layout process. the layout
% algorithm makes all panels as large as possible whilst
% not violating margin constraints. margins are
% respected between panels within their parent and
% between the root panel and the edges of the canvas
% (figure or image file).
%
% access: read/write
% default: [12 10 2 2] (mm)
%
% see also: marginleft, marginbottom, marginright, margintop
margin
% one element of the margin vector
%
% access: read/write
% default: see margin
%
% see also: margin
marginleft
% one element of the margin vector
%
% access: read/write
% default: see margin
%
% see also: margin
marginbottom
% one element of the margin vector
%
% access: read/write
% default: see margin
%
% see also: margin
marginright
% one element of the margin vector
%
% access: read/write
% default: see margin
%
% see also: margin
margintop
% return position of panel
%
% return the panel's position in normalized
% coordinates (normalized to the figure window that
% is associated with the panel). note that parent
% panels have positions too, even though nothing is
% usually rendered. uncommitted panels, too.
%
% access: read only
position
% return handle of associated figure
%
% access: read only
figure
% return handle of associated axis
%
% if the panel is not an axis panel, empty is returned.
% object includes axis, but axis does not include
% object.
%
% access: read only
%
% see also: object
axis
% return handle of associated object
%
% if the panel is not an object panel, empty is
% returned. object includes axis, but axis does not
% include object.
%
% access: read only
%
% see also: axis
object
% access properties of panel's children
%
% if the panel is a parent panel, "children" gives
% access to some properties of its children (direct
% descendants). "children" can be abbreviated "ch".
% properties that can be accessed are as follows.
%
% axis: read-only, returns an array
% object: read-only, returns an array
%
% margin: write-only
% fontname: write-only
% fontsize: write-only
% fontweight: write-only
%
% EXAMPLE:
% h = p.ch.axis;
% p.ch.margin = 3;
%
% see also: descendants, family
children
% access properties of panel's descendants
%
% if the panel is a parent panel, "descendants" gives
% access to some properties of its descendants
% (children, grandchildren, etc.). "descendants" can be
% abbreviated "de". properties that can be accessed are
% as follows.
%
% axis: read-only, returns an array
% object: read-only, returns an array
%
% margin: write-only
% fontname: write-only
% fontsize: write-only
% fontweight: write-only
%
% EXAMPLE:
% h = p.de.axis;
% p.de.margin = 3;
%
% see also: children, family
descendants
% access properties of panel's family
%
% if the panel is a parent panel, "family" gives access
% to some properties of its family (self, children,
% grandchildren, etc.). "family" can be abbreviated
% "fa". properties that can be accessed are as follows.
%
% axis: read-only, returns an array
% object: read-only, returns an array
%
% margin: write-only
% fontname: write-only
% fontsize: write-only
% fontweight: write-only
%
% EXAMPLE:
% h = p.fa.axis;
% p.fa.margin = 3;
%
% see also: children, descendants
family
end
properties (Access = private)
% associated figure window
h_figure
% parent graphics object
h_parent
% this is empty for the root PANEL, populated for all others
parent
% this is always the root panel associated with this
m_root
% packing specifier
%
% empty: relative positioning mode (stretch)
% scalar fraction: relative positioning mode
% scalar percentage: relative positioning mode
% 1x4 dimension: absolute positioning mode
packspec
% packing dimension of children
%
% 1 : horizontal
% 2 : vertical
packdim
% panel type
m_panelType
% fixdash lines
m_fixdash
m_fixdash_restore
% associated managed graphics object (usually, an axis)
h_object
% show axis (only the root has this extra axis, if show() is active)
h_showAxis
% children (only a parent panel has non-empty, here)
m_children
% callback (any functions listed in this cell array are called when events occur)
m_callback
% local properties (actual properties is this overlaid on inherited/default properties)
%
% see getPropertyValue()
prop
% state
%
% private state information used during various processing
state
% layout context for this panel
%
% this is the layout context for the panel. this is
% computed in the function recomputeLayout(), and used
% to reposition the panel in applyLayout(). storage of
% this data means that we can call applyLayout() to
% layout only a branch of the panel tree without having
% to recompute the whole thing. however, I don't know
% how efficient this system is, might need some work.
m_context
end
%% ---- PUBLIC CTOR/DTOR ----
methods
function p = panel(varargin)
% create a new panel
%
% p = panel(...)
% create a new root panel. optional arguments listed
% below can be supplied in any order. if "h_parent"
% is not supplied, it is set to gcf - that is, the
% panel fills the current figure.
%
% initially, the root panel is an "uncommitted
% panel". calling pack() or select() on it will
% commit it as a "parent panel" or an "object
% panel", respectively. the following arguments may
% be passed, in any order.
%
% h_parent
% a handle to a graphics object that will act as the
% parent of the new panel. this is usually a figure
% handle, but may be a handle to any graphics
% object, in principle. currently, an error is
% raised unless it's a figure or a uipanel - if you
% want to try other object types, edit the code
% where the error is raised, and let me know if you
% have positive results so I can update panel to
% allow other object types.
%
% 'add'
% usually, when you attach a new root panel to a
% figure, any existing attached root panels are
% first deleted to make way for it. if you pass this
% argument, this is not done, so that you can attach
% more than one root panel to the same figure. see
% demopanelE for an example of this use.
%
% 'no-manage-font'
% by default, a panel will manage fonts of titles
% and axis labels. this prevents the user from
% setting individual fonts on those items. pass this
% flag to disable font management for this panel.
%
% 'mm', 'cm', 'in', 'pt'
% by default, panel uses mm as the unit of
% communication with the user over margin sizes.
% pass any of these to change this (you can achieve
% the same effect after creating a panel by setting
% the property "units").
%
% see also: panel (overview), pack(), select()
% PRIVATE DOCUMENTATION
%
% 'defer'
% THIS IS NO LONGER ADVERTISED since we replaced the
% LP solution with a procedural solution, but still
% functions as before, to provide legacy support.
% the panel will be created with layout disabled.
% the layout computations take a little while when
% large numbers of panels are involved, and are
% re-run every time you add a panel or change a
% margin, by default. this is tedious if you are
% preparing a complex layout; pass 'defer', and
% layout will not be computed at all until you call
% refresh() or export() on the root panel.
%
% 'pack'
% this constructor is called internally from pack()
% to create new panels when packing them into
% parents. the first argument is passed as 'pack' in
% this case, which allows us to do slightly quicker
% parsing of the arguments, since we know the
% calling convention (see immediately below).
% default state
p.state = [];
p.state.name = '';
p.state.defer = 0;
p.state.manage_font = 1;
p.m_callback = {};
p.m_fixdash = {};
p.packspec = [];
p.packdim = 2;
p.m_panelType = p.PANEL_TYPE_UNCOMMITTED;
p.prop = panel.getPropertyInitialState();
% handle call from pack() aqap
if nargin && isequal(varargin{1}, 'pack')
% since we know the calling convention, in this
% case, we can handle this as quickly as possible,
% so that large recursive layouts do not get held up
% by spurious code, here.
% parent is a panel
passed_h_parent = varargin{2};
% become its child
indexInParent = int2str(length(passed_h_parent.m_children)+1);
if passed_h_parent.isRoot()
p.state.name = ['(' indexInParent ')'];
else
p.state.name = [passed_h_parent.state.name(1:end-1) ',' indexInParent ')'];
end
p.h_parent = passed_h_parent.h_parent;
p.h_figure = passed_h_parent.h_figure;
p.parent = passed_h_parent;
p.m_root = passed_h_parent.m_root;
% done!
return
end
% default condition
passed_h_parent = [];
add = false;
% peel off args
while ~isempty(varargin)
% get arg
arg = varargin{1};
varargin = varargin(2:end);
% handle text
if ischar(arg)
switch arg
case 'add'
add = true;
continue;
case 'defer'
p.state.defer = 1;
continue;
case 'no-manage-font'
p.state.manage_font = 0;
continue;
case {'mm' 'cm' 'in' 'pt'}
p.setPropertyValue('units', arg);
continue;
otherwise
error('panel:InvalidArgument', ['unrecognised text argument "' arg '"']);
end
end
% handle parent
if isscalar(arg) && ishandle(arg)
passed_h_parent = arg;
continue;
end
% error
error('panel:InvalidArgument', 'unrecognised argument to panel constructor');
end
% attach to current figure if no parent supplied
if isempty(passed_h_parent)
passed_h_parent = gcf;
% this might cause a figure to be created - if so,
% give it time to display now so we don't get a (or
% two, in fact!) resize event(s) later
drawnow
end
% we are a root panel
p.state.name = 'root';
p.parent = [];
p.m_root = p;
% get parent type
parentType = get(passed_h_parent, 'type');
% set handles
switch parentType
case 'uipanel'
p.h_parent = passed_h_parent;
p.h_figure = getParentFigure(passed_h_parent);
case 'figure'
p.h_parent = passed_h_parent;
p.h_figure = passed_h_parent;
otherwise
error('panel:InvalidArgument', ...
['panel() cannot be attached to an object of type "' parentType '"']);
end
% lay in callbacks
addHandleCallback(p.h_figure, 'CloseRequestFcn', @panel.closeCallback);
addHandleCallback(p.h_parent, 'ResizeFcn', @panel.resizeCallback);
% register for callbacks
if add
panel.callbackDispatcher('registerNoClear', p);
else
panel.callbackDispatcher('register', p);
end
% lock class in memory (prevent persistent from being cleared by clear all)
panel.lockClass();
end
function delete(p)
% destroy a panel
%
% delete(p)
% destroy the passed panel, deleting all associated
% graphics objects.
%
% NB: you won't usually have to call this explicitly.
% it is called automatically for all attached panels
% when you close the associated figure.
% debug output
% panel.debugmsg(['deleting "' p.state.name '"...']);
% delete managed graphics objects
for n = 1:length(p.h_object)
h = p.h_object(n);
if ishandle(h)
delete(h);
end
end
% delete associated show axis
if ~isempty(p.h_showAxis) && ishandle(p.h_showAxis)
delete(p.h_showAxis);
end
% delete all children (child will remove itself from
% "m_children" on delete())
while ~isempty(p.m_children)
delete(p.m_children(end));
end
% unregister...
if p.isRoot()
% ...for callbacks
panel.callbackDispatcher('unregister', p);
else
% ...from parent
p.parent.removeChild(p);
end
% debug output
% panel.debugmsg(['deleted "' p.state.name '"!']);
end
end
%% ---- PUBLIC DISPLAY ----
methods (Hidden = true)
function disp(p)
display(p);
end
function display(p, indent)
% default
if nargin < 2
indent = '';
end
% handle non-scalar (should not exist!)
nels = numel(p);
if nels > 1
sz = size(p);
sz = sprintf('%dx', sz);
disp([sz(1:end-1) ' array of panel objects']);
return
end
% header
header = indent;
if p.isObject()
header = [header 'Object ' p.state.name ': '];
elseif p.isParent()
header = [header 'Parent ' p.state.name ': '];
else
header = [header 'Uncommitted ' p.state.name ': '];
end
if p.isRoot()
pp = ['attached to Figure ' panel.fignum(p.h_figure)];
else
if isempty(p.packspec)
pp = 'stretch';
elseif iscell(p.packspec)
units = p.getPropertyValue('units');
val = panel.resolveUnits({p.packspec{1} 'mm'}, units);
pp = sprintf('%.1f%s', val, units);
elseif isscalar(p.packspec)
if p.packspec > 1
pp = sprintf('%.0f%%', p.packspec);
else
pp = sprintf('%.3f', p.packspec);
end
else
pp = sprintf('%.3f ', p.packspec);
pp = pp(1:end-1);
end
end
header = [header '[' pp];
if p.isParent()
edges = {'hori' 'vert'};
header = [header ', ' edges{p.packdim}];
end
header = [header ']'];
% margin
header = rpad(header, 60);
header = [header '[ margin ' sprintf('%.3g ', p.getPropertyValue('margin')) p.getPropertyValue('units') ']'];
% % index
% if isfield(p.state, 'index')
% header = [header ' (' int2str(p.state.index) ')'];
% end
% display
disp(header);
% children
for c = 1:length(p.m_children)
p.m_children(c).display([indent ' ']);
end
end
end
%% ---- PUBLIC METHODS ----
methods
function h = xlabel(p, text)
% apply an xlabel to the panel (or group)
%
% p.xlabel(...)
% behaves just like xlabel() at the prompt (you can
% use that as an alternative) when called on an axis
% panel. when called on a parent panel, however, the
% group of objects within that parent have a label
% applied. when called on a non-axis object panel,
% an error is raised.
h = get(p.getOrCreateAxis(), 'xlabel');
set(h, 'string', text);
if p.isParent()
set(h, 'visible', 'on');
end
end
function h = ylabel(p, text)
% apply a ylabel to the panel (or group)
%
% p.ylabel(...)
% behaves just like ylabel() at the prompt (you can
% use that as an alternative) when called on an axis
% panel. when called on a parent panel, however, the
% group of objects within that parent have a label
% applied. when called on a non-axis object panel,
% an error is raised.
h = get(p.getOrCreateAxis(), 'ylabel');
set(h, 'string', text);
if p.isParent()
set(h, 'visible', 'on');
end
end
function h = zlabel(p, text)
% apply a zlabel to the panel (or group)
%
% p.zlabel(...)