Skip to content

Commit 816be51

Browse files
committed
misc. polar fixup after AJ's review:
- fixup angular drag xy -> angle calculations - decrease min drag value for radial drag box, to catch smaller dx/dy that can determine rotateMove vs rerangeMove - better annulus path - typo in scatterpolar test
1 parent 7f7193d commit 816be51

File tree

3 files changed

+48
-26
lines changed

3 files changed

+48
-26
lines changed

src/plots/polar/polar.js

+45-23
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,9 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
528528

529529
proto.updateFx = function(fullLayout, polarLayout) {
530530
if(!this.gd._context.staticPlot) {
531-
this.updateMainDrag(fullLayout, polarLayout);
532531
this.updateAngularDrag(fullLayout, polarLayout);
533532
this.updateRadialDrag(fullLayout, polarLayout);
533+
this.updateMainDrag(fullLayout, polarLayout);
534534
}
535535
};
536536

@@ -858,6 +858,10 @@ proto.updateRadialDrag = function(fullLayout, polarLayout) {
858858
dragBox.clearSelect(fullLayout._zoomlayer);
859859
};
860860

861+
// decrease min drag value to be able to catch smaller dx/dy that
862+
// can determine rotateMove vs rerangeMove
863+
dragOpts.minDrag = 2;
864+
861865
dragElement.init(dragOpts);
862866
};
863867

@@ -871,17 +875,18 @@ proto.updateAngularDrag = function(fullLayout, polarLayout) {
871875
var cxx = _this.cxx;
872876
var cyy = _this.cyy;
873877
var sector = polarLayout.sector;
878+
var dbs = constants.angularDragBoxSize;
874879

875880
var angularDrag = dragBox.makeDragger(layers, 'path', 'angulardrag', 'move');
876881
var dragOpts = {element: angularDrag, gd: gd};
877882

878883
d3.select(angularDrag)
879-
.attr('d', pathAnnulus(radius, radius + constants.angularDragBoxSize, sector))
884+
.attr('d', pathAnnulus(radius, radius + dbs, sector))
880885
.attr('transform', strTranslate(cx, cy))
881886
.call(setCursor, 'move');
882887

883888
function xy2a(x, y) {
884-
return Math.atan2(cyy - y, x - cxx);
889+
return Math.atan2(cyy + dbs - y, x - cxx - dbs);
885890
}
886891

887892
// scatter trace, points and textpoints selections
@@ -909,6 +914,10 @@ proto.updateAngularDrag = function(fullLayout, polarLayout) {
909914
strTranslate(_this.xOffset2, _this.yOffset2) + strRotate([-da, cxx, cyy])
910915
);
911916

917+
_this.clipPaths.circle.select('path').attr('transform',
918+
strTranslate(cxx, cyy) + strRotate(da)
919+
);
920+
912921
// 'un-rotate' marker and text points
913922
scatterPoints.each(function() {
914923
var sel = d3.select(this);
@@ -1111,29 +1120,42 @@ function pathSectorClosed(r, sector) {
11111120
(isFullCircle(sector) ? '' : 'L0,0Z');
11121121
}
11131122

1114-
// inspired by https://gist.github.com/buschtoens/4190516
1115-
function pathAnnulus(r0, r1, _sector) {
1116-
var sector = _sector.slice();
1117-
var s0 = deg2rad(sector[0]);
1118-
var s1 = deg2rad(sector[1]);
1119-
1120-
// make a small cut on full sectors so that the
1121-
// inner region isn't filled
1122-
if(isFullCircle(sector)) s1 -= 1e-3;
1123+
// TODO recycle this routine with the ones used for pie traces.
1124+
function pathAnnulus(r0, r1, sector) {
1125+
var largeArc = Math.abs(sector[1] - sector[0]) <= 180 ? 0 : 1;
1126+
// sector angle at [s]tart, [m]iddle and [e]nd
1127+
var ss, sm, se;
11231128

1124-
var p00 = [r0 * Math.cos(s0), -r0 * Math.sin(s0)];
1125-
var p01 = [r0 * Math.cos(s1), -r0 * Math.sin(s1)];
1126-
var p10 = [r1 * Math.cos(s0), -r1 * Math.sin(s0)];
1127-
var p11 = [r1 * Math.cos(s1), -r1 * Math.sin(s1)];
1129+
function pt(r, s) {
1130+
return [r * Math.cos(s), -r * Math.sin(s)];
1131+
}
11281132

1129-
var largeArc = Math.abs(sector[1] - sector[0]) <= 180 ? 0 : 1;
1133+
function arc(r, s, cw) {
1134+
return 'A' + [r, r] + ' ' + [0, largeArc, cw] + ' ' + pt(r, s);
1135+
}
11301136

1131-
return 'M' + p00 +
1132-
'L' + p10 +
1133-
'A' + [r1, r1] + ' ' + [0, largeArc, 0] + ' ' + p11 +
1134-
'L' + p01 +
1135-
'A' + [r0, r0] + ' ' + [0, largeArc, 1] + ' ' + p00 +
1136-
'Z';
1137+
if(isFullCircle(sector)) {
1138+
ss = 0;
1139+
se = 2 * Math.PI;
1140+
sm = Math.PI;
1141+
return 'M' + pt(r0, ss) +
1142+
arc(r0, sm, 0) +
1143+
arc(r0, se, 0) +
1144+
'Z' +
1145+
'M' + pt(r1, ss) +
1146+
arc(r1, sm, 1) +
1147+
arc(r1, se, 1) +
1148+
'Z';
1149+
} else {
1150+
ss = deg2rad(sector[0]);
1151+
se = deg2rad(sector[1]);
1152+
return 'M' + pt(r0, ss) +
1153+
'L' + pt(r1, ss) +
1154+
arc(r1, se, 0) +
1155+
'L' + pt(r0, se) +
1156+
arc(r0, ss, 1) +
1157+
'Z';
1158+
}
11371159
}
11381160

11391161
function isFullCircle(sector) {

test/jasmine/tests/polar_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -922,12 +922,12 @@ describe('Test polar interactions:', function() {
922922
.then(_assertBase)
923923
.then(function() { return _drag(dragPos0, [-20, -20]); })
924924
.then(function() {
925-
_assert(7.7, 'move counterclockwise');
925+
_assert(9.9, 'move counterclockwise');
926926
})
927927
.then(_reset)
928928
.then(function() { return _drag(dragPos0, [20, 20]); })
929929
.then(function() {
930-
_assert(-6.3, 'move clockwise');
930+
_assert(-8.4, 'move clockwise');
931931
})
932932
.then(_reset)
933933
.then(function() {

test/jasmine/tests/scatterpolar_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('Test scatterpolar hover:', function() {
8686
nums: 'r: 4.022892\nθ: 2.239991',
8787
name: 'Trial 3'
8888
}, {
89-
desc: 'on work on log radial axis',
89+
desc: 'on log radial axis',
9090
patch: function(fig) {
9191
fig.layout.polar.radialaxis.type = 'log';
9292
return fig;

0 commit comments

Comments
 (0)