Skip to content

Commit 0aaba9b

Browse files
Add files via upload
''
1 parent 6b9925a commit 0aaba9b

File tree

3 files changed

+329
-3
lines changed

3 files changed

+329
-3
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
function converted = convertDate(date)
2-
converted = (date - datenum(1969,12,31,19,00,00))*1000*60*60*24;
3-
end
1+
function convertedDate = convertDate(date)
2+
date.Format = 'yyyy-MM-dd HH:mm:ss';
3+
convertedDate = char(date);
4+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function [converted,type] = convertDuration(duration)
2+
switch (duration.Format)
3+
case 's'
4+
converted = seconds(duration);
5+
type = 'sec';
6+
case 'm'
7+
converted = minutes(duration);
8+
type = 'min';
9+
case 'h'
10+
converted = hours(duration);
11+
type = 'hr';
12+
case 'd'
13+
converted = days(duration);
14+
type = 'days';
15+
case 'y'
16+
converted = years(duration);
17+
type = 'yrs';
18+
otherwise
19+
%no convertion is applied
20+
converted = duration;
21+
type = '';
22+
23+
end
24+
end
Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
function [axis] = extractAxisData(obj,axis_data,axisName)
2+
%extract information related to each axis
3+
% axis_data is the data extrated from the figure, axisName take the
4+
% values 'x' 'y' or 'z'
5+
6+
7+
%-------------------------------------------------------------------------%
8+
9+
%-axis-side-%
10+
axis.side = eval(['axis_data.' axisName 'AxisLocation;']);
11+
12+
%-------------------------------------------------------------------------%
13+
14+
%-axis zeroline-%
15+
axis.zeroline = false;
16+
17+
%-------------------------------------------------------------------------%
18+
19+
%-axis autorange-%
20+
axis.autorange = false;
21+
22+
%-------------------------------------------------------------------------%
23+
24+
%-axis exponent format-%
25+
axis.exponentformat = obj.PlotlyDefaults.ExponentFormat;
26+
27+
%-------------------------------------------------------------------------%
28+
29+
%-axis tick font size-%
30+
axis.tickfont.size = axis_data.FontSize;
31+
32+
%-------------------------------------------------------------------------%
33+
34+
%-axis tick font family-%
35+
axis.tickfont.family = matlab2plotlyfont(axis_data.FontName);
36+
37+
%-------------------------------------------------------------------------%
38+
39+
ticklength = min(obj.PlotlyDefaults.MaxTickLength,...
40+
max(axis_data.TickLength(1)*axis_data.Position(3)*obj.layout.width,...
41+
axis_data.TickLength(1)*axis_data.Position(4)*obj.layout.height));
42+
%-axis ticklen-%
43+
axis.ticklen = ticklength;
44+
45+
%-------------------------------------------------------------------------%
46+
47+
col = eval(['255*axis_data.' axisName 'Color;']);
48+
axiscol = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
49+
50+
%-axis linecolor-%
51+
axis.linecolor = axiscol;
52+
%-axis tickcolor-%
53+
axis.tickcolor = axiscol;
54+
%-axis tickfont-%
55+
axis.tickfont.color = axiscol;
56+
%-axis grid color-%
57+
axis.gridcolor = axiscol;
58+
59+
%-------------------------------------------------------------------------%
60+
61+
if strcmp(axis_data.XGrid, 'on') || strcmp(axis_data.XMinorGrid, 'on')
62+
%-axis show grid-%
63+
axis.showgrid = true;
64+
else
65+
axis.showgrid = false;
66+
end
67+
68+
%-------------------------------------------------------------------------%
69+
70+
grid = eval(['axis_data.' axisName 'Grid;']);
71+
minorGrid = eval(['axis_data.' axisName 'MinorGrid;']);
72+
73+
if strcmp(grid, 'on') || strcmp(minorGrid, 'on')
74+
%-axis show grid-%
75+
axis.showgrid = true;
76+
else
77+
axis.showgrid = false;
78+
end
79+
80+
%-------------------------------------------------------------------------%
81+
82+
linewidth = max(1,axis_data.LineWidth*obj.PlotlyDefaults.AxisLineIncreaseFactor);
83+
84+
%-axis line width-%
85+
axis.linewidth = linewidth;
86+
%-axis tick width-%
87+
axis.tickwidth = linewidth;
88+
%-axis grid width-%
89+
axis.gridwidth = linewidth;
90+
91+
%-------------------------------------------------------------------------%
92+
93+
%-axis type-%
94+
95+
axis.type = eval(['axis_data.' axisName 'Scale']);
96+
97+
%-------------------------------------------------------------------------%
98+
99+
%-axis showtick labels / ticks-%
100+
tick = eval(['axis_data.' axisName 'Tick']);
101+
if isempty(tick)
102+
103+
%-axis ticks-%
104+
axis.ticks = '';
105+
axis.showticklabels = false;
106+
107+
%-axis autorange-%
108+
axis.autorange = true;
109+
110+
%---------------------------------------------------------------------%
111+
112+
switch axis_data.Box
113+
case 'on'
114+
%-axis mirror-%
115+
axis.mirror = true;
116+
case 'off'
117+
axis.mirror = false;
118+
end
119+
120+
%---------------------------------------------------------------------%
121+
122+
else
123+
124+
%-axis tick direction-%
125+
switch axis_data.TickDir
126+
case 'in'
127+
axis.ticks = 'inside';
128+
case 'out'
129+
axis.ticks = 'outside';
130+
end
131+
132+
%---------------------------------------------------------------------%
133+
switch axis_data.Box
134+
case 'on'
135+
%-axis mirror-%
136+
axis.mirror = 'ticks';
137+
case 'off'
138+
axis.mirror = false;
139+
end
140+
141+
%---------------------------------------------------------------------%
142+
143+
if strcmp(axis.type,'log')
144+
145+
%-axis range-%
146+
axis.range = eval(['log10(axis_data.' axisName 'Lim);']);
147+
%-axis autotick-%
148+
axis.autotick = true;
149+
%-axis nticks-%
150+
axis.nticks = eval(['length(axis_data.' axisName 'Tick) + 1;']);
151+
152+
%---------------------------------------------------------------------%
153+
154+
elseif strcmp(axis.type,'linear')
155+
TickLabelMode = eval(['axis_data.' axisName 'TickLabelMode;']);
156+
if strcmp(TickLabelMode,'auto')
157+
158+
%-axis range-%
159+
dataLim = eval(['axis_data.' axisName 'Lim']);
160+
161+
%-------------------------------------------------------------%
162+
163+
if isnumeric(dataLim)
164+
axis.range = dataLim;
165+
166+
%-------------------------------------------------------------%
167+
168+
elseif isduration(dataLim)
169+
[temp,type] = convertDuration(dataLim);
170+
171+
if (~isduration(temp))
172+
axis.range = temp;
173+
axis.type = 'duration';
174+
axis.title = type;
175+
else
176+
nticks = eval(['length(axis_data.' axisName 'Tick)-1;']);
177+
delta = 0.1;
178+
axis.range = [-delta nticks+delta];
179+
axis.type = 'duration - specified format';
180+
end
181+
182+
%-------------------------------------------------------------%
183+
184+
elseif isdatetime(dataLim)
185+
axis.range = convertDate(dataLim);
186+
axis.type = 'date';
187+
else
188+
% data is a category type other then duration and datetime
189+
end
190+
191+
%-axis autotick-%
192+
axis.autotick = true;
193+
%-axis numticks-%
194+
axis.nticks = eval(['length(axis_data.' axisName 'Tick)+1']);
195+
%-----------------------------------------------------------------%
196+
197+
else
198+
%-axis show tick labels-%
199+
Tick = eval(['axis_data.' axisName 'TickLabel;']);
200+
if isempty(Tick)
201+
%-hide tick labels-%
202+
axis.showticklabels = false;
203+
%-axis autorange-%
204+
axis.autorange = true;
205+
else
206+
%-axis labels
207+
labels = str2double(axis_data.YTickLabel);
208+
try
209+
%find numbers in labels
210+
labelnums = find(~isnan(labels));
211+
%-axis type linear-%
212+
axis.type = 'linear';
213+
%-range (overwrite)-%
214+
delta = (labels(labelnums(2)) - labels(labelnums(1)))/(labelnums(2)-labelnums(1));
215+
axis.range = [labels(labelnums(1))-delta*(labelnums(1)-1) labels(labelnums(1)) + (length(labels)-labelnums(1))*delta];
216+
%-axis autotick-%
217+
axis.autotick = true;
218+
%-axis numticks-%
219+
axis.nticks = eval(['length(axis_data.' axisName 'Tick) + 1;']);
220+
catch
221+
%-axis type category-%
222+
axis.type = 'category';
223+
%-range (overwrite)-%
224+
axis.autorange = true;
225+
%-axis autotick-%
226+
axis.autotick = true;
227+
end
228+
end
229+
end
230+
end
231+
end
232+
233+
%-------------------------------------------------------------------------%
234+
235+
Dir = eval(['axis_data.' axisName 'Dir;']);
236+
if strcmp(Dir,'reverse')
237+
axis.range = [axis.range(2) axis.range(1)];
238+
end
239+
240+
%-------------------------------LABELS------------------------------------%
241+
242+
label = eval(['axis_data.' axisName 'Label;']);
243+
244+
label_data = get(label);
245+
246+
%STANDARDIZE UNITS
247+
fontunits = get(label,'FontUnits');
248+
set(label,'FontUnits','points');
249+
250+
%-------------------------------------------------------------------------%
251+
252+
%-title-%
253+
if ~isempty(label_data.String)
254+
axis.title = parseString(label_data.String,label_data.Interpreter);
255+
end
256+
257+
%-------------------------------------------------------------------------%
258+
259+
%-axis title font color-%
260+
col = 255*label_data.Color;
261+
axis.titlefont.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
262+
263+
%-------------------------------------------------------------------------%
264+
265+
%-axis title font size-%
266+
axis.titlefont.size = label_data.FontSize;
267+
268+
%-------------------------------------------------------------------------%
269+
270+
%-axis title font family-%
271+
axis.titlefont.family = matlab2plotlyfont(label_data.FontName);
272+
273+
%-------------------------------------------------------------------------%
274+
275+
%REVERT UNITS
276+
set(label,'FontUnits',fontunits);
277+
278+
%-------------------------------------------------------------------------%
279+
280+
if strcmp(axis_data.Visible,'on')
281+
%-axis showline-%
282+
axis.showline = true;
283+
else
284+
%-axis showline-%
285+
axis.showline = false;
286+
%-axis showticklabels-%
287+
axis.showticklabels = false;
288+
%-axis ticks-%
289+
axis.ticks = '';
290+
%-axis showline-%
291+
axis.showline = false;
292+
%-axis showticklabels-%
293+
axis.showticklabels = false;
294+
%-axis ticks-%
295+
axis.ticks = '';
296+
end
297+
298+
%-------------------------------------------------------------------------%
299+
end
300+
301+

0 commit comments

Comments
 (0)