Skip to content

Commit ea4b3ea

Browse files
fix issues and awesome improvements in fmesh functionality
1 parent b0adc2e commit ea4b3ea

File tree

2 files changed

+272
-0
lines changed

2 files changed

+272
-0
lines changed

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
updateBar3h(obj, dataIndex);
3030
elseif strcmpi(obj.PlotOptions.TreatAs, 'surf')
3131
updateSurf(obj, dataIndex);
32+
elseif strcmpi(obj.PlotOptions.TreatAs, 'fmesh')
33+
updateFmesh(obj, dataIndex);
3234

3335
% this one will be revomed
3436
elseif strcmpi(obj.PlotOptions.TreatAs, 'streamtube')
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
function obj = updateFmesh(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+
meshData = get(obj.State.Plot(surfaceIndex).Handle)
11+
figureData = get(obj.State.Figure.Handle);
12+
13+
%-AXIS STRUCTURE-%
14+
axisData = get(ancestor(meshData.Parent,'axes'));
15+
16+
%-SCENE DATA-%
17+
eval( sprintf('scene = obj.layout.scene%d;', xsource) );
18+
19+
%-------------------------------------------------------------------------%
20+
21+
%-associate scene-%
22+
obj.data{surfaceIndex}.scene = sprintf('scene%d', xsource);
23+
24+
%-------------------------------------------------------------------------%
25+
26+
%-surface xaxis-%
27+
obj.data{surfaceIndex}.xaxis = ['x' num2str(xsource)];
28+
29+
%-------------------------------------------------------------------------%
30+
31+
%-surface type-%
32+
obj.data{surfaceIndex}.type = 'scatter3d';
33+
obj.data{surfaceIndex}.mode = 'lines';
34+
35+
%-------------------------------------------------------------------------%
36+
37+
%-get plot data-%
38+
meshDensity = meshData.MeshDensity;
39+
xData = meshData.XData(1:meshDensity^2);
40+
yData = meshData.YData(1:meshDensity^2);
41+
zData = meshData.ZData(1:meshDensity^2);
42+
43+
%-reformat data to mesh-%
44+
xData = reshape(xData, [meshDensity, meshDensity])';
45+
yData = reshape(yData, [meshDensity, meshDensity])';
46+
zData = reshape(zData, [meshDensity, meshDensity])';
47+
48+
xData = [xData; NaN(1, size(xData, 2))];
49+
yData = [yData; NaN(1, size(yData, 2))];
50+
zData = [zData; NaN(1, size(zData, 2))];
51+
52+
xData = [xData; xData(1:end-1,:)'];
53+
yData = [yData; yData(1:end-1,:)'];
54+
zData = [zData; zData(1:end-1,:)'];
55+
56+
xData = [xData; NaN(1, size(xData, 2))];
57+
yData = [yData; NaN(1, size(yData, 2))];
58+
zData = [zData; NaN(1, size(zData, 2))];
59+
60+
xData = [xData(1, :)-0.01; xData];
61+
yData = [yData(1, :)-0.01; yData];
62+
zData = [NaN(1, size(zData, 2)); zData];
63+
64+
xData = [xData(:, 1)-0.01, xData];
65+
yData = [yData(:, 1)-0.01, yData];
66+
zData = [NaN(size(zData, 1), 1), zData];
67+
68+
%-------------------------------------------------------------------------%
69+
70+
%-set data-%
71+
obj.data{surfaceIndex}.x = xData(:);
72+
obj.data{surfaceIndex}.y = yData(:);
73+
obj.data{surfaceIndex}.z = zData(:);
74+
75+
%-------------------------------------------------------------------------%
76+
77+
%-COLORING-%
78+
79+
%-------------------------------------------------------------------------%
80+
81+
%-get colormap-%
82+
cMap = figureData.Colormap;
83+
fac = 1/(length(cMap)-1);
84+
colorScale = {};
85+
86+
for c = 1: length(cMap)
87+
colorScale{c} = { (c-1)*fac , sprintf('rgb(%f,%f,%f)', 255*cMap(c, :))};
88+
end
89+
90+
%-------------------------------------------------------------------------%
91+
92+
%-get edge color-%
93+
if isnumeric(meshData.EdgeColor)
94+
cData = sprintf('rgb(%f,%f,%f)', 255*meshData.EdgeColor);
95+
96+
elseif strcmpi(meshData.EdgeColor, 'interp')
97+
cData = zData(:);
98+
obj.data{surfaceIndex}.line.colorscale = colorScale;
99+
end
100+
101+
%-set edge color-%
102+
obj.data{surfaceIndex}.line.color = cData;
103+
104+
%-------------------------------------------------------------------------%
105+
106+
%-get face color-%
107+
if isnumeric(meshData.FaceColor)
108+
cData = sprintf('rgba(%f,%f,%f,0.99)', 255*meshData.FaceColor);
109+
110+
elseif strcmpi(meshData.EdgeColor, 'interp')
111+
cData = zData(:);
112+
obj.data{surfaceIndex}.colorscale = colorScale;
113+
end
114+
115+
%-set face color-%
116+
obj.data{surfaceIndex}.surfacecolor = cData;
117+
obj.data{surfaceIndex}.surfaceaxis = 2;
118+
119+
%-------------------------------------------------------------------------%
120+
121+
%-line style-%
122+
123+
obj.data{surfaceIndex}.line.width = 3*meshData.LineWidth;
124+
125+
switch meshData.LineStyle
126+
case '-'
127+
obj.data{surfaceIndex}.line.dash = 'solid';
128+
case '--'
129+
obj.data{surfaceIndex}.line.dash = 'dash';
130+
case '-.'
131+
obj.data{surfaceIndex}.line.dash = 'dashdot';
132+
case ':'
133+
obj.data{surfaceIndex}.line.dash = 'dot';
134+
end
135+
136+
%-------------------------------------------------------------------------%
137+
138+
%-SCENE CONFIGUTATION-%
139+
140+
%-------------------------------------------------------------------------%
141+
142+
%-aspect ratio-%
143+
asr = obj.PlotOptions.AspectRatio;
144+
145+
if ~isempty(asr)
146+
if ischar(asr)
147+
scene.aspectmode = asr;
148+
elseif isvector(ar) && length(asr) == 3
149+
xar = asr(1);
150+
yar = asr(2);
151+
zar = asr(3);
152+
end
153+
else
154+
155+
%-define as default-%
156+
xar = max(xData(:));
157+
yar = max(yData(:));
158+
xyar = max([xar, yar]);
159+
zar = 0.65*xyar;
160+
end
161+
162+
scene.aspectratio.x = 1.1*xyar;
163+
scene.aspectratio.y = 1.0*xyar;
164+
scene.aspectratio.z = zar;
165+
166+
%---------------------------------------------------------------------%
167+
168+
%-camera eye-%
169+
ey = obj.PlotOptions.CameraEye;
170+
171+
if ~isempty(ey)
172+
if isvector(ey) && length(ey) == 3
173+
scene.camera.eye.x = ey(1);
174+
scene.camera.eye.y = ey(2);
175+
scene.camera.eye.z = ey(3);
176+
end
177+
else
178+
179+
%-define as default-%
180+
xey = - xyar; if xey>0 xfac = 0.0; else xfac = 0.0; end
181+
yey = - xyar; if yey>0 yfac = -0.3; else yfac = 0.3; end
182+
if zar>0 zfac = 0.2; else zfac = -0.2; end
183+
184+
scene.camera.eye.x = xey + xfac*xey;
185+
scene.camera.eye.y = yey + yfac*yey;
186+
scene.camera.eye.z = zar + zfac*zar;
187+
end
188+
189+
%-------------------------------------------------------------------------%
190+
191+
%-scene axis configuration-%
192+
193+
scene.xaxis.range = axisData.XLim;
194+
scene.yaxis.range = axisData.YLim;
195+
scene.zaxis.range = axisData.ZLim;
196+
197+
scene.xaxis.tickvals = axisData.XTick;
198+
scene.xaxis.ticktext = axisData.XTickLabel;
199+
200+
scene.yaxis.tickvals = axisData.YTick;
201+
scene.yaxis.ticktext = axisData.YTickLabel;
202+
203+
scene.zaxis.tickvals = axisData.ZTick;
204+
scene.zaxis.ticktext = axisData.ZTickLabel;
205+
206+
scene.xaxis.zeroline = false;
207+
scene.yaxis.zeroline = false;
208+
scene.zaxis.zeroline = false;
209+
210+
scene.xaxis.showline = true;
211+
scene.yaxis.showline = true;
212+
scene.zaxis.showline = true;
213+
214+
scene.xaxis.tickcolor = 'rgba(0,0,0,1)';
215+
scene.yaxis.tickcolor = 'rgba(0,0,0,1)';
216+
scene.zaxis.tickcolor = 'rgba(0,0,0,1)';
217+
218+
scene.xaxis.ticklabelposition = 'outside';
219+
scene.yaxis.ticklabelposition = 'outside';
220+
scene.zaxis.ticklabelposition = 'outside';
221+
222+
scene.xaxis.title = axisData.XLabel.String;
223+
scene.yaxis.title = axisData.YLabel.String;
224+
scene.zaxis.title = axisData.ZLabel.String;
225+
226+
scene.xaxis.tickfont.size = axisData.FontSize;
227+
scene.yaxis.tickfont.size = axisData.FontSize;
228+
scene.zaxis.tickfont.size = axisData.FontSize;
229+
230+
scene.xaxis.tickfont.family = matlab2plotlyfont(axisData.FontName);
231+
scene.yaxis.tickfont.family = matlab2plotlyfont(axisData.FontName);
232+
scene.zaxis.tickfont.family = matlab2plotlyfont(axisData.FontName);
233+
234+
%-------------------------------------------------------------------------%
235+
236+
%-SET SCENE TO LAYOUT-%
237+
obj.layout = setfield(obj.layout, sprintf('scene%d', xsource), scene);
238+
239+
%-------------------------------------------------------------------------%
240+
241+
%-surface name-%
242+
obj.data{surfaceIndex}.name = meshData.DisplayName;
243+
244+
%-------------------------------------------------------------------------%
245+
246+
%-surface showscale-%
247+
obj.data{surfaceIndex}.showscale = false;
248+
249+
%-------------------------------------------------------------------------%
250+
251+
%-surface visible-%
252+
obj.data{surfaceIndex}.visible = strcmp(meshData.Visible,'on');
253+
254+
%-------------------------------------------------------------------------%
255+
256+
leg = get(meshData.Annotation);
257+
legInfo = get(leg.LegendInformation);
258+
259+
switch legInfo.IconDisplayStyle
260+
case 'on'
261+
showleg = true;
262+
case 'off'
263+
showleg = false;
264+
end
265+
266+
obj.data{surfaceIndex}.showlegend = showleg;
267+
268+
%-------------------------------------------------------------------------%
269+
270+
end

0 commit comments

Comments
 (0)