Skip to content

Commit b668260

Browse files
Refactor updateSurfaceplot
1 parent cb50cfe commit b668260

File tree

4 files changed

+69
-95
lines changed

4 files changed

+69
-95
lines changed

plotly/Test_plotlyfig.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ function testSurfacePlotData(tc)
280280
tc.verifyEqual(rmfield(p.data{1}, ["colorscale" "surfacecolor"]), struct( ...
281281
"xaxis", "x1", ...
282282
"yaxis", "y1", ...
283-
"type", 'surface', ...
283+
"type", "surface", ...
284284
"x", x, ...
285285
"y", y, ...
286286
"z", z, ...
@@ -290,14 +290,14 @@ function testSurfacePlotData(tc)
290290
"end", 2, ...
291291
"size", 0.102564102564103, ...
292292
"show", true, ...
293-
"color", 'black' ...
293+
"color", "black" ...
294294
), ...
295295
"y", struct( ...
296296
"start", -2, ...
297297
"end", 2, ...
298298
"size", 0.102564102564103, ...
299299
"show", true, ...
300-
"color", 'black' ...
300+
"color", "black" ...
301301
) ...
302302
), ...
303303
"name", '', ...

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
updateHeatmap(obj, dataIndex);
4747
case "image"
4848
if ~obj.PlotOptions.Image3D
49-
updateImage(obj, dataIndex);
49+
obj.data{dataIndex} = updateImage(obj, dataIndex);
5050
else
5151
updateImage3D(obj, dataIndex);
5252
end
@@ -95,7 +95,7 @@
9595
elseif ismember("slice", lower(obj.PlotOptions.TreatAs))
9696
updateSlice(obj, dataIndex);
9797
else
98-
updateSurfaceplot(obj,dataIndex);
98+
obj.data{dataIndex} = updateSurfaceplot(obj,dataIndex);
9999
end
100100
case {"functionsurface", "parameterizedfunctionsurface"}
101101
updateFunctionSurface(obj,dataIndex);
@@ -155,7 +155,7 @@
155155
case "stemseries"
156156
updateStemseries(obj, dataIndex);
157157
case "surfaceplot"
158-
updateSurfaceplot(obj,dataIndex);
158+
obj.data{dataIndex} = updateSurfaceplot(obj,dataIndex);
159159
case "implicitfunctionline"
160160
obj.data{dataIndex} = updateLineseries(obj, dataIndex);
161161
%--Plotly supported MATLAB group plot objects--%

plotly/plotlyfig_aux/handlegraphics/updateImage.m

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function obj = updateImage(obj, imageIndex)
1+
function data = updateImage(obj, imageIndex)
22
% HEATMAPS
33
% z: ...[DONE]
44
% x: ...[DONE]
@@ -33,71 +33,61 @@
3333
axis_data = obj.State.Plot(imageIndex).AssociatedAxis;
3434

3535
%-AXIS INDEX-%
36-
axIndex = obj.getAxisIndex(obj.State.Plot(imageIndex).AssociatedAxis);
36+
axIndex = obj.getAxisIndex(axis_data);
3737

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

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

44-
obj.data{imageIndex}.xaxis = "x" + xsource;
45-
obj.data{imageIndex}.yaxis = "y" + ysource;
46-
obj.data{imageIndex}.type = 'heatmap';
44+
data.xaxis = "x" + xsource;
45+
data.yaxis = "y" + ysource;
46+
data.type = 'heatmap';
4747

48-
%-image x-%
4948
x = image_data.XData;
5049
cdata = image_data.CData;
51-
5250
if (size(image_data.XData,2) == 2)
53-
obj.data{imageIndex}.x = linspace(x(1), x(2), size(cdata,2));
51+
data.x = linspace(x(1), x(2), size(cdata,2));
5452
else
55-
obj.data{imageIndex}.x = image_data.XData;
53+
data.x = image_data.XData;
5654
end
5755

