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

fix: for interactive charts, changed cursor to pointer (also updated tests) #9305

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions src/compile/mark/mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,21 @@ function getMarkGroup(model: UnitModel, opt: {fromPrefix: string} = {fromPrefix:
const key = encoding.key;
const sort = getSort(model);
const interactive = interactiveFlag(model);

let isPoint = false;
let isBind = false;
if (model.component.selection) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't look right. What if there is one point selection and one point selection with bind. Then this would not work.

for (const k of keys(model.component.selection)) {
if (model.component.selection[k].bind) {
isBind = true;
}
if (model.component.selection[k].type == 'point') {
isPoint = true;
}
}
}
interactive && isPoint && !isBind ? (model.markDef.cursor ??= 'pointer') : {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use an if statement?


const aria = getMarkPropOrConfig('aria', markDef, config);

const postEncodingTransform = markCompiler[mark].postEncodingTransform
Expand Down
52 changes: 52 additions & 0 deletions test/compile/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,55 @@ describe('compile/compile', () => {
expect(spec.autosize['resize']).toBeTruthy();
});
});

it('should generate right cursor for point selection', () => {
const {spec} = compile({
data: {url: 'data/population.json'},
params: [{name: 'select', select: 'point'}],
mark: 'bar',
encoding: {
x: {field: 'a', type: 'ordinal'},
y: {field: 'b', type: 'quantitative'}
}
});

expect(spec.marks[0].encode.update.cursor).toEqual({value: 'pointer'});
});

it('should not generate cursor for point selection with binding', () => {
const {spec} = compile({
data: {url: 'data/population.json'},
params: [
{
name: 'highlight',
value: [{Cylinders: 4, Year: 1977}],
select: {type: 'point', fields: ['Cylinders', 'Year']},
bind: {
Cylinders: {input: 'range', min: 3, max: 8, step: 1},
Year: {input: 'range', min: 1969, max: 1981, step: 1}
}
}
],
mark: 'bar',
encoding: {
x: {field: 'a', type: 'ordinal'},
y: {field: 'b', type: 'quantitative'}
}
});

expect(spec.marks[0].encode.update.cursor).toBeUndefined();
});

it('should not generate cursor for interval selection', () => {
const {spec} = compile({
data: {url: 'data/population.json'},
params: [{name: 'brush', select: {type: 'interval', encodings: ['x']}}],
mark: 'bar',
encoding: {
x: {field: 'a', type: 'ordinal'},
y: {field: 'b', type: 'quantitative'}
}
});

expect(spec.marks[0].encode.update.cursor).toBeUndefined();
});