Skip to content

fig2plotly working with cone plotly function when coneplot matlab function is required #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ function delete(obj)
|| strcmpi(fieldname,'scatterpolar') || strcmpi(fieldname,'barpolar') ...
|| strcmpi(fieldname,'scene') || strcmpi(fieldname,'layout') ...
|| strcmpi(fieldname,'heatmap') || strcmpi(fieldname,'xaxis') ...
|| strcmpi(fieldname,'yaxis') ...
|| strcmpi(fieldname,'yaxis') || strcmpi(fieldname,'cone')...
)
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
end
Expand Down
2 changes: 2 additions & 0 deletions plotly/plotlyfig_aux/core/updateData.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
updateLineseries(obj, dataIndex);
elseif strcmpi(obj.PlotOptions.TreatAs, 'polarhistogram')
updateHistogramPolar(obj, dataIndex);
elseif strcmpi(obj.PlotOptions.TreatAs, 'coneplot')
updateConeplot(obj, dataIndex);

% this one will be revomed
elseif strcmpi(obj.PlotOptions.TreatAs, 'streamtube')
Expand Down
166 changes: 166 additions & 0 deletions plotly/plotlyfig_aux/handlegraphics/updateConeplot.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
function obj = updateConeplot(obj, coneIndex)

%-AXIS INDEX-%
axIndex = obj.getAxisIndex(obj.State.Plot(coneIndex).AssociatedAxis);

%-CONE DATA STRUCTURE- %
cone_data = get(obj.State.Plot(coneIndex).Handle);

%-CHECK FOR MULTIPLE AXES-%
[xsource, ysource] = findSourceAxis(obj,axIndex);

%-SCENE DATA-%
eval(['scene = obj.layout.scene' num2str(xsource) ';']);

%-------------------------------------------------------------------------%

%-cone type-%
obj.data{coneIndex}.type = 'cone';

%-------------------------------------------------------------------------%

%-get plot data-%
xdata = cone_data.XData;
ydata = cone_data.YData;
zdata = cone_data.ZData;

%-------------------------------------------------------------------------%

%-reformat data-%
nfaces = size(xdata, 2);
ref = xdata(end,1);

for n=1:nfaces
if ref ~= xdata(end, n)
step1 = n-1;
break
end
end

ref = xdata(1,step1);

for n=step1:nfaces
if ref ~= xdata(1, n)
step2 = n-1;
break
end
end

x = []; y = []; z = [];
u = []; v = []; w = [];

for c = 1:step2:nfaces
xhead = xdata(end,c);
yhead = ydata(end,c);
zhead = zdata(end,c);

xtail = mean(xdata(2,c:c+step1-1));
ytail = mean(ydata(2,c:c+step1-1));
ztail = mean(zdata(2,c:c+step1-1));

u = [u; xhead - xtail];
v = [v; yhead - ytail];
w = [w; zhead - ztail];

% x = [x; xtail];
% y = [y; ytail];
% z = [z; ztail];

x = [x; 0.5*(xtail+xhead)];
y = [y; 0.5*(ytail+yhead)];
z = [z; 0.5*(ztail+zhead)];
end

%-------------------------------------------------------------------------%

%-set plot data-%
obj.data{coneIndex}.x = x;
obj.data{coneIndex}.y = y;
obj.data{coneIndex}.z = z;
obj.data{coneIndex}.u = u;
obj.data{coneIndex}.v = v;
obj.data{coneIndex}.w = w;

%-------------------------------------------------------------------------%

%-set cone color-%
obj.data{coneIndex}.colorscale{1} = {0, sprintf('rgb(%f,%f,%f)', cone_data.EdgeColor)};
obj.data{coneIndex}.colorscale{2} = {1, sprintf('rgb(%f,%f,%f)', cone_data.EdgeColor)};

%-------------------------------------------------------------------------%

%-plot setting-%
obj.data{coneIndex}.showscale = false;
obj.data{coneIndex}.sizemode = 'scaled';
obj.data{coneIndex}.sizeref = 1.5;

%-------------------------------------------------------------------------%

%-scene axis-%
scene.xaxis.tickvals = cone_data.Parent.XTick;
scene.xaxis.ticktext = cone_data.Parent.XTickLabel;
scene.yaxis.tickvals = cone_data.Parent.YTick;
scene.yaxis.ticktext = cone_data.Parent.YTickLabel;
scene.zaxis.range = cone_data.Parent.ZLim;
scene.zaxis.nticks = 10;

%---------------------------------------------------------------------%

%-aspect ratio-%
ar = obj.PlotOptions.AspectRatio;

if ~isempty(ar)
if ischar(ar)
scene.aspectmode = ar;
elseif isvector(ar) && length(ar) == 3
xar = ar(1);
yar = ar(2);
zar = ar(3);
end
else

%-define as default-%
xar = max(xdata(:));
yar = max(ydata(:));
xyar = min([xar, yar]);
xar = xyar;
yar = xyar;
zar = 0.7*xyar;
end

scene.aspectratio.x = xar;
scene.aspectratio.y = yar;
scene.aspectratio.z = zar;

%---------------------------------------------------------------------%

%-camera eye-%
ey = obj.PlotOptions.CameraEye;

if ~isempty(ey)
if isvector(ey) && length(ey) == 3
scene.camera.eye.x = ey(1);
scene.camera.eye.y = ey(2);
scene.camera.eye.z = ey(3);
end
else

%-define as default-%
xey = - xar; if xey>0 xfac = -0.2; else xfac = 0.2; end
yey = - yar; if yey>0 yfac = -0.2; else yfac = 0.2; end
if zar>0 zfac = 0.2; else zfac = -0.2; end

scene.camera.eye.x = xey + xfac*xey;
scene.camera.eye.y = yey + yfac*yey;
scene.camera.eye.z = zar + zfac*zar;
end

%---------------------------------------------------------------------%

%-set scene to layout-%
obj.layout = setfield(obj.layout,['scene' num2str(xsource)], scene);
obj.data{coneIndex}.scene = ['scene' num2str(xsource)];

%---------------------------------------------------------------------%

end