-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathupdateConstantLine.m
More file actions
129 lines (106 loc) · 3.95 KB
/
updateConstantLine.m
File metadata and controls
129 lines (106 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
function data = updateConstantLine(obj,plotIndex)
%-AXIS INDEX-%
axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
%-PLOT DATA STRUCTURE- %
plotData = obj.State.Plot(plotIndex).Handle;
%-CHECK FOR MULTIPLE AXES-%
[xsource, ysource] = findSourceAxis(obj, axIndex);
data.xaxis = "x" + xsource;
data.yaxis = "y" + ysource;
data.type = "scatter";
data.visible = plotData.Visible == "on";
xaxis = obj.layout.("xaxis" + xsource);
yaxis = obj.layout.("yaxis" + ysource);
value = [plotData.Value plotData.Value];
if plotData.InterceptAxis == "y"
data.x = xaxis.range;
data.y = value;
else
data.x = value;
data.y = yaxis.range;
end
if ~isempty(plotData.Label)
annotation = struct();
annotation.showarrow = false;
annotation.xref = "x" + xsource;
annotation.yref = "y" + ysource;
if plotData.InterceptAxis == "x"
annotation.textangle = -90;
end
annotation.xanchor = plotData.LabelHorizontalAlignment;
switch plotData.LabelVerticalAlignment
case {"top", "cap"}
annotation.yanchor = "top";
case "middle"
annotation.yanchor = "middle";
case {"baseline","bottom"}
annotation.yanchor = "bottom";
end
annotation.text = parseString( ...
plotData.Label, plotData.Interpreter);
annotation.text = "<b>" + join( ...
string(annotation.text), "<br>") + "</b>";
if plotData.InterceptAxis == "x"
annotation.x = plotData.Value;
annotation.y = yaxis.range(2);
else
annotation.x = xaxis.range(2);
annotation.y = plotData.Value;
end
col = round(255*plotData.LabelColor);
annotation.font.color = getStringColor(col);
annotation.font.family = matlab2plotlyfont(plotData.FontName);
annotation.font.size = plotData.FontSize;
switch plotData.FontWeight
case {"bold","demi"}
annotation.text = "<b>" + annotation.text + "</b>";
otherwise
end
if plotData.LabelHorizontalAlignment == "center"
if plotData.InterceptAxis == "x"
ylim = plotData.Parent.YLim;
textWidth = text(0,0,plotData.Label,units="normalized", ...
rotation=90,Visible="off").Extent(4);
textWidth = textWidth * (ylim(2) - ylim(1));
data.y(2) = data.y(2) - textWidth;
else
xlim = plotData.Parent.XLim;
textWidth = text(0,0,plotData.Label,units="normalized", ...
Visible="off").Extent(3);
textWidth = textWidth * (xlim(2) - xlim(1));
data.x(2) = data.x(2) - textWidth;
end
end
obj.layout.annotations{end+1} = annotation;
end
%-For 3D plots-%
obj.PlotOptions.is3d = false; % by default
if isfield(plotData,"ZData")
numbset = unique(plotData.ZData);
if any(plotData.ZData) && length(numbset)>1
data.z = plotData.ZData;
data.type = "scatter3d";
%-flag to manage 3d plots-%
obj.PlotOptions.is3d = true;
end
end
data.name = plotData.DisplayName;
if plotData.Type ~= "constantline" ...
&& lower(plotData.Marker) ~= "none" ...
&& lower(plotData.LineStyle) ~= "none"
mode = "lines+markers";
elseif plotData.Type ~= "constantline" ...
&& lower(plotData.Marker) ~= "none"
mode = "markers";
elseif lower(plotData.LineStyle) ~= "none"
mode = "lines";
else
mode = "none";
end
data.mode = mode;
data.line = extractLineLine(plotData);
if plotData.Type ~= "constantline"
data.marker = extractLineMarker(plotData);
end
data.showlegend = getShowLegend(plotData);
end