Skip to content

Commit 7f0fc26

Browse files
committed
don't attempt to draw radial axis when *polar.hole* is set to 1
1 parent 5fa493a commit 7f0fc26

File tree

2 files changed

+63
-18
lines changed

2 files changed

+63
-18
lines changed

src/plots/polar/polar.js

+31-18
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
380380
var radialLayout = polarLayout.radialaxis;
381381
var a0 = mod(polarLayout.sector[0], 360);
382382
var ax = _this.radialAxis;
383+
var hasRoomForIt = innerRadius < radius;
383384

384385
_this.fillViewInitialKey('radialaxis.angle', radialLayout.angle);
385386
_this.fillViewInitialKey('radialaxis.range', ax.range.slice());
@@ -410,8 +411,10 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
410411
_this.radialTickLayout = newTickLayout;
411412
}
412413

413-
ax.setScale();
414-
doTicksSingle(gd, ax, true);
414+
if(hasRoomForIt) {
415+
ax.setScale();
416+
doTicksSingle(gd, ax, true);
417+
}
415418

416419
// stash 'actual' radial axis angle for drag handlers (in degrees)
417420
var angle = _this.radialAxisAngle = _this.vangles ?
@@ -420,24 +423,31 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
420423

421424
var trans = strTranslate(cx, cy) + strRotate(-angle);
422425

423-
updateElement(layers['radial-axis'], radialLayout.showticklabels || radialLayout.ticks, {
424-
transform: trans
425-
});
426+
updateElement(
427+
layers['radial-axis'],
428+
hasRoomForIt && (radialLayout.showticklabels || radialLayout.ticks),
429+
{transform: trans}
430+
);
426431

427432
// move all grid paths to about circle center,
428433
// undo individual grid lines translations
429-
updateElement(layers['radial-grid'], radialLayout.showgrid, {
430-
transform: strTranslate(cx, cy)
431-
})
432-
.selectAll('path').attr('transform', null);
433-
434-
updateElement(layers['radial-line'].select('line'), radialLayout.showline, {
435-
x1: innerRadius,
436-
y1: 0,
437-
x2: radius,
438-
y2: 0,
439-
transform: trans
440-
})
434+
updateElement(
435+
layers['radial-grid'],
436+
hasRoomForIt && radialLayout.showgrid,
437+
{transform: strTranslate(cx, cy)}
438+
).selectAll('path').attr('transform', null);
439+
440+
updateElement(
441+
layers['radial-line'].select('line'),
442+
hasRoomForIt && radialLayout.showline,
443+
{
444+
x1: innerRadius,
445+
y1: 0,
446+
x2: radius,
447+
y2: 0,
448+
transform: trans
449+
}
450+
)
441451
.attr('stroke-width', radialLayout.linewidth)
442452
.call(Color.stroke, radialLayout.linecolor);
443453
};
@@ -963,7 +973,10 @@ proto.updateRadialDrag = function(fullLayout, polarLayout, rngIndex) {
963973

964974
var radialDrag = dragBox.makeRectDragger(layers, className, 'crosshair', -bl2, -bl2, bl, bl);
965975
var dragOpts = {element: radialDrag, gd: gd};
966-
d3.select(radialDrag).attr('transform', strTranslate(tx, ty));
976+
977+
updateElement(d3.select(radialDrag), radialAxis.visible && innerRadius < radius, {
978+
transform: strTranslate(tx, ty)
979+
});
967980

968981
// move function (either rotate or re-range flavor)
969982
var moveFn2;

test/jasmine/tests/polar_test.js

+32
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ var doubleClick = require('../assets/double_click');
1313
var drag = require('../assets/drag');
1414
var delay = require('../assets/delay');
1515

16+
var customAssertions = require('../assets/custom_assertions');
17+
var assertNodeDisplay = customAssertions.assertNodeDisplay;
18+
1619
describe('Test legacy polar plots logs:', function() {
1720
var gd;
1821

@@ -628,6 +631,35 @@ describe('Test relayout on polar subplots:', function() {
628631
.catch(failTest)
629632
.then(done);
630633
});
634+
635+
it('should not attempt to draw radial axis when *polar.hole* is set to 1', function(done) {
636+
var gd = createGraphDiv();
637+
638+
var queries = [
639+
'.radial-axis', '.radial-grid', '.radial-line > line',
640+
'.radialdrag', '.radialdrag-inner'
641+
];
642+
643+
function _assert(msg, showing) {
644+
var exp = showing ? null : 'none';
645+
var sp3 = d3.select(gd).select('.polarlayer > .polar');
646+
queries.forEach(function(q) {
647+
assertNodeDisplay(sp3.selectAll(q), [exp], msg + ' ' + q);
648+
});
649+
}
650+
651+
Plotly.plot(gd, [{
652+
type: 'scatterpolar',
653+
r: ['a', 'b', 'c']
654+
}])
655+
.then(function() { _assert('base', true); })
656+
.then(function() { return Plotly.relayout(gd, 'polar.hole', 1); })
657+
.then(function() { _assert('hole=1', false); })
658+
.then(function() { return Plotly.relayout(gd, 'polar.hole', 0.2); })
659+
.then(function() { _assert('hole=0.2', true); })
660+
.catch(failTest)
661+
.then(done);
662+
});
631663
});
632664

633665
describe('Test polar interactions:', function() {

0 commit comments

Comments
 (0)