Skip to content

Commit 8c3580f

Browse files
authored
Merge pull request #3023 from plotly/barpolar-validate
Fix #3022 - validate + polar.bargap
2 parents 2a3dc26 + 019bacf commit 8c3580f

File tree

7 files changed

+160
-27
lines changed

7 files changed

+160
-27
lines changed

src/plot_api/validate.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,23 @@ function crawl(objIn, objOut, schema, list, base, path) {
281281

282282
// the 'full' layout schema depends on the traces types presents
283283
function fillLayoutSchema(schema, dataOut) {
284+
var layoutSchema = schema.layout.layoutAttributes;
285+
284286
for(var i = 0; i < dataOut.length; i++) {
285-
var traceType = dataOut[i].type,
286-
traceLayoutAttr = schema.traces[traceType].layoutAttributes;
287+
var traceOut = dataOut[i];
288+
var traceSchema = schema.traces[traceOut.type];
289+
var traceLayoutAttr = traceSchema.layoutAttributes;
287290

288291
if(traceLayoutAttr) {
289-
Lib.extendFlat(schema.layout.layoutAttributes, traceLayoutAttr);
292+
if(traceOut.subplot) {
293+
Lib.extendFlat(layoutSchema[traceSchema.attributes.subplot.dflt], traceLayoutAttr);
294+
} else {
295+
Lib.extendFlat(layoutSchema, traceLayoutAttr);
296+
}
290297
}
291298
}
292299

293-
return schema.layout.layoutAttributes;
300+
return layoutSchema;
294301
}
295302

296303
// validation error codes

src/plots/polar/legacy/area_attributes.js

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,53 @@
1010

1111
var scatterAttrs = require('../../../traces/scatter/attributes');
1212
var scatterMarkerAttrs = scatterAttrs.marker;
13+
var extendFlat = require('../../../lib/extend').extendFlat;
14+
15+
var deprecationWarning = [
16+
'Area traces are deprecated!',
17+
'Please switch to the *barpolar* trace type.'
18+
].join(' ');
1319

1420
module.exports = {
15-
r: scatterAttrs.r,
16-
t: scatterAttrs.t,
21+
r: extendFlat({}, scatterAttrs.r, {
22+
description: [
23+
deprecationWarning,
24+
'Sets the radial coordinates',
25+
'for legacy polar chart only.'
26+
].join(' ')
27+
}),
28+
t: extendFlat({}, scatterAttrs.t, {
29+
description: [
30+
deprecationWarning,
31+
'Sets the angular coordinates',
32+
'for legacy polar chart only.'
33+
].join(' ')
34+
}),
1735
marker: {
18-
color: scatterMarkerAttrs.color,
19-
size: scatterMarkerAttrs.size,
20-
symbol: scatterMarkerAttrs.symbol,
21-
opacity: scatterMarkerAttrs.opacity,
36+
color: extendFlat({}, scatterMarkerAttrs.color, {
37+
description: [
38+
deprecationWarning,
39+
scatterMarkerAttrs.color.description
40+
].join(' ')
41+
}),
42+
size: extendFlat({}, scatterMarkerAttrs.size, {
43+
description: [
44+
deprecationWarning,
45+
scatterMarkerAttrs.size.description
46+
].join(' ')
47+
}),
48+
symbol: extendFlat({}, scatterMarkerAttrs.symbol, {
49+
description: [
50+
deprecationWarning,
51+
scatterMarkerAttrs.symbol.description
52+
].join(' ')
53+
}),
54+
opacity: extendFlat({}, scatterMarkerAttrs.opacity, {
55+
description: [
56+
deprecationWarning,
57+
scatterMarkerAttrs.opacity.description
58+
].join(' ')
59+
}),
2260
editType: 'calc'
2361
}
2462
};

src/plots/polar/legacy/axis_attributes.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ var axesAttrs = require('../../cartesian/layout_attributes');
1313
var extendFlat = require('../../../lib/extend').extendFlat;
1414
var overrideAll = require('../../../plot_api/edit_types').overrideAll;
1515

16+
var deprecationWarning = [
17+
'Legacy polar charts are deprecated!',
18+
'Please switch to *polar* subplots.'
19+
].join(' ');
20+
1621
var domainAttr = extendFlat({}, axesAttrs.domain, {
1722
description: [
1823
'Polar chart subplots are not supported yet.',
@@ -26,6 +31,7 @@ function mergeAttrs(axisName, nonCommonAttrs) {
2631
valType: 'boolean',
2732
role: 'style',
2833
description: [
34+
deprecationWarning,
2935
'Determines whether or not the line bounding this',
3036
axisName, 'axis',
3137
'will be shown on the figure.'
@@ -35,6 +41,7 @@ function mergeAttrs(axisName, nonCommonAttrs) {
3541
valType: 'boolean',
3642
role: 'style',
3743
description: [
44+
deprecationWarning,
3845
'Determines whether or not the',
3946
axisName, 'axis ticks',
4047
'will feature tick labels.'
@@ -45,6 +52,7 @@ function mergeAttrs(axisName, nonCommonAttrs) {
4552
values: ['horizontal', 'vertical'],
4653
role: 'style',
4754
description: [
55+
deprecationWarning,
4856
'Sets the orientation (from the paper perspective)',
4957
'of the', axisName, 'axis tick labels.'
5058
].join(' ')
@@ -54,31 +62,36 @@ function mergeAttrs(axisName, nonCommonAttrs) {
5462
min: 0,
5563
role: 'style',
5664
description: [
65+
deprecationWarning,
5766
'Sets the length of the tick lines on this', axisName, 'axis.'
5867
].join(' ')
5968
},
6069
tickcolor: {
6170
valType: 'color',
6271
role: 'style',
6372
description: [
73+
deprecationWarning,
6474
'Sets the color of the tick lines on this', axisName, 'axis.'
6575
].join(' ')
6676
},
6777
ticksuffix: {
6878
valType: 'string',
6979
role: 'style',
7080
description: [
81+
deprecationWarning,
7182
'Sets the length of the tick lines on this', axisName, 'axis.'
7283
].join(' ')
7384
},
7485
endpadding: {
7586
valType: 'number',
76-
role: 'style'
87+
role: 'style',
88+
description: deprecationWarning,
7789
},
7890
visible: {
7991
valType: 'boolean',
8092
role: 'info',
8193
description: [
94+
deprecationWarning,
8295
'Determines whether or not this axis will be visible.'
8396
].join(' ')
8497
}
@@ -97,6 +110,7 @@ module.exports = overrideAll({
97110
{ valType: 'number' }
98111
],
99112
description: [
113+
deprecationWarning,
100114
'Defines the start and end point of this radial axis.'
101115
].join(' ')
102116
},
@@ -105,6 +119,7 @@ module.exports = overrideAll({
105119
valType: 'number',
106120
role: 'style',
107121
description: [
122+
deprecationWarning,
108123
'Sets the orientation (an angle with respect to the origin)',
109124
'of the radial axis.'
110125
].join(' ')
@@ -120,6 +135,7 @@ module.exports = overrideAll({
120135
{ valType: 'number', dflt: 360 }
121136
],
122137
description: [
138+
deprecationWarning,
123139
'Defines the start and end point of this angular axis.'
124140
].join(' ')
125141
},
@@ -133,16 +149,18 @@ module.exports = overrideAll({
133149
values: ['clockwise', 'counterclockwise'],
134150
role: 'info',
135151
description: [
136-
'For polar plots only.',
137-
'Sets the direction corresponding to positive angles.'
152+
deprecationWarning,
153+
'Sets the direction corresponding to positive angles',
154+
'in legacy polar charts.'
138155
].join(' ')
139156
},
140157
orientation: {
141158
valType: 'angle',
142159
role: 'info',
143160
description: [
144-
'For polar plots only.',
145-
'Rotates the entire polar by the given angle.'
161+
deprecationWarning,
162+
'Rotates the entire polar by the given angle',
163+
'in legacy polar charts.'
146164
].join(' ')
147165
}
148166
}

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
};

src/traces/scatter/attributes.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,18 +544,20 @@ module.exports = {
544544
valType: 'data_array',
545545
editType: 'calc',
546546
description: [
547-
'For legacy polar chart only.',
548-
'Please switch to *scatterpolar* trace type.',
549-
'Sets the radial coordinates.'
547+
'r coordinates in scatter traces are deprecated!',
548+
'Please switch to the *scatterpolar* trace type.',
549+
'Sets the radial coordinates',
550+
'for legacy polar chart only.'
550551
].join('')
551552
},
552553
t: {
553554
valType: 'data_array',
554555
editType: 'calc',
555556
description: [
556-
'For legacy polar chart only.',
557-
'Please switch to *scatterpolar* trace type.',
558-
'Sets the angular coordinates.'
557+
't coordinates in scatter traces are deprecated!',
558+
'Please switch to the *scatterpolar* trace type.',
559+
'Sets the angular coordinates',
560+
'for legacy polar chart only.'
559561
].join('')
560562
}
561563
};

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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,4 +539,33 @@ describe('Plotly.validate', function() {
539539
var out = Plotly.validate(shapeMock.data, shapeMock.layout);
540540
expect(out).toBeUndefined();
541541
});
542+
543+
it('should work with *trace* layout attributes', function() {
544+
var out = Plotly.validate([{
545+
type: 'bar',
546+
y: [1, 2, 1]
547+
}, {
548+
type: 'barpolar',
549+
r: [1, 2, 3]
550+
}, {
551+
type: 'scatterpolar',
552+
theta: [0, 90, 200],
553+
subplot: 'polar2'
554+
}], {
555+
bargap: 0.3,
556+
polar: {bargap: 0.2},
557+
polar2: {bargap: 0.05},
558+
polar3: {bargap: 0.4}
559+
});
560+
561+
expect(out.length).toBe(2);
562+
assertErrorContent(
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',
568+
'In layout, container polar3 did not get coerced'
569+
);
570+
});
542571
});

0 commit comments

Comments
 (0)