Repository navigation
Expand file tree
/
Copy pathqplot.m
More file actions
1111 lines (964 loc) · 34 KB
/
Copy pathqplot.m
File metadata and controls
1111 lines (964 loc) · 34 KB
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
function [AX,UI] = qplot(fresh_start)
if nargin == 1
fresh_start = true;
else
fresh_start = false;
end
if check_environment()
[AX, UI] = init_gui(fresh_start);
else
AX = [];
UI = [];
end
end % main function
function [AX,UI] = init_gui(fresh_start)
global AX
global UI
% Initialize
gui = 9999;
UI.gui = gui;
fontSize = 12;
bottom = 94;
vert_delta = -6.5;
crt_vert = bottom;
txt_left = 2;
txt_width = 30;
txt_ht = 6;
txt_rt = 50;
grd_left = 15;
mnu_left = 35;
mnu_width = 55;
mnu_ht = 6;
chk_width = 25;
chk_ht = 6;
chk_rt = 50;
rb_left = 7;
rb_mid = 45;
rb_rt = 75;
rb_width = 40;
rb_ht = 10-2;
btn_left = 30;
btn_width = 42;
btn_ht = 6;
hlp_left = 88;
hlp_width = 7;
hlp_ht = 6;
frm_left = 2;
frm_width = 26;
frm_btm = 10;
frm_ht = 60;
fig = figure(gui);
if isoctave()
set(fig,'WindowStyle','normal');
end
set(gui,'name','QPlot 2.1','numbertitle','off');
set(gui,'MenuBar','none','ToolBar','none','DockControls','off');
UI.fig = fig;
% GUI position vector P: [left, bottom, width, height]
P = get_gui_size_position(fresh_start);
set(fig, 'Units', 'normalized', 'Position', P);
movegui(fig);
% figure list
[fignums, fh] = populate_figure_list();
% figure list popup widget
figtext = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','Figure: ', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
figList = uicontrol('style','popupmenu','units','normalized', ...
'position',[mnu_left crt_vert mnu_width mnu_ht]/100,'String',fignums, ...
'tooltipstring','Select a figure to prettify.', ...
'FontSize',fontSize);
UI.figList = figList;
list = get(UI.figList,'String');
if isempty(list{1})
crt_fignum = set_default_figure(1);
else
crt_fignum = get(fh(get(figList,'Value')),'Number');
end
% initialize current figure, then select gui as current
figure(crt_fignum);
AX = gca;
set(figList,'Callback', @(src, event) cb_dispatcher(src,'set_figure_number'));
figure(gui);
crt_vert = crt_vert + vert_delta;
% font list popup widget
% [left, bottom, width, height]
fonttext = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','Font: ', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
% font list
if exist('listfonts') == 2
allfonts = listfonts;
else
allfonts = listfonts_local;
end
fontList = uicontrol('style','popupmenu','units','normalized', ...
'position',[mnu_left crt_vert mnu_width mnu_ht]/100,'String',allfonts, ...
'FontSize',fontSize, ...
'tooltipstring','Select a font.', ...
'Callback', @(src, event) cb_dispatcher(src,'set_fontname'));
crt_font = get(AX,'FontName');
ix = find(strcmpi(allfonts,crt_font),1);
set(fontList,'Value',ix);
UI.fontList = fontList;
crt_vert = crt_vert + 1.1 * vert_delta;
% font size popup widgets
[ti,la,tc,le,na] = font_adjuster(AX);
sizetext = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','Size', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
crt_vert = crt_vert + vert_delta;
% title font size
titltext = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','Title: ', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
titlsizes_n = shiftdim(1:100);
titlsizes_s = num2str(titlsizes_n);
titlSzList = uicontrol('style','popupmenu','units','normalized', ...
'position',[mnu_left crt_vert mnu_width mnu_ht]/100,'String',titlsizes_s, ...
'FontSize',fontSize, ...
'tooltipstring','Select the title font size.', ...
'Callback', @(src, event) cb_dispatcher(src,'set_title_fontsize'));
crtTitlSz = round(ti); %get(get(AX,'Title'),'FontSize');
ix = find(titlsizes_n == round(crtTitlSz),1);
set(titlSzList,'Value',ix);
UI.titlSzList = titlSzList;
crt_vert = crt_vert + vert_delta;
% labels font size
labltext = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','XY Labels: ', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
lablsizes_n = shiftdim(1:100);
lablsizes_s = num2str(lablsizes_n);
lablSzList = uicontrol('style','popupmenu','units','normalized', ...
'position',[mnu_left crt_vert mnu_width mnu_ht]/100,'String',lablsizes_s, ...
'FontSize',fontSize, ...
'tooltipstring','Select the axis labels font size.', ...
'Callback', @(src, event) cb_dispatcher(src,'set_label_fontsize'));
crtXlablSz = round(la); %get(get(AX,'Xlabel'),'FontSize');
crtYlablSz = round(la); %get(get(AX,'Ylabel'),'FontSize');
ix = find(lablsizes_n == round(crtXlablSz),1);
set(lablSzList,'Value',ix);
UI.lablSzList = lablSzList;
crt_vert = crt_vert + vert_delta;
% ticks font size
tckstext = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','Ticks: ', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
tcksizes_n = shiftdim(1:100);
tcksizes_s = num2str(tcksizes_n);
tcksSzList = uicontrol('style','popupmenu','units','normalized', ...
'position',[mnu_left crt_vert mnu_width mnu_ht]/100,'String',tcksizes_s, ...
'FontSize',fontSize, ...
'tooltipstring','Select the axis ticks font size.', ...
'Callback', @(src, event) cb_dispatcher(src,'set_ticks_fontsize'));
crtXTcksSz = round(tc); %get(get(AX,'XAxis'),'FontSize');
crtYTcksSz = round(tc); %get(get(AX,'YAxis'),'FontSize');
ix = find(tcksizes_n == round(crtXTcksSz),1);
set(tcksSzList,'Value',ix);
UI.tcksSzList = tcksSzList;
crt_vert = crt_vert + vert_delta;
% legend font size
lgndtext = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','Legend: ', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
lgndsizes_n = shiftdim(1:100);
lgndsizes_s = num2str(lgndsizes_n);
lgndSzList = uicontrol('style','popupmenu','units','normalized', ...
'position',[mnu_left crt_vert mnu_width mnu_ht]/100,'String',lgndsizes_s, ...
'FontSize',fontSize, ...
'tooltipstring','Select the legend font size.', ...
'Callback', @(src, event) cb_dispatcher(src,'set_legend_fontsize'));
props = get(AX);
if isfield(props,'Legend')
crtLgnd = get(AX,'Legend');
elseif isfield(props,'__legend_handle__')
crtLgnd = get(AX,'__legend_handle__'); % gnu octave v5.2
else
crtLgnd = '';
end
if ~isempty(crtLgnd)
crtLgndSz = round(le); %get(crtLgnd,'FontSize');
ix = find(lgndsizes_n == crtLgndSz,1);
set(lgndSzList,'Value',ix);
end
UI.lgndSzList = lgndSzList;
crt_vert = crt_vert + vert_delta;
% Line Width
lwidtext = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','Line Width: ', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
lwidsizes_n = shiftdim(0.1:0.1:20);
lwidsizes_s = cellstr(num2str(lwidsizes_n));
lwidSzList = uicontrol('style','popupmenu','units','normalized', ...
'position',[mnu_left crt_vert mnu_width mnu_ht]/100,'String',lwidsizes_s, ...
'FontSize',fontSize, ...
'tooltipstring','Set line width.', ...
'Callback', @(src, event) cb_dispatcher(src,'set_line_width'));
init_line_width(lwidSzList);
UI.lwidSzList = lwidSzList;
fig = figure(gui);
crt_vert = crt_vert + 1.1 * vert_delta;
% Styles
styletext = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','Style', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
stylebold = uicontrol('style','text','units','normalized', ...
'position',[mnu_left crt_vert txt_width txt_ht]/100,'String','Bold', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
styleital = uicontrol('style','text','units','normalized', ...
'position',[txt_rt crt_vert txt_width txt_ht]/100,'String','Italic', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
crt_vert = crt_vert + vert_delta;
% title style checkbox widget
titlbox = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','Title: ', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
titlBold = uicontrol('style','checkbox','units','normalized', ...
'position',[mnu_left crt_vert chk_width chk_ht]/100, ...
'Callback', @(src, event) cb_dispatcher(src,'set_title_bold'));
titlItal = uicontrol('style','checkbox','units','normalized', ...
'position',[chk_rt crt_vert chk_width chk_ht]/100, ...
'Callback', @(src, event) cb_dispatcher(src,'set_title_italic'));
if strcmpi(get(get(AX,'Title'),'FontWeight'),'bold')
set(titlBold,'Value', 1);
else
set(titlBold,'Value', 0);
end
if strcmpi(get(get(AX,'Title'),'FontAngle'),'normal')
set(titlItal,'Value', 0);
else
set(titlItal,'Value', 1);
end
UI.titlBold = titlBold;
UI.titlItal = titlItal;
set_title_bold(UI.titlBold);
set_title_italic(UI.titlItal);
crt_vert = crt_vert + vert_delta;
% labels style checkbox widget
lablbox = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','XY Labels: ', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
lablBold = uicontrol('style','checkbox','units','normalized', ...
'position',[mnu_left crt_vert chk_width chk_ht]/100, ...
'Callback', @(src, event) cb_dispatcher(src,'set_label_bold'));
lablItal = uicontrol('style','checkbox','units','normalized', ...
'position',[chk_rt crt_vert chk_width chk_ht]/100, ...
'Callback', @(src, event) cb_dispatcher(src,'set_label_italic'));
UI.lablBold = lablBold;
UI.lablItal = lablItal;
set_label_bold(UI.lablBold);
set_label_italic(UI.lablItal);
crt_vert = crt_vert + vert_delta;
% legend style checkbox widget
lgndbox = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','Legend: ', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
lgndBold = uicontrol('style','checkbox','units','normalized', ...
'position',[mnu_left crt_vert chk_width chk_ht]/100, ...
'Callback', @(src, event) cb_dispatcher(src,'set_legend_bold'));
lgndItal = uicontrol('style','checkbox','units','normalized', ...
'position',[chk_rt crt_vert chk_width chk_ht]/100, ...
'Callback', @(src, event) cb_dispatcher(src,'set_legend_italic'));
UI.lgndBold = lgndBold;
UI.lgndItal = lgndItal;
set_legend_bold(UI.lgndBold);
set_legend_italic(UI.lgndItal);
crt_vert = crt_vert + 1.1 * vert_delta;
% Themes
themetext = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert+1 txt_width txt_ht]/100,'String','Theme', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize);
crt_vert = crt_vert + 0.9 * vert_delta;
% radio button widgets for normal, dark, and hand themes
rbnorm = uicontrol('style', 'radiobutton', ...
'units', 'normalized', ...
'position', [rb_left crt_vert rb_width rb_ht]/100, ...
'String',' Normal', ...
'Value',1, ...
'FontSize',fontSize);
rbdark = uicontrol('style', 'radiobutton', ...
'units', 'normalized', ...
'position', [rb_mid crt_vert rb_width rb_ht]/100, ...
'String',' Dark', ...
'Value',0, ...
'FontSize',fontSize);
rbhand = uicontrol('style', 'radiobutton', ...
'units', 'normalized', ...
'position', [rb_rt crt_vert rb_width rb_ht]/100, ...
'String',' Hand', ...
'Value',0, ...
'FontSize',fontSize);
set(rbnorm, 'Callback', @(src, event) cb_dispatcher(src, 'set_theme', rbnorm, rbdark, rbhand));
set(rbdark, 'Callback', @(src, event) cb_dispatcher(src, 'set_theme', rbdark, rbnorm, rbhand));
set(rbhand, 'Callback', @(src, event) cb_dispatcher(src, 'set_theme', rbhand, rbnorm, rbdark));
UI.rbnorm = rbnorm;
UI.rbdark = rbdark;
UI.rbhand = rbhand;
update_theme();
crt_vert = crt_vert + vert_delta;
% grid checkbox
gridtxt = uicontrol('style','text','units','normalized', ...
'position',[txt_left crt_vert txt_width txt_ht]/100,'String','Grid: ', ...
'HorizontalAlignment','Left', ...
'FontSize',fontSize-2);
gridbox = uicontrol('style','checkbox','units','normalized', ...
'position',[grd_left crt_vert chk_width chk_ht]/100, ...
'Callback', @(src, event) cb_dispatcher(src,'set_grid_onoff'));
UI.gridbox = gridbox;
init_grid_onoff(UI.gridbox);
fig = figure(gui);
% refresh button widget - scans for open figures - consider eliminating
refreshbtn = uicontrol('style', 'pushbutton', ...
'units', 'normalized', ...
'position', [btn_left crt_vert btn_width btn_ht]/100, ...
'String','Update Figure List ', ...
'Value',1, ...
'tooltipstring','Refresh the list of open figures.', ...
'FontSize',fontSize-2);
set(refreshbtn, 'Callback', @(src, event) cb_dispatcher(src, 'refresh'));
% help button widget
helpbtn = uicontrol('style', 'pushbutton', ...
'units', 'normalized', ...
'position', [hlp_left crt_vert hlp_width hlp_ht]/100, ...
'String','? ', ...
'Value',1, ...
'tooltipstring','Open QPlot help.', ...
'FontSize',fontSize-2);
set(helpbtn, 'Callback', @(src, event) cb_dispatcher(src, 'display_help'));
%set(UI.gui, 'SizeChangedFcn', @on_resize_callback);
set(UI.gui, 'CloseRequestFcn', @on_exit_callback);
set(UI.gui, 'Units', 'normalized', 'Position', P);
figure(fig);
set(gcf,'NextPlot','new');
movegui(fig);
figure(crt_fignum);
P
end % function
% dispatcher
function cb_dispatcher(src,fcn,varargin)
global AX
global UI
%get(UI.gui,'Position')
if strcmpi(fcn,'set_figure_number')
C = get(src,'String');
ix = get(src,'Value');
new_fignum = str2num(C{ix});
refresh_figure_list(new_fignum);
else
refresh_figure_list();
end
if numel(varargin) == 3
clicked_btn = varargin{1};
other_btn = varargin{2};
other_other_btn = varargin{3};
else
clicked_btn = 0;
other_btn = 0;
other_other_btn = 0;
end
figHandles = findall(groot, 'Type', 'figure');
if numel(figHandles) == 1
set_default_figure(1);
return
end
% Functions not requiring pre axis updates
ok = 1;
if strcmpi(fcn,'set_theme')
set_theme(src,clicked_btn,other_btn,other_other_btn);
elseif strcmpi(fcn,'refresh')
refresh();
elseif strcmpi(fcn,'set_figure_number')
set_figure_number(src);
elseif strcmpi(fcn,'set_line_width')
set_line_width(src);
elseif strcmpi(fcn,'display_help')
display_help();
else
ok = 0;
end
if ok
return
end
[figno, figha] = get_figure_number();
figarray = findobj(figha,'Type','axes');
% Functions requiring per axis updates
for kk = 1:numel(figarray)
AX = figarray(kk);
switch lower(fcn)
case 'set_fontname'
set_fontname(src);
case 'set_title_fontsize'
set_title_fontsize(src);
case 'set_label_fontsize'
set_label_fontsize(src);
case 'set_ticks_fontsize'
set_ticks_fontsize(src);
case 'set_legend_fontsize'
set_legend_fontsize(src);
case 'set_title_bold'
set_title_bold(src);
case 'set_title_italic'
set_title_italic(src);
case 'set_label_bold'
set_label_bold(src);
case 'set_label_italic'
set_label_italic(src);
case 'set_legend_bold'
set_legend_bold(src);
case 'set_legend_italic'
set_legend_italic(src);
case 'set_grid_onoff'
set_grid_onoff(src);
otherwise
fprintf(2,'Unknown callback function %s.\n', fcn);
end
end
figure(get_fignum_from_ax(AX));
end % function
% setters
function set_figure_number(src)
global AX
global UI
val = get(src,'Value');
C = get(src,'String');
C2 = cellfun(@strtrim,C,'UniformOutput',false);
if numel(C2) >= val
fignum = str2double(C2{val});
else
fignum = 1;
end
figure(fignum);
AX = gca;
UI.figList = src;
refresh();
end % function
function set_fontname(src)
global AX
global UI
namestr = get(src,'String');
name = namestr{get(src,'Value')};
[ti,la,tc,le,na] = font_adjuster(AX);
if ~strcmpi(na,name), na = name; end
[ti,la,tc,le,na] = font_adjuster(AX, ti, la, tc, le, na);
UI.fontList = src;
end % function
function set_title_fontsize(src)
global AX
global UI
titl = get(src,'Value');
[ti,la,tc,le,na] = font_adjuster(AX);
if titl ~= ti, ti = titl; end
[ti,la,tc,le,na] = font_adjuster(AX, ti, la, tc, le, na);
UI.titlSzList = src;
end % function
function set_label_fontsize(src)
global AX
global UI
labl = get(src,'Value');
[ti,la,tc,le,na] = font_adjuster(AX);
if labl ~= la, la = labl; end
[ti,la,tc,le,na] = font_adjuster(AX, ti, la, tc, le, na);
UI.lablSzList = src;
end % function
function set_ticks_fontsize(src)
global AX
global UI
tcks = get(src,'Value');
[ti,la,tc,le,na] = font_adjuster(AX);
if tcks ~= tc, tc = tcks; end
[ti,la,tc,le,na] = font_adjuster(AX, ti, la, tc, le, na);
UI.tcksSzList = src;
end % function
function set_legend_fontsize(src)
global AX
global UI
lgnd = get(src,'Value');
[ti,la,tc,le,na] = font_adjuster(AX);
if lgnd ~= le, le = lgnd; end
[ti,la,tc,le,na] = font_adjuster(AX, ti, la, tc, le, na);
UI.lgndSzList = src;
end % function
function init_line_width(src)
global AX
global UI
figno = get_figure_number();
wout = liner([],figno);
if ~isempty(wout)
s = get(src,'String');
n = str2double(s);
if isoctave()
init_ix = find(n==round(10*max(wout))/10);
else
init_ix = find(n==round(wout(1),1));
end
set(src,'Value',init_ix);
UI.lwidSzList = src;
end
end % function
function set_line_width(src)
global AX
global UI
figno = get_figure_number();
wout = liner([],figno);
if ~isempty(wout)
ix = get(src,'Value');
s = get(src,'String');
set(src,'Value',ix);
UI.lwidSzList = src;
new_wid = str2double(s{ix});
liner(new_wid,figno);
end
end % function
function set_title_bold(src)
global AX
global UI
if get(src,'Value')
set(get(AX,'Title'),'FontWeight','Bold');
else
set(get(AX,'Title'),'FontWeight','Normal');
end
UI.titBold = src;
end % function
function set_title_italic(src)
global AX
global UI
if get(src,'Value')
set(get(AX,'Title'),'FontAngle','Italic');
else
set(get(AX,'Title'),'FontAngle','normal');
end
UI.titItal = src;
end % function
function set_label_bold(src)
global AX
global UI
if get(src,'Value')
set(get(AX,'Xlabel'),'FontWeight','Bold');
set(get(AX,'Ylabel'),'FontWeight','Bold');
else
set(get(AX,'Xlabel'),'FontWeight','Normal');
set(get(AX,'Ylabel'),'FontWeight','Normal');
end
UI.lablBold = src;
end % function
function set_label_italic(src)
global AX
global UI
if get(src,'Value')
set(get(AX,'Xlabel'),'FontAngle','Italic');
set(get(AX,'Ylabel'),'FontAngle','Italic');
else
set(get(AX,'Xlabel'),'FontAngle','normal');
set(get(AX,'Ylabel'),'FontAngle','normal');
end
UI.lablItal = src;
end % function
function set_legend_bold(src)
global AX
global UI
props = get(AX);
if isfield(props,'Legend')
crtLgnd = get(AX,'Legend');
elseif isfield(props,'__legend_handle__')
crtLgnd = get(AX,'__legend_handle__');
else
crtLgnd = '';
end
if ~isempty(crtLgnd)
val = get(src,'Value');
if val
set(crtLgnd,'FontWeight','Bold');
else
set(crtLgnd,'FontWeight','Normal');
end
end
UI.lgndBold = src;
end % function
function set_legend_italic(src)
global AX
global UI
props = get(AX);
if isfield(props,'Legend')
crtLgnd = get(AX,'Legend');
elseif isfield(props,'__legend_handle__')
crtLgnd = get(AX,'__legend_handle__');
else
crtLgnd = '';
end
if ~isempty(crtLgnd)
val = get(src,'Value');
if val
set(crtLgnd,'FontAngle','Italic');
else
set(crtLgnd,'FontAngle','normal');
end
end
UI.lgndItal = src;
end % function
function init_grid_onoff(src)
global AX
global UI
figno = get_figure_number();
if figno == UI.gui
return
end
props = get(AX);
if isfield(props,'XGrid') || isfield(props,'xgrid')
crtgrid = get(AX,'xgrid');
if strcmpi(crtgrid,'on')
set(src,'Value',1);
else
set(src,'Value',0);
end
UI.gridbox = src;
end
end % function
function set_grid_onoff(src)
global AX
global UI
figno = get_figure_number();
if figno == UI.gui
return
end
props = get(AX);
if isfield(props,'XGrid') || isfield(props,'xgrid')
crtgrid = get(AX,'xgrid');
if strcmpi(crtgrid,'on')
set(AX,'xgrid','off');
set(AX,'ygrid','off');
set(AX,'zgrid','off');
set(src,'Value',0);
else
set(AX,'xgrid','on');
set(AX,'ygrid','on');
set(AX,'zgrid','on');
set(src,'Value',1);
end
UI.gridbox = src;
end
end % function
function set_theme(src,clicked_btn,other_btn,other_other_btn)
global AX
global UI
% Force the clicked button to stay selected
set(clicked_btn, 'Value', 1);
% Deselect the other button
set(other_btn, 'Value', 0);
% Deselect the other button
set(other_other_btn, 'Value', 0);
% Print the current selection to the command window
%disp(['Selected: ' get(clicked_btn, 'String')]);
figno = get_figure_number();
str = strtrim(get(clicked_btn, 'String'));
if strcmpi(str,'normal')
undark(figno);
UI.rbnorm = src;
elseif strcmpi(str,'dark')
dark([],figno);
UI.rbdark = src;
elseif strcmpi(str,'hand')
hand([],figno);
UI.rbhand = src;
end
refresh();
end % function
function display_help()
[fp,fn,fx] = fileparts(which('qplot'));
helpfile = sprintf('file://%s',[fp '/help.html']);
helpfile = strrep(helpfile,'\','/');
if exist('web') == 2
web(helpfile,'-browser')
elseif ispc
system(sprintf('start "" "%s"', helpfile));
elseif isunix
system(sprintf('xdg-open "%s" &', helpfile));
end
end % function
function [figno, figha] = get_figure_number()
global AX
global UI
figha = get(AX,'Parent');
figno = get(figha,'Number');
end % function
function update_theme()
global AX
global UI
CANVAS_RGB = [220 243 182]/256;
figcolor = get(AX,'Color');
if all(figcolor == 0)
% dark theme
set(UI.rbnorm,'Value',0)
set(UI.rbdark,'Value',1)
set(UI.rbhand,'Value',0)
elseif all(abs(figcolor - CANVAS_RGB) < 1e-6)
% hand theme
set(UI.rbnorm,'Value',0)
set(UI.rbdark,'Value',0)
set(UI.rbhand,'Value',1)
else
% normal theme
set(UI.rbnorm,'Value',1)
set(UI.rbdark,'Value',0)
set(UI.rbhand,'Value',0)
end
end % function
function refresh()
global AX
global UI
figure(UI.gui);
cla;
axis off;
refresh_figure_list()
% return if there are no plot windows
%if isempty(UI.figList.String{1})
figstr = get(UI.figList,'String');
if isempty(figstr{1})
crt_fignum = set_default_figure(1);
return
end
[ti,la,tc,le,na] = font_adjuster(AX);
ti = round(ti); la = round(la); tc = round(tc); le = round(le);
fontstr = get(UI.fontList,'String');
ix = find(strcmpi(fontstr,na));
set(UI.fontList,'Value',ix);
set(UI.titlSzList,'Value',ti);
set(UI.lablSzList,'Value',la);
set(UI.tcksSzList,'Value',tc);
if le
set(UI.lgndSzList,'Value',le);
end
init_line_width(UI.lwidSzList);
if strcmpi(get(get(AX,'Title'),'FontWeight'),'bold')
set(UI.titlBold,'Value', 1);
else
set(UI.titlBold,'Value', 0);
end
if strcmpi(get(get(AX,'Title'),'FontAngle'),'normal')
set(UI.titlItal,'Value', 0);
else
set(UI.titlItal,'Value', 1);
end
if strcmpi(get(get(AX,'Xlabel'), 'FontWeight'),'bold')
set(UI.lablBold,'Value', 1);
else
set(UI.lablBold,'Value', 0);
end
set_label_bold(UI.lablBold);
if strcmpi(get(get(AX,'Xlabel'), 'FontAngle'),'normal')
set(UI.lablItal,'Value', 0);
else
set(UI.lablItal,'Value', 1);
end
props = get(AX);
if isfield(props,'Legend')
crtLgnd = get(AX,'Legend');
elseif isfield(props,'__legend_handle__')
crtLgnd = get(AX,'__legend_handle__');
else
crtLgnd = '';
end
if ~isempty(crtLgnd)
if strcmpi(get(crtLgnd,'FontWeight'),'bold')
set(UI.lgndBold,'Value', 1);
else
set(UI.lgndBold,'Value', 0);
end
if strcmpi(get(crtLgnd,'FontAngle'),'normal')
set(UI.lgndItal,'Value', 0);
else
set(UI.lgndItal,'Value', 1);
end
end
init_grid_onoff(UI.gridbox);
update_theme();
end % function
function refresh_figure_list(fignum)
global AX
global UI
[fignums, fh] = populate_figure_list();
if nargin == 1
crt_fignum = fignum;
else
crt_fignum = get_fignum_from_ax(AX);
end
if ~isempty(crt_fignum)
figstr = num2str(crt_fignum);
C = get(UI.figList,'String');
C2 = cellfun(@strtrim,C,'UniformOutput',false);
ix = find(strcmp(C2,figstr));
new_fignum = str2double(C2{ix});
C3 = cellfun(@strtrim,fignums(:),'UniformOutput',false);
set(UI.figList,'String',C3);
set(UI.figList,'Value',ix);
figure(new_fignum);
AX = gca;
elseif ~isempty(fignums) && ~isempty(fignums{1})
figstr = fignums{1};
new_fignum = str2double(figstr);
C = cellfun(@strtrim,fignums(:),'UniformOutput',false);
set(UI.figList,'String',C);
set(UI.figList,'Value',1);
figure(new_fignum);
AX = gca;
else
crt_fignum = set_default_figure(1);
end
end % function
function [fignums, fh] = populate_figure_list()
if isoctave
[fignums, fh] = go_populate_figure_list();
else
[fignums, fh] = ml_populate_figure_list();
end
end % function
function [fignums, fh] = go_populate_figure_list()
% figure list
figHandles_unsorted = findobj('Type', 'figure');
figHandles = sort_fig_handles(figHandles_unsorted);
fh = figHandles([figHandles(:)] ~= 9999);
fignums = cellstr(num2str(fh));
end % function
function [fignums, fh] = ml_populate_figure_list()
% figure list
figHandles_unsorted = findobj('Type', 'figure');
figHandles = sort_fig_handles(figHandles_unsorted);
fh = figHandles([figHandles(:).Number] ~= 9999);
fignums = cellstr(num2str([figHandles([figHandles(:).Number] ~= 9999).Number].'));
end % function
function fh = sort_fig_handles(fh)
hnums = nan(numel(fh),1);
for kk = 1:numel(hnums)
n = get(fh(kk),'Number');
if ~isempty(n)
hnums(kk) = n;
end
end
[b,I] = sort(hnums);
fh = fh(I);
end % function
function fignum = get_fignum_from_ax(ax)
fignum = get(ancestor(ax, 'figure'), 'Number');
end % function
function fignum = set_default_figure(fignum)
global AX
global UI
if nargin == 0
fignum = 1;
end
figure(fignum);
AX = gca;
set(UI.figList,'String',{'1'});
set(UI.figList,'Value',1);
end % function
function y = isoctave()
y = exist('OCTAVE_VERSION', 'builtin') ~= 0;
end % function
function allfonts = listfonts_local