Skip to content

Commit 2eeab9f

Browse files
committed
fix and 🔒 category angular axis mocked range logic
- 🔪 useless axex.expand call in scatterpolar/calc, this is an artefact from an earlier angular dates attempt - set mocked angular axis range using max of set 'period' and total categories length. - more on period vs category in #2255
1 parent fa85e21 commit 2eeab9f

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed

Diff for: src/plots/polar/polar.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,15 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
416416
_counteraxis: true,
417417

418418
// don't use automargins routine for labels
419-
automargin: false
419+
automargin: false,
420+
421+
// don't pass through autorange logic
422+
autorange: false
420423
});
421424

422425
// Set the angular range in degrees to make auto-tick computation cleaner,
423426
// changing rotation/direction should not affect the angular tick labels.
424427
if(ax.type === 'linear') {
425-
ax.autorange = false;
426-
427428
if(isFullCircle(sector)) {
428429
ax.range = sector.slice();
429430
} else {
@@ -435,11 +436,18 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
435436
ax.tick0 = rad2deg(ax.tick0);
436437
ax.dtick = rad2deg(ax.dtick);
437438
}
439+
438440
}
439441
// Use tickval filter for category axes instead of tweaking
440442
// the range w.r.t sector, so that sectors that cross 360 can
441443
// show all their ticks.
442444
else if(ax.type === 'category') {
445+
var period = angularLayout.period ?
446+
Math.max(angularLayout.period, angularLayout._categories.length) :
447+
angularLayout._categories.length;
448+
449+
ax.range = [0, period];
450+
443451
ax._tickFilter = function(d) {
444452
return _this.isPtWithinSector({
445453
r: _this.radialAxis.range[1],
@@ -449,7 +457,6 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
449457
}
450458

451459
setScale(ax, angularLayout, fullLayout);
452-
doAutoRange(ax);
453460

454461
// wrapper around c2rad from setConvertAngular
455462
// note that linear ranges are always set in degrees for Axes.doTicks

Diff for: src/traces/scatterpolar/calc.js

-6
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ module.exports = function calc(gd, trace) {
5050
var ppad = calcMarkerSize(trace, len);
5151
Axes.expand(radialAxis, rArray, {ppad: ppad});
5252

53-
if(angularAxis.type !== 'linear') {
54-
angularAxis.autorange = true;
55-
Axes.expand(angularAxis, thetaArray);
56-
delete angularAxis.autorange;
57-
}
58-
5953
calcColorscale(trace);
6054
arraysToCalcdata(cd, trace);
6155
calcSelection(cd, trace);

Diff for: test/jasmine/tests/polar_test.js

+59
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,65 @@ describe('Test relayout on polar subplots:', function() {
543543
.catch(fail)
544544
.then(done);
545545
});
546+
547+
it('should update axis ranges when extending traces', function(done) {
548+
var gd = createGraphDiv();
549+
550+
function _assert(msg, exp) {
551+
expect(gd._fullLayout.polar.radialaxis.autorange).toBe(true);
552+
553+
expect(gd.layout.polar.radialaxis.range)
554+
.toBeCloseToArray(exp.rRange, 2, 'radial range in user layout - ' + msg);
555+
expect(gd._fullLayout.polar.radialaxis.range)
556+
.toBeCloseToArray(exp.rRange, 2, 'radial range in full layout - ' + msg);
557+
558+
expect(gd._fullLayout.polar._subplot.angularAxis.range)
559+
.toBeCloseToArray([0, exp.period], 2, 'range in mocked angular axis - ' + msg);
560+
561+
expect(d3.selectAll('path.angulartick').size())
562+
.toBe(exp.nTicks, '# of visible angular ticks - ' + msg);
563+
564+
expect([gd.calcdata[0][5].x, gd.calcdata[0][5].y])
565+
.toBeCloseToArray(exp.sampleXY, -1, 'sample (x,y) px coords in calcdata - ' + msg);
566+
}
567+
568+
Plotly.plot(gd, [{
569+
type: 'scatterpolar',
570+
r: [39, 28, 8, 7, 28, 39, 40, 30, 30, 30, 30],
571+
theta: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'A']
572+
}])
573+
.then(function() {
574+
_assert('base', {
575+
rRange: [0, 41.14],
576+
period: 10,
577+
nTicks: 10,
578+
sampleXY: [-39, 0]
579+
});
580+
return Plotly.extendTraces(gd, {
581+
r: [[-10, -5]],
582+
theta: [['y', 'z']]
583+
}, [0]);
584+
})
585+
.then(function() {
586+
_assert('after extending trace', {
587+
rRange: [-11.47, 41.47],
588+
period: 12,
589+
nTicks: 12,
590+
sampleXY: [-43, 25]
591+
});
592+
return Plotly.relayout(gd, 'polar.angularaxis.period', 15);
593+
})
594+
.then(function() {
595+
_assert('after angularaxis.period relayout', {
596+
rRange: [-11.47, 41.47],
597+
period: 15,
598+
nTicks: 12,
599+
sampleXY: [-25, 43]
600+
});
601+
})
602+
.catch(fail)
603+
.then(done);
604+
});
546605
});
547606

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

0 commit comments

Comments
 (0)