24ff088d65aa4b5765f2d1ba96f293d906a70705 braney Wed Dec 10 14:02:38 2014 -0800 changes in response to code review #14504 diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c index 8de7056..ec793d7 100644 --- src/hg/hgTracks/simpleTracks.c +++ src/hg/hgTracks/simpleTracks.c @@ -298,34 +298,34 @@ { return (tdbIsComposite(track->tdb) && track->subtracks != NULL); } Color slightlyLighterColor(struct hvGfx *hvg, Color color) /* Get slightly lighter shade of a color - closer to gray actually */ { struct rgbColor rgbColor = hvGfxColorIxToRgb(hvg, color); rgbColor.r = (rgbColor.r+128)/2; rgbColor.g = (rgbColor.g+128)/2; rgbColor.b = (rgbColor.b+128)/2; return hvGfxFindColorIx(hvg, rgbColor.r, rgbColor.g, rgbColor.b); } void checkIfWiggling(struct cart *cart, struct track *tg) -/* check to see if a linkedFeatures track should be drawing as a wiggle */ +/* Check to see if a linkedFeatures track should be drawing as a wiggle. */ { -char *doWiggle = cartOrTdbString(cart, tg->tdb, "doWiggle" , "0"); -if (sameString(doWiggle, "1")) +boolean doWiggle = cartOrTdbBoolean(cart, tg->tdb, "doWiggle" , FALSE); +if (doWiggle) { tg->drawLeftLabels = wigLeftLabels; tg->colorShades = shadesOfGray; tg->mapsSelf = TRUE; } } int packCountRowsOverflow(struct track *tg, int maxCount, boolean withLabels, boolean allowOverflow) /* Return packed height. */ { struct spaceSaver *ss; struct slList *item; MgFont *font = tl.font; int extraWidth = tl.mWidth * 2; @@ -410,32 +410,32 @@ /* Return the maximum number of items to allow overflow indication. */ { int answer = maxItemsToUseOverflowDefault; char *maxItemsString = trackDbSetting(tg->tdb, "maxItemsToOverflow"); if (maxItemsString != NULL) answer = sqlUnsigned(maxItemsString); return answer; } int tgFixedTotalHeightOptionalOverflow(struct track *tg, enum trackVisibility vis, int lineHeight, int heightPer, boolean allowOverflow) /* Most fixed height track groups will use this to figure out the height * they use. */ { -char *doWiggle = cartOrTdbString(cart, tg->tdb, "doWiggle" , "0"); -if (sameString(doWiggle, "1")) +boolean doWiggle = cartOrTdbBoolean(cart, tg->tdb, "doWiggle" , FALSE); +if (doWiggle) { struct wigCartOptions *wigCart = tg->wigCartData; if (tg->wigCartData == NULL) { wigCart = wigCartOptionsNew(cart, tg->tdb, 0, NULL ); tg->wigCartData = (void *) wigCart; } return wigTotalHeight(tg, vis); } int rows; double maxHeight = maximumTrackHeight(tg); int itemCount = slCount(tg->items); int maxItemsToUseOverflow = maxItemsToOverflow(tg); tg->heightPer = heightPer; @@ -3204,97 +3204,92 @@ { if (nextItemCompatible(tg)) genericDrawNextItemStuff(tg, hvg, vis, item, x2, textX, y, tg->heightPer, color); else { tg->mapItem(tg, hvg, item, tg->itemName(tg, item), tg->mapItemName(tg, item), s, e, textX, y, w, tg->heightPer); } } } withIndividualLabels = TRUE; /* reset in case done with pgSnp */ } static int normalizeCount(struct preDrawElement *el, double countFactor, double minVal, double maxVal, double sumData, double sumSquares) -/* normalize statistics to be based on an integer number of valid bases - * Integer value is the smallest integer not less than countFactor */ +/* Normalize statistics to be based on an integer number of valid bases. + * Integer value is the smallest integer not less than countFactor. */ { bits32 validCount = ceil(countFactor); double normFactor = (double)validCount/countFactor; el->count = validCount; el->min = minVal; el->max = maxVal; el->sumData = sumData * normFactor; el->sumSquares = sumSquares * normFactor; return validCount; } static unsigned *countOverlaps(struct track *track) -/* count up overlap of linked features */ +/* Count up overlap of linked features. */ { -int ii; struct slList *items = track->items; struct slList *item; unsigned size = winEnd - winStart; unsigned *counts = needHugeZeroedMem(size * sizeof(unsigned)); for (item = items; item; item = item->next) { unsigned start = track->itemStart(track, item); unsigned end = track->itemEnd(track, item); - if ((start >= winEnd) || (end < winStart)) + if (positiveRangeIntersection(start, end, winStart, winEnd) > 0) continue; - int x1 = start - winStart; - if (x1 < 0) - x1 = 0; - int x2 = end - winStart; - if (x2 > size) - x2 = size; + int x1 = max(start - winStart, 0); + int x2 = min(end - winStart, size); - for(ii=x1; ii < x2; ii++) - counts[ii]++; + for(; x1 < x2; x1++) + counts[x1]++; } return counts; } static void countsToPixelsUp(unsigned *counts, struct preDrawContainer *pre) -/* up sample counts into pixels */ +/* Up sample counts into pixels. */ { int preDrawZero = pre->preDrawZero; unsigned size = winEnd - winStart; double countsPerPixel = size / (double) insideWidth; int pixel; for (pixel=0; pixel<insideWidth; ++pixel) { struct preDrawElement *pe = &pre->preDraw[pixel + preDrawZero]; unsigned index = pixel * countsPerPixel; pe->count = 1; pe->min = counts[index]; pe->max = counts[index]; pe->sumData = counts[index] ; pe->sumSquares = counts[index] * counts[index]; } } static void countsToPixelsDown(unsigned *counts, struct preDrawContainer *pre) -/* down sample counts into pixels */ +/* Down sample counts into pixels. */ { int preDrawZero = pre->preDrawZero; unsigned size = winEnd - winStart; double countsPerPixel = size / (double) insideWidth; int pixel; for (pixel=0; pixel<insideWidth; ++pixel) { struct preDrawElement *pe = &pre->preDraw[pixel + preDrawZero]; double startReal = pixel * countsPerPixel; double endReal = (pixel + 1) * countsPerPixel; unsigned startUns = startReal; unsigned endUns = endReal; double realCount, realSum, realSumSquares, max, min; @@ -3333,45 +3328,45 @@ { if (max < counts[endUns]) max = counts[endUns]; if (min > counts[endUns]) min = counts[endUns]; realCount += lastFrac; realSum += lastSum; realSumSquares += lastSum * lastSum; } pe->count = normalizeCount(pe, realCount, min, max, realSum, realSumSquares); } } static void countsToPixels(unsigned *counts, struct preDrawContainer *pre) -/* sample counts into pixels */ +/* Sample counts into pixels. */ { unsigned size = winEnd - winStart; double countsPerPixel = size / (double) insideWidth; if (countsPerPixel <= 1.0) countsToPixelsUp(counts, pre); else countsToPixelsDown(counts, pre); } static void genericDrawItemsWiggle(struct track *tg, int seqStart, int seqEnd, struct hvGfx *hvg, int xOff, int yOff, int width, MgFont *font, Color color, enum trackVisibility vis) -/* draw a list of linked features into a wiggle */ +/* Draw a list of linked features into a wiggle. */ { struct preDrawContainer *pre = tg->preDrawContainer = initPreDrawContainer(insideWidth); unsigned *counts = countOverlaps(tg); countsToPixels(counts, pre); freez(&counts); hvGfxSetClip(hvg, insideX, yOff, insideWidth, tg->height); tg->mapsSelf = FALSE; // some magic to turn off the link out wigDrawPredraw(tg, seqStart, seqEnd, hvg, xOff, yOff, width, font, color, vis, tg->preDrawContainer, tg->preDrawContainer->preDrawZero, tg->preDrawContainer->preDrawSize, &tg->graphUpperLimit, &tg->graphLowerLimit); tg->mapsSelf = TRUE; hvGfxUnclip(hvg); } @@ -3457,32 +3452,32 @@ y += tg->lineHeight; } } } void genericDrawItems(struct track *tg, int seqStart, int seqEnd, struct hvGfx *hvg, int xOff, int yOff, int width, MgFont *font, Color color, enum trackVisibility vis) /* Draw generic item list. Features must be fixed height * and tg->drawItemAt has to be filled in. */ { if (tg->mapItem == NULL) tg->mapItem = genericMapItem; if (vis != tvDense && (! bedItemRgb(tg->tdb)) && baseColorCanDraw(tg)) baseColorInitTrack(hvg, tg); -char *doWiggle = cartOrTdbString(cart, tg->tdb, "doWiggle" , "0"); -if (sameString(doWiggle, "1")) +boolean doWiggle = cartOrTdbBoolean(cart, tg->tdb, "doWiggle" , FALSE); +if (doWiggle) { genericDrawItemsWiggle(tg, seqStart, seqEnd, hvg, xOff, yOff, width, font, color, vis); } else if (vis == tvPack || vis == tvSquish) { genericDrawItemsPackSquish(tg, seqStart, seqEnd, hvg, xOff, yOff, width, font, color, vis); } else genericDrawItemsFullDense(tg, seqStart, seqEnd, hvg, xOff, yOff, width, font, color, vis); } void linkedFeaturesSeriesDraw(struct track *tg, int seqStart, int seqEnd,