58-
%-image y-%
5956
y = image_data.YData;
60-
6157
if (size(image_data.YData,2) == 2)
62-
obj.data{imageIndex}.y = linspace(y(1), y(2), size(cdata,1));
58+
data.y = linspace(y(1), y(2), size(cdata,1));
6359
else
64-
obj.data{imageIndex}.y = y;
60+
data.y = y;
6561
end
6662

67-
%-image z-%
6863
isrgbimg = (size(image_data.CData,3) > 1);
69-
7064
if isrgbimg
7165
[IND,colormap] = rgb2ind(cdata, 256);
72-
obj.data{imageIndex}.z = IND;
66+
data.z = IND;
7367
else
74-
obj.data{imageIndex}.z = cdata;
68+
data.z = cdata;
7569
end
7670

77-
%-image name-%
7871
if isprop(image_data, "DisplayName")
79-
obj.data{imageIndex}.name = image_data.DisplayName;
72+
data.name = image_data.DisplayName;
8073
else
81-
obj.data{imageIndex}.name = '';
74+
data.name = '';
8275
end
8376

84-
obj.data{imageIndex}.opacity = image_data.AlphaData;
85-
obj.data{imageIndex}.visible = strcmp(image_data.Visible, 'on');
86-
obj.data{imageIndex}.showscale = false;
87-
obj.data{imageIndex}.zauto = false;
88-
obj.data{imageIndex}.zmin = axis_data.CLim(1);
77+
data.opacity = image_data.AlphaData;
78+
data.visible = image_data.Visible == "on";
79+
data.showscale = false;
80+
data.zauto = false;
81+
data.zmin = axis_data.CLim(1);
8982

90-
%-image zmax-%
91-
if ~strcmpi(image_data.CDataMapping, 'direct')
92-
obj.data{imageIndex}.zmax = axis_data.CLim(2);
83+
if lower(image_data.CDataMapping) ~= "direct"
84+
data.zmax = axis_data.CLim(2);
9385
else
94-
obj.data{imageIndex}.zmax = 255;
86+
data.zmax = 255;
9587
end
9688

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

99-
%-image colorscale-%
100-
10191
if ~isrgbimg
10292
colormap = figure_data.Colormap;
10393
end
@@ -106,21 +96,16 @@
10696

10797
for c = 1:size(colormap, 1)
10898
col = round(255*(colormap(c,:)));
109-
obj.data{imageIndex}.colorscale{c} = ...
110-
{(c-1)/len, sprintf("rgb(%d,%d,%d)", col)};
99+
data.colorscale{c} = {(c-1)/len, getStringColor(col)};
111100
end
112101

113-
%-image showlegend-%
114102
try
115-
leg = image_data.Annotation;
116-
legInfo = leg.LegendInformation;
117-
switch legInfo.IconDisplayStyle
118-
case 'on'
119-
showleg = true;
120-
case 'off'
121-
showleg = false;
103+
switch image_data.Annotation.LegendInformation.IconDisplayStyle
104+
case "on"
105+
data.showlegend = true;
106+
case "off"
107+
data.showlegend = false;
122108
end
123-
obj.data{imageIndex}.showlegend = showleg;
124109
catch
125110
%TODO to future
126111
end
Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function obj = updateSurfaceplot(obj, surfaceIndex)
1+
function data = updateSurfaceplot(obj, surfaceIndex)
22
%-AXIS INDEX-%
33
axIndex = obj.getAxisIndex(obj.State.Plot(surfaceIndex).AssociatedAxis);
44

@@ -10,13 +10,12 @@
1010
figure_data = obj.State.Figure.Handle;
1111

1212
%-surface xaxis and yaxis-%
13-
obj.data{surfaceIndex}.xaxis = "x" + xsource;
14-
obj.data{surfaceIndex}.yaxis = "y" + ysource;
13+
data.xaxis = "x" + xsource;
14+
data.yaxis = "y" + ysource;
1515

1616
% check for 3D
1717
if any(nonzeros(image_data.ZData))
18-
%-surface type-%
19-
obj.data{surfaceIndex}.type = 'surface';
18+
data.type = "surface";
2019

2120
%-format x an y data-%
2221
x = image_data.XData;
@@ -26,61 +25,51 @@
2625
[x, y] = meshgrid(x,y);
2726
end
2827

