Skip to content

Commit b0adc2e

Browse files
Merge pull request #375 from plotly/fix_issues_and_awesome_improvements_in_surf_functionality
Fix issues and awesome improvements in surf functionality
2 parents ba9eab2 + 3ed4703 commit b0adc2e

File tree

4 files changed

+258
-16
lines changed

4 files changed

+258
-16
lines changed

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
updateBar3(obj, dataIndex);
2828
elseif strcmpi(obj.PlotOptions.TreatAs, 'bar3h')
2929
updateBar3h(obj, dataIndex);
30+
elseif strcmpi(obj.PlotOptions.TreatAs, 'surf')
31+
updateSurf(obj, dataIndex);
3032

3133
% this one will be revomed
3234
elseif strcmpi(obj.PlotOptions.TreatAs, 'streamtube')

plotly/plotlyfig_aux/handlegraphics/updateBar3.m

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
switch bar_data.FaceColor
9494

9595
case 'none'
96-
marker.color = 'rgba(0,0,0,0)';
96+
col = 'rgba(0,0,0,0)';
9797

9898
case {'flat','interp'}
9999

@@ -207,12 +207,8 @@
207207
else
208208

209209
%-define as default-%
210-
xey = xar; if xey>0 xfac = 5; else xfac = 0.5*length(values); end
211-
yey = yar; if yey>0 yfac = 0.1; else yfac = -0.1; end
212-
if zar>0 zfac = -0.05; else zfac = 0.1; end
213-
214-
scene.camera.eye.x = xey + 7;
215-
scene.camera.eye.y = yey - 2;
210+
scene.camera.eye.x = xar + 7;
211+
scene.camera.eye.y = yar - 2;
216212
scene.camera.eye.z = zar + 0.5;
217213
end
218214

@@ -232,7 +228,7 @@
232228
scene.zaxis.tickvals = axis_data.ZTick;
233229
scene.zaxis.ticktext = axis_data.ZTickLabel;
234230

235-
scene.yaxis.zeroline = false;
231+
scene.xaxis.zeroline = false;
236232
scene.yaxis.zeroline = false;
237233
scene.zaxis.zeroline = false;
238234

plotly/plotlyfig_aux/handlegraphics/updateBar3h.m

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
switch bar_data.FaceColor
9494

9595
case 'none'
96-
marker.color = 'rgba(0,0,0,0)';
96+
col = 'rgba(0,0,0,0)';
9797

9898
case {'flat','interp'}
9999

@@ -207,12 +207,8 @@
207207
else
208208

209209
%-define as default-%
210-
xey = xar; if xey>0 xfac = 5; else xfac = 0.5*length(values); end
211-
yey = yar; if yey>0 yfac = 0.1; else yfac = -0.1; end
212-
if zar>0 zfac = -0.05; else zfac = 0.1; end
213-
214-
scene.camera.eye.x = xey + 7;
215-
scene.camera.eye.y = yey + 0;
210+
scene.camera.eye.x = xar + 7;
211+
scene.camera.eye.y = yar + 0;
216212
scene.camera.eye.z = zar + 0.5;
217213
end
218214

@@ -232,7 +228,7 @@
232228
scene.zaxis.tickvals = axis_data.ZTick;
233229
scene.zaxis.ticktext = axis_data.ZTickLabel;
234230

