Coloring specific rows in a table

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"

 

Can colors be applied to individual cells in a listbox? If so, translate the table to a listbox.

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.

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

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.

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.

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.

 

In reply to by ChrLie

Quote:
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.

For this purpose, instead of MatrixTranspose, you could change the viewed dimensions. For details, execute:

DisplayHelpTopic "Changing the Viewed Dimensions"

 

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?

In reply to by ChrLie

Quote:
I guess there is no way to swap the table with a command?

Assuming a 2D wave name mat:

ModifyTable elements(mat)=(-3,-2)       // Columns vertical, rows horizontal
ModifyTable elements(mat)=(-2,-3)       // Rows vertical, columns horizontal

 

In reply to 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.

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. 

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.

In reply to by hrodstein

hrodstein wrote:

 

Quote:

I guess there is no way to swap the table with a command?

 

Assuming a 2D wave name mat:

ModifyTable elements(mat)=(-3,-2)       // Columns vertical, rows horizontal
ModifyTable elements(mat)=(-2,-3)       // Rows vertical, columns horizontal

 

I should have known better! Thanks!