Skip to content

Commit

Permalink
fix: for global region selections, hide marks for inactive units
Browse files Browse the repository at this point in the history
  • Loading branch information
arvind committed Jul 7, 2023
1 parent 88f8567 commit 8c1d13b
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/compile/selection/region.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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}`,
Expand All @@ -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
}
}
},
Expand Down

0 comments on commit 8c1d13b

Please sign in to comment.