Skip to content

Commit 49def3a

Browse files
Refactor updateConstantLine
1 parent 058dc42 commit 49def3a

File tree

2 files changed

+34
-48
lines changed

2 files changed

+34
-48
lines changed
Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function updateConstantLine(obj,plotIndex)
1+
function data = updateConstantLine(obj,plotIndex)
22
%-AXIS INDEX-%
33
axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
44

@@ -8,30 +8,29 @@ function updateConstantLine(obj,plotIndex)
88
%-CHECK FOR MULTIPLE AXES-%
99
[xsource, ysource] = findSourceAxis(obj, axIndex);
1010

11-
obj.data{plotIndex}.xaxis = "x" + xsource;
12-
obj.data{plotIndex}.yaxis = "y" + ysource;
13-
obj.data{plotIndex}.type = "scatter";
14-
obj.data{plotIndex}.visible = strcmp(plotData.Visible, "on");
11+
data.xaxis = "x" + xsource;
12+
data.yaxis = "y" + ysource;
13+
data.type = "scatter";
14+
data.visible = plotData.Visible == "on";
1515

16-
%-scatter-%
17-
xaxis = obj.layout.("xaxis"+xsource);
18-
yaxis = obj.layout.("yaxis"+ysource);
16+
xaxis = obj.layout.("xaxis" + xsource);
17+
yaxis = obj.layout.("yaxis" + ysource);
1918
value = [plotData.Value plotData.Value];
2019
if plotData.InterceptAxis == "y"
21-
obj.data{plotIndex}.x = xaxis.range;
22-
obj.data{plotIndex}.y = value;
20+
data.x = xaxis.range;
21+
data.y = value;
2322
else
24-
obj.data{plotIndex}.x = value;
25-
obj.data{plotIndex}.y = yaxis.range;
23+
data.x = value;
24+
data.y = yaxis.range;
2625
end
2726

2827
if ~isempty(plotData.Label)
2928
annotation = struct();
3029

3130
annotation.showarrow = false;
3231

33-
annotation.xref = "x"+xsource;
34-
annotation.yref = "y"+ysource;
32+
annotation.xref = "x" + xsource;
33+
annotation.yref = "y" + ysource;
3534

3635
if plotData.InterceptAxis == "x"
3736
annotation.textangle = -90;
@@ -62,7 +61,7 @@ function updateConstantLine(obj,plotIndex)
6261
end
6362

6463
col = round(255*plotData.LabelColor);
65-
annotation.font.color = sprintf("rgb(%d,%d,%d)", col);
64+
annotation.font.color = getStringColor(col);
6665

6766
annotation.font.family = matlab2plotlyfont(plotData.FontName);
6867
annotation.font.size = plotData.FontSize;
@@ -75,14 +74,16 @@ function updateConstantLine(obj,plotIndex)
7574
if plotData.LabelHorizontalAlignment == "center"
7675
if plotData.InterceptAxis == "x"
7776
ylim = plotData.Parent.YLim;
78-
textWidth = text(0,0,plotData.Label,units="normalized",rotation=90,Visible="off").Extent(4);
77+
textWidth = text(0,0,plotData.Label,units="normalized", ...
78+
rotation=90,Visible="off").Extent(4);
7979
textWidth = textWidth * (ylim(2) - ylim(1));
80-
obj.data{plotIndex}.y(2) = obj.data{plotIndex}.y(2) - textWidth;
80+
data.y(2) = data.y(2) - textWidth;
8181
else
8282
xlim = plotData.Parent.XLim;
83-
textWidth = text(0,0,plotData.Label,units="normalized",Visible="off").Extent(3);
83+
textWidth = text(0,0,plotData.Label,units="normalized", ...
84+
Visible="off").Extent(3);
8485
textWidth = textWidth * (xlim(2) - xlim(1));
85-
obj.data{plotIndex}.x(2) = obj.data{plotIndex}.x(2) - textWidth;
86+
data.x(2) = data.x(2) - textWidth;
8687
end
8788
end
8889

@@ -95,54 +96,39 @@ function updateConstantLine(obj,plotIndex)
9596
if isfield(plotData,"ZData")
9697
numbset = unique(plotData.ZData);
9798
if any(plotData.ZData) && length(numbset)>1
98-
%-scatter z-%
99-
obj.data{plotIndex}.z = plotData.ZData;
100-
101-
%-overwrite type-%
102-
obj.data{plotIndex}.type = "scatter3d";
103-
99+
data.z = plotData.ZData;
100+
data.type = "scatter3d";
104101
%-flag to manage 3d plots-%
105102
obj.PlotOptions.is3d = true;
106103
end
107104
end
108105

109-
%-scatter name-%
110-
obj.data{plotIndex}.name = plotData.DisplayName;
106+
data.name = plotData.DisplayName;
111107

112-
%-scatter mode-%
113108
if plotData.Type ~= "constantline" ...
114-
&& ~strcmpi("none", plotData.Marker) ...
115-
&& ~strcmpi("none", plotData.LineStyle)
109+
&& lower(plotData.Marker) ~= "none" ...
110+
&& lower(plotData.LineStyle) ~= "none"
116111
mode = "lines+markers";
117112
elseif plotData.Type ~= "constantline" ...
118-
&& ~strcmpi("none", plotData.Marker)
113+
&& lower(plotData.Marker) ~= "none"
119114
mode = "markers";
120-
elseif ~strcmpi("none", plotData.LineStyle)
115+
elseif lower(plotData.LineStyle) ~= "none"
121116
mode = "lines";
122117
else
123118
mode = "none";
124119
end
125120

126-
obj.data{plotIndex}.mode = mode;
127-
128-
%-scatter line-%
129-
obj.data{plotIndex}.line = extractLineLine(plotData);
121+
data.mode = mode;
122+
data.line = extractLineLine(plotData);
130123

131-
%-scatter marker-%
132124
if plotData.Type ~= "constantline"
133-
obj.data{plotIndex}.marker = extractLineMarker(plotData);
125+
data.marker = extractLineMarker(plotData);
134126
end
135127

136-
%-scatter showlegend-%
137-
leg = get(plotData.Annotation);
138-
legInfo = get(leg.LegendInformation);
139-
140-
switch legInfo.IconDisplayStyle
128+
switch plotData.Annotation.LegendInformation.IconDisplayStyle
141129
case "on"
142-
showleg = true;
130+
data.showlegend = true;
143131
case "off"
144-
showleg = false;
132+
data.showlegend = false;
145133
end
146-
147-
obj.data{plotIndex}.showlegend = showleg;
148134
end

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
obj.data{dataIndex} = updateLineseries(obj, dataIndex);
6262
end
6363
case "constantline"
64-
updateConstantLine(obj, dataIndex);
64+
obj.data{dataIndex} = updateConstantLine(obj, dataIndex);
6565
case "categoricalhistogram"
6666
updateCategoricalHistogram(obj, dataIndex);
6767
case "histogram"

0 commit comments

Comments
 (0)