-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtfDeco.m
190 lines (168 loc) · 6.53 KB
/
tfDeco.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
function tfDeco(feature, arg1, arg2)
% draw decorations for the current view
%
% tfDeco viewbox
% all four edges of the view box
% tfDeco xline
% lower edge of the view box
% tfDeco yline
% left edge of the view box
% tfDeco lines
% 'xline' and 'yline'
% tfDeco xscale
% tfDeco('xscale', ticks)
% tfDeco('xscale', ticks, ticklabels)
% ticks and tick labels along the lower edge of the box
% tfDeco yscale
% tfDeco('yscale', ticks)
% tfDeco('yscale', ticks, ticklabels)
% ticks and tick labels along the left edge of the box
% tfDeco scales
% 'xscale' and 'yscale'
% tfDeco
% 'viewbox' and 'scales'
% tfDeco('xlabel', text)
% label at lower edge of the layout box
% tfDeco('ylabel', text)
% label at left edge of the layout box
% tfDeco('title', text)
% label at upper edge of the layout box
% tfDeco('viewlabel', text)
% label in upper left corner of the layout box
%
% The appearance of the decorations can be changed using the styles:
% viewboxstyle, tickinstyle, tickoutstyle, ticklabelstyle,
% axislabelstyle, titlestyle, viewlabelstyle
%
% See also tfStyle
% better: varargin with an argument consumation process, so that several
% options can be given at once
if nargin == 0
feature = 'default';
end
v = tf_get('currentview', 'No current view!');
blim = v(1 : 4);
alim = v(5 : 8);
olim = v(9 : 12);
tf_close_view
switch feature
case 'default'
tfDeco viewbox
tfDeco scales
case 'viewbox'
tf_rectangle('draw,viewboxstyle', reshape(blim, 2, 2));
case 'background'
tf_rectangle('draw,viewboxstyle', reshape(blim, 2, 2));
case 'lines'
tfDeco xline
tfDeco yline
case 'xline'
tf_rectangle('draw,viewboxstyle', blim([1 3; 2 3]));
case 'yline'
tf_rectangle('draw,viewboxstyle', blim([1 3; 1 4]));
case 'scales'
tfDeco xscale
tfDeco yscale
case 'xscale'
if nargin > 1
ticks = arg1;
else
ticks = tf_genticks(alim(1 : 2), diff(blim(1 : 2)));
end
if nargin > 2
if isempty(arg2)
arg2 = cell(1, numel(ticks));
end
if iscell(arg2)
ticklabels = arg2;
else
ticklabels = tf_genticklabels(arg2);
end
else
ticklabels = tf_genticklabels(ticks);
end
ticks = ticks(:);
xy = tf_transform_data2abs([ticks, ones(size(ticks)) * alim(3)]);
tf_plot('mark=tick,mark size=0.6pt,mark options={tickinstyle}', xy)
tf_append('\begin{scope} [local bounding box=lbx]')
tf_plot('mark=tick,mark size=0.6pt,mark options={rotate=180,tickoutstyle}', xy)
tf_append('\begin{scope}[ticklabelstyle]')
tf_append('\setfont') % make sure em and ex refer to correct font size
for i = 1 : numel(ticks)
tf_path('draw,yshift=-1.4 * \capheightfactor em,inner sep=0,outer sep=0', ...
xy(i, :), ['node[anchor=base] {' ticklabels{i} '}'])
end
if numel(ticklabels) > numel(ticks)
tf_path('draw,yshift=-0.2em', [blim(2) blim(3)], ...
['node[anchor=north east,inner sep=0,outer sep=0,scale=0.7] {' ticklabels{end} '}'])
end
tf_append('\end{scope}')
tf_append('\end{scope}')
tf_append('\typeheight{padinner(2)}{lbx}')
case 'yscale'
if nargin > 1
ticks = arg1;
else
ticks = tf_genticks(alim(3 : 4), diff(blim(3 : 4)));
end
if nargin > 2
if isempty(arg2)
arg2 = cell(1, numel(ticks));
end
if iscell(arg2)
ticklabels = arg2;
else
ticklabels = tf_genticklabels(arg2);
end
else
ticklabels = tf_genticklabels(ticks);
end
ticks = ticks(:);
xy = tf_transform_data2abs([ones(size(ticks)) * alim(1), ticks]);
tf_plot('mark=tick,mark size=0.6pt,mark options={rotate=270,tickinstyle}', xy)
tf_append('\begin{scope} [local bounding box=lbx]')
tf_plot('mark=tick,mark size=0.6pt,mark options={rotate=90,tickoutstyle}', xy)
tf_append('\begin{scope}[ticklabelstyle]')
tf_append('\setfont')
for i = 1 : numel(ticks)
tf_path('draw,xshift=-0.2em,yshift=-0.5ex', xy(i, :), ...
['node[anchor=base east,inner sep=0,outer sep=0] {' ticklabels{i} '}'])
end
if numel(ticklabels) > numel(ticks)
tf_path('draw,xshift=-0.2em', [blim(1) blim(4)], ...
['node[anchor=north east,inner sep=0,outer sep=0,scale=0.7] {' ticklabels{end} '}'])
end
tf_append('\end{scope}')
tf_append('\end{scope}')
tf_append('\typewidth{padinner(3)}{lbx}')
case 'xlabel'
tf_append('\begin{scope}[axislabelstyle,local bounding box=lbx]')
tf_append('\setfont')
tf_path('draw', [mean(blim(1 : 2)), olim(3)], ...
['node[anchor=base,yshift=\descenderfactor em,inner sep=0,outer sep=0] {' arg1 '}'])
tf_append('\end{scope}')
tf_append('\typeheight{padouter(2)}{lbx}')
case 'ylabel'
tf_append('\begin{scope}[axislabelstyle,local bounding box=lbx]')
tf_append('\setfont')
tf_path('draw', [olim(1), mean(blim(3 : 4))], ...
['node[anchor=base,xshift=\capheightfactor em,rotate=90,inner sep=0,outer sep=0] {' arg1 '}'])
tf_append('\end{scope}')
tf_append('\typewidth{padouter(3)}{lbx}')
case 'title'
tf_append('\begin{scope}[titlestyle,local bounding box=lbx]')
tf_append('\setfont')
tf_path('draw', [mean(blim(1 : 2)), olim(4)], ...
['node[anchor=base,yshift=-\capheightfactor em,inner sep=2pt,outer sep=0] {' arg1 '}'])
tf_append('\end{scope}')
tf_append('\typeheight{padouter(1)}{lbx}')
case 'viewlabel'
tf_append('\begin{scope}[viewlabelstyle,local bounding box=lbx]')
tf_append('\setfont')
tf_path('draw', [olim(1), olim(4)], ...
['node[anchor=base west,yshift=-\capheightfactor em,inner sep=0,outer sep=0] {' arg1 '}'])
tf_append('\end{scope}')
tf_append('\typeheight{padouter(1)}{lbx}')
otherwise
error('Unknown feature %s!', feature)
end