Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9298e52

Browse files
Merge pull request #328 from plotly/issue266
Issue266
2 parents 0c42866 + 9ae608f commit 9298e52

File tree

3 files changed

+135
-7
lines changed

3 files changed

+135
-7
lines changed

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
updateRectangle(obj,dataIndex);
3333
case 'surface'
3434
updateSurfaceplot(obj,dataIndex);
35+
case 'functionsurface'
36+
updateFunctionSurface(obj,dataIndex);
3537

3638
%-GROUP PLOT OBJECTS-%
3739
case 'area'
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
function obj = updateFunctionSurface(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+
%-surface x-%
35+
mden = image_data.MeshDensity;
36+
x = reshape(image_data.XData(1:mden*mden), [mden, mden]);
37+
obj.data{surfaceIndex}.x = x;
38+
39+
%---------------------------------------------------------------------%
40+
41+
%-surface y-%
42+
y = reshape(image_data.YData(1:mden*mden), [mden, mden]);
43+
obj.data{surfaceIndex}.y = y;
44+
45+
%---------------------------------------------------------------------%
46+
47+
%-surface z-%
48+
z = reshape(image_data.ZData(1:mden*mden), [mden, mden]);
49+
obj.data{surfaceIndex}.z = z;
50+
51+
%---------------------------------------------------------------------%
52+
53+
%- setting grid mesh by default -%
54+
% x-direction
55+
xmin = min(x(:));
56+
xmax = max(x(:));
57+
xsize = (xmax - xmin) / mden;
58+
obj.data{surfaceIndex}.contours.x.start = xmin;
59+
obj.data{surfaceIndex}.contours.x.end = xmax;
60+
obj.data{surfaceIndex}.contours.x.size = xsize;
61+
obj.data{surfaceIndex}.contours.x.show = true;
62+
obj.data{surfaceIndex}.contours.x.color = 'black';
63+
% y-direction
64+
ymin = min(y(:));
65+
ymax = max(y(:));
66+
ysize = (ymax - ymin) / mden;
67+
obj.data{surfaceIndex}.contours.y.start = ymin;
68+
obj.data{surfaceIndex}.contours.y.end = ymax;
69+
obj.data{surfaceIndex}.contours.y.size = ysize;
70+
obj.data{surfaceIndex}.contours.y.show = true;
71+
obj.data{surfaceIndex}.contours.y.color = 'black';
72+
73+
%-------------------------------------------------------------------------%
74+
75+
%-image colorscale-%
76+
77+
cmap = figure_data.Colormap;
78+
len = length(cmap)-1;
79+
80+
for c = 1: length(cmap)
81+
col = 255 * cmap(c, :);
82+
obj.data{surfaceIndex}.colorscale{c} = { (c-1)/len , ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')' ] };
83+
end
84+
85+
obj.data{surfaceIndex}.surfacecolor = z;
86+
87+
%-------------------------------------------------------------------------%
88+
89+
%-surface name-%
90+
obj.data{surfaceIndex}.name = image_data.DisplayName;
91+
92+
%-------------------------------------------------------------------------%
93+
94+
%-surface showscale-%
95+
obj.data{surfaceIndex}.showscale = false;
96+
97+
%-------------------------------------------------------------------------%
98+
99+
%-surface visible-%
100+
obj.data{surfaceIndex}.visible = strcmp(image_data.Visible,'on');
101+
102+
%-------------------------------------------------------------------------%
103+
104+
leg = get(image_data.Annotation);
105+
legInfo = get(leg.LegendInformation);
106+
107+
switch legInfo.IconDisplayStyle
108+
case 'on'
109+
showleg = true;
110+
case 'off'
111+
showleg = false;
112+
end
113+
114+
obj.data{surfaceIndex}.showlegend = showleg;
115+
116+
%-------------------------------------------------------------------------%
117+
118+
end

plotly/plotlyfig_aux/handlegraphics/updateImage.m

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,34 @@
6464
%-------------------------------------------------------------------------%
6565

6666
%-image x-%
67+
x = image_data.XData;
68+
cdata = image_data.CData;
69+
6770
if (size(image_data.XData,2) == 2)
68-
obj.data{imageIndex}.x = image_data.XData(1):image_data.XData(2);
71+
obj.data{imageIndex}.x = linspace(x(1), x(2), size(cdata,2));
6972
else
7073
obj.data{imageIndex}.x = image_data.XData;
7174
end
7275

7376
%-------------------------------------------------------------------------%
7477

7578
%-image y-%
79+
y = image_data.YData;
80+
7681
if (size(image_data.YData,2) == 2)
77-
obj.data{imageIndex}.y = image_data.YData(1):image_data.YData(2);
82+
obj.data{imageIndex}.y = linspace(y(1), y(2), size(cdata,1));
7883
else
79-
obj.data{imageIndex}.y = image_data.YData;
84+
obj.data{imageIndex}.y = y;
8085
end
8186

8287
%-------------------------------------------------------------------------%
8388

8489
%-image z-%
8590
if(size(image_data.CData,3) > 1)
8691
% TODO: ALLOW FOR TRUE COLOUR SPECS.
87-
obj.data{imageIndex}.z = image_data.CData(:,:,1);
92+
obj.data{imageIndex}.z = cdata(:,:,1);
8893
else
89-
obj.data{imageIndex}.z = image_data.CData;
94+
obj.data{imageIndex}.z = cdata;
9095
end
9196

9297
%-------------------------------------------------------------------------%
@@ -121,8 +126,11 @@
121126
%-------------------------------------------------------------------------%
122127

123128
%-image zmax-%
124-
axis_data.CLim(2);
125-
% obj.data{imageIndex}.zmax = 255; % comment this as optional
129+
if ~strcmpi(image_data.CDataMapping, 'direct')
130+
obj.data{imageIndex}.zmax = axis_data.CLim(2);
131+
else
132+
obj.data{imageIndex}.zmax = 255;
133+
end
126134

127135
%-------------------------------------------------------------------------%
128136

0 commit comments

Comments
 (0)