Skip to content

Commit

Permalink
move cursor logic into mark builder and simplify unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Jan 30, 2024
1 parent bec1bd7 commit 965e62e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 184 deletions.
8 changes: 4 additions & 4 deletions src/compile/selection/interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ const interval: SelectionCompiler<'interval'> = {
filters.push(filterExpr);
}
}
if (selCmpt.mark.cursor == null) {
selCmpt.mark.cursor = 'move';
}
}
},

Expand Down Expand Up @@ -251,6 +248,9 @@ const interval: SelectionCompiler<'interval'> = {
return def;
}, {});

// Set cursor to move unless the brush cannot be translated
const vgCursor = cursor ?? (selCmpt.translate ? 'move' : null);

return [
{
name: `${name + BRUSH}_bg`,
Expand All @@ -271,7 +271,7 @@ const interval: SelectionCompiler<'interval'> = {
clip: true,
encode: {
enter: {
...(cursor ? {cursor: {value: cursor}} : {}),
...(vgCursor ? {cursor: {value: vgCursor}} : {}),
fill: {value: 'transparent'}
},
update: {...update, ...vgStroke}
Expand Down
186 changes: 6 additions & 180 deletions test/compile/selection/interval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,94 +858,9 @@ describe('Interval Selections', () => {
});
nameModel.parseScale();

const marks: any[] = [{hello: 'world'}];

expect(interval.marks(nameModel, brushSelCmpts['crosshair'], marks)).toEqual([
{
name: 'crosshair_brush_bg',
type: 'rect',
clip: true,
encode: {
enter: {fill: {value: '#333'}, fillOpacity: {value: 0.125}},
update: {
x: [
{
test: 'data("crosshair_store").length && data("crosshair_store")[0].unit === ""',
signal: 'crosshair_x[0]'
},
{value: 0}
],
y: [
{
test: 'data("crosshair_store").length && data("crosshair_store")[0].unit === ""',
signal: 'crosshair_y[0]'
},
{value: 0}
],
x2: [
{
test: 'data("crosshair_store").length && data("crosshair_store")[0].unit === ""',
signal: 'crosshair_x[1]'
},
{value: 0}
],
y2: [
{
test: 'data("crosshair_store").length && data("crosshair_store")[0].unit === ""',
signal: 'crosshair_y[1]'
},
{value: 0}
]
}
}
},
{hello: 'world'},
{
name: 'crosshair_brush',
type: 'rect',
clip: true,
encode: {
enter: {cursor: {value: 'crosshair'}, fill: {value: 'transparent'}},
update: {
x: [
{
test: 'data("crosshair_store").length && data("crosshair_store")[0].unit === ""',
signal: 'crosshair_x[0]'
},
{value: 0}
],
y: [
{
test: 'data("crosshair_store").length && data("crosshair_store")[0].unit === ""',
signal: 'crosshair_y[0]'
},
{value: 0}
],
x2: [
{
test: 'data("crosshair_store").length && data("crosshair_store")[0].unit === ""',
signal: 'crosshair_x[1]'
},
{value: 0}
],
y2: [
{
test: 'data("crosshair_store").length && data("crosshair_store")[0].unit === ""',
signal: 'crosshair_y[1]'
},
{value: 0}
],
stroke: [
{
test: 'crosshair_x[0] !== crosshair_x[1] && crosshair_y[0] !== crosshair_y[1]',
value: 'white'
},
{value: null}
]
}
}
}
]);
expect(interval.marks(nameModel, brushSelCmpts['crosshair'], [])[1].encode.enter.cursor).toEqual({
value: 'crosshair'
});
});

it('should not change brush cursor when translate is set to "false"', () => {
Expand All @@ -957,99 +872,10 @@ describe('Interval Selections', () => {
}
});
nameModel.parseScale();
const marks: any[] = [{hello: 'world'}];

expect(interval.marks(model, brushSelCmpts['disabled'], marks)).toEqual([
{
name: 'disabled_brush_bg',
type: 'rect',
clip: true,
encode: {
enter: {
fill: {value: '#333'},
fillOpacity: {value: 0.125}
},
update: {
x: [
{
test: 'data("disabled_store").length && data("disabled_store")[0].unit === ""',
signal: 'disabled_x[0]'
},
{value: 0}
],
y: [
{
test: 'data("disabled_store").length && data("disabled_store")[0].unit === ""',
signal: 'disabled_y[0]'
},
{value: 0}
],
x2: [
{
test: 'data("disabled_store").length && data("disabled_store")[0].unit === ""',
signal: 'disabled_x[1]'
},
{value: 0}
],
y2: [
{
test: 'data("disabled_store").length && data("disabled_store")[0].unit === ""',
signal: 'disabled_y[1]'
},
{value: 0}
]
}
}
},
{hello: 'world'},
{
name: 'disabled_brush',
type: 'rect',
clip: true,
encode: {
enter: {
fill: {value: 'transparent'}
},
update: {
x: [
{
test: 'data("disabled_store").length && data("disabled_store")[0].unit === ""',
signal: 'disabled_x[0]'
},
{value: 0}
],
y: [
{
test: 'data("disabled_store").length && data("disabled_store")[0].unit === ""',
signal: 'disabled_y[0]'
},
{value: 0}
],
x2: [
{
test: 'data("disabled_store").length && data("disabled_store")[0].unit === ""',
signal: 'disabled_x[1]'
},
{value: 0}
],
y2: [
{
test: 'data("disabled_store").length && data("disabled_store")[0].unit === ""',
signal: 'disabled_y[1]'
},
{value: 0}
],
stroke: [
{
test: 'disabled_x[0] !== disabled_x[1] && disabled_y[0] !== disabled_y[1]',
value: 'white'
},
{value: null}
]
}
}
}
]);
expect(interval.marks(model, brushSelCmpts['disabled'], [])[1].encode.enter).toEqual({
fill: {value: 'transparent'}
});
});
});

Expand Down

0 comments on commit 965e62e

Please sign in to comment.