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: for interactive charts, changed cursor to pointer #9358

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions examples/compiled/concat_bar_layer_circle.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
"from": {"data": "data_3"},
"encode": {
"update": {
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"pts_store\")) || vlSelectionTest(\"pts_store\", datum)",
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/dynamic_color_legend.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@
"from": {"data": "data_1"},
"encode": {
"update": {
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"click_store\")) || vlSelectionTest(\"click_store\", datum)",
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/interactive_concat_layer.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
"from": {"data": "data_3"},
"encode": {
"update": {
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"pts_store\")) || vlSelectionTest(\"pts_store\", datum)",
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/interactive_global_development.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
"update": {
"opacity": {"value": 0.9},
"size": {"value": 100},
"cursor": {"value": "pointer"},
"fill": {"scale": "color", "field": "name"},
"ariaRoleDescription": {"value": "circle"},
"description": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
"from": {"data": "data_6"},
"encode": {
"update": {
"cursor": {"value": "pointer"},
"fill": {"value": "#ddd"},
"ariaRoleDescription": {"value": "bar"},
"description": {
Expand Down Expand Up @@ -414,6 +415,7 @@
"from": {"data": "data_7"},
"encode": {
"update": {
"cursor": {"value": "pointer"},
"fill": {"value": "#ddd"},
"ariaRoleDescription": {"value": "bar"},
"description": {
Expand Down Expand Up @@ -569,6 +571,7 @@
"from": {"data": "data_2"},
"encode": {
"update": {
"cursor": {"value": "pointer"},
"fill": {"value": "#ddd"},
"ariaRoleDescription": {"value": "bar"},
"description": {
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/interactive_point_init.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"CylYr_store\")) || vlSelectionTest(\"CylYr_store\", datum)",
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/interactive_seattle_weather.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@
"from": {"data": "data_1"},
"encode": {
"update": {
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"click_store\")) || vlSelectionTest(\"click_store\", datum)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"encode": {
"update": {
"opacity": {"value": 0},
"cursor": {"value": "pointer"},
"fill": {"value": "transparent"},
"stroke": {"value": "#4c78a8"},
"ariaRoleDescription": {"value": "point"},
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/param_expr.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"update": {
"opacity": {"signal": "opacityVar/100"},
"size": {"signal": "sel.Miles_per_Gallon * 10 || 75"},
"cursor": {"value": "pointer"},
"fill": {"value": "transparent"},
"stroke": {"value": "#4c78a8"},
"ariaRoleDescription": {"value": "point"},
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/selection_heatmap.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"encode": {
"update": {
"strokeWidth": {"value": 2},
"cursor": {"value": "pointer"},
"fill": {"scale": "fill", "field": "count"},
"stroke": [
{
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/selection_insert.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"paintbrush_store\")) || vlSelectionIdTest(\"paintbrush_store\", datum)",
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/selection_project_multi.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": {"value": "transparent"},
"stroke": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": {"value": "transparent"},
"stroke": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": {"value": "transparent"},
"stroke": [
{
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/selection_project_multi_origin.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": {"value": "transparent"},
"stroke": [
{
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/selection_project_single.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": {"value": "transparent"},
"stroke": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": {"value": "transparent"},
"stroke": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": {"value": "transparent"},
"stroke": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": {"value": "transparent"},
"stroke": [
{
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/selection_toggle_altKey.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"paintbrush_store\")) || vlSelectionIdTest(\"paintbrush_store\", datum)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"paintbrush_store\")) || vlSelectionIdTest(\"paintbrush_store\", datum)",
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/selection_toggle_shiftKey.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"paintbrush_store\")) || vlSelectionIdTest(\"paintbrush_store\", datum)",
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/selection_type_point.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"from": {"data": "source_0"},
"encode": {
"update": {
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"pts_store\")) || vlSelectionIdTest(\"pts_store\", datum)",
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/selection_type_single_dblclick.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"from": {"data": "source_0"},
"encode": {
"update": {
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"pts_store\")) || vlSelectionIdTest(\"pts_store\", datum)",
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/vconcat_flatten.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"encode": {
"update": {
"opacity": {"value": 0.7},
"cursor": {"value": "pointer"},
"fill": [
{
"test": "!length(data(\"pts_store\")) || vlSelectionTest(\"pts_store\", datum)",
Expand Down
3 changes: 1 addition & 2 deletions examples/specs/interactive_bar_select_highlight.vl.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"mark": {
"type": "bar",
"fill": "#4C78A8",
"stroke": "black",
"cursor": "pointer"
"stroke": "black"
},
"encoding": {
"x": {"field": "a", "type": "ordinal"},
Expand Down
3 changes: 2 additions & 1 deletion src/compile/mark/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export function initMarkdef(originalMarkDef: MarkDef, encoding: Encoding<string>
markDef.opacity = opacity(markDef.type, encoding);
}

// set cursor, which should be pointer if href channel is present unless otherwise specified
// Set cursor, which should be pointer if href channel is present unless otherwise specified.
// We will also set the cursor in parse via getMarkGroup since we need access to the selections.
const specifiedCursor = getMarkPropOrConfig('cursor', markDef, config);
if (specifiedCursor === undefined) {
markDef.cursor = cursor(markDef, encoding, config);
Expand Down
15 changes: 15 additions & 0 deletions src/compile/mark/mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ function getMarkGroup(model: UnitModel, opt: {fromPrefix: string} = {fromPrefix:
const key = encoding.key;
const sort = getSort(model);
const interactive = interactiveFlag(model);

// set pointer cursor for point selections that are not bound
if (
interactive &&
Object.values(model.component.selection).some(
s =>
s.type === 'point' &&
!s.bind &&
// if on is a pointerover (hover) the pointer makes less sense since the mark is not clickable.
(s as any).on !== 'pointerover'
)
) {
model.markDef.cursor ??= 'pointer';
}

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