diff --git a/examples/compiled/interactive_global_development.png b/examples/compiled/interactive_global_development.png
index e69de29bb2..9ad106c350 100644
Binary files a/examples/compiled/interactive_global_development.png and b/examples/compiled/interactive_global_development.png differ
diff --git a/examples/compiled/interactive_global_development.svg b/examples/compiled/interactive_global_development.svg
index e69de29bb2..d102c1b135 100644
--- a/examples/compiled/interactive_global_development.svg
+++ b/examples/compiled/interactive_global_development.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/examples/compiled/interactive_global_development.vg.json b/examples/compiled/interactive_global_development.vg.json
index 4c451fb429..856381419e 100644
--- a/examples/compiled/interactive_global_development.vg.json
+++ b/examples/compiled/interactive_global_development.vg.json
@@ -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)"
}
]
},
diff --git a/examples/compiled/interactive_legend.png b/examples/compiled/interactive_legend.png
index e69de29bb2..0b09bd75f9 100644
Binary files a/examples/compiled/interactive_legend.png and b/examples/compiled/interactive_legend.png differ
diff --git a/examples/compiled/interactive_legend.svg b/examples/compiled/interactive_legend.svg
index e69de29bb2..eb158638ff 100644
--- a/examples/compiled/interactive_legend.svg
+++ b/examples/compiled/interactive_legend.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/examples/compiled/interactive_legend.vg.json b/examples/compiled/interactive_legend.vg.json
index de7108253a..3b21b16a8e 100644
--- a/examples/compiled/interactive_legend.vg.json
+++ b/examples/compiled/interactive_legend.vg.json
@@ -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": [
diff --git a/examples/compiled/interactive_legend_dblclick.png b/examples/compiled/interactive_legend_dblclick.png
index e69de29bb2..0b09bd75f9 100644
Binary files a/examples/compiled/interactive_legend_dblclick.png and b/examples/compiled/interactive_legend_dblclick.png differ
diff --git a/examples/compiled/interactive_legend_dblclick.svg b/examples/compiled/interactive_legend_dblclick.svg
index e69de29bb2..eb158638ff 100644
--- a/examples/compiled/interactive_legend_dblclick.svg
+++ b/examples/compiled/interactive_legend_dblclick.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/examples/compiled/interactive_legend_dblclick.vg.json b/examples/compiled/interactive_legend_dblclick.vg.json
index a8c638935c..4a3eab425c 100644
--- a/examples/compiled/interactive_legend_dblclick.vg.json
+++ b/examples/compiled/interactive_legend_dblclick.vg.json
@@ -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": [
diff --git a/examples/compiled/interactive_query_widgets.png b/examples/compiled/interactive_query_widgets.png
index e69de29bb2..6cdc162535 100644
Binary files a/examples/compiled/interactive_query_widgets.png and b/examples/compiled/interactive_query_widgets.png differ
diff --git a/examples/compiled/interactive_query_widgets.svg b/examples/compiled/interactive_query_widgets.svg
index e69de29bb2..6592fcc7a5 100644
--- a/examples/compiled/interactive_query_widgets.svg
+++ b/examples/compiled/interactive_query_widgets.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/examples/compiled/interactive_query_widgets.vg.json b/examples/compiled/interactive_query_widgets.vg.json
index a1d8b4a367..4a6f26bb8c 100644
--- a/examples/compiled/interactive_query_widgets.vg.json
+++ b/examples/compiled/interactive_query_widgets.vg.json
@@ -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)"
}
]
}
diff --git a/examples/compiled/selection_bind_cylyr.png b/examples/compiled/selection_bind_cylyr.png
index e69de29bb2..736276ee37 100644
Binary files a/examples/compiled/selection_bind_cylyr.png and b/examples/compiled/selection_bind_cylyr.png differ
diff --git a/examples/compiled/selection_bind_cylyr.svg b/examples/compiled/selection_bind_cylyr.svg
index e69de29bb2..070523c04b 100644
--- a/examples/compiled/selection_bind_cylyr.svg
+++ b/examples/compiled/selection_bind_cylyr.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/examples/compiled/selection_bind_cylyr.vg.json b/examples/compiled/selection_bind_cylyr.vg.json
index ca3e421043..f3bba31669 100644
--- a/examples/compiled/selection_bind_cylyr.vg.json
+++ b/examples/compiled/selection_bind_cylyr.vg.json
@@ -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)"
}
]
}
diff --git a/examples/compiled/selection_bind_origin.png b/examples/compiled/selection_bind_origin.png
index e69de29bb2..fd14702d2c 100644
Binary files a/examples/compiled/selection_bind_origin.png and b/examples/compiled/selection_bind_origin.png differ
diff --git a/examples/compiled/selection_bind_origin.svg b/examples/compiled/selection_bind_origin.svg
index e69de29bb2..b4d12d9a69 100644
--- a/examples/compiled/selection_bind_origin.svg
+++ b/examples/compiled/selection_bind_origin.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/examples/compiled/selection_bind_origin.vg.json b/examples/compiled/selection_bind_origin.vg.json
index 22f69f7399..cbd75a71cc 100644
--- a/examples/compiled/selection_bind_origin.vg.json
+++ b/examples/compiled/selection_bind_origin.vg.json
@@ -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)"
}
]
}
diff --git a/examples/compiled/trellis_selections.vg.json b/examples/compiled/trellis_selections.vg.json
index 8e447472ec..19677b166f 100644
--- a/examples/compiled/trellis_selections.vg.json
+++ b/examples/compiled/trellis_selections.vg.json
@@ -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)"
}
]
}
diff --git a/src/compile/selection/index.ts b/src/compile/selection/index.ts
index 58ee9c36fb..68c023d902 100644
--- a/src/compile/selection/index.ts
+++ b/src/compile/selection/index.ts
@@ -50,7 +50,7 @@ export interface SelectionComponent {
// Transforms
project: SelectionProjectionComponent;
scales?: SelectionProjection[];
- toggle?: any;
+ toggle?: string;
translate?: any;
zoom?: any;
nearest?: any;
@@ -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;
}
diff --git a/src/compile/selection/legends.ts b/src/compile/selection/legends.ts
index 5168bc4f90..d248222437 100644
--- a/src/compile/selection/legends.ts
+++ b/src/compile/selection/legends.ts
@@ -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';
diff --git a/src/compile/selection/toggle.ts b/src/compile/selection/toggle.ts
index fb7927e7ca..4245662067 100644
--- a/src/compile/selection/toggle.ts
+++ b/src/compile/selection/toggle.ts
@@ -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) => {