Skip to content

Commit 25b4e7b

Browse files
committed
even more robust relayout
1 parent cb78d19 commit 25b4e7b

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

src/plots/polar/polar.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ function Polar(gd, id) {
5151

5252
this.clipIds.circle = clipIdBase + '-circle';
5353
this.clipPaths.circle = fullLayout._clips.append('clipPath')
54-
.attr('id', this.clipIds.circle)
55-
.append('path');
54+
.attr('id', this.clipIds.circle);
55+
this.clipPaths.circle.append('path');
5656

5757
this.framework = fullLayout._polarlayer.append('g')
5858
.attr('class', id);
@@ -242,7 +242,7 @@ proto.updateLayout = function(fullLayout, polarLayout) {
242242
})
243243
.call(Color.fill, polarLayout.bgcolor);
244244

245-
_this.clipPaths.circle
245+
_this.clipPaths.circle.select('path')
246246
.attr('d', pathSectorClosed(radius, sector))
247247
.attr('transform', strTranslate(cx - xOffset2, cy - yOffset2));
248248
};
@@ -304,7 +304,7 @@ proto.updateRadialAxis = function(fullLayout, polarLayout) {
304304
return pathSector(r, sector);
305305
};
306306

307-
var newTickLayout = radialLayout.ticks + radialLayout.showticklabels;
307+
var newTickLayout = strTickLayout(radialLayout);
308308
if(_this.radialTickLayout !== newTickLayout) {
309309
layers['radial-axis'].selectAll('.xtick').remove();
310310
_this.radialTickLayout = newTickLayout;
@@ -505,7 +505,7 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
505505
'middle';
506506
};
507507

508-
var newTickLayout = angularLayout.ticks + angularLayout.showticklabels;
508+
var newTickLayout = strTickLayout(angularLayout);
509509
if(_this.angularTickLayout !== newTickLayout) {
510510
layers['angular-axis'].selectAll('.angulartick').remove();
511511
_this.angularTickLayout = newTickLayout;
@@ -708,7 +708,7 @@ proto.updateMainDrag = function(fullLayout, polarLayout) {
708708
strTranslate(xOffset2, yOffset2) + strRotate([-dangle, cxx, cyy])
709709
);
710710

711-
_this.clipPaths.circle.attr('transform',
711+
_this.clipPaths.circle.select('circle').attr('transform',
712712
strTranslate(cxx, cyy) + strRotate(dangle)
713713
);
714714

@@ -987,6 +987,10 @@ function setScale(ax, axLayout, fullLayout) {
987987
ax.setScale();
988988
}
989989

990+
function strTickLayout(axLayout) {
991+
return axLayout.ticks + String(axLayout.ticklen) + String(axLayout.showticklabels);
992+
}
993+
990994
// Finds the bounding box of a given circle sector,
991995
// inspired by https://math.stackexchange.com/q/1852703
992996
//

test/jasmine/tests/polar_test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ describe('Test polar plots defaults:', function() {
113113
expect(layoutOut.polar.radialaxis.type).toBe('linear', 'not date');
114114
expect(layoutOut.polar.angularaxis.type).toBe('linear', 'not category');
115115
});
116+
117+
it('should propagate axis *color* settings', function() {
118+
_supply({
119+
polar: {
120+
angularaxis: {color: 'red'},
121+
radialaxis: {color: 'blue'}
122+
}
123+
});
124+
125+
expect(layoutOut.polar.angularaxis.linecolor).toBe('red');
126+
expect(layoutOut.polar.angularaxis.gridcolor).toBe('rgb(255, 153, 153)', 'blend by 60% with bgcolor');
127+
128+
expect(layoutOut.polar.radialaxis.titlefont.color).toBe('blue');
129+
expect(layoutOut.polar.radialaxis.linecolor).toBe('blue');
130+
expect(layoutOut.polar.radialaxis.gridcolor).toBe('rgb(153, 153, 255)', 'blend by 60% with bgcolor');
131+
});
116132
});
117133

118134
describe('Test relayout on polar subplots:', function() {
@@ -399,4 +415,35 @@ describe('Test relayout on polar subplots:', function() {
399415
.then(done);
400416
});
401417

418+
it('should clean up its framework, clip paths and info layers when getting deleted', function(done) {
419+
var gd = createGraphDiv();
420+
var fig = Lib.extendDeep({}, require('@mocks/polar_scatter.json'));
421+
422+
function _assert(exp) {
423+
expect(d3.selectAll('g.polar').size()).toBe(exp.subplot, '# subplot layer');
424+
expect(d3.selectAll('g.g-polartitle').size()).toBe(exp.rtitle, '# radial title');
425+
426+
var clipCnt = 0;
427+
d3.selectAll('clipPath').each(function() {
428+
if(/polar-circle$/.test(this.id)) clipCnt++;
429+
});
430+
expect(clipCnt).toBe(exp.clip, '# clip paths');
431+
}
432+
433+
Plotly.plot(gd, fig).then(function() {
434+
_assert({subplot: 1, clip: 1, rtitle: 1});
435+
436+
return Plotly.restyle(gd, 'visible', false);
437+
})
438+
.then(function() {
439+
_assert({subplot: 0, clip: 0, rtitle: 0});
440+
441+
return Plotly.restyle(gd, 'visible', true);
442+
})
443+
.then(function() {
444+
_assert({subplot: 1, clip: 1, rtitle: 1});
445+
})
446+
.catch(fail)
447+
.then(done);
448+
});
402449
});

0 commit comments

Comments
 (0)