Skip to content

Commit 6852981

Browse files
committed
plotly_relayouting for polar plots
1 parent 4520a21 commit 6852981

File tree

2 files changed

+86
-5
lines changed

2 files changed

+86
-5
lines changed

src/plots/polar/polar.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,10 @@ proto.updateMainDrag = function(fullLayout) {
836836
corners.attr('d', cpath);
837837
dragBox.transitionZoombox(zb, corners, dimmed, lum);
838838
dimmed = true;
839+
840+
var updateObj = {};
841+
computeZoomUpdates(updateObj);
842+
gd.emit('plotly_relayouting', updateObj);
839843
}
840844

841845
function zoomMove(dx, dy) {
@@ -889,16 +893,22 @@ proto.updateMainDrag = function(fullLayout) {
889893
dragBox.removeZoombox(gd);
890894

891895
if(r0 === null || r1 === null) return;
896+
var updateObj = {};
897+
computeZoomUpdates(updateObj);
892898

893899
dragBox.showDoubleClickNotifier(gd);
894900

901+
Registry.call('_guiRelayout', gd, updateObj);
902+
}
903+
904+
function computeZoomUpdates(update) {
895905
var rl = radialAxis._rl;
896906
var m = (rl[1] - rl[0]) / (1 - innerRadius / radius) / radius;
897907
var newRng = [
898908
rl[0] + (r0 - innerRadius) * m,
899909
rl[0] + (r1 - innerRadius) * m
900910
];
901-
Registry.call('_guiRelayout', gd, _this.id + '.radialaxis.range', newRng);
911+
update[_this.id + '.radialaxis.range'] = newRng;
902912
}
903913

904914
function zoomClick(numClicks, evt) {
@@ -1236,18 +1246,25 @@ proto.updateAngularDrag = function(fullLayout) {
12361246
clearGlCanvases(gd);
12371247
redrawReglTraces(gd);
12381248
}
1239-
}
12401249

1241-
function doneFn() {
1242-
scatterTextPoints.select('text').attr('transform', null);
1250+
var update = {};
1251+
computeRotationUpdates(update);
1252+
gd.emit('plotly_relayouting', update);
1253+
}
12431254

1244-
var updateObj = {};
1255+
function computeRotationUpdates(updateObj) {
12451256
updateObj[_this.id + '.angularaxis.rotation'] = rot1;
12461257

12471258
if(_this.vangles) {
12481259
updateObj[_this.id + '.radialaxis.angle'] = rrot1;
12491260
}
1261+
}
12501262

1263+
function doneFn() {
1264+
scatterTextPoints.select('text').attr('transform', null);
1265+
1266+
var updateObj = {};
1267+
computeRotationUpdates(updateObj);
12511268
Registry.call('_guiRelayout', gd, updateObj);
12521269
}
12531270

test/jasmine/tests/polar_test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,70 @@ describe('Test polar interactions:', function() {
12471247
});
12481248
});
12491249
});
1250+
1251+
describe('plotly_relayouting', function() {
1252+
afterEach(destroyGraphDiv);
1253+
1254+
['zoom'].forEach(function(dragmode) {
1255+
function _drag(p0, dp, nsteps) {
1256+
var node = d3.select('.polar > .draglayer > .maindrag').node();
1257+
return drag(node, dp[0], dp[1], null, p0[0], p0[1], nsteps);
1258+
}
1259+
1260+
it('should emit plotly_relayouting events on ' + dragmode, function(done) {
1261+
var events = []; var path = [[150, 250], [175, 250]]; var relayoutCallback;
1262+
var fig = Lib.extendDeep({}, require('@mocks/polar_scatter.json'));
1263+
fig.layout.dragmode = dragmode;
1264+
1265+
var gd = createGraphDiv();
1266+
Plotly.plot(gd, fig)
1267+
.then(function() {
1268+
relayoutCallback = jasmine.createSpy('relayoutCallback');
1269+
gd.on('plotly_relayout', relayoutCallback);
1270+
gd.on('plotly_relayouting', function(e) {
1271+
events.push(e);
1272+
});
1273+
return _drag(path[0], path[1]);
1274+
})
1275+
.then(function() {
1276+
expect(events.length).toEqual(path.length - 1);
1277+
expect(events[0]['polar.radialaxis.range']).toBeCloseToArray([6, 11], 0.1);
1278+
expect(relayoutCallback).toHaveBeenCalledTimes(1);
1279+
})
1280+
.catch(failTest)
1281+
.then(done);
1282+
});
1283+
});
1284+
it('should emit plotly_relayouting events on angular drag', function(done) {
1285+
var events = []; var relayoutCallback;
1286+
var fig = Lib.extendDeep({}, require('@mocks/polar_scatter.json'));
1287+
1288+
function _drag(p0, dp, nsteps) {
1289+
var node = d3.select('.polar > .draglayer > .angulardrag').node();
1290+
return drag(node, dp[0], dp[1], null, p0[0], p0[1], nsteps);
1291+
}
1292+
1293+
var dragPos0 = [360, 180];
1294+
1295+
var gd = createGraphDiv();
1296+
Plotly.plot(gd, fig)
1297+
.then(function() {
1298+
relayoutCallback = jasmine.createSpy('relayoutCallback');
1299+
gd.on('plotly_relayout', relayoutCallback);
1300+
gd.on('plotly_relayouting', function(e) {
1301+
events.push(e);
1302+
});
1303+
return _drag(dragPos0, [0, -110], 10);
1304+
})
1305+
.then(function() {
1306+
expect(events.length).toEqual(10);
1307+
expect(events.splice(-1, 1)[0]['polar.angularaxis.rotation']).toBeCloseTo(29, 0);
1308+
expect(relayoutCallback).toHaveBeenCalledTimes(1);
1309+
})
1310+
.catch(failTest)
1311+
.then(done);
1312+
});
1313+
});
12501314
});
12511315

12521316
describe('Test polar *gridshape linear* interactions', function() {

0 commit comments

Comments
 (0)