Tuesday, August 5, 2008

Cocoa Heat Mapper

I started working on a Cocoa app that draws heat maps. It is pretty rough still, but works well enough to show a screenshot. Drawing the colored rectangles is entry-level NSView stuff. I added the ability to show the actual data in the squares. Since my data consists of counts of objects between 1 and 100 or so, this works fine. We switch the text color based on the background of the rectangle.

In its current state it allows toggling between two different methods for assigning the colors. The first is to compute the frequency by dividing the count by the maximum value in that column, and the second just bases the assignment on the count. Adding additional methods is simple. I'm hoping to explore various methods of "turning up the contrast" to vary the level of visible detail in the data.

I didn't use bindings, except that the value of the popup is bound to a list of available methods, but the popup itself is wired up to the view like so:

def popupChanged_(self, sender):
print 'popupChanged_',
self.index = sender.selectedItem().tag()
print self.index

Here's a sneak peak at part of the view in the version which I'm using to analyze my data. We have counts of bacteria assigned to broad (genus-level or higher) groups, with the name color coded by the Phylum.

No comments: