From 965e62e1e4cb595198edd08fba738fa9ec4d509e Mon Sep 17 00:00:00 2001 From: Dominik Moritz Date: Mon, 29 Jan 2024 21:13:57 -0500 Subject: [PATCH] move cursor logic into mark builder and simplify unit tests --- src/compile/selection/interval.ts | 8 +- test/compile/selection/interval.test.ts | 186 +----------------------- 2 files changed, 10 insertions(+), 184 deletions(-) diff --git a/src/compile/selection/interval.ts b/src/compile/selection/interval.ts index cada183d62..12456bfa31 100644 --- a/src/compile/selection/interval.ts +++ b/src/compile/selection/interval.ts @@ -51,9 +51,6 @@ const interval: SelectionCompiler<'interval'> = { filters.push(filterExpr); } } - if (selCmpt.mark.cursor == null) { - selCmpt.mark.cursor = 'move'; - } } }, @@ -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`, @@ -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} diff --git a/test/compile/selection/interval.test.ts b/test/compile/selection/interval.test.ts index 690fb8d0f0..3c415a2c6f 100644 --- a/test/compile/selection/interval.test.ts +++ b/test/compile/selection/interval.test.ts @@ -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"', () => { @@ -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'} + }); }); });