Show all posts
5 years ago

How to reveal aggregations with Taucharts

In this post I would like to describe a case where the Taucharts library integrates seamlessly into a third-party system. It is good to show once again the deep data-centric nature of the library.

First, I have to highlight that Taucharts operates with simple a data model which can be described as single, de-normalized table. A simple example of such data is CSV or JSON data.
A user is free to explore the original data snapshot by applying aggregate functions to data columns. This process corresponds to the “Interaction – Data” segment of the Taucharts loop.

data interaction segment

Aggregate functions perform calculations on a set of values and return a single value. All aggregate functions are deterministic. This means aggregate functions return the same value any time that they are called by using a specific set of input values.

Often it is useful to reveal which source rows a particular aggregate value is based on. For this task we need a concept of “aggregation reverse engineering”. Fortunately, this is pretty easy with our simple data model.

Let’s consider a histogram:

The data for this chart is a frequency of appearance of each X value in the source data. Using SQL this can be expressed as:

SELECT gender, COUNT() FROM responses GROUP BY gender;

To execute this query, our SQL engine needs to split the source data into subgroups by similar gender value and then apply the aggregate function to each subgroup (e.g. COUNT rows).


Obviously, the dataset behind an aggregation value is independent of aggregation type. To fetch a particular subset we need to apply filter by gender value to the original data source:

SELECT * FROM responses WHERE gender = "female"

In the case of more complex charts like facets, grouping becomes more deep and granular but it can still be expressed as a series of plain filters over the original data since in our model “filter” is an associative operation.

Now, once we grasp the idea of “aggregation reverse engineering” let’s implement it as a plugin for Taucharts. In general, Taucharts doesn’t provide direct access to the original data and doesn’t make any semantic assumptions about the data associated with an element, so it is the chart developer’s responsibility to pass meta information on which fields in the data correspond to grouping parameters and how to fetch the original data by filter.

Of course, you are free to reuse this script or put it in a separate plugin, but I believe the Taucharts tooltip plugin is more appropriate place for this feature. Once a user interacts with a chart element (like point or bar) it is not necessarily a good idea to give them the ability to reveal data behind an aggregate value that the element represents.

The tooltip plugin provides 2 settings to customize “reveal” function:

Once user clicks button “Reveal” – the plugin callback fires with the corresponding filters’ descriptor. It is up to the callback consumer to translate this descriptor to a data-source specific query (e.g. SQL, REST or javascript filter), fetch data (probably asynchronously), and display it in the appropriate place. This feature will be available in the next Taucharts release, 0.6.0.

Please, share your feedback and have fun!