|
1 |
| -function obj = updateStem(obj, dataIndex) |
| 1 | +function data = updateStem(obj, dataIndex) |
2 | 2 | %-AXIS INDEX-%
|
3 | 3 | axIndex = obj.getAxisIndex(obj.State.Plot(dataIndex).AssociatedAxis);
|
4 | 4 |
|
5 | 5 | %-PLOT DATA STRUCTURE- %
|
6 |
| - data = obj.State.Plot(dataIndex).Handle; |
| 6 | + stem_data = obj.State.Plot(dataIndex).Handle; |
7 | 7 |
|
8 | 8 | %-CHECK FOR MULTIPLE AXES-%
|
9 | 9 | [xsource, ysource] = findSourceAxis(obj,axIndex);
|
10 | 10 |
|
11 | 11 | %-get coordinate x,y,z data-%
|
12 |
| - xdata = data.XData; |
13 |
| - ydata = data.YData; |
14 |
| - zdata = data.ZData; |
| 12 | + xdata = stem_data.XData; |
| 13 | + ydata = stem_data.YData; |
| 14 | + zdata = stem_data.ZData; |
15 | 15 | npoints = length(xdata);
|
16 | 16 |
|
17 | 17 | %-check if stem-%
|
|
27 | 27 |
|
28 | 28 | %-scatter3d scene-%
|
29 | 29 | if isstem
|
30 |
| - stem_data.scene = "scene" + xsource; |
| 30 | + data.scene = "scene" + xsource; |
31 | 31 | else
|
32 |
| - stem_data.xaxis = "x" + xsource; |
33 |
| - stem_data.yaxis = "y" + xsource; |
| 32 | + data.xaxis = "x" + xsource; |
| 33 | + data.yaxis = "y" + xsource; |
34 | 34 | end
|
35 | 35 |
|
36 | 36 | %-scatter3d type-%
|
37 | 37 | if isstem
|
38 |
| - stem_data.type = "scatter3d"; |
| 38 | + data.type = "scatter3d"; |
39 | 39 | else
|
40 |
| - stem_data.type = "scatter"; |
| 40 | + data.type = "scatter"; |
41 | 41 | end
|
42 | 42 |
|
43 |
| - stem_data.visible = strcmp(data.Visible, "on"); |
44 |
| - stem_data.name = data.DisplayName; |
45 |
| - stem_data.mode = "lines+markers"; |
| 43 | + data.visible = stem_data.Visible == "on"; |
| 44 | + data.name = stem_data.DisplayName; |
| 45 | + data.mode = "lines+markers"; |
46 | 46 |
|
47 | 47 | if isdatetime(xdata)
|
48 | 48 | xdata = datenum(xdata);
|
|
52 | 52 | end
|
53 | 53 |
|
54 | 54 | %-allocated space for extended data-%
|
55 |
| - xdata_extended = zeros(3*npoints, 1); |
56 |
| - ydata_extended = zeros(3*npoints, 1); |
| 55 | + xdata_extended = NaN(3*npoints, 1); |
| 56 | + ydata_extended = NaN(3*npoints, 1); |
| 57 | + |
| 58 | + % Create indices for extended data |
| 59 | + idx1 = 3*(1:npoints) - 2; % 3n-2 positions |
| 60 | + idx2 = 3*(1:npoints) - 1; % 3n-1 positions |
| 61 | + idx3 = 3*(1:npoints); % 3n positions |
| 62 | + |
| 63 | + xdata_extended(idx1) = xdata; |
| 64 | + xdata_extended(idx2) = xdata; |
57 | 65 |
|
58 | 66 | if isstem
|
59 |
| - zdata_extended = zeros(3*npoints, 1); |
| 67 | + ydata_extended(idx1) = ydata; |
| 68 | + else |
| 69 | + ydata_extended(idx1) = 0; |
60 | 70 | end
|
| 71 | + ydata_extended(idx2) = ydata; |
61 | 72 |
|
62 |
| - %-format data-% |
63 |
| - m = 1; |
64 |
| - for n = 1:npoints |
65 |
| - %-x data-% |
66 |
| - xdata_extended(m) = xdata(n); |
67 |
| - xdata_extended(m+1) = xdata(n); |
68 |
| - xdata_extended(m+2) = nan; |
69 |
| - |
70 |
| - %-y data-% |
71 |
| - ydata_extended(m) = 0; |
72 |
| - if isstem |
73 |
| - ydata_extended(m) = ydata(n); |
74 |
| - end |
75 |
| - ydata_extended(m+1) = ydata(n); |
76 |
| - ydata_extended(m+2) = nan; |
77 |
| - |
78 |
| - %-z data-% |
79 |
| - if isstem |
80 |
| - zdata_extended(m) = 0; |
81 |
| - zdata_extended(m+1) = zdata(n); |
82 |
| - zdata_extended(m+2) = nan; |
83 |
| - end |
84 |
| - m = m + 3; |
| 73 | + if isstem |
| 74 | + zdata_extended = NaN(3*npoints, 1); |
| 75 | + zdata_extended(idx1) = 0; |
| 76 | + zdata_extended(idx2) = zdata; |
85 | 77 | end
|
86 | 78 |
|
87 |
| - stem_data.line = extractLineLine(data); |
88 |
| - stem_data.marker = extractLineMarker(data); |
| 79 | + |
| 80 | + data.line = extractLineLine(stem_data); |
| 81 | + data.marker = extractLineMarker(stem_data); |
89 | 82 |
|
90 | 83 | if isstem
|
91 | 84 | %-fix marker symbol-%
|
92 |
| - symbol = stem_data.marker.symbol; |
| 85 | + symbol = data.marker.symbol; |
93 | 86 |
|
94 |
| - if strcmpi(symbol, "asterisk-open") ... |
95 |
| - || strcmpi(symbol, "cross-thin-open") |
96 |
| - stem_data.marker.symbol = "cross"; |
| 87 | + if contains(lower(symbol), ["asterisk-open" "cross-thin-open"]) |
| 88 | + data.marker.symbol = "cross"; |
97 | 89 | end
|
98 | 90 |
|
99 |
| - stem_data.marker.size = stem_data.marker.size * 0.6; |
| 91 | + data.marker.size = data.marker.size * 0.6; |
100 | 92 |
|
101 | 93 | %-fix dash line-%
|
102 |
| - dash = stem_data.line.dash; |
103 |
| - |
104 |
| - if strcmpi(dash, "dash") |
105 |
| - stem_data.line.dash = "dot"; |
| 94 | + if lower(data.line.dash) == "dash" |
| 95 | + data.line.dash = "dot"; |
106 | 96 | end
|
107 | 97 | end
|
108 | 98 |
|
|
111 | 101 | linecolor = cell(3*npoints,1);
|
112 | 102 | hidecolor = "rgba(0,0,0,0)";
|
113 | 103 |
|
114 |
| - linecolor(1:3:3*npoints) = {hidecolor}; |
115 |
| - markercolor(1:3:3*npoints) = {hidecolor}; |
| 104 | + linecolor(idx1) = {hidecolor}; |
| 105 | + markercolor(idx1) = {hidecolor}; |
116 | 106 |
|
117 | 107 | try
|
118 |
| - linecolor(2:3:3*npoints) = {stem_data.marker.line.color}; |
119 |
| - markercolor(2:3:3*npoints) = {stem_data.marker.color}; |
| 108 | + linecolor(idx2) = {data.marker.line.color}; |
| 109 | + markercolor(idx2) = {data.marker.color}; |
120 | 110 | catch
|
121 |
| - linecolor(2:3:3*npoints) = {stem_data.marker.color}; |
122 |
| - markercolor(2:3:3*npoints) = {hidecolor}; |
| 111 | + linecolor(idx2) = {data.marker.color}; |
| 112 | + markercolor(idx2) = {hidecolor}; |
123 | 113 | end
|
124 | 114 |
|
125 |
| - linecolor(3:3:3*npoints) = {hidecolor}; |
126 |
| - markercolor(3:3:3*npoints) = {hidecolor}; |
| 115 | + linecolor(idx3) = {hidecolor}; |
| 116 | + markercolor(idx3) = {hidecolor}; |
127 | 117 |
|
128 | 118 | %-add new marker/line colors-%
|
129 |
| - stem_data.marker.color = markercolor; |
130 |
| - stem_data.marker.line.color = linecolor; |
| 119 | + data.marker.color = markercolor; |
| 120 | + data.marker.line.color = linecolor; |
131 | 121 |
|
132 |
| - stem_data.marker.line.width = stem_data.marker.line.width * 2; |
133 |
| - stem_data.line.width = stem_data.line.width * 2; |
| 122 | + data.marker.line.width = data.marker.line.width * 2; |
| 123 | + data.line.width = data.line.width * 2; |
134 | 124 |
|
135 | 125 | %-set x y z data-%
|
136 |
| - stem_data.x = xdata_extended; |
137 |
| - stem_data.y = ydata_extended; |
| 126 | + data.x = xdata_extended; |
| 127 | + data.y = ydata_extended; |
138 | 128 |
|
139 | 129 | if isstem
|
140 |
| - stem_data.z = zdata_extended; |
| 130 | + data.z = zdata_extended; |
141 | 131 | end
|
142 | 132 |
|
143 |
| - %-set plotly data-% |
144 |
| - obj.data{dataIndex} = stem_data; |
145 |
| - |
146 | 133 | %-SETTING SCENE-%
|
147 | 134 | if isstem
|
148 |
| - %-aspect ratio-% |
149 | 135 | asr = obj.PlotOptions.AspectRatio;
|
150 | 136 |
|
151 | 137 | if ~isempty(asr)
|
|
158 | 144 | end
|
159 | 145 | else
|
160 | 146 | %-define as default-%
|
161 |
| - xar = max(xdata(:)); |
162 |
| - yar = max(ydata(:)); |
163 |
| - xyar = max([xar, yar]); |
| 147 | + xyar = max([max(xdata(:)), max(ydata(:))]); |
164 | 148 | xar = xyar;
|
165 | 149 | yar = xyar;
|
166 |
| - zar = 0.7*max([xar, yar]); |
| 150 | + zar = 0.7*xyar; |
167 | 151 | end
|
168 | 152 |
|
169 | 153 | scene.aspectratio.x = xar;
|
|
181 | 165 | end
|
182 | 166 | else
|
183 | 167 | %-define as default-%
|
184 |
| - xey = - xar; |
185 |
| - if xey>0 |
| 168 | + xey = -xar; |
| 169 | + if xey > 0 |
186 | 170 | xfac = 0.2;
|
187 | 171 | else
|
188 | 172 | xfac = -0.2;
|
189 | 173 | end
|
190 |
| - yey = - yar; |
191 |
| - if yey>0 |
| 174 | + yey = -yar; |
| 175 | + if yey > 0 |
192 | 176 | yfac = -0.2;
|
193 | 177 | else
|
194 | 178 | yfac = 0.2;
|
195 | 179 | end
|
196 | 180 |
|
197 |
| - if zar>0 |
| 181 | + if zar > 0 |
198 | 182 | zfac = 0.2;
|
199 | 183 | else
|
200 | 184 | zfac = -0.2;
|
|
222 | 206 | scene.yaxis.tickcolor = "rgba(0,0,0,0.8)";
|
223 | 207 | scene.zaxis.tickcolor = "rgba(0,0,0,0.8)";
|
224 | 208 |
|
225 |
| - scene.xaxis.range = data.Parent.XLim; |
226 |
| - scene.yaxis.range = data.Parent.YLim; |
227 |
| - scene.zaxis.range = data.Parent.ZLim; |
| 209 | + scene.xaxis.range = stem_data.Parent.XLim; |
| 210 | + scene.yaxis.range = stem_data.Parent.YLim; |
| 211 | + scene.zaxis.range = stem_data.Parent.ZLim; |
228 | 212 |
|
229 |
| - scene.xaxis.tickvals = data.Parent.XTick; |
230 |
| - scene.yaxis.tickvals = data.Parent.YTick; |
231 |
| - scene.zaxis.tickvals = data.Parent.ZTick; |
| 213 | + scene.xaxis.tickvals = stem_data.Parent.XTick; |
| 214 | + scene.yaxis.tickvals = stem_data.Parent.YTick; |
| 215 | + scene.zaxis.tickvals = stem_data.Parent.ZTick; |
232 | 216 |
|
233 |
| - scene.xaxis.title = data.Parent.XLabel.String; |
234 |
| - scene.yaxis.title = data.Parent.YLabel.String; |
235 |
| - scene.zaxis.title = data.Parent.ZLabel.String; |
| 217 | + scene.xaxis.title = stem_data.Parent.XLabel.String; |
| 218 | + scene.yaxis.title = stem_data.Parent.YLabel.String; |
| 219 | + scene.zaxis.title = stem_data.Parent.ZLabel.String; |
236 | 220 |
|
237 | 221 | obj.layout.("scene" + xsource) = scene;
|
238 | 222 | else
|
|
244 | 228 | xaxis.tickcolor = "rgba(0,0,0,0.4)";
|
245 | 229 | yaxis.tickcolor = "rgba(0,0,0,0.4)";
|
246 | 230 |
|
247 |
| - xaxis.tickvals = data.Parent.XTick; |
248 |
| - yaxis.tickvals = data.Parent.YTick; |
| 231 | + xaxis.tickvals = stem_data.Parent.XTick; |
| 232 | + yaxis.tickvals = stem_data.Parent.YTick; |
249 | 233 |
|
250 |
| - xaxis.title = data.Parent.XLabel.String; |
251 |
| - yaxis.title = data.Parent.YLabel.String; |
| 234 | + xaxis.title = stem_data.Parent.XLabel.String; |
| 235 | + yaxis.title = stem_data.Parent.YLabel.String; |
252 | 236 |
|
253 | 237 | obj.layout.("xaxis" + xsource) = xaxis;
|
254 | 238 | obj.layout.("yaxis" + ysource) = yaxis;
|
|
0 commit comments