235-
scene.yaxis.zeroline = false;
231+
scene.xaxis.zeroline = false;
236232
scene.yaxis.zeroline = false;
237233
scene.zaxis.zeroline = false;
238234

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
function obj = updateSurf(obj, surfaceIndex)
2+
3+
%-AXIS INDEX-%
4+
axIndex = obj.getAxisIndex(obj.State.Plot(surfaceIndex).AssociatedAxis);
5+
6+
%-CHECK FOR MULTIPLE AXES-%
7+
[xsource, ysource] = findSourceAxis(obj,axIndex);
8+
9+
%-SURFACE DATA STRUCTURE- %
10+
surfData = get(obj.State.Plot(surfaceIndex).Handle);
11+
figureData = get(obj.State.Figure.Handle);
12+
13+
%-AXIS STRUCTURE-%
14+
axisData = get(ancestor(surfData.Parent,'axes'));
15+
16+
%-GET SCENE-%
17+
eval(['scene = obj.layout.scene' num2str(xsource) ';']);
18+
19+
%-------------------------------------------------------------------------%
20+
21+
%-associate scene-%
22+
obj.data{surfaceIndex}.scene = sprintf('scene%d', xsource);
23+
24+
%-------------------------------------------------------------------------%
25+
26+
%-surface type-%
27+
obj.data{surfaceIndex}.type = 'surface';
28+
29+
%---------------------------------------------------------------------%
30+
31+
%-get plot data-%
32+
xData = surfData.XData;
33+
yData = surfData.YData;
34+
zData = surfData.ZData;
35+
cData = surfData.CData;
36+
37+
%---------------------------------------------------------------------%
38+
39+
%-set surface data-%
40+
obj.data{surfaceIndex}.x = xData;
41+
obj.data{surfaceIndex}.y = yData;
42+
obj.data{surfaceIndex}.z = zData;
43+
44+
%---------------------------------------------------------------------%
45+
46+
%-setting grid mesh by default-%
47+
48+
edgeColor = surfData.EdgeColor;
49+
50+
if isnumeric(edgeColor)
51+
edgeColor = sprintf('rgb(%f,%f,%f)', 255*edgeColor);
52+
elseif strcmpi(edgeColor, 'none')
53+
edgeColor = 'rgba(1,1,1,0)';
54+
end
55+
56+
% x-direction
57+
xMin = min(xData(:));
58+
xMax = max(xData(:));
59+
xsize = (xMax - xMin) / (size(xData, 2)-1);
60+
obj.data{surfaceIndex}.contours.x.start = xMin;
61+
obj.data{surfaceIndex}.contours.x.end = xMax;
62+
obj.data{surfaceIndex}.contours.x.size = xsize;
63+
obj.data{surfaceIndex}.contours.x.show = true;
64+
obj.data{surfaceIndex}.contours.x.color = edgeColor;
65+
66+
% y-direction
67+
yMin = min(yData(:));
68+
yMax = max(yData(:));
69+
ysize = (yMax - yMin) / (size(yData, 1)-1);
70+
obj.data{surfaceIndex}.contours.y.start = yMin;
71+
obj.data{surfaceIndex}.contours.y.end = yMax;
72+
obj.data{surfaceIndex}.contours.y.size = ysize;
73+
obj.data{surfaceIndex}.contours.y.show = true;
74+
obj.data{surfaceIndex}.contours.y.color = edgeColor;
75+
76+
%-------------------------------------------------------------------------%
77+
78+
%-set colorscales-%
79+
cMap = figureData.Colormap;
80+
81+
if isnumeric(surfData.FaceColor)
82+
for n = 1:size(cData, 2)
83+
for m = 1:size(cData, 1)
84+
cDataNew(m, n, :) = surfData.FaceColor;
85+
end
86+
end
87+
88+
cData = rgb2ind(cDataNew, cMap);
89+
obj.data{surfaceIndex}.cmin = 0;
90+
obj.data{surfaceIndex}.cmax = 255;
91+
end
92+
93+
if size(cData, 3) ~= 1
94+
cMap = unique( reshape(cData, ...
95+
[size(cData,1)*size(cData,2), size(cData,3)]), 'rows' );
96+
cData = rgb2ind(cData, cMap);
97+
end
98+
99+
colorScale = {};
100+
fac = 1/(length(cMap)-1);
101+
102+
for c = 1: length(cMap)
103+
colorScale{c} = { (c-1)*fac , sprintf('rgb(%f,%f,%f)', 255*cMap(c, :))};
104+
end
105+
106+
obj.data{surfaceIndex}.colorscale = colorScale;
107+
108+
%-surface coloring-%
109+
obj.data{surfaceIndex}.surfacecolor = cData;
110+
111+
%-------------------------------------------------------------------------%
112+
113+
%-surface opacity-%
114+
obj.data{surfaceIndex}.opacity = surfData.FaceAlpha;
115+
116+
%-surface showscale-%
117+
obj.data{surfaceIndex}.showscale = false;
118+
119+
%-------------------------------------------------------------------------%
120+
121+
%-SCENE CONFIGUTATION-%
122+
123+
%-------------------------------------------------------------------------%
124+
125+
%-aspect ratio-%
126+
asr = obj.PlotOptions.AspectRatio;
127+
128+
if ~isempty(asr)
129+
if ischar(asr)
130+
scene.aspectmode = asr;
131+
elseif isvector(ar) && length(asr) == 3
132+
xar = asr(1);
133+
yar = asr(2);
134+
zar = asr(3);
135+
end
136+
else
137+
138+
%-define as default-%
139+
xar = max(xData(:));
140+
yar = max(yData(:));
141+
xyar = max([xar, yar]);
142+
zar = 0.65*xyar;
143+
end
144+
145+
scene.aspectratio.x = 1.1*xyar;
146+
scene.aspectratio.y = 1.0*xyar;
147+
scene.aspectratio.z = zar;
148+
149+
%---------------------------------------------------------------------%
150+
151+
%-camera eye-%
152+
ey = obj.PlotOptions.CameraEye;
153+
154+
if ~isempty(ey)
155+
if isvector(ey) && length(ey) == 3
156+
scene.camera.eye.x = ey(1);
157+
scene.camera.eye.y = ey(2);
158+
scene.camera.eye.z = ey(3);
159+
end
160+
else
161+
162+
%-define as default-%
163+
xey = - xyar; if xey>0 xfac = -0.2; else xfac = 0.2; end
164+
yey = - xyar; if yey>0 yfac = -0.2; else yfac = 0.2; end
165+
if zar>0 zfac = 0.2; else zfac = -0.2; end
166+
167+
scene.camera.eye.x = xey + xfac*xey;
168+
scene.camera.eye.y = yey + yfac*yey;
169+
scene.camera.eye.z = zar + zfac*zar;
170+
end
171+
172+
%-------------------------------------------------------------------------%
173+
174+
%-scene axis configuration-%
175+
176+
scene.xaxis.range = axisData.XLim;
177+
scene.yaxis.range = axisData.YLim;
178+
scene.zaxis.range = axisData.ZLim;
179+
180+
scene.xaxis.tickvals = axisData.XTick;
181+
scene.xaxis.ticktext = axisData.XTickLabel;
182+
183+
scene.yaxis.tickvals = axisData.YTick;
184+
scene.yaxis.ticktext = axisData.YTickLabel;
185+
186+
scene.zaxis.tickvals = axisData.ZTick;
187+
scene.zaxis.ticktext = axisData.ZTickLabel;
188+
189+
scene.xaxis.zeroline = false;
190+
scene.yaxis.zeroline = false;
191+
scene.zaxis.zeroline = false;
192+
193+
scene.xaxis.showline = true;
194+
scene.yaxis.showline = true;
195+
scene.zaxis.showline = true;
196+
197+
scene.xaxis.tickcolor = 'rgba(0,0,0,1)';
198+
scene.yaxis.tickcolor = 'rgba(0,0,0,1)';
199+
scene.zaxis.tickcolor = 'rgba(0,0,0,1)';
200+
201+
scene.xaxis.ticklabelposition = 'outside';
202+
scene.yaxis.ticklabelposition = 'outside';
203+
scene.zaxis.ticklabelposition = 'outside';
204+
205+
scene.xaxis.title = axisData.XLabel.String;
206+
scene.yaxis.title = axisData.YLabel.String;
207+
scene.zaxis.title = axisData.ZLabel.String;
208+
209+
scene.xaxis.tickfont.size = axisData.FontSize;
210+
scene.yaxis.tickfont.size = axisData.FontSize;
211+
scene.zaxis.tickfont.size = axisData.FontSize;
212+
213+
scene.xaxis.tickfont.family = matlab2plotlyfont(axisData.FontName);
214+
scene.yaxis.tickfont.family = matlab2plotlyfont(axisData.FontName);
215+
scene.zaxis.tickfont.family = matlab2plotlyfont(axisData.FontName);
216+
217+
%-------------------------------------------------------------------------%
218+
219+
%-SET SCENE TO LAYOUT-%
220+
obj.layout = setfield(obj.layout, sprintf('scene%d', xsource), scene);
221+
222+
%-------------------------------------------------------------------------%
223+
224+
%-surface name-%
225+
obj.data{surfaceIndex}.name = surfData.DisplayName;
226+
227+
%-------------------------------------------------------------------------%
228+
229+
%-surface visible-%
230+
obj.data{surfaceIndex}.visible = strcmp(surfData.Visible,'on');
231+
232+
%-------------------------------------------------------------------------%
233+
234+
leg = get(surfData.Annotation);
235+
legInfo = get(leg.LegendInformation);
236+
237+
switch legInfo.IconDisplayStyle
238+
case 'on'
239+
showleg = true;
240+
case 'off'
241+
showleg = false;
242+
end
243+
244+
obj.data{surfaceIndex}.showlegend = showleg;
245+
246+
%-------------------------------------------------------------------------%
247+
248+
end

0 commit comments

Comments
 (0)