From 246793512dd1a3c526315ed99db723eac3a6ab03 Mon Sep 17 00:00:00 2001 From: Allie Feldman Date: Fri, 15 Dec 2023 23:40:31 -0500 Subject: [PATCH] add null edge case and requested test cases --- src/compile/selection/interval.ts | 5 +- test/compile/selection/interval.test.ts | 217 ++++++++++++++++++++++++ 2 files changed, 221 insertions(+), 1 deletion(-) diff --git a/src/compile/selection/interval.ts b/src/compile/selection/interval.ts index 0b70f24790..29c3055c49 100644 --- a/src/compile/selection/interval.ts +++ b/src/compile/selection/interval.ts @@ -51,7 +51,10 @@ const interval: SelectionCompiler<'interval'> = { filters.push(filterExpr); } } - selCmpt.mark.cursor = 'move'; + if (selCmpt.mark.cursor == null) { + selCmpt.mark.cursor = 'move'; + } + } }, diff --git a/test/compile/selection/interval.test.ts b/test/compile/selection/interval.test.ts index 4bb06d8be9..d33fe7e375 100644 --- a/test/compile/selection/interval.test.ts +++ b/test/compile/selection/interval.test.ts @@ -836,6 +836,223 @@ describe('Interval Selections', () => { } ]); }); + + const brushSelCmpts = parseUnitSelection(model, [ + { + name: 'crosshair', + select: {type: 'interval', clear: false, translate: true, zoom: false, mark: {cursor: 'crosshair'}} + }, + { + name: 'disabled', + select: {type: 'interval', clear: false, translate: false, zoom: false} + }] + ); + + it('should not override manual cursor assignment', () => { + const nameModel = parseUnitModel({ + mark: 'circle', + encoding: { + x: {field: 'x', type: 'quantitative'}, + y: {field: 'y', type: 'quantitative'} + } + }); + 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} + ] + } + } + } + ]) + }); + + it('should not change brush cursor when translate is set to "false"', () => { + const nameModel = parseUnitModel({ + mark: 'circle', + encoding: { + x: {field: 'x', type: 'quantitative'}, + y: {field: 'y', type: 'quantitative'} + } + }); + 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} + ] + } + } + } + ]); + }); }); describe('Geo intervals', () => {