Skip to content

Commit 33b05eb

Browse files
committed
split out angular part of polar.isPtWithinSector into own fn
- which speeds up the category angular tick filter, and will help with polygon grids
1 parent 7e16134 commit 33b05eb

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/plots/polar/polar.js

+22-21
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,7 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
453453
angularLayout._categories.length;
454454

455455
ax.range = [0, period];
456-
457-
ax._tickFilter = function(d) {
458-
return _this.isPtWithinSector({
459-
r: _this.radialAxis.range[1],
460-
rad: ax.c2rad(d.x)
461-
});
462-
};
456+
ax._tickFilter = function(d) { return isAngleInSector(c2rad(d), sector); };
463457
}
464458

465459
setScale(ax, angularLayout, fullLayout);
@@ -1003,17 +997,15 @@ proto.updateAngularDrag = function(fullLayout, polarLayout) {
1003997

1004998
proto.isPtWithinSector = function(d) {
1005999
var sector = this.sector;
1000+
1001+
if(!isAngleInSector(d.rad, sector)) {
1002+
return false;
1003+
}
1004+
10061005
var radialAxis = this.radialAxis;
10071006
var radialRange = radialAxis.range;
10081007
var r = radialAxis.c2r(d.r);
10091008

1010-
var s0 = wrap360(sector[0]);
1011-
var s1 = wrap360(sector[1]);
1012-
if(s0 > s1) s1 += 360;
1013-
1014-
var deg = wrap360(rad2deg(d.rad));
1015-
var nextTurnDeg = deg + 360;
1016-
10171009
var r0, r1;
10181010
if(radialRange[1] >= radialRange[0]) {
10191011
r0 = radialRange[0];
@@ -1023,13 +1015,8 @@ proto.isPtWithinSector = function(d) {
10231015
r1 = radialRange[0];
10241016
}
10251017

1026-
return (
1027-
(r >= r0 && r <= r1) &&
1028-
(isFullCircle(sector) ||
1029-
(deg >= s0 && deg <= s1) ||
1030-
(nextTurnDeg >= s0 && nextTurnDeg <= s1)
1031-
)
1032-
);
1018+
1019+
return r >= r0 && r <= r1;
10331020
};
10341021

10351022
proto.fillViewInitialKey = function(key, val) {
@@ -1110,6 +1097,20 @@ function computeSectorBBox(sector) {
11101097
return [x0, y0, x1, y1];
11111098
}
11121099

1100+
function isAngleInSector(rad, sector) {
1101+
if(isFullCircle(sector)) return true;
1102+
1103+
var s0 = wrap360(sector[0]);
1104+
var s1 = wrap360(sector[1]);
1105+
if(s0 > s1) s1 += 360;
1106+
1107+
var deg = wrap360(rad2deg(rad));
1108+
var nextTurnDeg = deg + 360;
1109+
1110+
return (deg >= s0 && deg <= s1) ||
1111+
(nextTurnDeg >= s0 && nextTurnDeg <= s1);
1112+
}
1113+
11131114
function pathSector(r, sector) {
11141115
if(isFullCircle(sector)) {
11151116
return Drawing.symbolFuncs[0](r);

0 commit comments

Comments
 (0)