Skip to content

Commit efa4e91

Browse files
Refactor updateFunctionContour
1 parent b0ac865 commit efa4e91

File tree

3 files changed

+65
-92
lines changed

3 files changed

+65
-92
lines changed

plotly/Test_plotlyfig.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,16 +769,16 @@ function testFunctionContourPlotData(tc)
769769
"xaxis", "x1", ...
770770
"yaxis", "y1", ...
771771
"name", '{sin}({3} {x}) {cos}({x}+{y})', ...
772-
"type", 'contour', ...
772+
"type", "contour", ...
773773
"visible", true, ...
774-
"xtype", 'array', ...
775-
"ytype", 'array', ...
774+
"xtype", "array", ...
775+
"ytype", "array", ...
776776
"autocontour", false, ...
777777
"contours", struct( ...
778778
"start", -1, ...
779779
"end", 0.8, ...
780780
"size", 0.2, ...
781-
"coloring", 'fill' ...
781+
"coloring", "fill" ...
782782
), ...
783783
"zauto", false, ...
784784
"zmin", -1, ...
@@ -787,7 +787,7 @@ function testFunctionContourPlotData(tc)
787787
"reversescale", false, ...
788788
"line", struct( ...
789789
"width", 0.5, ...
790-
"dash", 'solid', ...
790+
"dash", "solid", ...
791791
"color", "rgb(0,0,0)", ...
792792
"smoothing", 0 ...
793793
), ...

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
updateContourgroup(obj,dataIndex);
124124
end
125125
case "functioncontour"
126-
updateFunctionContour(obj,dataIndex);
126+
obj.data{dataIndex} = updateFunctionContour(obj,dataIndex);
127127
case "errorbar"
128128
updateErrorbar(obj,dataIndex);
129129
case "errorbarseries"
Lines changed: 59 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,62 @@
1-
function obj = updateFunctionContour(obj,contourIndex)
1+
function data = updateFunctionContour(obj,contourIndex)
22
%-FIGURE DATA STRUCTURE-%
33
figure_data = obj.State.Figure.Handle;
44

5-
%-AXIS INDEX-%
65
axIndex = obj.getAxisIndex(obj.State.Plot(contourIndex).AssociatedAxis);
7-
8-
%-AXIS DATA STRUCTURE-%
96
axis_data = obj.State.Plot(contourIndex).AssociatedAxis;
10-
11-
%-PLOT DATA STRUCTURE- %
127
contour_data = obj.State.Plot(contourIndex).Handle;
13-
14-
%-CHECK FOR MULTIPLE AXES-%
158
[xsource, ysource] = findSourceAxis(obj,axIndex);
169

17-
obj.data{contourIndex}.xaxis = "x" + xsource;
18-
obj.data{contourIndex}.yaxis = "y" + ysource;
19-
obj.data{contourIndex}.name = contour_data.DisplayName;
20-
obj.data{contourIndex}.type = 'contour';
10+
data.xaxis = "x" + xsource;
11+
data.yaxis = "y" + ysource;
12+
data.name = contour_data.DisplayName;
13+
data.type = "contour";
2114

22-
%-setting the plot-%
2315
xdata = contour_data.XData;
2416
ydata = contour_data.YData;
2517
zdata = contour_data.ZData;
2618

27-
%-contour x data-%
2819
if ~isvector(xdata)
29-
obj.data{contourIndex}.x = xdata(1,:);
20+
data.x = xdata(1,:);
3021
else
31-
obj.data{contourIndex}.x = xdata;
22+
data.x = xdata;
3223
end
3324

34-
%-contour y data-%
3525
if ~isvector(ydata)
36-
obj.data{contourIndex}.y = ydata(:,1);
26+
data.y = ydata(:,1);
3727
else
38-
obj.data{contourIndex}.y = ydata;
28+
data.y = ydata;
3929
end
4030

41-
%-contour z data-%
42-
obj.data{contourIndex}.z = zdata;
31+
data.z = zdata;
4332

44-
obj.data{contourIndex}.xtype = 'array';
45-
obj.data{contourIndex}.ytype = 'array';
46-
obj.data{contourIndex}.visible = strcmp(contour_data.Visible,'on');
47-
obj.data{contourIndex}.showscale = false;
48-
obj.data{contourIndex}.zauto = false;
49-
obj.data{contourIndex}.zmin = axis_data.CLim(1);
50-
obj.data{contourIndex}.zmax = axis_data.CLim(2);
33+
data.xtype = "array";
34+
data.ytype = "array";
35+
data.visible = contour_data.Visible == "on";
36+
data.showscale = false;
37+
data.zauto = false;
38+
data.zmin = axis_data.CLim(1);
39+
data.zmax = axis_data.CLim(2);
5140

5241
%-colorscale (ASSUMES PATCH CDATAMAP IS 'SCALED')-%
5342
colormap = figure_data.Colormap;
5443

5544
for c = 1:size((colormap),1)
5645
col = round(255*(colormap(c,:)));
57-
obj.data{contourIndex}.colorscale{c} = ...
58-
{(c-1)/(size(colormap,1)-1), sprintf("rgb(%d,%d,%d)", col)};
46+
data.colorscale{c} = ...
47+
{(c-1)/(size(colormap,1)-1), getStringColor(col)};
5948
end
6049

61-
obj.data{contourIndex}.reversescale = false;
62-
obj.data{contourIndex}.autocontour = false;
50+
data.reversescale = false;
51+
data.autocontour = false;
6352

64-
%-contour contours-%
65-
66-
%-coloring-%
6753
switch contour_data.Fill
68-
case 'off'
69-
obj.data{contourIndex}.contours.coloring = 'lines';
70-
case 'on'
71-
obj.data{contourIndex}.contours.coloring = 'fill';
54+
case "off"
55+
data.contours.coloring = "lines";
56+
case "on"
57+
data.contours.coloring = "fill";
7258
end
7359

74-
%-contour levels-%
7560
if length(contour_data.LevelList) > 1
7661
cstart = contour_data.LevelList(1);
7762
cend = contour_data.LevelList(end);
@@ -82,63 +67,51 @@
8267
csize = 2e-3;
8368
end
8469

85-
%-start-%
86-
obj.data{contourIndex}.contours.start = cstart;
87-
%-end-%
88-
obj.data{contourIndex}.contours.end = cend;
89-
%-step-%
90-
obj.data{contourIndex}.contours.size = csize;
70+
data.contours.start = cstart;
71+
data.contours.end = cend;
72+
data.contours.size = csize;
9173

92-
if (~strcmp(contour_data.LineStyle,'none'))
93-
%-contour line colour-%
74+
if contour_data.LineStyle ~= "none"
9475
if isnumeric(contour_data.LineColor)
9576
col = round(255*contour_data.LineColor);
96-
obj.data{contourIndex}.line.color = ...
97-
sprintf("rgb(%d,%d,%d)", col);
77+
data.line.color = getStringColor(col);
9878
else
99-
obj.data{contourIndex}.line.color = "rgba(0,0,0,0)";
79+
data.line.color = "rgba(0,0,0,0)";
10080
end
10181

102-
%-contour line width-%
103-
obj.data{contourIndex}.line.width = contour_data.LineWidth;
82+
data.line.width = contour_data.LineWidth;
10483

105-
%-contour line dash-%
10684
switch contour_data.LineStyle
107-
case '-'
108-
LineStyle = 'solid';
109-
case '--'
110-
LineStyle = 'dash';
111-
case ':'
112-
LineStyle = 'dot';
113-
case '-.'
114-
LineStyle = 'dashdot';
85+
case "-"
86+
LineStyle = "solid";
87+
case "--"
88+
LineStyle = "dash";
89+
case ":"
90+
LineStyle = "dot";
91+
case "-."
92+
LineStyle = "dashdot";
11593
end
116-
obj.data{contourIndex}.line.dash = LineStyle;
117-
obj.data{contourIndex}.line.smoothing = 0;
94+
data.line.dash = LineStyle;
95+
data.line.smoothing = 0;
11896
else
119-
obj.data{contourIndex}.contours.showlines = false;
97+
data.contours.showlines = false;
12098
end
12199

122-
%-contour showlegend-%
123-
leg = contour_data.Annotation;
124-
legInfo = leg.LegendInformation;
125-
switch legInfo.IconDisplayStyle
126-
case 'on'
127-
showleg = true;
128-
case 'off'
129-
showleg = false;
100+
switch contour_data.Annotation.LegendInformation.IconDisplayStyle
101+
case "on"
102+
data.showlegend = true;
103+
case "off"
104+
data.showlegend = false;
130105
end
131-
obj.data{contourIndex}.showlegend = showleg;
132-
133-
%-axis layout-%
134-
t = 'linear';
135-
obj.layout.("xaxis" + xsource).type=t;
136-
obj.layout.("xaxis" + xsource).autorange=true;
137-
obj.layout.("xaxis" + xsource).ticktext=axis_data.XTickLabel;
138-
obj.layout.("xaxis" + xsource).tickvals=axis_data.XTick;
139-
140-
obj.layout.("yaxis" + xsource).type=t;
141-
obj.layout.("yaxis" + xsource).autorange=true;
142-
obj.layout.("yaxis" + xsource).ticktext=axis_data.YTickLabel;
143-
obj.layout.("yaxis" + xsource).tickvals=axis_data.YTick;
106+
107+
t = "linear";
108+
obj.layout.("xaxis" + xsource).type = t;
109+
obj.layout.("xaxis" + xsource).autorange = true;
110+
obj.layout.("xaxis" + xsource).ticktext = axis_data.XTickLabel;
111+
obj.layout.("xaxis" + xsource).tickvals = axis_data.XTick;
112+
113+
obj.layout.("yaxis" + xsource).type = t;
114+
obj.layout.("yaxis" + xsource).autorange = true;
115+
obj.layout.("yaxis" + xsource).ticktext = axis_data.YTickLabel;
116+
obj.layout.("yaxis" + xsource).tickvals = axis_data.YTick;
144117
end

0 commit comments

Comments
 (0)