Skip to content
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

feat: use view descriptions for accessibility #6520

Merged
merged 2 commits into from
May 21, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/compile/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,29 @@ export abstract class Model {
// Exclude "style"
const {style: _, ...baseView} = view;

const e = {};
const e: VgEncodeEntry = {};
for (const property of keys(baseView)) {
const value = baseView[property];
if (value !== undefined) {
e[property] = signalOrValueRef(value);
}
}

return e;
}

public assembleGroupEncodeEntry(isTopLevel: boolean): VgEncodeEntry {
let encodeEntry: VgEncodeEntry = undefined;
let encodeEntry: VgEncodeEntry = {};
if (this.view) {
encodeEntry = this.assembleEncodeFromView(this.view);
}

if (!isTopLevel) {
// Descriptions are already added to the top-level description so we only need to add them to the inner views.
if (this.description) {
encodeEntry['description'] = signalOrValueRef(this.description);
}

// For top-level spec, we can set the global width and height signal to adjust the group size.
// For other child specs, we have to manually set width and height in the encode entry.
if (this.type === 'unit' || this.type === 'layer') {
Expand Down
12 changes: 12 additions & 0 deletions test/compile/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,17 @@ describe('Model', () => {
fill: {signal: '"red"'}
});
});

it('should support descriptions for non-top level models', () => {
const model = parseModel({
data: {values: []},
mark: 'point',
description: 'My awesome view'
});

expect(model.assembleGroupEncodeEntry(true)).toEqual({});

expect(model.assembleGroupEncodeEntry(false)['description']).toEqual({value: 'My awesome view'});
});
});
});