Using a Data Grid component to simulate a Heat Map

I was pleased with the outcome of trying to generate a heat map, see below. However, I was stuck with this item:

Q. Is it possible to apply a filter to hide empty columns? It seems possible to filter rows but not obvious for columns. In this example there are only 5 patient types. It would be nice to hide the other columns.

2 Likes

Here is a custom Heat Map I created, please feel free to try it. It uses dates for the heat map, but even if it doesn’t fit your needs, maybe it could spark some ideas.

1 Like

TBH I stopped the video as soon as you mentioned Java and then CSS… I prefer no code solutions and am not willing to go down that rabbit hole… but thank you for responding and your output does look cool. Nice job.

1 Like

Hi @Simon_Hill!

Well… here is an idea, without JavaScript nor CSS.

Also gonna be honest: it works, it’s dynamic, it was fun to think about how to help you on this one. The rest is up to you (especially the “should I really do that” part :smiley: )

The result


The starting point


The logic

  1. Identify columns with data
  2. Create new columns to store values from columns with data only
  3. Get the correct headers for these columns
  4. Count the number of columns with values
  5. Add data grids and use visibility conditions to display the right component

Right now - I’m pretty sure there are many ways to optimize this stuff - it costs that many columns (with X the number of real columns):

  • X for testing if there are values
  • X for “new values”
  • X for headers
  • X for knowing what to target
  • 4 “scaffoling” columns (not depending on X)
  • 1 to count the number of columns with values
Number of columns Total of new columns
1 9
2 13
3 17
4 21
5 25
6 29
7 33
8 37
9 41
10 45

The method

  1. Create a Patient # data? for each column:

    With my Sample Data, I get 4 new columns.


  1. Create a Patients data (template) to concatenate the columns from step 1

    It’s important to add a special character such as # at the end of each replacement (see below)


  1. Remove empty column names just like this (Patients without 0):

    Here is the regular expression in the screenshot: 0;.*?#


  1. Proceed the same to remove the numbers associated to each column (Patients without values):

  1. Use a Split Text to get an array of columns with values only (Patients (array))

At this point, you should have something similar to:


  1. Create as many Slice Array columns as needed (4 in my case again) [Patient new #]:

    You’ll be careful to adapt Start and End value for each new column by incrementing them by 1 (0 and 1, then 1 and 2 and so on).


  1. Same as step 6. to create header columns (Patient new # header):

  1. Now we get the values dynamicaly, without empty columns like this (Patient new # values):

    Again, you’ll change Patient new 1 for each condition. A good point here: you can modify the value using the dropdown without to have to rewrite the rest of the condition. So if you duplicate your column, it only takes the time to change the targeted column and the name (it’s quick).


  1. Lastly, we need to know how many columns are really containing values so we use a Rollup based on a previously created column (Number of new columns):

Here is a screenshot of these newly created columns:


The layout

  1. Create a Data Grid. Add as many columns as the maximum you can have.
    Set up each column like this:

Here is my set up with 4 columns:


  1. Add a Visibily condition to this component. In my case, because I have 4 sample columns, the condition will be Number of new columnsequals 4:

  1. Duplicate your component as many times as expected. It’s not satisfying from an intelectual perspective but it’s very quick from a manual one :stuck_out_tongue:
    Just remove the last column (cf. Step 1) by clicking on the little cross and change the visibility condition (around 30 seconds for each duplicated component).

  1. Enjoy the show!
    A dynamic Data Grid

Final though

It’s just a way to make it works, and there’s probably much better approachs here (maybe with JSON columns?). Because there are not many If → Then → Else columns involved, I think it should be fine in terms of performance.
It’s not as simple as using a checkbox to hide empty columns, but that’s fun right :smiley: ?

That being said, I hope you’ll find this helpful anyway :+1:

1 Like

I fear there is a misunderstanding about the request. I have successfully created the heat map component and it is working perfectly well. It dynamically adjusts to the data and displays cells in 10 incremental shades of green corresponding to the percentile of the cell value.

My question was how to hide blank unused columns?. You wrote:

“Create a Data Grid . Add as many columns as the maximum you can have.”

With the greatest respect, this tip for manually defining the columns does not help at all. It needs to be dynamic and automatically filter out empty columns.

What I understood - going back to your first screenshot - is that you only want to display the columns Patient 1, Patient 2, Patient 3, Patient 4 and Patient 5.
As for Patient 6 and following columns, they are empty, so you want them to be hidden.

That was the assumption I made in my answer, and I believe taht’s exactly was it does :thinking:

So you’re right: I clearly missed something here - either in how I interpreted your need or in how I explained my solution.


Let’s have a look at two examples:

  1. Column Patient 3 is empty

  2. Columns Patient 1 and Patient 2 are empty


What the Data part does is creating new columns while skipping the empty ones.


In the worst case scenario, you’ll end up with as many new columns as your actual number of columns - that’swhen none of the original columns are empty.
In any other case, one or more of the new columns at the end will be empty.


The main drawback here is that we lose the original column names. We don’t know where the values came from.
For example, in case 2., how can we know that Simon was orignially in column Patient 3?
That’s where the Patient new # header columns come into play.


Now in the Layout, we need a way to display only the filled Patient new # columns.

Here’s what we know for sure: thanks to our work in Data, if there are 3 filled columns (regardless of their original position), their values will appear in Patient 1 new, Patient 2 new and Patient 3 new.
If there’s only 1 filled column, only the Patient 1 new will contain data.
We’ve also calculated the number of filled columns (see Number of new columns).


So now, we just need to create X Data Grid components to handle all possible cases.
I started with the version that includes all columns, because I think it’s easier to set up once and then duplicate it, remove one column and adjust the visibility condition accordingly.

As shown in examples 1. and 2., we display a different Data Grid component depending on the number of filled columns.

  • In 1., it’s the component with 3 Patient new # values columns and a visibility condition where Number of new columns equals 3
  • In 2., it’s the component with 2 Patient new # values columns and a visibility condition where Number of new columns equals 2

Since the components are mutually exclusive and depend on the number of initially filled columns, the end user only see the Data Grid with the correct number of visible columns - i.e., the non-empty ones.


Again, please let us know if I missed anything - it would help us move closer to a solution :wink:

1 Like

Nope, I still don’t see how you are solving for the question. Focus on the Data Grid Component. You still have to stipulate how many columns (data series) are required. That is a manual step. It is not possible to hide a data series even when the data is empty.

In the meantime I have installed a workaround solution. I have duplicated the Grid component several times, each with different number of columns (from 2 -10 in fact). I then simply only display one Grid component, i.e. the one corresponding to the number of columns with data. (Side note: there are never column gaps. The only challenge is the max number of columns since the count varies from 2 -10).

1 Like

I think that was the point of the solution provided by @Nicolas_Joseph. He used multiple data grids as well, but I believe his solution does in fact account for column gaps.

But even if you have column gaps that are accounted for the solution proposed still does not hide empty columns in the Grid component. You still have to manually specify the number of columns. There is no way to dynamically control visibility (remember each column will have a title even if the data is empty), e.g. with a visibility condition for each series.