Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add peers attribute to toggle interactor #164

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions dev/yaml/highlight-toggle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ vconcat:
plot:
- mark: barX
data: { from: penguins, filterBy: $filter }
x: { count: '' }
x: { count: }
xLabel: Total →
xDomain: Fixed
- vspace: 20
Expand All @@ -24,14 +24,20 @@ vconcat:
- mark: barY
data: { from: penguins, filterBy: $filter }
x: sex
y: { count: '' }
y: { count: }
- select: highlight
by: $select
- select: toggleX
as: $select
- select: toggleX
as: $filter
xLabel: ''
- mark: text
data: { from: penguins, filterBy: $filter }
x: sex
y: { count: }
text: { count: }
dy: -10
xLabel: null
yLabel: Total
xDomain: Fixed
yDomain: Fixed
1 change: 1 addition & 0 deletions docs/api/vgplot/interactors.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Select individual data values by clicking / shift-clicking points. The supported

- _as_: The [Selection](../core/selection) to populate with filter predicates.
- _channels_: An array of encoding channels (e.g., `"x"`, `"y"`, `"color"`) indicating the data values to select.
- _peers_: A Boolean-flag (default `true`) indicating if all marks in the current plot should be considered "peers" in the clients set used to perform cross-filtering. A peer mark will be exempt from filtering. Set this to false if you are using a cross-filtered selection but want to filter across marks within the same plot.

### toggleX

Expand Down
12 changes: 6 additions & 6 deletions packages/vgplot/src/directives/interactors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ export function toggle({ as, ...rest }) {
return interactor(Toggle, { ...rest, selection: as });
}

export function toggleX({ as }) {
return toggle({ as, channels: ['x'] });
export function toggleX(options) {
return toggle({ ...options, channels: ['x'] });
}

export function toggleY({ as }) {
return toggle({ as, channels: ['y'] });
export function toggleY(options) {
return toggle({ ...options, channels: ['y'] });
}

export function toggleColor({ as }) {
return toggle({ as, channels: ['color'] });
export function toggleColor(options) {
return toggle({ ...options, channels: ['color'] });
}

export function nearestX({ as, ...rest }) {
Expand Down
9 changes: 5 additions & 4 deletions packages/vgplot/src/interactors/Toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { and, or, isNotDistinct, literal } from '@uwdata/mosaic-sql';
export class Toggle {
constructor(mark, {
selection,
channels
channels,
peers = true
}) {
this.value = null;
this.mark = mark;
this.selection = selection;
this.clients = new Set().add(mark);
this.peers = peers;
this.channels = channels.map(c => {
const q = c === 'color' ? ['fill', 'stroke']
: c === 'x' ? ['x', 'x1', 'x2']
Expand All @@ -26,7 +27,7 @@ export class Toggle {
}

clause(value) {
const { channels, clients } = this;
const { channels, mark } = this;
let predicate = null;

if (value) {
Expand All @@ -42,7 +43,7 @@ export class Toggle {
return {
source: this,
schema: { type: 'point' },
clients,
clients: this.peers ? mark.plot.markSet : new Set().add(mark),
value,
predicate
};
Expand Down