f4aba74550dea6d8548ba891cb9d057eaf6de43e
kate
  Wed Mar 22 12:30:24 2017 -0700
Fix bogus color cacheing.  Its now per-track

diff --git src/hg/hgTracks/barChartTrack.c src/hg/hgTracks/barChartTrack.c
index 0fde3db..1acadff 100644
--- src/hg/hgTracks/barChartTrack.c
+++ src/hg/hgTracks/barChartTrack.c
@@ -6,123 +6,126 @@
 #include "common.h"
 #include "hgTracks.h"
 #include "bed.h"
 #include "hvGfx.h"
 #include "spaceSaver.h"
 #include "barChartBed.h"
 #include "barChartCategory.h"
 #include "barChartUi.h"
 
 
 struct barChartTrack
 /* Track info */
     {
     boolean noWhiteout;         /* Suppress whiteout of graph background (allow highlight, blue lines) */
     double maxMedian;           /* Maximum median across all categories */
-    struct rgbColor *colors;    /* Colors  for all categories */
     boolean doLogTransform;     /* Log10(x+1) */
-    struct barChartCategory *categories; /* Cache category names, colors */
+    struct barChartCategory *categories; /* Category names, colors, etc. */
+    int categCount;             /* Count of categories - derived from above */
+    char **categNames;          /* Category names  - derived from above */
+    char **categLabels;         /* Category labels  - derived from above */
+    struct rgbColor *colors;    /* Colors  for all categories */
     struct hash *categoryFilter;  /* NULL out excluded factors */
     };
 
 struct barChartItem
 /* BED item plus computed values for display */
     {
     struct barChartItem *next;  /* Next in singly linked list */
     struct barChartBed *bed;    /* Item coords, name, exp count and values */
     int height;                 /* Item height in pixels */
     };
 
 /***********************************************/
-/* Cache category info */
-/* TODO: multi-thread caching by track name */
+/* Organize category info */
 
 struct barChartCategory *getCategories(struct track *tg)
 /* Get and cache category info */
 {
-static struct barChartCategory *categs = NULL;
-
-if (!categs)
-    categs = barChartUiGetCategories(database, tg->tdb);
-return categs;
+struct barChartTrack *info = (struct barChartTrack *)tg->extraUiData;
+if (info->categories == NULL)
+    info->categories = barChartUiGetCategories(database, tg->tdb);
+return info->categories;
 }
 
 int getCategoryCount(struct track *tg)
 /* Get and cache the number of categories */
 {
-static int categCount = 0;
-
-if (!categCount)
-    categCount = slCount(getCategories(tg));
-return categCount;
+struct barChartTrack *info = (struct barChartTrack *)tg->extraUiData;
+if (info->categCount == 0)
+    info->categCount = slCount(getCategories(tg));
+return info->categCount;
 }
 
 /* TODO: Do we need names ? */
 
 char *getCategoryName(struct track *tg, int id)
 /* Get category name from id, cacheing */
 {
-static char **categNames = NULL;
 struct barChartCategory *categ;
 int count = getCategoryCount(tg);
-if (!categNames)
+struct barChartTrack *info = (struct barChartTrack *)tg->extraUiData;
+if (!info->categNames)
     {
     struct barChartCategory *categs = getCategories(tg);
-    AllocArray(categNames, count);
+    AllocArray(info->categNames, count);
     for (categ = categs; categ != NULL; categ = categ->next)
-        categNames[categ->id] = cloneString(categ->name);
+        info->categNames[categ->id] = cloneString(categ->name);
     }
 if (id >= count)
     errAbort("Bar chart track: can't find id %d\n", id);
-return categNames[id];
+return info->categNames[id];
 }
 
 char *getCategoryLabel(struct track *tg, int id)
 /* Get category descriptive label from id, cacheing */
 {
-static char **categLabels = NULL;
+struct barChartTrack *info = (struct barChartTrack *)tg->extraUiData;
 struct barChartCategory *categ;
 int count = getCategoryCount(tg);
-if (!categLabels)
+if (!info->categLabels)
     {
     struct barChartCategory *categs = getCategories(tg);
-    AllocArray(categLabels, count);
+    AllocArray(info->categLabels, count);
     for (categ = categs; categ != NULL; categ = categ->next)
-        categLabels[categ->id] = cloneString(categ->label);
+        info->categLabels[categ->id] = cloneString(categ->label);
     }
 if (id >= count)
     errAbort("Bar chart track: can't find id %d\n", id);
-return categLabels[id];
+return info->categLabels[id];
 }
 
 struct rgbColor *getCategoryColors(struct track *tg)
 /* Get RGB colors from category table */
 {
 struct barChartCategory *categs = getCategories(tg);
 struct barChartCategory *categ = NULL;
 int count = slCount(categs);
-struct rgbColor *colors;
-AllocArray(colors, count);
+struct barChartTrack *info = (struct barChartTrack *)tg->extraUiData;
+if (!info->colors)
+    {
+    AllocArray(info->colors, count);
     int i = 0;
     for (categ = categs; categ != NULL; categ = categ->next)
         {
         // TODO: reconcile 
-    colors[i] = (struct rgbColor){.r=COLOR_32_BLUE(categ->color), .g=COLOR_32_GREEN(categ->color), .b=COLOR_32_RED(categ->color)};
+        info->colors[i] = (struct rgbColor){.r=COLOR_32_BLUE(categ->color), .g=COLOR_32_GREEN(categ->color), .b=COLOR_32_RED(categ->color)};
         //colors[i] = mgColorIxToRgb(NULL, categ->color);
         i++;
         }
-return colors;
+    }
+return info->colors;
 }
 
 /*****************************************************************/
 /* Convenience functions for draw */
 
 static int barChartSquishItemHeight()
 /* Height of squished item (request to have it larger than usual) */
 {
 return tl.fontHeight - tl.fontHeight/2;
 }
 
 static int barChartBoxModelHeight()
 /* Height of indicator box drawn under graph to show gene extent */
 {
 long winSize = virtWinBaseCount;