6c1cd3e0c73bd70d57da2340d75415a90e2e5dfb kent Wed Feb 13 11:50:01 2013 -0800 Some refactoring to make it easier to do normalized transparency. diff --git src/hg/hgTracks/wigTrack.c src/hg/hgTracks/wigTrack.c index f11dabb..922462f 100644 --- src/hg/hgTracks/wigTrack.c +++ src/hg/hgTracks/wigTrack.c @@ -988,30 +988,52 @@ double grayValue; int grayIndex; /* honor the viewLimits, data below is white, data above is black */ grayValue = max(dataValue,graphLowerLimit); grayValue = min(grayValue,graphUpperLimit); grayIndex = ((grayValue-graphLowerLimit)/graphRange)*MAX_WIG_VALUE; drawColor = tg->colorShades[grayInRange(grayIndex, 0, MAX_WIG_VALUE)]; hvGfxBox(hvg, x, yOff, 1, tg->lineHeight, drawColor); } /* vis == tvDense || vis == tvSquish */ } /* if (preDraw[].count) */ } /* for (x1 = 0; x1 < width; ++x1) */ } /* graphPreDraw() */ +static void graphAllInContainer(struct preDrawContainer *preDrawList, int preDrawZero, int width, + struct track *tg, struct hvGfx *hvg, int xOff, int yOff, + double graphUpperLimit, double graphLowerLimit, double graphRange, + enum trackVisibility vis, struct wigCartOptions *wigCart) +/* Draw the graphs for all tracks in container. */ +{ +double epsilon = graphRange / tg->lineHeight; +struct preDrawElement *preDraw = preDrawList->preDraw; +Color *colorArray = makeColorArray(preDraw, width, preDrawZero, wigCart, tg, hvg); +struct preDrawContainer *preContainer; +for(preContainer = preDrawList; preContainer; preContainer = preContainer->next) + { + struct preDrawElement *preDraw = preContainer->preDraw; + graphPreDraw(preDraw, preDrawZero, width, + tg, hvg, xOff, yOff, graphUpperLimit, graphLowerLimit, graphRange, + epsilon, colorArray, vis, wigCart); + } + +freez(&colorArray); +} + + void drawZeroLine(enum trackVisibility vis, enum wiggleGridOptEnum horizontalGrid, double graphUpperLimit, double graphLowerLimit, struct hvGfx *hvg, int xOff, int yOff, int width, int lineHeight) /* draw a line at y=0 on the graph */ { /* Do we need to draw a zero line ? * This is to be generalized in the future to allow horizontal grid * lines, perhaps user specified to indicate thresholds. */ if ((vis == tvFull) && (horizontalGrid == wiggleHorizontalGridOn)) { Color black = hvGfxFindColorIx(hvg, 0, 0, 0); int x1, x2, y1, y2; @@ -1130,31 +1152,30 @@ int preDrawSize, double *retGraphUpperLimit, double *retGraphLowerLimit) /* Draw once we've figured out predraw (numerical values to graph) we draw it here. * This code is shared by wig, bigWig, and bedGraph drawers. */ { enum wiggleYLineMarkEnum yLineOnOff; double yLineMark; /* determined from data */ double overallUpperLimit = wigEncodeStartingUpperLimit; double overallLowerLimit = wigEncodeStartingLowerLimit; double overallRange=0; /* determined from data */ double graphUpperLimit=0; /* scaling choice will set these */ double graphLowerLimit=0; /* scaling choice will set these */ double graphRange=0; /* scaling choice will set these */ double epsilon; /* range of data in one pixel */ -Color *colorArray = NULL; /* Array of pixels to be drawn. */ struct wigCartOptions *wigCart = (struct wigCartOptions *) tg->extraUiData; yLineOnOff = wigCart->yLineOnOff; yLineMark = wigCart->yLineMark; /* width - width of drawing window in pixels * pixelsPerBase - pixels per base * basesPerPixel - calculated as 1.0/pixelsPerBase */ struct preDrawContainer *preContainer; /* loop through all the preDraw containers */ for(preContainer = preDrawList; preContainer; preContainer = preContainer->next) { @@ -1200,55 +1221,44 @@ /* if we're autoscaling and the range is 0 this implies that all values * in the given range are the same. We create a bottom of the scale * by subtracting one from the only value. * This results in drawing a box that fills the range. */ if ((graphUpperLimit == graphLowerLimit)) { graphRange = 1.0; graphLowerLimit = graphUpperLimit - 1; } else { graphRange = graphUpperLimit - graphLowerLimit; } -epsilon = graphRange / tg->lineHeight; -struct preDrawElement *preDraw = preDrawList->preDraw; -colorArray = makeColorArray(preDraw, width, preDrawZero, wigCart, tg, hvg); - -/* now draw all the containers */ -for(preContainer = preDrawList; preContainer; preContainer = preContainer->next) - { - struct preDrawElement *preDraw = preContainer->preDraw; - graphPreDraw(preDraw, preDrawZero, width, - tg, hvg, xOff, yOff, graphUpperLimit, graphLowerLimit, graphRange, - epsilon, colorArray, vis, wigCart); - } +graphAllInContainer(preDrawList, preDrawZero, width, tg, hvg, xOff, yOff, + graphUpperLimit, graphLowerLimit, graphRange, vis, wigCart); drawZeroLine(vis, wigCart->horizontalGrid, graphUpperLimit, graphLowerLimit, hvg, xOff, yOff, width, tg->lineHeight); drawArbitraryYLine(vis, wigCart->yLineOnOff, graphUpperLimit, graphLowerLimit, hvg, xOff, yOff, width, tg->lineHeight, wigCart->yLineMark, graphRange, wigCart->yLineOnOff); wigMapSelf(tg, hvg, seqStart, seqEnd, xOff, yOff, width); -freez(&colorArray); if (retGraphUpperLimit != NULL) *retGraphUpperLimit = graphUpperLimit; if (retGraphLowerLimit != NULL) *retGraphLowerLimit = graphLowerLimit; } struct preDrawContainer *wigLoadPreDraw(struct track *tg, int seqStart, int seqEnd, int width) /* Do bits that load the predraw buffer tg->preDrawContainer. */ { /* Just need to do this once... */ if (tg->preDrawContainer) return tg->preDrawContainer; struct wigItem *wi; double pixelsPerBase = scaleForPixels(width);