Skip to content

Issue284 fixed #346

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
merged 3 commits into from
Aug 18, 2021
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
1 change: 1 addition & 0 deletions plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
obj.PlotOptions.TriangulatePatch = false;
obj.PlotOptions.StripMargins = false;
obj.PlotOptions.TreatAs = '_';
obj.PlotOptions.Image3D = false;

% offline options
obj.PlotOptions.Offline = true;
Expand Down
6 changes: 5 additions & 1 deletion plotly/plotlyfig_aux/core/updateData.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
case 'heatmap'
updateHeatmap(obj, dataIndex);
case 'image'
updateImage(obj, dataIndex);
if ~obj.PlotOptions.Image3D
updateImage(obj, dataIndex);
else
updateImage3D(obj, dataIndex);
end
case 'line'
updateLineseries(obj, dataIndex);
case 'categoricalhistogram'
Expand Down
197 changes: 197 additions & 0 deletions plotly/plotlyfig_aux/handlegraphics/updateImage3D.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
function obj = updateImage3D(obj, imageIndex)

% AS SURFACE
% z: ...[DONE]
% x: ...[DONE]
% y: ...[DONE]
% name: ...[DONE]
% zauto: ...[DONE]
% zmin: ...[DONE]
% zmax: ...[DONE]
% colorscale: ...[DONE]
% reversescale: ...[DONE]
% showscale: ...[DONE]
% colorbar: ...[HANDLED BY COLORBAR]
% zsmooth: ...[NOT SUPPORTED BY MATLAB]
% opacity: ---[TODO]
% xaxis: ...[DONE]
% yaxis: ...[DONE]
% showlegend: ...[DONE]
% stream: ...[HANDLED BY PLOTLYSTREAM]
% visible: ...[DONE]
% x0: ...[NOT SUPPORTED IN MATLAB]
% dx: ...[NOT SUPPORTED IN MATLAB]
% y0: ...[NOT SUPPORTED IN MATLAB]
% dy: ...[NOT SUPPORTED IN MATLAB]
% xtype: ...[NOT SUPPORTED IN MATLAB]
% ytype: ...[NOT SUPPORTED IN MATLAB]
% type: ...[DONE]

%-FIGURE STRUCTURE-%
figure_data = get(obj.State.Figure.Handle);

%-AXIS STRUCTURE-%
axis_data = get(obj.State.Plot(imageIndex).AssociatedAxis);

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

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

%-IMAGE DATA STRUCTURE- %
image_data = get(obj.State.Plot(imageIndex).Handle);

%-AXIS DATA-%
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);

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

%-image xaxis-%
obj.data{imageIndex}.xaxis = ['x' num2str(xsource)];

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

%-image yaxis-%
obj.data{imageIndex}.yaxis = ['y' num2str(ysource)];

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

%-image type-%
obj.data{imageIndex}.type = 'surface';

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

%-format x an y data-%
x = image_data.XData;
y = image_data.YData;
cdata = image_data.CData;

if isvector(x)
if size(x,2) == 2
x = linspace(x(1), x(2), size(cdata,2));
end

if size(y,2) == 2
y = linspace(y(1), y(2), size(cdata,1));
end

[x, y] = meshgrid(x, y);
end

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

%-surface x-%
obj.data{imageIndex}.x = x;

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

%-surface x-%
obj.data{imageIndex}.y = y;

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

%-surface z-%
isrgbimg = (size(image_data.CData,3) > 1);

if isrgbimg
[IND,colormap] = rgb2ind(cdata, 256);
obj.data{imageIndex}.z = IND;
else
obj.data{imageIndex}.z = zeros(size(cdata));
end

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

%-surface coloring-%
obj.data{imageIndex}.surfacecolor = cdata;

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

%-surface setting-%
obj.layout.scene.aspectmode = 'cube';

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

%-image name-%
try
obj.data{imageIndex}.name = image_data.DisplayName;
catch
obj.data{imageIndex}.name = '';
end

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

