Drawing on Dashboards

On the 25th of November I gave a talk at the South West England and Wales Tableau User Group (#SWEWTUG) that covered two main topics:

  • An introduction to the Tableau Beta Programs (e.g. Viz Animations, New Data Modelling Capabilities)
  • Experimenting with new Tableau features

For the second part, I demonstrated some examples of Parameter Actions and Show/Hide Containers that were created during the 2019.2 beta phase, along with a variety of examples and inspiration from the Tableau community.

I then focused on the idea of ‘drawing on dashboards’, which makes use Parameter Actions and the technique of using a parameter as a data source which I learned about from Jonathan Drummey‘s excellent blog post.

This post will focus on the techniques used for drawing on dashboards with sections on:

  • Drawing lines and squares using the Line mark type
  • Creating concentric circles of points on a map representing the distance from selected points using the DISTANCE() calculation
  • Drawing connected lines between spatial points on a map using MAKEPOINT() and MAKELINE()

Using a parameter as a data source

For full details of how this works, I highly recommend reading Jonathan Drummey’s detailed blog post, which has examples and a workbook with many of the regex functions used in the technique, some of which I have edited and added to for the below use cases to work.

In summary, this technique uses text parameters and parameter actions to perform various operations, such as:

  • Adding a value
  • Removing a value
  • Finding the position of a value in the parameter
  • and many more…

This is done by storing a modified version of the current parameter value in a calculation that, for example, in the case of appending a value, concatenates the new value (of a selected point) at the end of the existing parameter value as can be seen in the calculation below:

In this example, [p.ln.Point List] is the text parameter that holds the series of x and y points that I will use to draw a line, and [Point ID] is the x and y values of the current point being hovered over (with some text on either side of each value to help with regex later) and finally a delimiter at the end.

Drawing a Line

After reading Jonathan’s blog, I wondered if it would be possible to use this technique to draw lines on a dashboard, and it turns out it is:

This works by passing X and Y values of selected points in a 100 by 100 grid to a parameter using parameter actions and then drawing a line between those selected points:

The below diagram shows the parameter value after one point is selected:

Then after 4 points are selected:

A separate calculation [ln.Position in List] is then calculating the position of each point in the parameter using regex.

Drawing rectangles

This technique can be adapted to draw rectangles by calculating the remaining two corners from the two selected points:

Concentric circles showing distance from selected point

This was inspired by a tweet from Kent Marten some months back during the 2019.3 beta phase:

This gets a little trickier as, to use the DISTANCE calculation, spatial points need to be used, so the grid can’t just be a matrix of x and y numbers; instead, it needs to be a grid of latitude and longitude values, which can then be converted into spatial points using the MAKEPOINT function within Tableau.

To generate a grid of lat-long values I created a Tableau Prep flow, which takes as input the lat-long of the top left corner of the grid and the lat-long of the lower right corner of the grid and then calculates the specified number of lat-long pairs for all other points.

The spatial points are then added to the view and a single point can be selected using parameter actions – the values of which are passed to two parameters: [Source lat] and [Source long]. The DISTANCE calculation is then used to calculate the distance between the selected point and all other spatial points in the grid:

This is the final view:

Below is a dynamic view – selecting points in the grid and making the colour more transparent:

Selecting multiple points and calculating the minimum distance

There were a few improvements I wanted to make to the above example:

  • Make the map visible as it is currently obscured by the grid of points
  • Allow multiple points to be selected
  • For all other points in the grid, calculate the minimum distance to the nearest selected point

To achieve this I added another grid layer to the dashboard underneath the map and made the top grid layer transparent:

I then used the parameter as a data source technique to be able to select multiple points sequentially.

Finally I created a new calculation to return the minimum distance from each grid point to any of the 5 selected grid points:

The below GIF shows how the grid of distance “circles” updating as each additional point is selected:

Drawing connected lines between spatial points on a map

In this example I want to draw lines between cities on a map and calculate the cumulative distance as more cities are added to the ‘journey’.

The source data (Superstore Sales) has latitude and longitude data for the United States. I need to turn those into spatial points using MAKEPOINT so that I can then use the DISTANCE calculation to calculate the distance between all selected cities in the order they have been selected.

To do this, I need a calculation to return the prior city that was selected so that each line of my data will have the current city and the prior city. I can then use the distance calculation on each row for the current and prior cities.

The below calculation extracts the latitude of the previously selected city:

As the above is a string, I then need to convert this to a float:

This is repeated for longitude and I can then create the spatial point for the previous point:

Below is the final result:

Summary

Jonathan mentions a number of possible use cases for using a parameter as a data source in his blog, such as “building games, creating surveys or quizzes inside a viz, dynamically re-sorting marks”.

The above examples, with being able to draw a route between points on a maps, in particular, I think open up some other interesting use cases.

Workbook

The workbook with all the above example can be found on my Tableau Public profile here.

Note: at this time (Nov 2019), a Distance calculation containing parameters (or LODs) does not work with extracts, so some views will not render in Tableau Public. Download the workbook and switch to using live data source connections for full functionality.

I hope you’ve found this post interesting and if you have any feedback or thoughts on possible use cases, I’d be happy to hear your ideas. Thanks!

@Marc_DS5

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

WordPress.com.

Up ↑

%d bloggers like this: