The linked chart contains only a legend and the legend works as follows:
- clicking on a fruit name toggles it on and off
- shift-clicking on a fruit name switches it ON and switches OFF all other fruit names
Legend display is controlled by two entities:
- data set SELECTED remembers selected items
- signal FILTERMODE toggles the type of the filter between include and exclude
Currently, if only one fruit name is ON, then a click on it switches it OFF (so all fruit names become OFF). I would like to modify this behavior so that a click on the last enabled fruit name would switch everything ON. (In other words - it would not be possible to deselect everything.)
In order to switch everything ON I only need to change the value of signal FILTERMODE to exclude. This is where I hit a snag. I have tried the following in the signal definition:
"update": "event.shiftKey? 'include' : (length(data('selected'))? filtermode : 'exclude')",
This does not work. I am fairly sure this happens because of a race condition. When I check for the length of data('source'), it is still non-empty.
So the sequence of events is the following:
- click
- update signal FILTERMODE (check if the data set SELECTED is empty - it is not)
- update data set SELECTED (only now it has become empty)
What would be the most elegant work-around?