6403a1e3c5844253ea26149aca71f89a2afd3d7e kent Thu Apr 5 17:41:33 2012 -0700 Adding commas to ruler on Genome Browser. Redmine #7559 diff --git src/hg/lib/hvGfx.c src/hg/lib/hvGfx.c index 3909e33..8ecf7a6 100644 --- src/hg/lib/hvGfx.c +++ src/hg/lib/hvGfx.c @@ -1,21 +1,22 @@ /* hvGfx - browser graphics interface. This is a thin layer on top of vGfx * providing genome browser-specific features. It was added to handle * reverse-complement display. */ #include "common.h" #include "hvGfx.h" +#include "obscure.h" static struct hvGfx *hvGfxAlloc(struct vGfx *vg) /* allocate a hvgGfx object */ { struct hvGfx *hvg; AllocVar(hvg); hvg->vg = vg; hvg->pixelBased = vg->pixelBased; hvg->width = vg->width; hvg->height = vg->height; hvg->clipMaxX = vg->width; hvg->clipMaxY = vg->height; return hvg; } @@ -75,77 +76,65 @@ int i; int tickLen = 1; for (i=0; i<9; ++i) { if (roughTickLen < tickLen) return tickLen; tickLen *= 5; if (roughTickLen < tickLen) return tickLen; tickLen *= 2; } return 1000000000; } -static void numLabelString(int num, char *label) -/* Returns a numerical labeling string. */ -{ -char *sign = ""; -if (num < 0) - { - num = -num; - sign = "-"; - } -sprintf(label, "%s%d", sign, num); -} - void hvGfxDrawRulerBumpText(struct hvGfx *hvg, int xOff, int yOff, int height, int width, Color color, MgFont *font, int startNum, int range, int bumpX, int bumpY) /* Draw a ruler inside the indicated part of mg with numbers that start at * startNum and span range. Bump text positions slightly. */ { int tickSpan; int tickPos; double scale; int firstTick; int remainder; int end = startNum + range; int x; -char tbuf[14]; +char tbuf[18]; int numWid; int goodNumTicks; int niceNumTicks = width/35; -numLabelString(startNum+range, tbuf); +sprintLongWithCommas(tbuf, startNum+range); numWid = mgFontStringWidth(font, tbuf)+4+bumpX; goodNumTicks = width/numWid; if (goodNumTicks < 1) goodNumTicks = 1; if (goodNumTicks > niceNumTicks) goodNumTicks = niceNumTicks; tickSpan = figureTickSpan(range, goodNumTicks); scale = (double)width / range; firstTick = startNum + tickSpan; remainder = firstTick % tickSpan; firstTick -= remainder; for (tickPos=firstTick; tickPos<end; tickPos += tickSpan) { - numLabelString(tickPos, tbuf); + sprintLongWithCommas(tbuf, tickPos); numWid = mgFontStringWidth(font, tbuf)+4; x = (int)((tickPos-startNum) * scale) + xOff; hvGfxBox(hvg, x, yOff, 1, height, color); if (x - numWid >= xOff) { hvGfxTextCentered(hvg, x-numWid + bumpX, yOff + bumpY, numWid, height, color, font, tbuf); } } } void hvGfxDrawRuler(struct hvGfx *hvg, int xOff, int yOff, int height, int width, Color color, MgFont *font, int startNum, int range) /* Draw a ruler inside the indicated part of mg with numbers that start at