|
1 | 1 | function obj = updateHistogram(obj,histIndex) |
| 2 | + % x:...[DONE] |
| 3 | + % y:...[DONE] |
| 4 | + % histnorm:...[DONE] |
| 5 | + % name:...[DONE] |
| 6 | + % autobinx:...[DONE] |
| 7 | + % nbinsx:...[DONE] |
| 8 | + % xbins:...[DONE] |
| 9 | + % autobiny:...[DONE] |
| 10 | + % nbinsy:...[DONE] |
| 11 | + % ybins:...[DONE] |
| 12 | + % text:...[NOT SUPPORTED IN MATLAB] |
| 13 | + % error_y:...[HANDLED BY ERRORBARSERIES] |
| 14 | + % error_x:...[HANDLED BY ERRORBARSERIES] |
| 15 | + % opacity: --- [TODO] |
| 16 | + % xaxis:...[DONE] |
| 17 | + % yaxis:...[DONE] |
| 18 | + % showlegend:...[DONE] |
| 19 | + % stream:...[HANDLED BY PLOTLYSTREAM] |
| 20 | + % visible:...[DONE] |
| 21 | + % type:...[DONE] |
| 22 | + % orientation:...[DONE] |
| 23 | + |
| 24 | + % MARKER: |
| 25 | + % color: ...[DONE] |
| 26 | + % size: ...[NA] |
| 27 | + % symbol: ...[NA] |
| 28 | + % opacity: ...[TODO] |
| 29 | + % sizeref: ...[NA] |
| 30 | + % sizemode: ...[NA] |
| 31 | + % colorscale: ...[NA] |
| 32 | + % cauto: ...[NA] |
| 33 | + % cmin: ...[NA] |
| 34 | + % cmax: ...[NA] |
| 35 | + % outliercolor: ...[NA] |
| 36 | + % maxdisplayed: ...[NA] |
| 37 | + |
| 38 | + % MARKER LINE: |
| 39 | + % color: ...[DONE] |
| 40 | + % width: ...[DONE] |
| 41 | + % dash: ...[NA] |
| 42 | + % opacity: ...[TODO] |
| 43 | + % shape: ...[NA] |
| 44 | + % smoothing: ...[NA] |
| 45 | + % outliercolor: ...[NA] |
| 46 | + % outlierwidth: ...[NA] |
| 47 | + |
| 48 | + %---------------------------------------------------------------------% |
| 49 | + |
| 50 | + %-AXIS INDEX-% |
| 51 | + axIndex = obj.getAxisIndex(obj.State.Plot(histIndex).AssociatedAxis); |
| 52 | + |
| 53 | + %-HIST DATA STRUCTURE- % |
| 54 | + hist_data = obj.State.Plot(histIndex).Handle; |
| 55 | + |
| 56 | + %-CHECK FOR MULTIPLE AXES-% |
| 57 | + [xsource, ysource] = findSourceAxis(obj,axIndex); |
| 58 | + |
| 59 | + %---------------------------------------------------------------------% |
| 60 | + |
| 61 | + %-hist axis-% |
| 62 | + obj.data{histIndex}.xaxis = "x" + xsource; |
| 63 | + obj.data{histIndex}.yaxis = "y" + ysource; |
| 64 | + |
| 65 | + %---------------------------------------------------------------------% |
| 66 | + |
| 67 | + %-bar type-% |
| 68 | + obj.data{histIndex}.type = "bar"; |
| 69 | + |
| 70 | + %---------------------------------------------------------------------% |
| 71 | + |
| 72 | + if isprop(hist_data, "Orientation") |
| 73 | + %-Matlab 2014+ histogram() function-% |
| 74 | + orientation = hist_data.Orientation; |
| 75 | + else |
| 76 | + %-Matlab <2014 hist() function-% |
| 77 | + orientation = histogramOrientation(hist_data); |
| 78 | + end |
| 79 | + |
| 80 | + switch orientation |
| 81 | + case {"vertical", "horizontal"} |
| 82 | + %-hist y data-% |
| 83 | + obj.data{histIndex}.x = hist_data.BinEdges(1:end-1) ... |
| 84 | + + 0.5*diff(hist_data.BinEdges); |
| 85 | + obj.data{histIndex}.width = diff(hist_data.BinEdges); |
| 86 | + obj.data{histIndex}.y = double(hist_data.Values); |
| 87 | + case "v" |
| 88 | + %-hist x data-% |
| 89 | + xdata = mean(hist_data.XData(2:3,:)); |
| 90 | + |
| 91 | + %-------------------------------------------------------------% |
| 92 | + |
| 93 | + %-hist y data-% |
| 94 | + xlength = 0; |
| 95 | + for d = 1:length(xdata) |
| 96 | + xnew = repmat(xdata(d),1,hist_data.YData(2,d)); |
| 97 | + obj.data{histIndex}.x(xlength+1:xlength+length(xnew)) = xnew; |
| 98 | + xlength = length(obj.data{histIndex}.x); |
| 99 | + end |
| 100 | + |
| 101 | + %-------------------------------------------------------------% |
| 102 | + |
| 103 | + %-hist autobinx-% |
| 104 | + obj.data{histIndex}.autobinx = false; |
| 105 | + |
| 106 | + %-------------------------------------------------------------% |
| 107 | + |
| 108 | + %-hist xbins-% |
| 109 | + xbins.start = hist_data.XData(2,1); |
| 110 | + xbins.end = hist_data.XData(3,end); |
| 111 | + xbins.size = diff(hist_data.XData(2:3,1)); |
| 112 | + obj.data{histIndex}.xbins = xbins; |
| 113 | + |
| 114 | + %-------------------------------------------------------------% |
| 115 | + |
| 116 | + %-layout bargap-% |
| 117 | + obj.layout.bargap = ... |
| 118 | + (hist_data.XData(3,1) - hist_data.XData(2,2)) ... |
| 119 | + / (hist_data.XData(3,1) - hist_data.XData(2,1)); |
| 120 | + case "h" |
| 121 | + %-hist y data-% |
| 122 | + ydata = mean(hist_data.YData(2:3,:)); |
2 | 123 |
|
3 | | -% x:...[DONE] |
4 | | -% y:...[DONE] |
5 | | -% histnorm:...[DONE] |
6 | | -% name:...[DONE] |
7 | | -% autobinx:...[DONE] |
8 | | -% nbinsx:...[DONE] |
9 | | -% xbins:...[DONE] |
10 | | -% autobiny:...[DONE] |
11 | | -% nbinsy:...[DONE] |
12 | | -% ybins:...[DONE] |
13 | | -% text:...[NOT SUPPORTED IN MATLAB] |
14 | | -% error_y:...[HANDLED BY ERRORBARSERIES] |
15 | | -% error_x:...[HANDLED BY ERRORBARSERIES] |
16 | | -% opacity: --- [TODO] |
17 | | -% xaxis:...[DONE] |
18 | | -% yaxis:...[DONE] |
19 | | -% showlegend:...[DONE] |
20 | | -% stream:...[HANDLED BY PLOTLYSTREAM] |
21 | | -% visible:...[DONE] |
22 | | -% type:...[DONE] |
23 | | -% orientation:...[DONE] |
24 | | - |
25 | | -% MARKER: |
26 | | -% color: ...[DONE] |
27 | | -% size: ...[NA] |
28 | | -% symbol: ...[NA] |
29 | | -% opacity: ...[TODO] |
30 | | -% sizeref: ...[NA] |
31 | | -% sizemode: ...[NA] |
32 | | -% colorscale: ...[NA] |
33 | | -% cauto: ...[NA] |
34 | | -% cmin: ...[NA] |
35 | | -% cmax: ...[NA] |
36 | | -% outliercolor: ...[NA] |
37 | | -% maxdisplayed: ...[NA] |
38 | | - |
39 | | -% MARKER LINE: |
40 | | -% color: ...[DONE] |
41 | | -% width: ...[DONE] |
42 | | -% dash: ...[NA] |
43 | | -% opacity: ...[TODO] |
44 | | -% shape: ...[NA] |
45 | | -% smoothing: ...[NA] |
46 | | -% outliercolor: ...[NA] |
47 | | -% outlierwidth: ...[NA] |
48 | | - |
49 | | -%-------------------------------------------------------------------------% |
50 | | - |
51 | | -%-AXIS INDEX-% |
52 | | -axIndex = obj.getAxisIndex(obj.State.Plot(histIndex).AssociatedAxis); |
53 | | - |
54 | | -%-HIST DATA STRUCTURE- % |
55 | | -hist_data = obj.State.Plot(histIndex).Handle; |
56 | | - |
57 | | -%-CHECK FOR MULTIPLE AXES-% |
58 | | -[xsource, ysource] = findSourceAxis(obj,axIndex); |
59 | | - |
60 | | -%-------------------------------------------------------------------------% |
61 | | - |
62 | | -%-hist xaxis-% |
63 | | -obj.data{histIndex}.xaxis = ['x' num2str(xsource)]; |
64 | | - |
65 | | -%-------------------------------------------------------------------------% |
66 | | - |
67 | | -%-hist yaxis-% |
68 | | -obj.data{histIndex}.yaxis = ['y' num2str(ysource)]; |
69 | | - |
70 | | -%-------------------------------------------------------------------------% |
71 | | - |
72 | | -%-bar type-% |
73 | | -obj.data{histIndex}.type = 'bar'; |
74 | | - |
75 | | -%-------------------------------------------------------------------------% |
76 | | - |
77 | | -if isprop(hist_data, 'Orientation') |
78 | | - %-Matlab 2014+ histogram() function-% |
79 | | - orientation = hist_data.Orientation; |
80 | | -else |
81 | | - %-Matlab <2014 hist() function-% |
82 | | - orientation = histogramOrientation(hist_data); |
83 | | -end |
| 124 | + %-------------------------------------------------------------% |
84 | 125 |
|
85 | | -switch orientation |
86 | | - case {'vertical', 'horizontal'} |
87 | | - |
88 | | - %-------------------------------------------------------------------------% |
89 | | - %-hist y data-% |
90 | | - |
91 | | - obj.data{histIndex}.x = hist_data.BinEdges(1:end-1) + 0.5*diff(hist_data.BinEdges); |
92 | | - obj.data{histIndex}.width = diff(hist_data.BinEdges);%[hist_data.BinEdges(2:end), hist_data.Data(end)]; |
93 | | - obj.data{histIndex}.y = double(hist_data.Values); |
94 | | - |
95 | | - %-------------------------------------------------------------------------% |
96 | | - |
97 | | - case 'v' |
98 | | - %-hist x data-% |
99 | | - xdata = mean(hist_data.XData(2:3,:)); |
100 | | - |
101 | | - %-------------------------------------------------------------------------% |
102 | | - |
103 | | - %-hist y data-% |
104 | | - xlength = 0; |
105 | | - for d = 1:length(xdata) |
106 | | - obj.data{histIndex}.x(xlength + 1: xlength + hist_data.YData(2,d)) = repmat(xdata(d),1,hist_data.YData(2,d)); |
107 | | - xlength = length(obj.data{histIndex}.x); |
108 | | - end |
109 | | - |
110 | | - %-------------------------------------------------------------------------% |
111 | | - |
112 | | - %-hist autobinx-% |
113 | | - obj.data{histIndex}.autobinx = false; |
114 | | - |
115 | | - %-------------------------------------------------------------------------% |
116 | | - |
117 | | - %-hist xbins-% |
118 | | - xbins.start = hist_data.XData(2,1); |
119 | | - xbins.end = hist_data.XData(3,end); |
120 | | - xbins.size = diff(hist_data.XData(2:3,1)); |
121 | | - obj.data{histIndex}.xbins = xbins; |
122 | | - |
123 | | - %-------------------------------------------------------------------------% |
124 | | - |
125 | | - %-layout bargap-% |
126 | | - obj.layout.bargap = (hist_data.XData(3,1)-hist_data.XData(2,2))/(hist_data.XData(3,1)-hist_data.XData(2,1)); |
127 | | - |
128 | | - %-------------------------------------------------------------------------% |
129 | | - |
130 | | - |
131 | | - case 'h' |
132 | | - |
133 | | - %-hist y data-% |
134 | | - ydata = mean(hist_data.YData(2:3,:)); |
135 | | - |
136 | | - %-------------------------------------------------------------------------% |
137 | | - |
138 | | - ylength = 0; |
139 | | - for d = 1:length(ydata) |
140 | | - obj.data{histIndex}.y(ylength + 1: ylength + hist_data.XData(2,d)) = repmat(ydata(d),1,hist_data.XData(2,d)); |
141 | | - ylength = length(obj.data{histIndex}.y); |
142 | | - end |
143 | | - |
144 | | - %-------------------------------------------------------------------------% |
145 | | - |
146 | | - %-hist autobiny-% |
147 | | - obj.data{histIndex}.autobiny = false; |
148 | | - |
149 | | - %-------------------------------------------------------------------------% |
150 | | - |
151 | | - %-hist ybins-% |
152 | | - ybins.start = hist_data.YData(2,1); |
153 | | - ybins.end = hist_data.YData(3,end); |
154 | | - ybins.size = diff(hist_data.YData(2:3,1)); |
155 | | - obj.data{histIndex}.ybins = ybins; |
156 | | - |
157 | | - %-------------------------------------------------------------------------% |
158 | | - |
159 | | - %-layout bargap-% |
160 | | - obj.layout.bargap = (hist_data.XData(3,1)-hist_data.XData(2,2))/(hist_data.XData(3,1)-hist_data.XData(2,1)); |
161 | | - |
162 | | - %-------------------------------------------------------------------------% |
163 | | - |
164 | | -end |
| 126 | + ylength = 0; |
| 127 | + for d = 1:length(ydata) |
| 128 | + ynew = repmat(ydata(d),1,hist_data.XData(2,d)); |
| 129 | + obj.data{histIndex}.y(ylength+1:ylength+length(ynew)) = ynew; |
| 130 | + ylength = length(obj.data{histIndex}.y); |
| 131 | + end |
165 | 132 |
|
166 | | -%-------------------------------------------------------------------------% |
| 133 | + %-------------------------------------------------------------% |
167 | 134 |
|
168 | | -%-hist name-% |
169 | | -obj.data{histIndex}.name = hist_data.DisplayName; |
| 135 | + %-hist autobiny-% |
| 136 | + obj.data{histIndex}.autobiny = false; |
170 | 137 |
|
171 | | -%-------------------------------------------------------------------------% |
| 138 | + %-------------------------------------------------------------% |
172 | 139 |
|
173 | | -%-layout barmode-% |
174 | | -obj.layout.barmode = 'group'; |
| 140 | + %-hist ybins-% |
| 141 | + ybins.start = hist_data.YData(2,1); |
| 142 | + ybins.end = hist_data.YData(3,end); |
| 143 | + ybins.size = diff(hist_data.YData(2:3,1)); |
| 144 | + obj.data{histIndex}.ybins = ybins; |
175 | 145 |
|
176 | | -%-------------------------------------------------------------------------% |
| 146 | + %-------------------------------------------------------------% |
177 | 147 |
|
178 | | -%-hist line width-% |
179 | | -obj.data{histIndex}.marker.line.width = hist_data.LineWidth; |
| 148 | + %-layout bargap-% |
| 149 | + obj.layout.bargap = ... |
| 150 | + (hist_data.XData(3,1) - hist_data.XData(2,2)) ... |
| 151 | + / (hist_data.XData(3,1) - hist_data.XData(2,1)); |
| 152 | + end |
180 | 153 |
|
181 | | -%-------------------------------------------------------------------------% |
| 154 | + %---------------------------------------------------------------------% |
182 | 155 |
|
183 | | -%-hist opacity-% |
184 | | -if ~ischar(hist_data.FaceAlpha) |
185 | | - obj.data{histIndex}.opacity = hist_data.FaceAlpha * 1.25; |
186 | | -end |
| 156 | + %-hist name-% |
| 157 | + obj.data{histIndex}.name = hist_data.DisplayName; |
187 | 158 |
|
188 | | -%-------------------------------------------------------------------------% |
| 159 | + %---------------------------------------------------------------------% |
189 | 160 |
|
190 | | -%-marker data-% |
191 | | -obj.data{histIndex}.marker = extractPatchFace(hist_data); |
| 161 | + %-layout barmode-% |
| 162 | + obj.layout.barmode = "overlay"; |
192 | 163 |
|
193 | | -%-------------------------------------------------------------------------% |
| 164 | + %---------------------------------------------------------------------% |
194 | 165 |
|
195 | | -%-change color when multiple histograms same axes-% |
196 | | -if min([xsource, ysource]) == 1 |
197 | | - obj.data{histIndex}.marker = rmfield(obj.data{histIndex}.marker, 'color'); |
198 | | -end |
| 166 | + %-hist line width-% |
| 167 | + obj.data{histIndex}.marker.line.width = hist_data.LineWidth; |
199 | 168 |
|
200 | | -%-------------------------------------------------------------------------% |
| 169 | + %---------------------------------------------------------------------% |
201 | 170 |
|
202 | | -%-hist visible-% |
203 | | -obj.data{histIndex}.visible = strcmp(hist_data.Visible,'on'); |
| 171 | + %-hist opacity-% |
| 172 | + if ~ischar(hist_data.FaceAlpha) |
| 173 | + obj.data{histIndex}.opacity = hist_data.FaceAlpha * 1.25; |
| 174 | + end |
204 | 175 |
|
205 | | -%-------------------------------------------------------------------------% |
| 176 | + %---------------------------------------------------------------------% |
206 | 177 |
|
207 | | -%-hist showlegend-% |
208 | | -leg = hist_data.Annotation; |
209 | | -legInfo = leg.LegendInformation; |
| 178 | + %-marker data-% |
| 179 | + obj.data{histIndex}.marker = extractPatchFace(hist_data); |
210 | 180 |
|
211 | | -switch legInfo.IconDisplayStyle |
212 | | - case 'on' |
213 | | - showleg = true; |
214 | | - case 'off' |
215 | | - showleg = false; |
216 | | -end |
| 181 | + %---------------------------------------------------------------------% |
| 182 | + |
| 183 | + %-hist visible-% |
| 184 | + obj.data{histIndex}.visible = strcmp(hist_data.Visible,"on"); |
217 | 185 |
|
218 | | -obj.data{histIndex}.showlegend = showleg; |
| 186 | + %---------------------------------------------------------------------% |
219 | 187 |
|
220 | | -%-------------------------------------------------------------------------% |
| 188 | + %-hist showlegend-% |
| 189 | + leg = hist_data.Annotation; |
| 190 | + legInfo = leg.LegendInformation; |
221 | 191 |
|
| 192 | + switch legInfo.IconDisplayStyle |
| 193 | + case "on" |
| 194 | + showleg = true; |
| 195 | + case "off" |
| 196 | + showleg = false; |
| 197 | + end |
| 198 | + obj.data{histIndex}.showlegend = showleg; |
222 | 199 | end |
0 commit comments