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 0b339d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 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
10 changes: 9 additions & 1 deletion test/compile/selection/region.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ describe('Multi Selection', () => {
strokeWidth: {value: 4},
strokeDash: {value: [10, 5]}
},
update: {path: {signal: 'lassoPath(two_screen_path)'}}
update: {
path: [
{
test: 'data("two_store").length && data("two_store")[0].unit === ""',
signal: 'lassoPath(two_screen_path)'
},
{value: '[]'}
]
}
}
}
]);
Expand Down

0 comments on commit 0b339d9

Please sign in to comment.