|
1 |
| -function obj = updateContourgroup(obj,plotIndex) |
| 1 | +function data = updateContourgroup(obj,plotIndex) |
2 | 2 | %-INITIALIZATIONS-%
|
3 | 3 |
|
4 | 4 | axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
|
|
21 | 21 | contourEnd = plotData.TextList(end);
|
22 | 22 | contourSize = mean(diff(plotData.TextList));
|
23 | 23 |
|
24 |
| - if length(plotData.TextList) == 1 |
| 24 | + if isscalar(plotData.TextList) |
25 | 25 | contourStart = plotData.TextList(1) - 1e-3;
|
26 | 26 | contourEnd = plotData.TextList(end) + 1e-3;
|
27 | 27 | contourSize = 2e-3;
|
28 | 28 | end
|
29 | 29 |
|
30 |
| - %-set trace-% |
31 |
| - obj.data{plotIndex}.type = 'contour'; |
32 |
| - obj.data{plotIndex}.xaxis = sprintf('x%d', xSource); |
33 |
| - obj.data{plotIndex}.yaxis = sprintf('y%d', ySource); |
34 |
| - obj.data{plotIndex}.name = plotData.DisplayName; |
35 |
| - obj.data{plotIndex}.visible = strcmp(plotData.Visible, 'on'); |
36 |
| - obj.data{plotIndex}.xtype = 'array'; |
37 |
| - obj.data{plotIndex}.ytype = 'array'; |
38 |
| - |
39 |
| - %-set trace data-% |
40 |
| - obj.data{plotIndex}.x = xData; |
41 |
| - obj.data{plotIndex}.y = yData; |
42 |
| - obj.data{plotIndex}.z = zData; |
43 |
| - |
44 |
| - %-set contour levels-% |
45 |
| - obj.data{plotIndex}.autocontour = false; |
46 |
| - obj.data{plotIndex}.contours.start = contourStart; |
47 |
| - obj.data{plotIndex}.contours.end = contourEnd; |
48 |
| - obj.data{plotIndex}.contours.size = contourSize; |
49 |
| - |
50 |
| - %-set trace coloring-% |
51 |
| - obj.data{plotIndex}.zauto = false; |
52 |
| - obj.data{plotIndex}.zmin = axisData.CLim(1); |
53 |
| - obj.data{plotIndex}.zmax = axisData.CLim(2); |
54 |
| - obj.data{plotIndex}.showscale = false; |
55 |
| - obj.data{plotIndex}.reversescale = false; |
56 |
| - obj.data{plotIndex}.colorscale = getColorScale(plotData, axisData); |
57 |
| - |
58 |
| - if strcmp(plotData.Fill, 'off') |
59 |
| - obj.data{plotIndex}.contours.coloring = 'lines'; |
| 30 | + data.type = "contour"; |
| 31 | + data.xaxis = "x" + xSource; |
| 32 | + data.yaxis = "y" + ySource; |
| 33 | + data.name = plotData.DisplayName; |
| 34 | + data.visible = plotData.Visible == "on"; |
| 35 | + data.xtype = "array"; |
| 36 | + data.ytype = "array"; |
| 37 | + |
| 38 | + data.x = xData; |
| 39 | + data.y = yData; |
| 40 | + data.z = zData; |
| 41 | + |
| 42 | + data.autocontour = false; |
| 43 | + data.contours.start = contourStart; |
| 44 | + data.contours.end = contourEnd; |
| 45 | + data.contours.size = contourSize; |
| 46 | + |
| 47 | + data.zauto = false; |
| 48 | + data.zmin = axisData.CLim(1); |
| 49 | + data.zmax = axisData.CLim(2); |
| 50 | + data.showscale = false; |
| 51 | + data.reversescale = false; |
| 52 | + data.colorscale = getColorScale(plotData, axisData); |
| 53 | + |
| 54 | + if plotData.Fill == "off" |
| 55 | + data.contours.coloring = "lines"; |
60 | 56 | else
|
61 |
| - obj.data{plotIndex}.contours.coloring = 'fill'; |
| 57 | + data.contours.coloring = "fill"; |
62 | 58 | end
|
63 | 59 |
|
64 | 60 | %-set contour line-%
|
65 |
| - if ~strcmp(plotData.LineStyle, 'none') |
66 |
| - obj.data{plotIndex}.contours.showlines = true; |
67 |
| - obj.data{plotIndex}.line = getContourLine(plotData); |
| 61 | + if plotData.LineStyle ~= "none" |
| 62 | + data.contours.showlines = true; |
| 63 | + data.line = getContourLine(plotData); |
68 | 64 | else
|
69 |
| - obj.data{plotIndex}.contours.showlines = false; |
| 65 | + data.contours.showlines = false; |
70 | 66 | end
|
71 | 67 |
|
72 | 68 | %-set contour label-%
|
73 |
| - if strcmpi(plotData.ShowText, 'on') |
74 |
| - obj.data{plotIndex}.contours.showlabels = true; |
75 |
| - obj.data{plotIndex}.contours.labelfont = getLabelFont(axisData); |
| 69 | + if lower(plotData.ShowText) == "on" |
| 70 | + data.contours.showlabels = true; |
| 71 | + data.contours.labelfont = getLabelFont(axisData); |
76 | 72 | end
|
77 | 73 |
|
78 | 74 | %-set trace legend-%
|
79 |
| - obj.data{plotIndex}.showlegend = getShowLegend(plotData); |
| 75 | + data.showlegend = getShowLegend(plotData); |
80 | 76 | end
|
81 | 77 |
|
82 | 78 | function contourLine = getContourLine(plotData)
|
83 |
| - %-initializations-% |
84 |
| - lineStyle = plotData.LineStyle; |
85 |
| - lineWidth = 1.5*plotData.LineWidth; |
86 |
| - lineColor = plotData.LineColor; |
87 |
| - |
88 |
| - %-line color-% |
89 |
| - if isnumeric(lineColor) |
90 |
| - lineColor = getStringColor(round(255*lineColor)); |
| 79 | + if isnumeric(plotData.LineColor) |
| 80 | + lineColor = getStringColor(round(255*plotData.LineColor)); |
91 | 81 | else
|
92 | 82 | lineColor = "rgba(0,0,0,0)";
|
93 | 83 | end
|
94 | 84 |
|
95 |
| - %-line dash-% |
96 |
| - switch lineStyle |
97 |
| - case '-' |
98 |
| - lineStyle = 'solid'; |
99 |
| - case '--' |
100 |
| - lineStyle = 'dash'; |
101 |
| - case ':' |
102 |
| - lineStyle = 'dot'; |
103 |
| - case '-.' |
104 |
| - lineStyle = 'dashdot'; |
| 85 | + switch plotData.LineStyle |
| 86 | + case "-" |
| 87 | + lineStyle = "solid"; |
| 88 | + case "--" |
| 89 | + lineStyle = "dash"; |
| 90 | + case ":" |
| 91 | + lineStyle = "dot"; |
| 92 | + case "-." |
| 93 | + lineStyle = "dashdot"; |
105 | 94 | end
|
106 | 95 |
|
107 |
| - %-return-% |
108 |
| - contourLine.width = lineWidth; |
109 |
| - contourLine.dash = lineStyle; |
110 |
| - contourLine.color = lineColor; |
111 |
| - contourLine.smoothing = 0; |
| 96 | + contourLine = struct( ... |
| 97 | + "width", 1.5*plotData.LineWidth, ... |
| 98 | + "dash", lineStyle, ... |
| 99 | + "color", lineColor, ... |
| 100 | + "smoothing", 0 ... |
| 101 | + ); |
112 | 102 | end
|
113 | 103 |
|
114 | 104 | function colorScale = getColorScale(plotData, axisData)
|
115 |
| - %-initializations-% |
116 | 105 | cMap = axisData.Colormap;
|
117 | 106 | nColors = size(cMap, 1);
|
118 | 107 | isBackground = any(plotData.ZData(:) < plotData.TextList(1));
|
119 | 108 | nContours = length(plotData.TextList);
|
120 | 109 | cScaleInd = linspace(0,1, nContours);
|
121 |
| - if nContours==1 |
| 110 | + if nContours == 1 |
122 | 111 | cScaleInd = 0.5;
|
123 | 112 | end
|
124 |
| - cMapInd = floor( (nColors-1)*cScaleInd ) + 1; |
| 113 | + cMapInd = floor((nColors-1)*cScaleInd) + 1; |
125 | 114 |
|
126 |
| - %-colorscale-% |
127 |
| - if strcmp(plotData.Fill, 'on') |
| 115 | + if plotData.Fill == "on" |
| 116 | + colorScale = cell(1, nContours); |
| 117 | + colors = cMap(cMapInd, :); |
128 | 118 | if isBackground
|
129 |
| - colorScale{1} = {0, getStringColor(round(255*ones(1,3)))}; |
130 |
| - cScaleInd = linspace(1/nContours, 1, nContours); |
131 |
| - end |
132 |
| - for n = 1:nContours |
133 |
| - m = n; |
134 |
| - if isBackground |
135 |
| - m = n+1; |
136 |
| - end |
137 |
| - stringColor = getStringColor(round(255*cMap(cMapInd(n), :))); |
138 |
| - colorScale{m} = {cScaleInd(n), stringColor}; |
| 119 | + colorScale = cell(1, nContours+1); |
| 120 | + colors = [ones(1,3); colors]; |
| 121 | + cScaleInd = linspace(0, 1, nContours+1); |
139 | 122 | end
|
140 | 123 | else
|
| 124 | + colors = cMap; |
| 125 | + colorScale = cell(1,nColors); |
141 | 126 | cScaleInd = rescale(1:nColors, 0, 1);
|
142 |
| - for n = 1:nColors |
143 |
| - stringColor = getStringColor(round(255*cMap(n,:))); |
144 |
| - colorScale{n} = {cScaleInd(n), stringColor}; |
145 |
| - end |
| 127 | + end |
| 128 | + for n = 1:numel(colorScale) |
| 129 | + stringColor = getStringColor(round(255*colors(n,:))); |
| 130 | + colorScale{n} = {cScaleInd(n), stringColor}; |
146 | 131 | end
|
147 | 132 | end
|
148 | 133 |
|
149 | 134 | function labelFont = getLabelFont(axisData)
|
150 |
| - labelColor = getStringColor(round(255*axisData.XAxis.Color)); |
151 |
| - labelSize = axisData.XAxis.FontSize; |
152 |
| - labelFamily = matlab2plotlyfont(axisData.XAxis.FontName); |
153 |
| - |
154 |
| - labelFont.color = labelColor; |
155 |
| - labelFont.size = labelSize; |
156 |
| - labelFont.family = labelFamily; |
| 135 | + labelFont = struct( ... |
| 136 | + "color", getStringColor(round(255*axisData.XAxis.Color)), ... |
| 137 | + "size", axisData.XAxis.FontSize, ... |
| 138 | + "family", matlab2plotlyfont(axisData.XAxis.FontName) ... |
| 139 | + ); |
157 | 140 | end
|
0 commit comments