Skip to content

Commit f5f0d5d

Browse files
fix issues and awesome improvements in fmesh functionality
1 parent 3405ea7 commit f5f0d5d

File tree

2 files changed

+73
-50
lines changed

2 files changed

+73
-50
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/handlegraphics/updateFmesh.m

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@
1616
%-SCENE DATA-%
1717
eval( sprintf('scene = obj.layout.scene%d;', xsource) );
1818

19+
%-GET CONTOUR INDEX-%
20+
obj.PlotOptions.nPlots = obj.PlotOptions.nPlots + 1;
21+
contourIndex = obj.PlotOptions.nPlots;
22+
1923
%-------------------------------------------------------------------------%
2024

2125
%-associate scene-%
2226
obj.data{surfaceIndex}.scene = sprintf('scene%d', xsource);
27+
obj.data{contourIndex}.scene = sprintf('scene%d', xsource);
2328

2429
%-------------------------------------------------------------------------%
2530

26-
%-surface xaxis-%
27-
obj.data{surfaceIndex}.xaxis = ['x' num2str(xsource)];
28-
29-
%-------------------------------------------------------------------------%
31+
%-surface type for face color-%
32+
obj.data{surfaceIndex}.type = 'surface';
3033

31-
%-surface type-%
32-
obj.data{surfaceIndex}.type = 'scatter3d';
33-
obj.data{surfaceIndex}.mode = 'lines';
34+
%-scatter3d type for contour mesh lines-%
35+
obj.data{contourIndex}.type = 'scatter3d';
36+
obj.data{contourIndex}.mode = 'lines';
3437

3538
%-------------------------------------------------------------------------%
3639

@@ -41,36 +44,35 @@
4144
zData = meshData.ZData(1:meshDensity^2);
4245

4346
%-reformat data to mesh-%
44-
xData = reshape(xData, [meshDensity, meshDensity])';
45-
yData = reshape(yData, [meshDensity, meshDensity])';
46-
zData = reshape(zData, [meshDensity, meshDensity])';
47+
xDataSurface = reshape(xData, [meshDensity, meshDensity])';
48+
yDataSurface = reshape(yData, [meshDensity, meshDensity])';
49+
zDataSurface = reshape(zData, [meshDensity, meshDensity])';
4750

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+
xDataContour = [xDataSurface; NaN(1, size(xDataSurface, 2))];
52+
yDataContour = [yDataSurface; NaN(1, size(yDataSurface, 2))];
53+
zDataContour = [zDataSurface; NaN(1, size(zDataSurface, 2))];
5154

