internal bool draw() { Font font = gdef.smallFont; Color mGridColor = gdef.colors[COLOR_MGRID]; Color fontColor = gdef.colors[COLOR_FONT]; int labelOffset = (int)(worker.getFontAscent(font) / 2); if (Double.IsNaN((im.maxval - im.minval) / im.magfact)) { return(false); } int xLeft = im.xorigin; int xRight = im.xorigin + im.xsize; String labfmt; if (im.scaledstep / im.magfact * Math.Max(Math.Abs(im.quadrant), Math.Abs(4 - im.quadrant)) <= 1.0) { labfmt = "{0,5:f2}"; } else { labfmt = string.Format("{0,4:f}", 1 - ((im.scaledstep / im.magfact > 10.0 || Math.Ceiling(im.scaledstep / im.magfact) == im.scaledstep / im.magfact) ? 1 : 0)); } if (im.symbol != ' ' || im.unit != null) { labfmt += " "; } if (im.symbol != ' ') { labfmt += im.symbol; } if (im.unit != null) { labfmt += im.unit; } for (int i = 0; i <= 4; i++) { int y = im.yorigin - im.ysize * i / 4; if (y >= im.yorigin - im.ysize && y <= im.yorigin) { String graph_label = string.Format(labfmt, im.scaledstep / im.magfact * (i - im.quadrant)); int length = (int)(worker.getStringWidth(graph_label, font)); worker.drawString(graph_label, xLeft - length - PADDING_VLABEL, y + labelOffset, font, fontColor); worker.drawLine(xLeft - 2, y, xLeft + 2, y, mGridColor, TICK_STROKE); worker.drawLine(xRight - 2, y, xRight + 2, y, mGridColor, TICK_STROKE); worker.drawLine(xLeft, y, xRight, y, mGridColor, GRID_STROKE); } } return(true); }
internal bool draw() { Font font = gdef.smallFont; Color gridColor = gdef.colors[COLOR_GRID]; Color mGridColor = gdef.colors[COLOR_MGRID]; Color fontColor = gdef.colors[COLOR_FONT]; int fontHeight = (int)Math.Ceiling(rrdGraph.getSmallFontHeight()); int labelOffset = (int)(worker.getFontAscent(font) / 2); double pixpex = (double)im.ysize / (Math.Log10(im.maxval) - Math.Log10(im.minval)); if (Double.IsNaN(pixpex)) { return(false); } double minstep, pixperstep; int minoridx = 0, majoridx = 0; for (int i = 0; yloglab[i][0] > 0; i++) { minstep = Math.Log10(yloglab[i][0]); for (int ii = 1; yloglab[i][ii + 1] > 0; ii++) { if (yloglab[i][ii + 2] == 0) { minstep = Math.Log10(yloglab[i][ii + 1]) - Math.Log10(yloglab[i][ii]); break; } } pixperstep = pixpex * minstep; if (pixperstep > 5) { minoridx = i; } if (pixperstep > 2 * fontHeight) { majoridx = i; } } int x0 = im.xorigin, x1 = x0 + im.xsize; for (double value = Math.Pow(10, Math.Log10(im.minval) - Math.Log10(im.minval) % Math.Log10(yloglab[minoridx][0])); value <= im.maxval; value *= yloglab[minoridx][0]) { if (value < im.minval) { continue; } int i = 0; while (yloglab[minoridx][++i] > 0) { int y = rrdGraph.mapper.ytr(value * yloglab[minoridx][i]); if (y <= im.yorigin - im.ysize) { break; } worker.drawLine(x0 - 1, y, x0 + 1, y, gridColor, TICK_STROKE); worker.drawLine(x1 - 1, y, x1 + 1, y, gridColor, TICK_STROKE); worker.drawLine(x0, y, x1, y, gridColor, GRID_STROKE); } } for (double value = Math.Pow(10, Math.Log10(im.minval) - (Math.Log10(im.minval) % Math.Log10(yloglab[majoridx][0]))); value <= im.maxval; value *= yloglab[majoridx][0]) { if (value < im.minval) { continue; } int i = 0; while (yloglab[majoridx][++i] > 0) { int y = rrdGraph.mapper.ytr(value * yloglab[majoridx][i]); if (y <= im.yorigin - im.ysize) { break; } worker.drawLine(x0 - 2, y, x0 + 2, y, mGridColor, TICK_STROKE); worker.drawLine(x1 - 2, y, x1 + 2, y, mGridColor, TICK_STROKE); worker.drawLine(x0, y, x1, y, mGridColor, GRID_STROKE); String graph_label = string.Format("{0,3:E0}", value * yloglab[majoridx][i]); int length = (int)(worker.getStringWidth(graph_label, font)); worker.drawString(graph_label, x0 - length - PADDING_VLABEL, y + labelOffset, font, fontColor); } } return(true); }
private void drawRules() { worker.clip(im.xorigin + 1, im.yorigin - gdef.height - 1, gdef.width - 1, gdef.height + 2); foreach (PlotElement pe in gdef.plotElements) { if (pe.GetType() == typeof(HRule)) { HRule hr = (HRule)pe; if (hr.value >= im.minval && hr.value <= im.maxval) { int y = mapper.ytr(hr.value); worker.drawLine(im.xorigin, y, im.xorigin + im.xsize, y, hr.color, hr.width); } } else if (pe.GetType() == typeof(VRule)) { VRule vr = (VRule)pe; if (vr.timestamp >= im.start && vr.timestamp <= im.end) { int x = mapper.xtr(vr.timestamp); worker.drawLine(x, im.yorigin, x, im.yorigin - im.ysize, vr.color, vr.width); } } } worker.reset(); }