Skip to content

Commit 86e18fb

Browse files
committed
include 'trace' layout attributes set in subplot containers
... during validation. This solution is not-strict as it could be, but at least fixes the false-negative case of #3022.
1 parent 4225f9e commit 86e18fb

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
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

test/jasmine/tests/validate_test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,4 +539,36 @@ 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(1);
562+
assertErrorContent(
563+
out[0], 'unused', 'layout', null, ['polar3'], 'polar3',
564+
'In layout, container polar3 did not get coerced'
565+
);
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.
573+
});
542574
});

0 commit comments

Comments
 (0)