Skip to content

Commit 276db0f

Browse files
fix issue #284
1 parent e6f63e4 commit 276db0f

File tree

4 files changed

+232
-10
lines changed

4 files changed

+232
-10
lines changed

plotly/plotlyfig.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
obj.PlotOptions.TriangulatePatch = false;
6262
obj.PlotOptions.StripMargins = false;
6363
obj.PlotOptions.TreatAs = '_';
64+
obj.PlotOptions.Image3D = false;
6465

6566
% offline options
6667
obj.PlotOptions.Offline = true;

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
case 'heatmap'
2626
updateHeatmap(obj, dataIndex);
2727
case 'image'
28-
updateImage(obj, dataIndex);
28+
if ~obj.PlotOptions.Image3D
29+
updateImage(obj, dataIndex);
30+
else
31+
updateImage3D(obj, dataIndex);
32+
end
2933
case 'line'
3034
updateLineseries(obj, dataIndex);
3135
case 'categoricalhistogram'
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
function obj = updateImage3D(obj, imageIndex)
2+
3+
% AS SURFACE
4+
% z: ...[DONE]
5+
% x: ...[DONE]
6+
% y: ...[DONE]
7+
% name: ...[DONE]
8+
% zauto: ...[DONE]
9+
% zmin: ...[DONE]
10+
% zmax: ...[DONE]
11+
% colorscale: ...[DONE]
12+
% reversescale: ...[DONE]
13+
% showscale: ...[DONE]
14+
% colorbar: ...[HANDLED BY COLORBAR]
15+
% zsmooth: ...[NOT SUPPORTED BY MATLAB]
16+
% opacity: ---[TODO]
17+
% xaxis: ...[DONE]
18+
% yaxis: ...[DONE]
19+
% showlegend: ...[DONE]
20+
% stream: ...[HANDLED BY PLOTLYSTREAM]
21+
% visible: ...[DONE]
22+
% x0: ...[NOT SUPPORTED IN MATLAB]
23+
% dx: ...[NOT SUPPORTED IN MATLAB]
24+
% y0: ...[NOT SUPPORTED IN MATLAB]
25+
% dy: ...[NOT SUPPORTED IN MATLAB]
26+
% xtype: ...[NOT SUPPORTED IN MATLAB]
27+
% ytype: ...[NOT SUPPORTED IN MATLAB]
28+
% type: ...[DONE]
29+
30+
%-FIGURE STRUCTURE-%
31+
figure_data = get(obj.State.Figure.Handle);
32+
33+
%-AXIS STRUCTURE-%
34+
axis_data = get(obj.State.Plot(imageIndex).AssociatedAxis);
35+
36+
%-AXIS INDEX-%
37+
axIndex = obj.getAxisIndex(obj.State.Plot(imageIndex).AssociatedAxis);
38+
39+
%-CHECK FOR MULTIPLE AXES-%
40+
[xsource, ysource] = findSourceAxis(obj,axIndex);
41+
42+
%-IMAGE DATA STRUCTURE- %
43+
image_data = get(obj.State.Plot(imageIndex).Handle);
44+
45+
%-AXIS DATA-%
46+
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
47+
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
48+
49+
%-------------------------------------------------------------------------%
50+
51+
%-image xaxis-%
52+
obj.data{imageIndex}.xaxis = ['x' num2str(xsource)];
53+
54+
%-------------------------------------------------------------------------%
55+
56+
%-image yaxis-%
57+
obj.data{imageIndex}.yaxis = ['y' num2str(ysource)];
58+
59+
%-------------------------------------------------------------------------%
60+
61+
%-image type-%
62+
obj.data{imageIndex}.type = 'surface';
63+
64+
%-------------------------------------------------------------------------%
65+
66+
%-format x an y data-%
67+
x = image_data.XData;
68+
y = image_data.YData;
69+
cdata = image_data.CData;
70+
71+
if isvector(x)
72+
if size(x,2) == 2
73+
x = linspace(x(1), x(2), size(cdata,2));
74+
end
75+
76+
if size(y,2) == 2
77+
y = linspace(y(1), y(2), size(cdata,1));
78+
end
79+
80+
[x, y] = meshgrid(x, y);
81+
end
82+
83+
%-------------------------------------------------------------------------%
84+
85+
%-surface x-%
86+
obj.data{imageIndex}.x = x;
87+
88+
%-------------------------------------------------------------------------%
89+
90+
%-surface x-%
91+
obj.data{imageIndex}.y = y;
92+
93+
%-------------------------------------------------------------------------%
94+
95+
%-surface z-%
96+
isrgbimg = (size(image_data.CData,3) > 1);
97+
98+
if isrgbimg
99+
[IND,colormap] = rgb2ind(cdata, 256);
100+
obj.data{imageIndex}.z = IND;
101+
else
102+
obj.data{imageIndex}.z = zeros(size(cdata));
103+
end
104+
105+
%-------------------------------------------------------------------------%
106+
107+
%-surface coloring-%
108+
obj.data{imageIndex}.surfacecolor = cdata;
109+
110+
%-------------------------------------------------------------------------%
111+
112+
%-surface setting-%
113+
obj.layout.scene.aspectmode = 'cube';
114+
115+
%-------------------------------------------------------------------------%
116+
117+
%-image name-%
118+
try
119+
obj.data{imageIndex}.name = image_data.DisplayName;
120+
catch
121+
obj.data{imageIndex}.name = '';
122+
end
123+
124+
%-------------------------------------------------------------------------%
125+
126+
%-set the opacity-%
127+
obj.data{imageIndex}.opacity = image_data.AlphaData;
128+
129+
%-------------------------------------------------------------------------%
130+
131+
%-image visible-%
132+
obj.data{imageIndex}.visible = strcmp(image_data.Visible,'on');
133+
134+
%-------------------------------------------------------------------------%
135+
136+
%-image showscale-%
137+
obj.data{imageIndex}.showscale = false;
138+
139+
%-------------------------------------------------------------------------%
140+
141+
%-image zauto-%
142+
obj.data{imageIndex}.zauto = false;
143+
144+
%-------------------------------------------------------------------------%
145+
146+
%-image zmin-%
147+
obj.data{imageIndex}.zmin = axis_data.CLim(1);
148+
149+
%-------------------------------------------------------------------------%
150+
151+
%-image zmax-%
152+
if ~strcmpi(image_data.CDataMapping, 'direct')
153+
obj.data{imageIndex}.zmax = axis_data.CLim(2);
154+
else
155+
obj.data{imageIndex}.zmax = 255;
156+
end
157+
158+
%-------------------------------------------------------------------------%
159+
160+
%-COLORSCALE (ASSUMES IMAGE CDATAMAP IS 'SCALED')-%
161+
162+
%-image colorscale-%
163+
164+
if ~isrgbimg
165+
colormap = figure_data.Colormap;
166+
end
167+
168+
len = length(colormap) - 1;
169+
170+
for c = 1:size(colormap, 1)
171+
col = 255*(colormap(c,:));
172+
obj.data{imageIndex}.colorscale{c} = {(c-1)/len, ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']};
173+
end
174+
175+
%-------------------------------------------------------------------------%
176+
177+
%-image showlegend-%
178+
try
179+
leg = get(image_data.Annotation);
180+
legInfo = get(leg.LegendInformation);
181+
182+
switch legInfo.IconDisplayStyle
183+
case 'on'
184+
showleg = true;
185+
case 'off'
186+
showleg = false;
187+
end
188+
189+
obj.data{imageIndex}.showlegend = showleg;
190+
catch
191+
%TODO to future
192+
end
193+
194+
%-------------------------------------------------------------------------%
195+
196+
end
197+

plotly/plotlyfig_aux/handlegraphics/updateSurfaceplot.m

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,57 @@
2929
% check for 3D
3030
if any(nonzeros(image_data.ZData))
3131

32+
%---------------------------------------------------------------------%
33+
3234
%-surface type-%
3335
obj.data{surfaceIndex}.type = 'surface';
3436

3537
%---------------------------------------------------------------------%
3638

39+
%-format x an y data-%
40+
x = image_data.XData;
41+
y = image_data.YData;
42+
cdata = image_data.CData;
43+
if isvector(x)
44+
[x, y] = meshgrid(x,y);
45+
end
46+
47+
%---------------------------------------------------------------------%
48+
3749
%-surface x-%
38-
obj.data{surfaceIndex}.x = image_data.XData;
50+
obj.data{surfaceIndex}.x = x;
3951

4052
%---------------------------------------------------------------------%
4153

4254
%-surface y-%
43-
obj.data{surfaceIndex}.y = image_data.YData;
55+
obj.data{surfaceIndex}.y = y;
4456

4557
%---------------------------------------------------------------------%
4658

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

62+
%---------------------------------------------------------------------%
63+
64+
%-if image comes would a 3D plot-%
65+
obj.PlotOptions.Image3D = true;
66+
5067
%---------------------------------------------------------------------%
5168

5269
%- setting grid mesh by default -%
5370
% x-direction
54-
xmin = min(image_data.XData(:));
55-
xmax = max(image_data.XData(:));
56-
xsize = (xmax - xmin) / (size(image_data.XData, 2) - 1);
71+
xmin = min(x(:));
72+
xmax = max(x(:));
73+
xsize = (xmax - xmin) / (size(x, 2));
5774
obj.data{surfaceIndex}.contours.x.start = xmin;
5875
obj.data{surfaceIndex}.contours.x.end = xmax;
5976
obj.data{surfaceIndex}.contours.x.size = xsize;
6077
obj.data{surfaceIndex}.contours.x.show = true;
6178
obj.data{surfaceIndex}.contours.x.color = 'black';
6279
% y-direction
63-
ymin = min(image_data.YData(:));
64-
ymax = max(image_data.YData(:));
65-
ysize = (ymax - ymin) / (size(image_data.YData, 2));
80+
ymin = min(y(:));
81+
ymax = max(y(:));
82+
ysize = (ymax - ymin) / (size(y, 1));
6683
obj.data{surfaceIndex}.contours.y.start = ymin;
6784
obj.data{surfaceIndex}.contours.y.end = ymax;
6885
obj.data{surfaceIndex}.contours.y.size = ysize;
@@ -94,7 +111,10 @@
94111
obj.data{surfaceIndex}.colorscale{c} = { (c-1)/len , ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')' ] };
95112
end
96113

97-
obj.data{surfaceIndex}.surfacecolor = image_data.CData;
114+
%-------------------------------------------------------------------------%
115+
116+
%-surface coloring-%
117+
obj.data{surfaceIndex}.surfacecolor = cdata;
98118

99119
%-------------------------------------------------------------------------%
100120

0 commit comments

Comments
 (0)