424d7d72c6d433f4799f6e505fb76a10fe173408 max Sat Apr 6 14:24:06 2013 -0700 use only best color if several defined diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c index 32a29ae..7a990d5 100644 --- src/hg/hgTracks/simpleTracks.c +++ src/hg/hgTracks/simpleTracks.c @@ -12079,60 +12079,61 @@ matchStr[i++] = '+'; for(; *str && !isspace(*str);str++) matchStr[i++] = *str; for(;*str && isspace(*str);str++) ; } matchStr[i++] = 0; return matchStr; } struct pubsExtra /* additional info needed for publication blat linked features: author+year and title */ { char *label; // usually author+year char *mouseOver; // usually title of article + char *class; // class of article, usually a curated database // color depends on cart settings, either based on topic, impact or year // support to ways to color: either by shade (year, impact) or directly with rgb values int shade; // year or impact are shades which we can't resolve to rgb easily struct rgbColor *color; }; /* assignment of pubs classes to colors */ static struct hash* pubsClassColors = NULL; static void pubsParseClassColors() /* parse class colors from hgFixed.pubsClassColors into the hash pubsClassColors */ { if (pubsClassColors!=NULL) return; pubsClassColors = hashNew(0); struct sqlConnection *conn = hAllocConn(database); if (!sqlTableExists(conn, "hgFixed.pubsClassColors")) { - //fprintf(stderr, "simpleTracks.c: table hgFixed.pubsClassColors does not exist\n"); return; } char *query = "SELECT class, rgbColor FROM hgFixed.pubsClassColors"; struct sqlResult *sr = sqlGetResult(conn, query); char **row = NULL; -if ((row = sqlNextRow(sr)) != NULL) +while ((row = sqlNextRow(sr)) != NULL) { char *class = row[0]; char *colStr = row[1]; // copied from genePredItemClassColor - is there no function for this? + // convert comma sep rgb string to array char *rgbVals[5]; chopString(colStr, ",", rgbVals, sizeof(rgbVals)); struct rgbColor *rgb; AllocVar(rgb); rgb->r = (sqlUnsigned(rgbVals[0])); rgb->g = (sqlUnsigned(rgbVals[1])); rgb->b = (sqlUnsigned(rgbVals[2])); //printf("Adding hash: %s -> %d,%d,%d", class, rgb->r, rgb->g, rgb->b); hashAdd(pubsClassColors, cloneString(class), rgb); } sqlFreeResult(&sr); } static char* pubsFeatureLabel(char* author, char* year) /* create label <author><year> given authors and year strings */ @@ -12173,53 +12174,64 @@ { safef(query, sizeof(query), "SELECT firstAuthor, year, title FROM %s WHERE articleId = '%s'", articleTable, lf->name); newFormat = false; } sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) { char* firstAuthor = row[0]; char* year = row[1]; char* title = row[2]; char* impact = NULL; char* classes = NULL; + extra = needMem(sizeof(struct pubsExtra)); extra->label = pubsFeatureLabel(firstAuthor, year); if (isEmpty(title)) extra->mouseOver = extra->label; else extra->mouseOver = cloneString(title); extra->color = NULL; extra->shade = -1; if (newFormat) { impact = row[3]; classes = row[4]; if (!isEmpty(impact)) { char *colorBy = cartOptionalStringClosestToHome(cart, tg->tdb, FALSE, "pubsColorBy"); if ((colorBy==NULL) || strcmp(colorBy,"topic")==0) { - char *class; - while ((class=cloneNextWordByDelimiter(&classes, ','))!=NULL) + char *classCopy = classes; + char* mainClass = cloneNextWordByDelimiter(&classes, ','); + classes = classCopy; + if (mainClass!=NULL) { - struct rgbColor *col = (struct rgbColor*) hashFindVal(pubsClassColors, class); + struct rgbColor *col = (struct rgbColor*) hashFindVal(pubsClassColors, mainClass); extra->color = col; + // add class to mouseover text + struct dyString *mo = dyStringNew(0); + dyStringAppend(mo, extra->mouseOver); + dyStringAppend(mo, " (categories: "); + dyStringAppend(mo, classes); + dyStringAppend(mo, ")"); + freeMem(extra->mouseOver); + extra->mouseOver = dyStringContents(mo); } } else { if (strcmp(colorBy,"impact")==0) { char impInt = atoi(impact); extra->shade = impInt/25; } if (strcmp(colorBy,"year")==0) { int relYear = (atoi(year)-1990); extra->shade = min(relYear/3, 10); //extra->color = shadesOfGray[yearShade]; }