Skip to content

Commit 568f391

Browse files
Merge pull request #366 from plotly/fig2plotly_working_with_cone_plotly-func_when_coneplot-matlab_is-required
fig2plotly working with cone plotly function when coneplot matlab function is required
2 parents 56d961d + 9d15697 commit 568f391

File tree

3 files changed

+169
-1
lines changed

3 files changed

+169
-1
lines changed

plotly/plotlyfig.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ function delete(obj)
10141014
|| strcmpi(fieldname,'scatterpolar') || strcmpi(fieldname,'barpolar') ...
10151015
|| strcmpi(fieldname,'scene') || strcmpi(fieldname,'layout') ...
10161016
|| strcmpi(fieldname,'heatmap') || strcmpi(fieldname,'xaxis') ...
1017-
|| strcmpi(fieldname,'yaxis') ...
1017+
|| strcmpi(fieldname,'yaxis') || strcmpi(fieldname,'cone')...
10181018
)
10191019
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
10201020
end

plotly/plotlyfig_aux/core/updateData.m

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
updateLineseries(obj, dataIndex);
2222
elseif strcmpi(obj.PlotOptions.TreatAs, 'polarhistogram')
2323
updateHistogramPolar(obj, dataIndex);
24+
elseif strcmpi(obj.PlotOptions.TreatAs, 'coneplot')
25+
updateConeplot(obj, dataIndex);
2426

2527
% this one will be revomed
2628
elseif strcmpi(obj.PlotOptions.TreatAs, 'streamtube')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
function obj = updateConeplot(obj, coneIndex)
2+
3+
%-AXIS INDEX-%
4+
axIndex = obj.getAxisIndex(obj.State.Plot(coneIndex).AssociatedAxis);
5+
6+
%-CONE DATA STRUCTURE- %
7+
cone_data = get(obj.State.Plot(coneIndex).Handle);
8+
9+
%-CHECK FOR MULTIPLE AXES-%
10+
[xsource, ysource] = findSourceAxis(obj,axIndex);
11+
12+
%-SCENE DATA-%
13+
eval(['scene = obj.layout.scene' num2str(xsource) ';']);
14+
15+
%-------------------------------------------------------------------------%
16+
17+
%-cone type-%
18+
obj.data{coneIndex}.type = 'cone';
19+
20+
%-------------------------------------------------------------------------%
21+
22+
%-get plot data-%
23+
xdata = cone_data.XData;
24+
ydata = cone_data.YData;
25+
zdata = cone_data.ZData;
26+
27+
%-------------------------------------------------------------------------%
28+
29+
%-reformat data-%
30+
nfaces = size(xdata, 2);
31+
ref = xdata(end,1);
32+
33+
for n=1:nfaces
34+
if ref ~= xdata(end, n)
35+
step1 = n-1;
36+
break
37+
end
38+
end
39+
40+
ref = xdata(1,step1);
41+
42+
for n=step1:nfaces
43+
if ref ~= xdata(1, n)
44+
step2 = n-1;
45+
break
46+
end
47+
end
48+
49+
x = []; y = []; z = [];
50+
u = []; v = []; w = [];
51+
52+
for c = 1:step2:nfaces
53+
xhead = xdata(end,c);
54+
yhead = ydata(end,c);
55+
zhead = zdata(end,c);
56+
57+
xtail = mean(xdata(2,c:c+step1-1));
58+
ytail = mean(ydata(2,c:c+step1-1));
59+
ztail = mean(zdata(2,c:c+step1-1));
60+
61+
u = [u; xhead - xtail];
62+
v = [v; yhead - ytail];
63+
w = [w; zhead - ztail];
64+
65+
% x = [x; xtail];
66+
% y = [y; ytail];
67+
% z = [z; ztail];
68+
69+
x = [x; 0.5*(xtail+xhead)];
70+
y = [y; 0.5*(ytail+yhead)];
71+
z = [z; 0.5*(ztail+zhead)];
72+
end
73+
74+
%-------------------------------------------------------------------------%
75+
76+
%-set plot data-%
77+
obj.data{coneIndex}.x = x;
78+
obj.data{coneIndex}.y = y;
79+
obj.data{coneIndex}.z = z;
80+
obj.data{coneIndex}.u = u;
81+
obj.data{coneIndex}.v = v;
82+
obj.data{coneIndex}.w = w;
83+
84+
%-------------------------------------------------------------------------%
85+
86+
%-set cone color-%
87+
obj.data{coneIndex}.colorscale{1} = {0, sprintf('rgb(%f,%f,%f)', cone_data.EdgeColor)};
88+
obj.data{coneIndex}.colorscale{2} = {1, sprintf('rgb(%f,%f,%f)', cone_data.EdgeColor)};
89+
90+
%-------------------------------------------------------------------------%
91+
92+
%-plot setting-%
93+
obj.data{coneIndex}.showscale = false;
94+
obj.data{coneIndex}.sizemode = 'scaled';
95+
obj.data{coneIndex}.sizeref = 1.5;
96+
97+
%-------------------------------------------------------------------------%
98+
99+
%-scene axis-%
100+
scene.xaxis.tickvals = cone_data.Parent.XTick;
101+
scene.xaxis.ticktext = cone_data.Parent.XTickLabel;
102+
scene.yaxis.tickvals = cone_data.Parent.YTick;
103+
scene.yaxis.ticktext = cone_data.Parent.YTickLabel;
104+
scene.zaxis.range = cone_data.Parent.ZLim;
105+
scene.zaxis.nticks = 10;
106+
107+
%---------------------------------------------------------------------%
108+
109+
%-aspect ratio-%
110+
ar = obj.PlotOptions.AspectRatio;
111+
112+
if ~isempty(ar)
113+
if ischar(ar)
114+
scene.aspectmode = ar;
115+
elseif isvector(ar) && length(ar) == 3
116+
xar = ar(1);
117+
yar = ar(2);
118+
zar = ar(3);
119+
end
120+
else
121+
122+
%-define as default-%
123+
xar = max(xdata(:));
124+
yar = max(ydata(:));
125+
xyar = min([xar, yar]);
126+
xar = xyar;
127+
yar = xyar;
128+
zar = 0.7*xyar;
129+
end
130+
131+
scene.aspectratio.x = xar;
132+
scene.aspectratio.y = yar;
133+
scene.aspectratio.z = zar;
134+
135+
%---------------------------------------------------------------------%
136+
137+
%-camera eye-%
138+
ey = obj.PlotOptions.CameraEye;
139+
140+
if ~isempty(ey)
141+
if isvector(ey) && length(ey) == 3
142+
scene.camera.eye.x = ey(1);
143+
scene.camera.eye.y = ey(2);
144+
scene.camera.eye.z = ey(3);
145+
end
146+
else
147+
148+
%-define as default-%
149+
xey = - xar; if xey>0 xfac = -0.2; else xfac = 0.2; end
150+
yey = - yar; if yey>0 yfac = -0.2; else yfac = 0.2; end
151+
if zar>0 zfac = 0.2; else zfac = -0.2; end
152+
153+
scene.camera.eye.x = xey + xfac*xey;
154+
scene.camera.eye.y = yey + yfac*yey;
155+
scene.camera.eye.z = zar + zfac*zar;
156+
end
157+
158+
%---------------------------------------------------------------------%
159+
160+
%-set scene to layout-%
161+
obj.layout = setfield(obj.layout,['scene' num2str(xsource)], scene);
162+
obj.data{coneIndex}.scene = ['scene' num2str(xsource)];
163+
164+
%---------------------------------------------------------------------%
165+
166+
end

0 commit comments

Comments
 (0)