Recently Tableau introduced Set Actions to Tableau Desktop. While they have a lot of analytical use, there is also a lot of fun to be had with them, so here’s a little game which wasn’t possible in earlier versions of Tableau.
Set actions is the possibility to dynamically assign values to a a set in Tableau. When it was first introduced at #TC18 my reaction was “So what?” but as soon as I saw what they can actually do, I understood that they provide a lot more interactivity and a lot more possibility for the community to find (mis)-uses for them.
My first very basic idea was the one of hidden pies which caused, lets say, mixed reactions:
The next unconventional use case I saw was Ken Flerlage’s “Connect the Dots” dashboard in Tableau.
It was a simple but creative take on the possibilities that come with set actions and I very quickly got the idea to create a “Hot Wire” or “Buzz Wire” game in Tableau. The idea is very similar to Ken’s, You use the set actions to determine if you are on a mark. It needs to happen on hover and there should be some indicator when you leave the “wire” but these were the only real requirements – and from what I understood, that should be possible with set actions.
The following is the result of a lot of trial and error. While it hopefully makes sense when you read through it, at the time it didn’t, so bare with me when I try to put words around it. Also I will concentrate more on how and why I did things rather than explaining every calculation and configuration. If you are curious about the details, head over to Tableau Public and download the workbook to reverse engineer it.
Creating the “Wire”
I chose to utilise Ken’s rabbit, partly to relate it to his game and partly because I have to admit I was too lazy to come up with a different shape just for the sake of it. The data set is a bunch of coordinates for each dot and a running ID which determines the order in which the dots are connected. In Tableau I just had to create a scatterplot with a line on it to get the basic shape:
To get interactivity going, I needed to create a set and a set action. A set is a grouping of values, you determine which values you want in the group and which you want out of it. In this case I want only the point which the player is currently hovering over in the group, so I created a set based on the [point] field and a set action on hover. Important here is to define that clearing the selection will remove all values from the set. This makes sure I can capture if somebody doesn’t touch the wire any longer, ie. loses.
In order to indicate which part of the “wire” the player is currently hovering over, I can use the set as well to alter the colour and thickness of the line. To make sure that this doesn’t interrupt the line, I needed to create a calculated field which is TRUE or FALSE when a value is IN or OUT of the set and use it as an attribute on colour and size.
I now have a visual indicator where we are on the wire and with the set action we have the interactivity.
Creating game mechanics
So far there is some interactivity but it’s a long shot from a game, so lets think about the mechanics which we need.
- We need a way to define that a game starts, this is to initiate all “variables” and/or to reset anything from a previous round
- We need to prevent the player from just continuing playing once they lost a round
- We need to identify when the end of the wire is reached so we can tell somebody won
Setting up the game
There needs to be functionality which initiates the game to start playing. In this case, I would like to highlight the first dot of the rabbit to indicate where to start. For this I can reuse the set we already created and just add the first point to it. I do this by creating another sheet and filtering it to only include point 1. To make it a bit more obvious I add a label which reads “start game” and add it to the dashboard. With a simple select set action I can now add the first dot to the set and it will automatically highlight on the main sheet. I also want to make sure that removing the selection keeps the members of the set, this makes sure repeated clicking doesn’t remove the indicator.
Keeping track of the game
I already have a way to highlight where the player hovers their mouse and when they technically “lose”. Currently the player could just continue with the game as nothing had happened but this doesn’t create much of a challenge. So the idea is to hide the whole game until the player clicks on “Start Game” again. I did this (and add the game again once it is started) with another calculation and two set actions!
Thinking about it theoretically: We want to hide all marks when we move the cursor and display them again when the player clicks on “Start Game”. If we had a feature which could dynamically determine which points are to be displayed or not…
Do implement this feature, I created a calculated field with the value and name “constant” (very creative, I know) and a set on top of this. Now with a set action, I can add this value to the set from my “Start Game” sheet and dynamically remove everything from the set on the game sheet. To hide and display the rabbit, I just need to add the set to the filter and only display the points which are IN the set.
Figuring out whether the game is won
This one was the hardest and I am still trying to figure out how to do it properly. The problem is not to identify that the player reached the last point, the problem is to make sure that the player went through the whole shape first and didn’t go straight to the last point.
I didn’t figure out the last part yet but I have a few ideas how to address it, so this might come in form of an update. For the moment, I just identify the last point.
I created a calculation “IF [point] = 67 THEN [Y] END” and another calculation “IF [point] = 67 THEN ‘endpoint’ END”.
With the [Y] calculation I can create a dual axis chart to then put the ‘endpoint’ calculation on detail. I had to do this to make sure that the line is not interrupted.
With that setup, I was then able to create a final set action with adds the last point to a set on hover and keeps it there when the point is left.
In total I ended up with 3 different sets (one for each bit of the game) and 6 different set actions (one each to activate and deactivate something). During the development I easily created 10 different sets and 20 different actions, most of them turned out to do something which something else did already so I deleted them again. The one thing this taught me was that naming is even more important than for the other actions!
Displaying a win or a loss
Now to bring it all together, I needed to check if the last point is within all three sets which I created. If this is the case, the game is won! There might be more elegant solutions, in this case I just output a message when the conditions are TRUE and filter on the sheet to only show this message and nothing if it is NULL.
I also needed to indicate if a game is lost. In this case I created a boolean field to check if records where IN our OUT of the set. The calculation below checks how many distinct values there are and if there is only 1 it displays the “lost” message. The idea behind it is that there should be always 2 values, as one point would be IN the set and all others should be OUT of the set. In case the player leaves the “wire”, everything will be OUT of the set and therefore the distinct count will be 1.
Good question! I have a few ideas to improve on the game as it is right now and also some other ideas on what this technique could be used for. Arguably there are probably not many applications for this kind of interactivity but it taught me a whole lot about sets, how they can be used and what limitations they have. Let me know if you have other ideas, if you develop something yourself based on this work or if you have any questions about what I did here.