forked from plotly/plotly_matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateAnnotation.m
More file actions
201 lines (151 loc) · 5.95 KB
/
updateAnnotation.m
File metadata and controls
201 lines (151 loc) · 5.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
function obj = updateAnnotation(obj,anIndex)
%-------X/YLABEL FIELDS--------%
% title...[DONE]
% titlefont.size...[DONE]
% titlefont.family...[DONE]
% titlefont.color...[DONE]
%------ANNOTATION FIELDS-------%
% x: ...[DONE]
% y: ...[DONE]
% xref: ...[DONE]
% yref: ...[DONE]
% text: ...[DONE]
% showarrow: ...[HANDLED BY CALL TO ANNOTATION];
% font: ...[DONE]
% xanchor: ...[DONE]
% yanchor: ...[DONE]
% align: ...[DONE]
% arrowhead: ...[HANDLED BY CALL FROM ANNOTATION];
% arrowsize: ...[HANDLED BY CALL FROM ANNOTATION];
% arrowwidth: ...[HANDLED BY CALL FROM ANNOTATION];
% arrowcolor: ...[HANDLED BY CALL FROM ANNOTATION];
% ax: ...[HANDLED BY CALL FROM ANNOTATION];
% ay: ...[HANDLED BY CALL FROM ANNOTATION];
% textangle: ...[DONE]
% bordercolor: ...[DONE]
% borderwidth: ...[DONE]
% borderpad: ...[DONE]
% bgcolor: ...[DONE]
% opacity: ...[NOT SUPPORTED IN MATLAB]
%-AXIS INDEX-%
axIndex = obj.getAxisIndex(obj.State.Text(anIndex).AssociatedAxis);
%-CHECK FOR MULTIPLE AXES-%
[xsource, ysource] = findSourceAxis(obj,axIndex);
%-STANDARDIZE UNITS-%
textunits = get(obj.State.Text(anIndex).Handle,'Units');
fontunits = get(obj.State.Text(anIndex).Handle,'FontUnits');
set(obj.State.Text(anIndex).Handle,'Units','data');
set(obj.State.Text(anIndex).Handle,'FontUnits','points');
%-TEXT DATA STRUCTURE-%
text_data = get(obj.State.Text(anIndex).Handle);
%-------------------------------------------------------------------------%
%-show arrow-%
obj.layout.annotations{anIndex}.showarrow = false;
%-------------------------------------------------------------------------%
%-anchor title to paper-%
if obj.State.Text(anIndex).Title
%-xref-%
obj.layout.annotations{anIndex}.xref = 'paper';
%-yref-%
obj.layout.annotations{anIndex}.yref = 'paper';
else
%-xref-%
obj.layout.annotations{anIndex}.xref = ['x' num2str(xsource)];
%-yref-%
obj.layout.annotations{anIndex}.yref = ['y' num2str(ysource)];
end
%-------------------------------------------------------------------------%
%-xanchor-%
obj.layout.annotations{anIndex}.xanchor = text_data.HorizontalAlignment;
%-------------------------------------------------------------------------%
%-align-%
obj.layout.annotations{anIndex}.align = text_data.HorizontalAlignment;
%-------------------------------------------------------------------------%
switch text_data.VerticalAlignment
%-yanchor-%
case {'top', 'cap'}
obj.layout.annotations{anIndex}.yanchor = 'top';
case 'middle'
obj.layout.annotations{anIndex}.yanchor = 'middle';
case {'baseline','bottom'}
obj.layout.annotations{anIndex}.yanchor = 'bottom';
end
%-------------------------------------------------------------------------%
%-text-%
obj.layout.annotations{anIndex}.text = parseString(text_data.String,text_data.Interpreter);
if obj.State.Text(anIndex).Title && isempty(text_data.String)
obj.layout.annotations{anIndex}.text = '<b></b>'; %empty string annotation
end
%-------------------------------------------------------------------------%
if obj.State.Text(anIndex).Title
%-AXIS DATA-%
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
%-x position-%
obj.layout.annotations{anIndex}.x = mean(xaxis.domain);
%-y position-%
obj.layout.annotations{anIndex}.y = (yaxis.domain(2) + obj.PlotlyDefaults.TitleHeight);
else
%-x position-%
obj.layout.annotations{anIndex}.x = text_data.Position(1);
%-y position-%
obj.layout.annotations{anIndex}.y = text_data.Position(2);
end
%-font color-%
col = 255*text_data.Color;
obj.layout.annotations{anIndex}.font.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
%---------------------------------------------------------------------%
%-font family-%
obj.layout.annotations{anIndex}.font.family = matlab2plotlyfont(text_data.FontName);
%---------------------------------------------------------------------%
%-font size-%
obj.layout.annotations{anIndex}.font.size = text_data.FontSize;
%---------------------------------------------------------------------%
switch text_data.FontWeight
case {'bold','demi'}
%-bold text-%
obj.layout.annotations{anIndex}.text = ['<b>' obj.layout.annotations{anIndex}.text '</b>'];
otherwise
end
%---------------------------------------------------------------------%
%-background color-%
if ~ischar(text_data.BackgroundColor)
switch text_data.BackgroundColor
case 'ne'
obj.layout.annotations{anIndex}.bgcolor = 'rgba(0,0,0,0)';
otherwise
end
end
%---------------------------------------------------------------------%
%-border color-%
if ~ischar(text_data.EdgeColor)
col = 255*text_data.EdgeColora;
obj.layout.annotations{anIndex}.bordercolor = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
else
%-none-%
obj.layout.annotations{anIndex}.bordercolor = 'rgba(0,0,0,0)';
end
%---------------------------------------------------------------------%
%-text angle-%
obj.layout.annotations{anIndex}.textangle = text_data.Rotation;
if text_data.Rotation > 180
obj.layout.annotations{anIndex}.textangle = text_data.Rotation - 360;
end
%---------------------------------------------------------------------%
%-border width-%
obj.layout.annotations{anIndex}.borderwidth = text_data.LineWidth;
%---------------------------------------------------------------------%
%-border pad-%
obj.layout.annotations{anIndex}.borderpad = text_data.Margin;
%hide text (a workaround)
if strcmp(text_data.Visible,'off')
obj.layout.annotations{anIndex}.text = ' ';
else
obj.layout.annotations{anIndex}.text = obj.layout.annotations{anIndex}.text;
end
%-------------------------------------------------------------------------%
%-REVERT UNITS-%
set(obj.State.Text(anIndex).Handle,'Units',textunits);
set(obj.State.Text(anIndex).Handle,'FontUnits',fontunits);
%-------------------------------------------------------------------------%
end