Skip to content

Commit 1088c6f

Browse files
fix issue #267
1 parent 8e4caef commit 1088c6f

File tree

2 files changed

+160
-0
lines changed

2 files changed

+160
-0
lines changed

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
updateSurfaceplot(obj,dataIndex);
3535
case 'functionsurface'
3636
updateFunctionSurface(obj,dataIndex);
37+
case 'implicitfunctionsurface'
38+
updateImplicitFunctionSurface(obj,dataIndex);
3739

3840
%-GROUP PLOT OBJECTS-%
3941
case 'area'
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
function obj = updateImplicitFunctionSurface(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+
image_data = get(obj.State.Plot(surfaceIndex).Handle);
11+
figure_data = get(obj.State.Figure.Handle);
12+
13+
%-AXIS DATA-%
14+
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
15+
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
16+
17+
%-------------------------------------------------------------------------%
18+
19+
%-surface xaxis-%
20+
obj.data{surfaceIndex}.xaxis = ['x' num2str(xsource)];
21+
22+
%-------------------------------------------------------------------------%
23+
24+
%-surface yaxis-%
25+
obj.data{surfaceIndex}.yaxis = ['y' num2str(ysource)];
26+
27+
%-------------------------------------------------------------------------%
28+
29+
%-surface type-%
30+
obj.data{surfaceIndex}.type = 'surface';
31+
32+
%---------------------------------------------------------------------%
33+
34+
%-getting x,y,z surface data-%
35+
36+
strf = func2str(image_data.Function);
37+
ind1 = strfind(strf, '('); ind1 = ind1(1)+1;
38+
ind2 = strfind(strf, ')'); ind2 = ind2(1)-1;
39+
vars = split(strf(ind1:ind2), ',');
40+
41+
strf = [strf(ind2+2:end) '==0'];
42+
strf = replace(strf, vars{1}, 'Xx');
43+
strf = replace(strf, vars{2}, 'Yy');
44+
strf = replace(strf, vars{3}, 'Zz');
45+
46+
syms Xx Yy Zz;
47+
f = eval(strf);
48+
s = solve(f, Zz);
49+
50+
x = image_data.XRange;
51+
y = image_data.YRange;
52+
z = image_data.ZRange;
53+
N = 400;
54+
55+
[Xx,Yy] = meshgrid(linspace(x(1),x(2),N), linspace(y(1),y(2),N));
56+
X = []; Y = []; Z = [];
57+
58+
for n = 1:length(s)
59+
X = [X; Xx];
60+
Y = [Y; Yy];
61+
Z = [Z; eval(s(n))];
62+
end
63+
64+
clear Xx Yy Zz;
65+
Z(Z < z(1)) = nan; Z(Z > z(2)) = nan;
66+
X(Z < z(1)) = nan; X(Z > z(2)) = nan;
67+
Y(Z < z(1)) = nan; Y(Z > z(2)) = nan;
68+
69+
%---------------------------------------------------------------------%
70+
71+
%-surface x-%
72+
obj.data{surfaceIndex}.x = X;
73+
74+
%---------------------------------------------------------------------%
75+
76+
%-surface y-%
77+
obj.data{surfaceIndex}.y = Y;
78+
79+
%---------------------------------------------------------------------%
80+
81+
%-surface z-%
82+
obj.data{surfaceIndex}.z = Z;
83+
84+
%---------------------------------------------------------------------%
85+
86+
%- setting grid mesh by default -%
87+
% x-direction
88+
mden = image_data.MeshDensity;
89+
xsize = (x(2) - x(1)) / mden;
90+
obj.data{surfaceIndex}.contours.x.start = x(1);
91+
obj.data{surfaceIndex}.contours.x.end = x(2);
92+
obj.data{surfaceIndex}.contours.x.size = xsize;
93+
obj.data{surfaceIndex}.contours.x.show = true;
94+
obj.data{surfaceIndex}.contours.x.color = 'black';
95+
% y-direction
96+
ysize = (y(2) - y(1)) / mden;
97+
obj.data{surfaceIndex}.contours.y.start = y(1);
98+
obj.data{surfaceIndex}.contours.y.end = y(2);
99+
obj.data{surfaceIndex}.contours.y.size = ysize;
100+
obj.data{surfaceIndex}.contours.y.show = true;
101+
obj.data{surfaceIndex}.contours.y.color = 'black';
102+
% z-direction
103+
zsize = (z(2) - z(1)) / mden;
104+
obj.data{surfaceIndex}.contours.z.start = z(1);
105+
obj.data{surfaceIndex}.contours.z.end = z(2);
106+
obj.data{surfaceIndex}.contours.z.size = zsize;
107+
obj.data{surfaceIndex}.contours.z.show = true;
108+
obj.data{surfaceIndex}.contours.z.color = 'black';
109+
110+
%-------------------------------------------------------------------------%
111+
112+
%-image colorscale-%
113+
114+
cmap = figure_data.Colormap;
115+
len = length(cmap)-1;
116+
117+
for c = 1: length(cmap)
118+
col = 255 * cmap(c, :);
119+
obj.data{surfaceIndex}.colorscale{c} = { (c-1)/len , ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')' ] };
120+
end
121+
122+
%-------------------------------------------------------------------------%
123+
124+
%-image surfacescale-%
125+
obj.data{surfaceIndex}.surfacecolor = Z;
126+
127+
%-------------------------------------------------------------------------%
128+
129+
%-surface name-%
130+
obj.data{surfaceIndex}.name = image_data.DisplayName;
131+
132+
%-------------------------------------------------------------------------%
133+
134+
%-surface showscale-%
135+
obj.data{surfaceIndex}.showscale = false;
136+
137+
%-------------------------------------------------------------------------%
138+
139+
%-surface visible-%
140+
obj.data{surfaceIndex}.visible = strcmp(image_data.Visible,'on');
141+
142+
%-------------------------------------------------------------------------%
143+
144+
leg = get(image_data.Annotation);
145+
legInfo = get(leg.LegendInformation);
146+
147+
switch legInfo.IconDisplayStyle
148+
case 'on'
149+
showleg = true;
150+
case 'off'
151+
showleg = false;
152+
end
153+
154+
obj.data{surfaceIndex}.showlegend = showleg;
155+
156+
%-------------------------------------------------------------------------%
157+
158+
end

0 commit comments

Comments
 (0)