%-set the opacity-%
obj.data{imageIndex}.opacity = image_data.AlphaData;

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

%-image visible-%
obj.data{imageIndex}.visible = strcmp(image_data.Visible,'on');

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

%-image showscale-%
obj.data{imageIndex}.showscale = false;

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

%-image zauto-%
obj.data{imageIndex}.zauto = false;

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

%-image zmin-%
obj.data{imageIndex}.zmin = axis_data.CLim(1);

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

%-image zmax-%
if ~strcmpi(image_data.CDataMapping, 'direct')
obj.data{imageIndex}.zmax = axis_data.CLim(2);
else
obj.data{imageIndex}.zmax = 255;
end

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

%-COLORSCALE (ASSUMES IMAGE CDATAMAP IS 'SCALED')-%

%-image colorscale-%

if ~isrgbimg
colormap = figure_data.Colormap;
end

len = length(colormap) - 1;

for c = 1:size(colormap, 1)
col = 255*(colormap(c,:));
obj.data{imageIndex}.colorscale{c} = {(c-1)/len, ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']};
end

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

%-image showlegend-%
try
leg = get(image_data.Annotation);
legInfo = get(leg.LegendInformation);

switch legInfo.IconDisplayStyle
case 'on'
showleg = true;
case 'off'
showleg = false;
end

obj.data{imageIndex}.showlegend = showleg;
catch
%TODO to future
end

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

end

38 changes: 29 additions & 9 deletions plotly/plotlyfig_aux/handlegraphics/updateSurfaceplot.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,57 @@
% check for 3D
if any(nonzeros(image_data.ZData))

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

%-surface type-%
obj.data{surfaceIndex}.type = 'surface';

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

%-format x an y data-%
x = image_data.XData;
y = image_data.YData;
cdata = image_data.CData;
if isvector(x)
[x, y] = meshgrid(x,y);
end

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

%-surface x-%
obj.data{surfaceIndex}.x = image_data.XData;
obj.data{surfaceIndex}.x = x;

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

%-surface y-%
obj.data{surfaceIndex}.y = image_data.YData;
obj.data{surfaceIndex}.y = y;

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

%-surface z-%
obj.data{surfaceIndex}.z = image_data.ZData;

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

%-if image comes would a 3D plot-%
obj.PlotOptions.Image3D = true;

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

%- setting grid mesh by default -%
% x-direction
xmin = min(image_data.XData(:));
xmax = max(image_data.XData(:));
xsize = (xmax - xmin) / (size(image_data.XData, 2) - 1);
xmin = min(x(:));
xmax = max(x(:));
xsize = (xmax - xmin) / (size(x, 2));
obj.data{surfaceIndex}.contours.x.start = xmin;
obj.data{surfaceIndex}.contours.x.end = xmax;
obj.data{surfaceIndex}.contours.x.size = xsize;
obj.data{surfaceIndex}.contours.x.show = true;
obj.data{surfaceIndex}.contours.x.color = 'black';
% y-direction
ymin = min(image_data.YData(:));
ymax = max(image_data.YData(:));
ysize = (ymax - ymin) / (size(image_data.YData, 2));
ymin = min(y(:));
ymax = max(y(:));
ysize = (ymax - ymin) / (size(y, 1));
obj.data{surfaceIndex}.contours.y.start = ymin;
obj.data{surfaceIndex}.contours.y.end = ymax;
obj.data{surfaceIndex}.contours.y.size = ysize;
Expand Down Expand Up @@ -94,7 +111,10 @@
obj.data{surfaceIndex}.colorscale{c} = { (c-1)/len , ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')' ] };
end

obj.data{surfaceIndex}.surfacecolor = image_data.CData;
%-------------------------------------------------------------------------%

%-surface coloring-%
obj.data{surfaceIndex}.surfacecolor = cdata;

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

Expand Down