Skip to content

Commit

Permalink
fix: interactive legends should be toggleable by default (#7115)
Browse files Browse the repository at this point in the history
* fix: interactive legends should be toggleable by default

* chore: update examples [CI]

* Update src/compile/selection/legends.ts

Co-authored-by: Dominik Moritz <domoritz@gmail.com>

Co-authored-by: GitHub Actions Bot <vega-actions-bot@users.noreply.github.com>
Co-authored-by: Dominik Moritz <domoritz@gmail.com>
  • Loading branch information
3 people committed Dec 15, 2020
1 parent 1a9b43a commit e73e71a
Show file tree
Hide file tree
Showing 22 changed files with 44 additions and 30 deletions.
Binary file modified examples/compiled/interactive_global_development.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/compiled/interactive_global_development.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/compiled/interactive_global_development.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"on": [
{
"events": {"signal": "year_tuple"},
"update": "modify(\"year_store\", year_toggle ? null : year_tuple, year_toggle ? null : true, year_toggle ? year_tuple : null)"
"update": "modify(\"year_store\", year_tuple, true)"
}
]
},
Expand Down
Binary file modified examples/compiled/interactive_legend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/compiled/interactive_legend.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions examples/compiled/interactive_legend.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@
"name": "industry_tuple_fields",
"value": [{"type": "E", "field": "series"}]
},
{
"name": "industry_toggle",
"value": false,
"on": [
{
"events": {"merge": [{"source": "view", "type": "click"}]},
"update": "event.shiftKey"
}
]
},
{
"name": "industry_modify",
"on": [
Expand Down
Binary file modified examples/compiled/interactive_legend_dblclick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/compiled/interactive_legend_dblclick.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions examples/compiled/interactive_legend_dblclick.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@
"name": "industry_tuple_fields",
"value": [{"type": "E", "field": "series"}]
},
{
"name": "industry_toggle",
"value": false,
"on": [
{
"events": {"merge": [{"source": "view", "type": "dblclick"}]},
"update": "event.shiftKey"
}
]
},
{
"name": "industry_modify",
"on": [
Expand Down
Binary file modified examples/compiled/interactive_query_widgets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/compiled/interactive_query_widgets.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/compiled/interactive_query_widgets.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"on": [
{
"events": {"signal": "CylYr_tuple"},
"update": "modify(\"CylYr_store\", CylYr_toggle ? null : CylYr_tuple, CylYr_toggle ? null : true, CylYr_toggle ? CylYr_tuple : null)"
"update": "modify(\"CylYr_store\", CylYr_tuple, true)"
}
]
}
Expand Down
Binary file modified examples/compiled/selection_bind_cylyr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/compiled/selection_bind_cylyr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/compiled/selection_bind_cylyr.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"on": [
{
"events": {"signal": "CylYr_tuple"},
"update": "modify(\"CylYr_store\", CylYr_toggle ? null : CylYr_tuple, CylYr_toggle ? null : true, CylYr_toggle ? CylYr_tuple : null)"
"update": "modify(\"CylYr_store\", CylYr_tuple, true)"
}
]
}
Expand Down
Binary file modified examples/compiled/selection_bind_origin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/compiled/selection_bind_origin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/compiled/selection_bind_origin.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"on": [
{
"events": {"signal": "org_tuple"},
"update": "modify(\"org_store\", org_toggle ? null : org_tuple, org_toggle ? null : true, org_toggle ? org_tuple : null)"
"update": "modify(\"org_store\", org_tuple, true)"
}
]
}
Expand Down
18 changes: 1 addition & 17 deletions examples/compiled/trellis_selections.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,28 +445,12 @@
"update": "xenc_X !== null ? {fields: xenc_tuple_fields, values: [xenc_X]} : null"
},
{"name": "xenc_tuple_fields", "value": [{"type": "E", "field": "X"}]},
{
"name": "xenc_toggle",
"value": false,
"on": [
{
"events": [
{
"source": "scope",
"type": "mouseover",
"markname": "child_voronoi"
}
],
"update": "event.shiftKey"
}
]
},
{
"name": "xenc_modify",
"on": [
{
"events": {"signal": "xenc_tuple"},
"update": "modify(\"xenc_store\", xenc_toggle ? null : xenc_tuple, xenc_toggle ? null : true, xenc_toggle ? xenc_tuple : null)"
"update": "modify(\"xenc_store\", xenc_tuple, true)"
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion src/compile/selection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface SelectionComponent<T extends SelectionType = SelectionType> {
// Transforms
project: SelectionProjectionComponent;
scales?: SelectionProjection[];
toggle?: any;
toggle?: string;
translate?: any;
zoom?: any;
nearest?: any;
Expand Down Expand Up @@ -119,4 +119,5 @@ export function requiresSelectionId(model: Model) {
export function disableDirectManipulation(selCmpt: SelectionComponent, selDef: SelectionDef<'point'>) {
if (isString(selDef.select) || !selDef.select.on) delete selCmpt.events;
if (isString(selDef.select) || !selDef.select.clear) delete selCmpt.clear;
if (isString(selDef.select) || !selDef.select.toggle) delete selCmpt.toggle;
}
7 changes: 6 additions & 1 deletion src/compile/selection/legends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ const legendBindings: SelectionCompiler<'point'> = {
},

parse: (model, selCmpt, selDef) => {
disableDirectManipulation(selCmpt, selDef);
// Allow legend items to be toggleable by default even though direct manipulation is disabled.
const selDef_ = duplicate(selDef);
selDef_.select = isString(selDef_.select)
? {type: selDef_.select, toggle: selCmpt.toggle}
: {...selDef_.select, toggle: selCmpt.toggle};
disableDirectManipulation(selCmpt, selDef_);

if (isObject(selDef.select) && (selDef.select.on || selDef.select.clear)) {
const legendFilter = 'event.item && indexof(event.item.mark.role, "legend") < 0';
Expand Down
12 changes: 5 additions & 7 deletions src/compile/selection/toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ const toggle: SelectionCompiler<'point'> = {
},

signals: (model, selCmpt, signals) => {
return selCmpt.events
? signals.concat({
name: selCmpt.name + TOGGLE,
value: false,
on: [{events: selCmpt.events, update: selCmpt.toggle}]
})
: signals;
return signals.concat({
name: selCmpt.name + TOGGLE,
value: false,
on: [{events: selCmpt.events, update: selCmpt.toggle}]
});
},

modifyExpr: (model, selCmpt) => {
Expand Down

0 comments on commit e73e71a

Please sign in to comment.