Skip to content

Commit ea58447

Browse files
Merge pull request #376 from plotly/fix_issues_and_awesome_improvements_in_fmesh_functionality
Fix issues and awesome improvements in fmesh functionality
2 parents b0adc2e + f5f0d5d commit ea58447

File tree

3 files changed

+297
-2
lines changed

3 files changed

+297
-2
lines changed

plotly/plotlyfig.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ function validate(obj)
714714
end
715715

716716
% update plots
717-
obj.PlotOptions.nplots = obj.State.Figure.NumPlots;
717+
obj.PlotOptions.nPlots = obj.State.Figure.NumPlots;
718718

719719
for n = 1:obj.State.Figure.NumPlots
720720
updateData(obj,n);
@@ -1051,7 +1051,7 @@ function delete(obj)
10511051
|| strcmpi(fieldname,'heatmap') || strcmpi(fieldname,'xaxis') ...
10521052
|| strcmpi(fieldname,'yaxis') || strcmpi(fieldname,'cone')...
10531053
|| strcmpi(fieldname,'legend') || strcmpi(fieldname,'histogram')...
1054-
|| strcmpi(fieldname,'scatter')...
1054+
|| strcmpi(fieldname,'scatter') || strcmpi(fieldname,'line')...
10551055
)
10561056
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
10571057
end

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

0 commit comments

Comments
 (0)