From 8c1d13b680fffdfec4b3ecfa1557347619cac364 Mon Sep 17 00:00:00 2001 From: Arvind Satyanarayan Date: Fri, 7 Jul 2023 12:59:45 -0400 Subject: [PATCH] fix: for global region selections, hide marks for inactive units --- src/compile/selection/region.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/compile/selection/region.ts b/src/compile/selection/region.ts index 4bc2b27e285..bb0b4cd85b5 100644 --- a/src/compile/selection/region.ts +++ b/src/compile/selection/region.ts @@ -1,6 +1,6 @@ import {OnEvent, Signal} from 'vega'; import {stringValue} from 'vega-util'; -import {SelectionCompiler, TUPLE, unitName} from '.'; +import {SelectionCompiler, STORE, TUPLE, unitName} from '.'; import {warn} from '../../log'; import {BRUSH} from './interval'; import scales from './scales'; @@ -65,12 +65,15 @@ const region: SelectionCompiler<'region'> = { const {fill, fillOpacity, stroke, strokeDash, strokeWidth} = selCmpt.mark; const screenPathName = `${name}${SCREEN_PATH}`; + const store = `data(${stringValue(selCmpt.name + STORE)})`; // Do not add a brush if we're binding to scales. if (scales.defined(selCmpt)) { return marks; } + const path = {signal: `lassoPath(${screenPathName})`}; + return [ { name: `${name + BRUSH}`, @@ -84,9 +87,21 @@ const region: SelectionCompiler<'region'> = { strokeDash: {value: strokeDash} }, update: { - path: { - signal: `lassoPath(${screenPathName})` - } + path: + // If the selection is resolved to global, only a single region is in the store. + // We wrap a region mark's path encoding with a production rule to hide the mark + // if it corresponds to a unit different from the one in the store. + selCmpt.resolve === 'global' + ? [ + { + test: `${store}.length && ${store}[0].unit === ${unitName(model)}`, + ...path + }, + { + value: '[]' + } + ] + : path } } },