Skip to content

Commit 97b0122

Browse files
Merge pull request #494 from plotly/speed-up-isOverlappingAxis
Speed up 'isOverlappingAxis' in redundant base case that axIndex = 1
2 parents e010e93 + ff1dcb8 commit 97b0122

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed
Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
function [overlapping, overlapaxes] = isOverlappingAxis(obj, axIndex)
2+
%-STANDARDIZE UNITS-%
3+
axis_units = cell(1,axIndex);
4+
for a = 1:axIndex
5+
axis_units{a} = obj.State.Axis(a).Handle.Units;
6+
obj.State.Axis(a).Handle.Units = "normalized";
7+
end
28

3-
%-STANDARDIZE UNITS-%
4-
axis_units = cell(1,axIndex);
5-
for a = 1:axIndex
6-
axis_units{a} = obj.State.Axis(a).Handle.Units;
7-
set(obj.State.Axis(a).Handle,'Units','normalized');
8-
end
9-
10-
% check axis overlap
11-
overlapaxes = find(arrayfun(@(x)(isequal(x.Handle.Position,obj.State.Axis(axIndex).Handle.Position)),obj.State.Axis(1:axIndex)));
12-
overlapping = length(overlapaxes) > 1; %greater than 1 because obj.State.Axis(axIndex) will always be an overlapping axis
13-
14-
%-REVERT UNITS-%
15-
for a = 1:axIndex
16-
set(obj.State.Axis(a).Handle,'Units',axis_units{a});
17-
end
9+
% check axis overlap
10+
if axIndex == 1 % redundant to check this case
11+
overlapaxes = 1;
12+
else
13+
overlapaxes = find(arrayfun(@(x) isequal(x.Handle.Position, ...
14+
obj.State.Axis(axIndex).Handle.Position), ...
15+
obj.State.Axis(1:axIndex)));
16+
end
17+
% greater than 1 because obj.State.Axis(axIndex) will always be an
18+
% overlapping axis
19+
overlapping = length(overlapaxes) > 1;
1820

21+
%-REVERT UNITS-%
22+
for a = 1:axIndex
23+
obj.State.Axis(a).Handle.Units = axis_units{a};
24+
end
1925
end

0 commit comments

Comments
 (0)