Skip to content

Commit

Permalink
fix: prevent brush marks from triggering point selections (#7436)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominik Moritz <domoritz@gmail.com>
Co-authored-by: GitHub Actions Bot <vega-actions-bot@users.noreply.github.com>
  • Loading branch information
3 people committed May 5, 2021
1 parent 27e9328 commit 10921c7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/compiled/selection_multi_condition.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
"events": [
{"source": "scope", "type": "mouseover", "markname": "voronoi"}
],
"update": "datum && item().mark.marktype !== 'group' ? {unit: \"\", fields: hoverbrush_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)[\"_vgsid_\"]]} : null",
"update": "datum && item().mark.marktype !== 'group' && indexof(item().mark.name, 'brush_brush') < 0 ? {unit: \"\", fields: hoverbrush_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)[\"_vgsid_\"]]} : null",
"force": true
},
{"events": [{"source": "view", "type": "dblclick"}], "update": "null"}
Expand Down
13 changes: 12 additions & 1 deletion src/compile/selection/point.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Stream} from 'vega';
import {stringValue} from 'vega-util';
import {SelectionCompiler, TUPLE, unitName} from '.';
import {vals} from '../../util';
import {BRUSH} from './interval';
import {TUPLE_FIELDS} from './project';

const point: SelectionCompiler<'point'> = {
Expand Down Expand Up @@ -33,14 +35,23 @@ const point: SelectionCompiler<'point'> = {

const events: Stream[] = selCmpt.events;

const brushes = vals(model.component.selection ?? {})
.reduce((acc, cmpt) => {
return cmpt.type === 'interval' ? acc.concat(cmpt.name + BRUSH) : acc;
}, [])
.map(b => `indexof(item().mark.name, '${b}') < 0`)
.join(' && ');

const test = `datum && item().mark.marktype !== 'group'` + (brushes ? ` && ${brushes}` : '');

return signals.concat([
{
name: name + TUPLE,
on: events
? [
{
events,
update: `datum && item().mark.marktype !== 'group' ? {${update}: [${values}]} : null`,
update: `${test} ? {${update}: [${values}]} : null`,
force: true
}
]
Expand Down
24 changes: 24 additions & 0 deletions test/compile/selection/point.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,30 @@ describe('Multi Selection', () => {

const signals = assembleUnitSelectionSignals(model, []);
expect(signals).toEqual(expect.arrayContaining([...oneSg, ...twoSg, ...threeSg, ...fourSg, ...fiveSg, ...sixSg]));

// Ensure that interval brushes are accounted for.
// (We define selections separately so as not to pollute other test cases.)
const selCmpts2 = parseUnitSelection(model, [
{name: 'one', select: 'point'},
{name: 'two', select: 'interval'},
{name: 'three', select: 'interval'}
]);
model.component.selection = selCmpts2;
const oneSgInterval = point.signals(model, selCmpts['one'], []);
expect(oneSgInterval).toEqual([
{
name: 'one_tuple',
on: [
{
events: selCmpts['one'].events,
update:
"datum && item().mark.marktype !== 'group' && indexof(item().mark.name, 'two_brush') < 0 && indexof(item().mark.name, 'three_brush') < 0 ? {unit: \"\", fields: one_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)[\"_vgsid_\"]]} : null",
force: true
}
]
}
]);
model.component.selection = selCmpts;
});

it('builds modify signals', () => {
Expand Down

0 comments on commit 10921c7

Please sign in to comment.