Skip to content

Fix #3022 - validate + polar.bargap #3023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
etpinard committed Sep 18, 2018
commit 86e18fb0e646edcfb66e01f36b07d1ff14a1fcbe
15 changes: 11 additions & 4 deletions src/plot_api/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,23 @@ function crawl(objIn, objOut, schema, list, base, path) {

// the 'full' layout schema depends on the traces types presents
function fillLayoutSchema(schema, dataOut) {
var layoutSchema = schema.layout.layoutAttributes;

for(var i = 0; i < dataOut.length; i++) {
var traceType = dataOut[i].type,
traceLayoutAttr = schema.traces[traceType].layoutAttributes;
var traceOut = dataOut[i];
var traceSchema = schema.traces[traceOut.type];
var traceLayoutAttr = traceSchema.layoutAttributes;

if(traceLayoutAttr) {
Lib.extendFlat(schema.layout.layoutAttributes, traceLayoutAttr);
if(traceOut.subplot) {
Lib.extendFlat(layoutSchema[traceSchema.attributes.subplot.dflt], traceLayoutAttr);
} else {
Lib.extendFlat(layoutSchema, traceLayoutAttr);
}
}
}

return schema.layout.layoutAttributes;
return layoutSchema;
}

// validation error codes
Expand Down
32 changes: 32 additions & 0 deletions test/jasmine/tests/validate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,36 @@ describe('Plotly.validate', function() {
var out = Plotly.validate(shapeMock.data, shapeMock.layout);
expect(out).toBeUndefined();
});

it('should work with *trace* layout attributes', function() {
var out = Plotly.validate([{
type: 'bar',
y: [1, 2, 1]
}, {
type: 'barpolar',
r: [1, 2, 3]
}, {
type: 'scatterpolar',
theta: [0, 90, 200],
subplot: 'polar2'
}], {
bargap: 0.3,
polar: {bargap: 0.2},
polar2: {bargap: 0.05},
polar3: {bargap: 0.4}
});

expect(out.length).toBe(1);
assertErrorContent(
out[0], 'unused', 'layout', null, ['polar3'], 'polar3',
'In layout, container polar3 did not get coerced'
);

// Plotly.validate should be more strict here.
//
// It should log an 'unused' warning for `polar2.bargap`,
// but trace layout attribute set in subplot containers are considered
// valid as long as one trace on that graph has those trace layout
// attributes.
});
});