forked from plotly/plotly_matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateBoxplot.m
More file actions
304 lines (216 loc) · 8.32 KB
/
updateBoxplot.m
File metadata and controls
304 lines (216 loc) · 8.32 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
function obj = updateBoxplot(obj, boxIndex)
% y: ...[DONE]
% x0: ...[DONE]
% x: ...[DONE]
% name: ...[DONE]
% boxmean: ...[NOT SUPPORTED IN MATLAB]
% boxpoints: ...[NOT SUPPORTED IN MATLAB]
% jitter: ...[NOT SUPPORTED IN MATLAB]
% pointpos: ...[NOT SUPPORTED IN MATLAB]
% whiskerwidth: ........................[TODO]
% fillcolor: ...[DONE]
% opacity: ---[TODO]
% xaxis: ...[DONE]
% yaxis: ...[DONE]
% showlegend: ...[DONE]
% stream: ...[HANDLED BY PLOTLY STREAM]
% visible: ...[DONE]
% type: ...[DONE]
% MARKER
% color: ...[NA]
% width: ...[NA]
% dash: ...[NA]
% opacity: ...[NA]
% shape: ...[NA]
% smoothing: ...[NA]
% outliercolor: ...[NOT SUPPORTED IN MATLAB]
% outlierwidth: ...[NOT SUPPORTED IN MATLAB]
% LINE
% color: ...[DONE]
% width: ...[DONE]
% dash: ...[DONE]
% opacity: ---[TODO]
% shape: ...[DONE]
% smoothing: ...[NOT SUPPORTED IN MATLAB]
%-------------------------------------------------------------------------%
%-AXIS INDEX-%
axIndex = obj.getAxisIndex(obj.State.Plot(boxIndex).AssociatedAxis);
%-BOX DATA STRUCTURE-%
box_data = get(obj.State.Plot(boxIndex).Handle);
%-BOX CHILDREN-%
box_child = box_data.Children;
%-------------------------------------------------------------------------%
%-CONFIRM PROPER BOXPLOT STRUCTURE-%
% check for compact boxplot
isCompact = ~isempty(findobj(obj.State.Plot(boxIndex).Handle,'Tag','Whisker'));
% number of boxplots
if isCompact
bpcompnum = 6;
bpnum = length(box_child)/bpcompnum;
% check for assumed box structure
if mod(length(box_child), bpcompnum)~=0
return
end
else
bpcompnum = 8;
bpnum = length(box_child)/bpcompnum;
% check for assumed box structure
if mod(length(box_child),bpcompnum)~=0
return
end
end
% initialize ydata
ydata = [];
%-------------------------------------------------------------------------%
%-box groupgap-%
obj.layout.bargroupgap = 1/bpnum;
%-------------------------------------------------------------------------%
%-box name-%
obj.data{boxIndex}.name = box_data.DisplayName;
%-------------------------------------------------------------------------%
% iterate through box plot children in reverse order
for bp = bpnum:-1:1
%-CHECK FOR MULTIPLE AXES-%
[xsource, ysource] = findSourceAxis(obj,axIndex);
%-AXIS DATA-%
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
%---------------------------------------------------------------------%
%-box xaxis-%
obj.data{boxIndex}.xaxis = ['x' num2str(xsource)];
%---------------------------------------------------------------------%
%-box yaxis-%
obj.data{boxIndex}.yaxis = ['y' num2str(ysource)];
%---------------------------------------------------------------------%
%-box type-%
obj.data{boxIndex}.type = 'box';
%---------------------------------------------------------------------%
%-box visible-%
obj.data{boxIndex}.visible = strcmp(box_data.Visible,'on');
%---------------------------------------------------------------------%
%-box fillcolor-%
obj.data{boxIndex}.fillcolor = 'rgba(0, 0, 0, 0)';
%---------------------------------------------------------------------%
%-box showlegend-%
leg = get(box_data.Annotation);
legInfo = get(leg.LegendInformation);
switch legInfo.IconDisplayStyle
case 'on'
showleg = true;
case 'off'
showleg = false;
end
obj.data{boxIndex}.showlegend = showleg;
%-boxplot components-%
Q1 = [];
Q3 = [];
median = [];
outliers = [];
uwhisker = [];
lwhisker = [];
% iterate through boxplot components
for bpc = 1:bpcompnum
%get box child data
box_child_data = get(box_child(bp+bpnum*(bpc-1)));
%box name
if strcmp(box_child_data.Type,'text')
if iscell(box_child_data.String)
boxname = box_child_data.String{1};
else
boxname = box_child_data.String;
end
end
% parse boxplot tags
switch box_child_data.Tag
%-median-%
case 'Median'
median = box_child_data.YData(1);
%-upper whisker-%
case 'Upper Whisker'
uwhisker = box_child_data.YData(2);
%-boxplot whisker width-%
obj.data{boxIndex}.whiskerwidth = 1;
%-lower whisker-%
case 'Lower Whisker'
lwhisker = box_child_data.YData(1);
case 'Box'
%-Q1-%
Q1 = min(box_child_data.YData);
%-Q3-%
Q3 = max(box_child_data.YData);
%-boxplot line style-%
if isCompact
col = 255*box_child_data.Color;
obj.data{boxIndex}.fillcolor = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
else
obj.data{boxIndex}.line = extractLineLine(box_child_data);
end
%-outliers-%
case 'Outliers'
if ~isnan(box_child_data.YData)
%-outlier marker data-%
outliers = box_child_data.YData;
%-outlier marker style-%
obj.data{boxIndex}.marker = extractLineMarker(box_child_data);
end
%-compact whiskers-%
case 'Whisker'
%-boxplot line style-%
obj.data{boxIndex}.line = extractLineLine(box_child_data);
%-boxplot whisker width-%
obj.data{boxIndex}.whiskerwidth = 0;
%-whisker data-%
uwhisker = box_child_data.YData(2);
lwhisker = box_child_data.YData(1);
%-compact median-%
case 'MedianInner'
median = box_child_data.YData(1);
end
end
%-generate boxplot data-%
gendata = generateBoxData(outliers, lwhisker, Q1, median, Q3, uwhisker);
%-boxplot y-data-%
obj.data{boxIndex}.y(length(ydata)+1:length(ydata)+length(gendata)) = ...
generateBoxData(outliers, lwhisker, Q1, median, Q3, uwhisker);
%-boxplot x-data-%
if (bpnum > 1)
for n = (length(ydata)+1):(length(ydata)+length(gendata))
obj.data{boxIndex}.x{n} = boxname;
end
end
%-update ydata-%
ydata = obj.data{boxIndex}.y;
end
%----------------------------!AXIS UPDATE!--------------------------------%
% take first text object as prototype for axis tick style/layout
text_child = findobj(obj.State.Plot(boxIndex).Handle,'Type','text');
%-STANDARDIZE UNITS-%
fontunits = get(text_child(1),'FontUnits');
set(text_child(1),'FontUnits','points');
%-text data -%
text_data = get(text_child(1));
%-------------------------------------------------------------------------%
%-xaxis tick font size-%
xaxis.tickfont.size = text_data.FontSize;
%-------------------------------------------------------------------------%
%-xaxis tick font family-%
xaxis.tickfont.family = matlab2plotlyfont(text_data.FontName);
%-------------------------------------------------------------------------%
%-xaxis tick font color-%
xaxis.tickfont.color = text_data.Color;
%-------------------------------------------------------------------------%
%-axis type-%
xaxis.type = 'category';
%-------------------------------------------------------------------------%
%-show tick labels-%
xaxis.showticklabels = true;
%-------------------------------------------------------------------------%
%-autorange-%
xaxis.autorange = true;
%-------------------------------------------------------------------------%
%-set the layout axis field-%
obj.layout = setfield(obj.layout,['xaxis' num2str(xsource)],xaxis);
%-------------------------------------------------------------------------%
%-REVERT UNITS-%
set(text_child(1),'FontUnits',fontunits);
end