29-
obj.data{surfaceIndex}.x = x;
30-
obj.data{surfaceIndex}.y = y;
31-
obj.data{surfaceIndex}.z = image_data.ZData;
28+
data.x = x;
29+
data.y = y;
30+
data.z = image_data.ZData;
3231
obj.PlotOptions.Image3D = true;
3332
obj.PlotOptions.ContourProjection = true;
3433

35-
%- setting grid mesh by default -%
36-
% x-direction
37-
xmin = min(x(:));
38-
xmax = max(x(:));
39-
xsize = (xmax - xmin) / (size(x, 2)-1);
40-
obj.data{surfaceIndex}.contours.x.start = xmin;
41-
obj.data{surfaceIndex}.contours.x.end = xmax;
42-
obj.data{surfaceIndex}.contours.x.size = xsize;
43-
obj.data{surfaceIndex}.contours.x.show = true;
44-
obj.data{surfaceIndex}.contours.x.color = 'black';
45-
% y-direction
46-
ymin = min(y(:));
47-
ymax = max(y(:));
48-
ysize = (ymax - ymin) / (size(y, 1)-1);
49-
obj.data{surfaceIndex}.contours.y.start = ymin;
50-
obj.data{surfaceIndex}.contours.y.end = ymax;
51-
obj.data{surfaceIndex}.contours.y.size = ysize;
52-
obj.data{surfaceIndex}.contours.y.show = true;
53-
obj.data{surfaceIndex}.contours.y.color = 'black';
34+
data.contours = struct( ...
35+
"x", struct( ...
36+
"start", min(x(:)), ...
37+
"end", max(x(:)), ...
38+
"size", rangeLength(x(:)) / (size(x, 2)-1), ...
39+
"show", true, ...
40+
"color", "black" ...
41+
), ...
42+
"y", struct( ...
43+
"start", min(y(:)), ...
44+
"end", max(y(:)), ...
45+
"size", rangeLength(y(:)) / (size(y, 1)-1), ...
46+
"show", true, ...
47+
"color", "black" ...
48+
) ...
49+
);
5450
else
55-
%-surface type-%
56-
obj = updateImage(obj, surfaceIndex);
57-
58-
obj.data{surfaceIndex}.x = image_data.XData(1,:);
59-
obj.data{surfaceIndex}.y = image_data.YData(:,1);
51+
data = updateImage(obj, surfaceIndex);
52+
data.x = image_data.XData(1,:);
53+
data.y = image_data.YData(:,1);
6054
end
6155

62-
%-image colorscale-%
6356
cmap = figure_data.Colormap;
6457
len = length(cmap)-1;
6558

6659
for c = 1: length(cmap)
6760
col = round(255 * cmap(c, :));
68-
obj.data{surfaceIndex}.colorscale{c} = ...
69-
{(c-1)/len, sprintf("rgb(%d,%d,%d)", col)};
61+
data.colorscale{c} = {(c-1)/len, getStringColor(col)};
7062
end
7163

72-
obj.data{surfaceIndex}.surfacecolor = cdata;
73-
obj.data{surfaceIndex}.name = image_data.DisplayName;
74-
obj.data{surfaceIndex}.showscale = false;
75-
obj.data{surfaceIndex}.visible = strcmp(image_data.Visible,'on');
64+
data.surfacecolor = cdata;
65+
data.name = image_data.DisplayName;
66+
data.showscale = false;
67+
data.visible = image_data.Visible == "on";
7668

77-
leg = image_data.Annotation;
78-
legInfo = leg.LegendInformation;
79-
switch legInfo.IconDisplayStyle
80-
case 'on'
81-
showleg = true;
82-
case 'off'
83-
showleg = false;
69+
switch image_data.Annotation.LegendInformation.IconDisplayStyle
70+
case "on"
71+
data.showlegend = true;
72+
case "off"
73+
data.showlegend = false;
8474
end
85-
obj.data{surfaceIndex}.showlegend = showleg;
8675
end

0 commit comments

Comments
 (0)