Coloring specific rows in a table
Ben Murphy-Baum
I recently came across a situation where coloring the text of a multidimensional table might be useful. I can see that you can specify a columnSpec to color a specific column, but I can't seem to find a way to color specific rows in the table, or individual cells for that matter. I was hoping to color blocks of rows based on common content, is there a way to do this currently?
There is no way to color rows of a table.
Igor Pro 9 includes a package for creating what I call "presentation tables" as opposed to normal tables which are primarily for data entry and inspection. In Igor Pro 9, execute:
DisplayHelpTopic "Draw Presentation Table"
May 5, 2021 at 12:48 pm - Permalink
Can colors be applied to individual cells in a listbox? If so, translate the table to a listbox.
May 5, 2021 at 02:20 pm - Permalink
Yes, listbox controls can be arbitrarily colored. See the documentation for the colorWave keyword for the Listbox command, and the Details subsection has a section with all the details. Very flexible, which means confusing the first time through :)
See the Color Wave editor package for an example of using this capability.
May 5, 2021 at 02:32 pm - Permalink
Yep, list boxes are definitely an option. I'll test it out, but my fear is that the list box will feel a bit awkward for my use case. I would need to be able to easily cut and paste data between list boxes, which might force a bunch of extra code for hooks/buttons to handle it. But maybe that wouldn't be too bad...
As for the presentation tables, I unfortunately need to be back-compatible down to IP7
May 5, 2021 at 04:13 pm - Permalink
Yes, an Igor table has lots of spreadsheet-like behavior and intimate knowledge of waves as data structures. If you need to copy wave data, or data that looks like wave data, then a listbox could be pretty awkward. I've done things that allow copying a column or a row from a listbox, it can be done. It's hard to make it feel totally right, though.
And, of course, a regular table doesn't do what you want: color a single cell or row.
May 5, 2021 at 05:02 pm - Permalink
I have a different idea. Suppose that you have n rows in a table, each with m columns. Create a matrix of size (n x 2m). Copy the data from the table into every other column in the matrix (e.g. the odd numbered columns). Set the even-numbered columns to NaN. Display the matrix. Now, when you want to highlight a certain cell, say the position (4, 5) (fifth row, sixth column), set the matrix positions side-by-side to 1. In this case, set [3][5] and [5][5] to 1. You will create a "side-by-side" marker around the cell that has the number that you need to highlight.
I mention this only because you are doing the work programmatically rather than through a context menu click.
May 5, 2021 at 09:44 pm - Permalink
would a simple MatrixTranspose do the job?
I often do this temporarily if I want to manually alter dimension labels of 2D waves, which is easy for rows, but not so convenient for columns.
May 6, 2021 at 02:21 am - Permalink
In reply to would a simple… by ChrLie
For this purpose, instead of MatrixTranspose, you could change the viewed dimensions. For details, execute:
DisplayHelpTopic "Changing the Viewed Dimensions"
May 6, 2021 at 03:30 am - Permalink
I used to do this, but at least for me MatrixTranspose is much quicker, but for a more permanent table view, this is probably better.
I guess there is no way to swap the table with a command?
May 6, 2021 at 04:53 am - Permalink
In reply to I used to do this, but at… by ChrLie
Assuming a 2D wave name mat:
ModifyTable elements(mat)=(-2,-3) // Rows vertical, columns horizontal
May 6, 2021 at 05:34 am - Permalink
In reply to I have a different idea… by jjweimer
@jjweimer That's a good idea for numeric waves - I should have said that for this purpose I'm dealing with text waves, so displaying it as an image isn't an option. The data held in the table are wave names, their paths within Igor and on disk, stimulus protocol information, and other meta data. I use it to define data sets that can be accessed by other functions, but can be easily added to and modified as more data comes in. The coloring would be a way for me to quickly highlight wave definitions that have certain meta data properties, like all waves that came from a certain stimulus protocol for instance.
May 6, 2021 at 08:49 am - Permalink
Interestingly, escape codes for font color etc. don't seem to work in tables, even though the 'Edit Text Cell' button at the top of the table brings you to an interface that provides all of those options.
A quick work around is just to add an extra column into my table, and to toggle its contents from empty string to "X" according to the highlight I want to make. That's probably the most practical for now.
May 6, 2021 at 09:14 am - Permalink
Your description actually sounds like a pretty good case for a Listbox control. The text wave can be used directly as the wave in the listbox. The listbox would allow you to watch for things like a click on a cell to take some action, like doing something with the protocol info, or showing the linked wave in some way.
May 6, 2021 at 09:32 am - Permalink
In reply to Quote: I guess there is no… by hrodstein
I should have known better! Thanks!
May 6, 2021 at 10:13 am - Permalink