52-
xData = [xData; xData(1:end-1,:)'];
53-
yData = [yData; yData(1:end-1,:)'];
54-
zData = [zData; zData(1:end-1,:)'];
55+
xDataContour = [xDataContour; xDataContour(1:end-1,:)'];
56+
yDataContour = [yDataContour; yDataContour(1:end-1,:)'];
57+
zDataContour = [zDataContour; zDataContour(1:end-1,:)'];
5558

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+
xDataContour = [xDataContour; NaN(1, size(xDataContour, 2))];
60+
yDataContour = [yDataContour; NaN(1, size(yDataContour, 2))];
61+
zDataContour = [zDataContour; NaN(1, size(zDataContour, 2))];
5962

60-
xData = [xData(1, :)-0.01; xData];
61-
yData = [yData(1, :)-0.01; yData];
62-
zData = [NaN(1, size(zData, 2)); zData];
63+
%-------------------------------------------------------------------------%
6364

64-
xData = [xData(:, 1)-0.01, xData];
65-
yData = [yData(:, 1)-0.01, yData];
66-
zData = [NaN(size(zData, 1), 1), zData];
65+
%-set data on surface-%
66+
obj.data{surfaceIndex}.x = xDataSurface;
67+
obj.data{surfaceIndex}.y = yDataSurface;
68+
obj.data{surfaceIndex}.z = zDataSurface;
6769

6870
%-------------------------------------------------------------------------%
6971

70-
%-set data-%
71-
obj.data{surfaceIndex}.x = xData(:);
72-
obj.data{surfaceIndex}.y = yData(:);
73-
obj.data{surfaceIndex}.z = zData(:);
72+
%-set data on scatter3d-%
73+
obj.data{contourIndex}.x = xDataContour(:);
74+
obj.data{contourIndex}.y = yDataContour(:);
75+
obj.data{contourIndex}.z = zDataContour(:);
7476

7577
%-------------------------------------------------------------------------%
7678

@@ -91,46 +93,66 @@
9193

9294
%-get edge color-%
9395
if isnumeric(meshData.EdgeColor)
94-
cData = sprintf('rgb(%f,%f,%f)', 255*meshData.EdgeColor);
96+
cDataContour = sprintf('rgb(%f,%f,%f)', 255*meshData.EdgeColor);
9597

9698
elseif strcmpi(meshData.EdgeColor, 'interp')
97-
cData = zData(:);
98-
obj.data{surfaceIndex}.line.colorscale = colorScale;
99+
cDataContour = zDataContour(:);
100+
obj.data{contourIndex}.line.colorscale = colorScale;
99101
end
100102

101103
%-set edge color-%
102-
obj.data{surfaceIndex}.line.color = cData;
104+
obj.data{contourIndex}.line.color = cDataContour;
103105

104106
%-------------------------------------------------------------------------%
105107

106108
%-get face color-%
107109
if isnumeric(meshData.FaceColor)
108-
cData = sprintf('rgba(%f,%f,%f,0.99)', 255*meshData.FaceColor);
109110

110-
elseif strcmpi(meshData.EdgeColor, 'interp')
111-
cData = zData(:);
112-
obj.data{surfaceIndex}.colorscale = colorScale;
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;
113128
end
114129

115130
%-set face color-%
116-
obj.data{surfaceIndex}.surfacecolor = cData;
117-
obj.data{surfaceIndex}.surfaceaxis = 2;
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;
118140

119141
%-------------------------------------------------------------------------%
120142

121143
%-line style-%
122144

123-
obj.data{surfaceIndex}.line.width = 3*meshData.LineWidth;
145+
obj.data{contourIndex}.line.width = 3*meshData.LineWidth;
124146

125147
switch meshData.LineStyle
126148
case '-'
127-
obj.data{surfaceIndex}.line.dash = 'solid';
149+
obj.data{contourIndex}.line.dash = 'solid';
128150
case '--'
129-
obj.data{surfaceIndex}.line.dash = 'dash';
151+
obj.data{contourIndex}.line.dash = 'dash';
130152
case '-.'
131-
obj.data{surfaceIndex}.line.dash = 'dashdot';
153+
obj.data{contourIndex}.line.dash = 'dashdot';
132154
case ':'
133-
obj.data{surfaceIndex}.line.dash = 'dot';
155+
obj.data{contourIndex}.line.dash = 'dot';
134156
end
135157

136158
%-------------------------------------------------------------------------%
@@ -156,7 +178,7 @@
156178
xar = max(xData(:));
157179
yar = max(yData(:));
158180
xyar = max([xar, yar]);
159-
zar = 0.65*xyar;
181+
zar = 0.75*xyar;
160182
end
161183

162184
scene.aspectratio.x = 1.1*xyar;
@@ -239,17 +261,18 @@
239261
%-------------------------------------------------------------------------%
240262

241263
%-surface name-%
242-
obj.data{surfaceIndex}.name = meshData.DisplayName;
264+
obj.data{contourIndex}.name = meshData.DisplayName;
243265

244266
%-------------------------------------------------------------------------%
245267

246268
%-surface showscale-%
247269
obj.data{surfaceIndex}.showscale = false;
270+
obj.data{contourIndex}.showscale = false;
248271

249272
%-------------------------------------------------------------------------%
250273

251274
%-surface visible-%
252-
obj.data{surfaceIndex}.visible = strcmp(meshData.Visible,'on');
275+
obj.data{contourIndex}.visible = strcmp(meshData.Visible,'on');
253276

254277
%-------------------------------------------------------------------------%
255278

@@ -263,7 +286,7 @@
263286
showleg = false;
264287
end
265288

266-
obj.data{surfaceIndex}.showlegend = showleg;
289+
obj.data{contourIndex}.showlegend = showleg;
267290

268291
%-------------------------------------------------------------------------%
269292

0 commit comments

Comments
 (0)