Skip to content

Commit e8aec86

Browse files
committed
un-rotate markers and text pts during angular drag
1 parent 974740b commit e8aec86

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

src/plots/polar/polar.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ proto.plot = function(polarCalcData, fullLayout) {
8989

9090
_this.updateLayers(fullLayout, polarLayout);
9191
_this.updateLayout(fullLayout, polarLayout);
92-
_this.updateFx(fullLayout, polarLayout);
9392
Plots.generalUpdatePerTraceModule(_this, polarCalcData, polarLayout);
93+
_this.updateFx(fullLayout, polarLayout);
9494
};
9595

9696
proto.updateLayers = function(fullLayout, polarLayout) {
@@ -891,6 +891,11 @@ proto.updateAngularDrag = function(fullLayout, polarLayout) {
891891
return Math.atan2(cyy - y, x - cxx);
892892
}
893893

894+
// scatter trace, points and textpoints selections
895+
var scatterTraces = layers.frontplot.select('.scatterlayer').selectAll('.trace');
896+
var scatterPoints = scatterTraces.selectAll('.point');
897+
var scatterTextPoints = scatterTraces.selectAll('.textpoint');
898+
894899
// mouse px position at drag start (0), move (1)
895900
var x0, y0;
896901
// angular axis angle rotation at drag start (0), move (1)
@@ -911,9 +916,19 @@ proto.updateAngularDrag = function(fullLayout, polarLayout) {
911916
strTranslate(_this.xOffset2, _this.yOffset2) + strRotate([-da, cxx, cyy])
912917
);
913918

914-
_this.clipPaths.circle.select('path').attr('transform',
915-
strTranslate(cxx, cyy) + strRotate(da)
916-
);
919+
// 'un-rotate' marker and text points
920+
scatterPoints.each(function() {
921+
var sel = d3.select(this);
922+
var xy = Drawing.getTranslate(sel);
923+
sel.attr('transform', strTranslate(xy.x, xy.y) + strRotate([da]));
924+
});
925+
scatterTextPoints.each(function() {
926+
var sel = d3.select(this);
927+
var tx = sel.select('text');
928+
var xy = Drawing.getTranslate(sel);
929+
// N.B rotate -> translate ordering matters
930+
sel.attr('transform', strRotate([da, tx.attr('x'), tx.attr('y')]) + strTranslate(xy.x, xy.y));
931+
});
917932

918933
var angularAxis = _this.angularAxis;
919934
angularAxis.rotation = wrap180(rot1);
@@ -931,10 +946,7 @@ proto.updateAngularDrag = function(fullLayout, polarLayout) {
931946
if(_this._hasClipOnAxisFalse && !isFullCircle(sector)) {
932947
// mutate sector to trick isPtWithinSector
933948
_this.sector = [sector0[0] - da, sector0[1] - da];
934-
935-
layers.frontplot
936-
.select('.scatterlayer').selectAll('.trace')
937-
.call(Drawing.hideOutsideRangePoints, _this);
949+
scatterTraces.call(Drawing.hideOutsideRangePoints, _this);
938950
}
939951

940952
for(var k in _this.traceHash) {
@@ -950,6 +962,7 @@ proto.updateAngularDrag = function(fullLayout, polarLayout) {
950962
}
951963

952964
function doneFn() {
965+
scatterTextPoints.select('text').attr('transform', null);
953966
var updateObj = {};
954967
updateObj[_this.id + '.angularaxis.rotation'] = rot1;
955968
Plotly.relayout(gd, updateObj);
83 Bytes
Loading

test/image/mocks/polar_subplots.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"theta": [0, 45, 180],
77
"text": ["A0", "B0", "C0"],
88
"hovertext": ["hover A0", "hover B0", "hover C0"],
9-
"line": { "shape": "spline" },
9+
"line": {"shape": "spline"},
10+
"marker": {"symbol": "square", "size": 15},
1011
"textfont": {
1112
"color": ["red", "green", "blue"],
1213
"size": 20
@@ -19,7 +20,8 @@
1920
"theta": [-0, -45, -180],
2021
"text": ["A1", "B1", "C1"],
2122
"hovertext": ["hover A1", "hover B1", "hover C1"],
22-
"line": { "shape": "spline" },
23+
"line": {"shape": "spline"},
24+
"marker": {"symbol": "square", "size": 15},
2325
"textfont": {
2426
"color": "green",
2527
"size": [20, 15, 10]

0 commit comments

Comments
 (0)