Skip to content

Commit c5cf89b

Browse files
committed
make supplyDefault (and Plotly.validate) more strict w/ polar?.bar*
- coerce polar?.bargap and polar?.barmode only for subplots with visible barpolar traces on them.
1 parent 86e18fb commit c5cf89b

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

src/traces/barpolar/layout_defaults.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@
1111
var Lib = require('../../lib');
1212
var attrs = require('./layout_attributes');
1313

14-
module.exports = function(layoutIn, layoutOut) {
15-
var subplotIds = layoutOut._subplots.polar;
14+
module.exports = function(layoutIn, layoutOut, fullData) {
15+
var subplotsDone = {};
1616
var sp;
1717

1818
function coerce(attr, dflt) {
1919
return Lib.coerce(layoutIn[sp] || {}, layoutOut[sp], attrs, attr, dflt);
2020
}
2121

22-
for(var i = 0; i < subplotIds.length; i++) {
23-
sp = subplotIds[i];
24-
coerce('barmode');
25-
coerce('bargap');
22+
for(var i = 0; i < fullData.length; i++) {
23+
var trace = fullData[i];
24+
if(trace.type === 'barpolar' && trace.visible === true) {
25+
sp = trace.subplot;
26+
if(!subplotsDone[sp]) {
27+
coerce('barmode');
28+
coerce('bargap');
29+
subplotsDone[sp] = 1;
30+
}
31+
}
2632
}
2733
};

test/jasmine/tests/barpolar_test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
var Plotly = require('@lib');
22
var Lib = require('@src/lib');
33

4+
var supplyAllDefaults = require('../assets/supply_defaults');
45
var createGraphDiv = require('../assets/create_graph_div');
56
var destroyGraphDiv = require('../assets/destroy_graph_div');
67
var failTest = require('../assets/fail_test');
78

9+
describe('Test barpolar defaults:', function() {
10+
var gd;
11+
12+
function _supply(opts, layout) {
13+
gd = {};
14+
opts = Array.isArray(opts) ? opts : [opts];
15+
16+
gd.data = opts.map(function(o) {
17+
return Lib.extendFlat({type: 'barpolar'}, o || {});
18+
});
19+
gd.layout = layout || {};
20+
21+
supplyAllDefaults(gd);
22+
}
23+
24+
it('should not coerce polar.bar* attributes on subplot w/o visible barpolar', function() {
25+
_supply([
26+
{visible: false, subplot: 'polar'},
27+
{r: [1], subplot: 'polar2'},
28+
{type: 'scatterpolar', r: [1], subplot: 'polar3'}
29+
]);
30+
31+
var fullLayout = gd._fullLayout;
32+
expect(fullLayout.polar.barmode).toBeUndefined();
33+
expect(fullLayout.polar.bargap).toBeUndefined();
34+
expect(fullLayout.polar2.barmode).toBe('stack');
35+
expect(fullLayout.polar2.bargap).toBe(0.1);
36+
expect(fullLayout.polar3.barmode).toBeUndefined();
37+
expect(fullLayout.polar3.bargap).toBeUndefined();
38+
});
39+
});
40+
841
describe('Test barpolar hover:', function() {
942
var gd;
1043

test/jasmine/tests/validate_test.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,17 +558,14 @@ describe('Plotly.validate', function() {
558558
polar3: {bargap: 0.4}
559559
});
560560

561-
expect(out.length).toBe(1);
561+
expect(out.length).toBe(2);
562562
assertErrorContent(
563-
out[0], 'unused', 'layout', null, ['polar3'], 'polar3',
563+
out[0], 'unused', 'layout', null, ['polar2', 'bargap'], 'polar2.bargap',
564+
'In layout, key polar2.bargap did not get coerced'
565+
);
566+
assertErrorContent(
567+
out[1], 'unused', 'layout', null, ['polar3'], 'polar3',
564568
'In layout, container polar3 did not get coerced'
565569
);
566-
567-
// Plotly.validate should be more strict here.
568-
//
569-
// It should log an 'unused' warning for `polar2.bargap`,
570-
// but trace layout attribute set in subplot containers are considered
571-
// valid as long as one trace on that graph has those trace layout
572-
// attributes.
573570
});
574571
});

0 commit comments

Comments
 (0)