public override void Render(Settings settings) { penLine.Color = color; penLine.Width = (float)lineWidth; PointF[] points = new PointF[xs.Length]; for (int i = 0; i < xs.Length; i++) { points[i] = settings.GetPixel(xs[i], ys[i]); } PointF[] pointsStep = null; if (stepDisplay) { pointsStep = new PointF[xs.Length * 2 - 1]; for (int i = 0; i < points.Length; i++) { pointsStep[i * 2] = points[i]; } for (int i = 0; i < points.Length - 1; i++) { pointsStep[i * 2 + 1] = new PointF(points[i + 1].X, points[i].Y); } } if (errorY != null) { for (int i = 0; i < points.Length; i++) { PointF errorBelow = settings.GetPixel(xs[i], ys[i] - errorY[i]); PointF errorAbove = settings.GetPixel(xs[i], ys[i] + errorY[i]); float xCenter = errorBelow.X; float yTop = errorAbove.Y; float yBot = errorBelow.Y; settings.gfxData.DrawLine(penLineError, xCenter, yBot, xCenter, yTop); settings.gfxData.DrawLine(penLineError, xCenter - errorCapSize, yBot, xCenter + errorCapSize, yBot); settings.gfxData.DrawLine(penLineError, xCenter - errorCapSize, yTop, xCenter + errorCapSize, yTop); } } if (errorX != null) { for (int i = 0; i < points.Length; i++) { PointF errorLeft = settings.GetPixel(xs[i] - errorX[i], ys[i]); PointF errorRight = settings.GetPixel(xs[i] + errorX[i], ys[i]); float yCenter = errorLeft.Y; float xLeft = errorLeft.X; float xRight = errorRight.X; settings.gfxData.DrawLine(penLineError, xLeft, yCenter, xRight, yCenter); settings.gfxData.DrawLine(penLineError, xLeft, yCenter - errorCapSize, xLeft, yCenter + errorCapSize); settings.gfxData.DrawLine(penLineError, xRight, yCenter - errorCapSize, xRight, yCenter + errorCapSize); } } if (penLine.Width > 0 && points.Length > 1) { if (stepDisplay) { settings.gfxData.DrawLines(penLine, pointsStep); } else { settings.gfxData.DrawLines(penLine, points); } } if ((markerSize > 0) && (markerShape != MarkerShape.none)) { for (int i = 0; i < points.Length; i++) { MarkerTools.DrawMarker(settings.gfxData, points[i], markerShape, markerSize, color); } } }
protected virtual void DrawPoint(Settings settings, List <PointF> points, int i) { MarkerTools.DrawMarker(settings.gfxData, points[i], markerShape, markerSize, color); }
public override void Render(Settings settings) { for (int i = 0; i < xs.Length; i++) { double QSize = (int)Math.Floor(ys[i].Length / 4.0); double[] sortedYs = ys[i].OrderBy(y => y).ToArray(); double Q1 = sortedYs[(int)Math.Floor(QSize)]; double median = sortedYs[(int)Math.Floor(2 * QSize)]; double Q3 = sortedYs[(int)Math.Floor(sortedYs.Length - QSize - 1)]; double lowerBoundary = Q1 - 1.5 * (Q3 - Q1); double upperBoundary = Q3 + 1.5 * (Q3 - Q1); //These could be made faster knowing that we have already sorted the list above List <double> lowOutliers = ys[i].Where(y => y < lowerBoundary).ToList(); List <double> highOutliers = ys[i].Where(y => y > upperBoundary).ToList(); PointF topLeft = settings.GetPixel((xs[i] - (boxWidth / (2 * settings.xAxisScale))), Q3); PointF bottomLeft = settings.GetPixel((xs[i] - (boxWidth / (2 * settings.xAxisScale))), Q1); int middleX = (int)Math.Floor(topLeft.X + boxWidth / 2); PointF medianLine = settings.GetPixel(middleX, median); PointF bottomWhisker; PointF topWhisker; if (lowOutliers.Count == 0) { bottomWhisker = settings.GetPixel(0, ys[i].Min()); } else { bottomWhisker = settings.GetPixel(0, lowerBoundary); } if (highOutliers.Count == 0) { topWhisker = settings.GetPixel(0, ys[i].Max()); } else { topWhisker = settings.GetPixel(0, upperBoundary); } bottomWhisker.X = middleX; topWhisker.X = middleX; int whiskerSpread = (int)Math.Floor(boxWidth / 5); settings.gfxData.DrawLine(pen, topWhisker.X, topWhisker.Y, middleX, topLeft.Y); //Whisker Centre settings.gfxData.DrawLine(pen, bottomWhisker.X, bottomWhisker.Y, middleX, bottomLeft.Y); //Whisker Centre settings.gfxData.DrawLine(pen, bottomWhisker.X - whiskerSpread, bottomWhisker.Y, bottomWhisker.X + whiskerSpread, bottomWhisker.Y); //Whisker Cap settings.gfxData.DrawLine(pen, topWhisker.X - whiskerSpread, topWhisker.Y, topWhisker.X + whiskerSpread, topWhisker.Y); //Whisker Cap settings.gfxData.DrawRectangle(pen, topLeft.X, topLeft.Y, (int)boxWidth, (int)Math.Round((Q3 - Q1) * settings.yAxisScale)); //Box settings.gfxData.DrawLine(pen, topLeft.X, medianLine.Y, (int)boxWidth + topLeft.X, medianLine.Y); //Median List <double> allOutliers = lowOutliers; allOutliers.AddRange(highOutliers); foreach (double curr in allOutliers) { PointF point = settings.GetPixel(0, curr); point.X = middleX; MarkerTools.DrawMarker(settings.gfxData, point, markerShape, (float)lineWidth * 3, color);//Outliers } } }
public override void Render(Settings settings) { Random rand = new Random(0); foreach (Statistics.BoxAndWhisker baw in boxAndWhiskers) { float center = (float)settings.GetPixelX(baw.xPosition); if (baw.whisker.visible) { float whiskerMax = (float)settings.GetPixelY(baw.whisker.max); float whiskerMin = (float)settings.GetPixelY(baw.whisker.min); float whiskerLeft = (float)settings.GetPixelX(baw.xPosition - baw.whisker.width / 2); float whiskerRight = (float)settings.GetPixelX(baw.xPosition + baw.whisker.width / 2); var whiskerPen = new Pen(baw.whisker.lineColor, baw.whisker.lineWidth); settings.gfxData.DrawLine(whiskerPen, center, whiskerMin, center, whiskerMax); settings.gfxData.DrawLine(whiskerPen, whiskerLeft, whiskerMax, whiskerRight, whiskerMax); settings.gfxData.DrawLine(whiskerPen, whiskerLeft, whiskerMin, whiskerRight, whiskerMin); } if (baw.box.outline || baw.box.fill) { float boxMax = (float)settings.GetPixelY(baw.box.max); float boxMin = (float)settings.GetPixelY(baw.box.min); float boxLeft = (float)settings.GetPixelX(baw.xPosition - baw.box.width / 2); float boxRight = (float)settings.GetPixelX(baw.xPosition + baw.box.width / 2); float boxHeight = boxMin - boxMax; float boxWidth = boxRight - boxLeft; PointF boxOrigin = new PointF(boxLeft, boxMax); SizeF boxSize = new SizeF(boxWidth, boxHeight); RectangleF boxRect = new RectangleF(boxOrigin, boxSize); if (baw.box.fill) { var boxBrush = new SolidBrush(baw.box.fillColor); settings.gfxData.FillRectangle(boxBrush, Rectangle.Round(boxRect)); } if (baw.box.outline) { var boxPen = new Pen(baw.box.lineColor, baw.box.lineWidth); settings.gfxData.DrawRectangle(boxPen, Rectangle.Round(boxRect)); } } if (baw.midline.visible) { float boxLeft = (float)settings.GetPixelX(baw.xPosition - baw.box.width / 2); float boxRight = (float)settings.GetPixelX(baw.xPosition + baw.box.width / 2); float midlineY = (float)settings.GetPixelY(baw.midline.position); var mindlinePen = new Pen(baw.midline.lineColor, baw.midline.lineWidth); settings.gfxData.DrawLine(mindlinePen, boxLeft, midlineY, boxRight, midlineY); } double boxWidthPixels = baw.box.width * settings.xAxisScale; double boxOffsetPixels = (baw.box.width / 2 * baw.dataPoints.offsetFraction) * settings.xAxisScale; double spreadPixels = (baw.box.width / 2 * baw.dataPoints.spreadFraction) * settings.xAxisScale; // TODO: make the scatter placement smarter to avoid overlapping points foreach (double curr in baw.dataPoints.values) { PointF point = new PointF(center, (float)settings.GetPixelY(curr)); point.X += (float)boxOffsetPixels; point.X += (float)((rand.NextDouble() - .5) * spreadPixels); MarkerTools.DrawMarker(settings.gfxData, point, baw.dataPoints.markerShape, baw.dataPoints.markerSize, color); } } }
public override void Render(Settings settings) { foreach (Statistics.BoxAndWhisker baw in boxAndWhiskers) { float center = (float)settings.GetPixelX(baw.xPosition); if (baw.whisker.visible) { float whiskerMax = (float)settings.GetPixelY(baw.whisker.max); float whiskerMin = (float)settings.GetPixelY(baw.whisker.min); float whiskerLeft = (float)settings.GetPixelX(baw.xPosition - baw.whisker.width / 2); float whiskerRight = (float)settings.GetPixelX(baw.xPosition + baw.whisker.width / 2); var whiskerPen = new Pen(baw.whisker.lineColor, baw.whisker.lineWidth); settings.gfxData.DrawLine(whiskerPen, center, whiskerMin, center, whiskerMax); settings.gfxData.DrawLine(whiskerPen, whiskerLeft, whiskerMax, whiskerRight, whiskerMax); settings.gfxData.DrawLine(whiskerPen, whiskerLeft, whiskerMin, whiskerRight, whiskerMin); } if (baw.box.outline || baw.box.fill) { float boxMax = (float)settings.GetPixelY(baw.box.max); float boxMin = (float)settings.GetPixelY(baw.box.min); float boxLeft = (float)settings.GetPixelX(baw.xPosition - baw.box.width / 2); float boxRight = (float)settings.GetPixelX(baw.xPosition + baw.box.width / 2); float boxHeight = boxMin - boxMax; float boxWidth = boxRight - boxLeft; PointF boxOrigin = new PointF(boxLeft, boxMax); SizeF boxSize = new SizeF(boxWidth, boxHeight); RectangleF boxRect = new RectangleF(boxOrigin, boxSize); if (baw.box.fill) { var boxBrush = new SolidBrush(baw.box.fillColor); settings.gfxData.FillRectangle(boxBrush, Rectangle.Round(boxRect)); } if (baw.box.outline) { var boxPen = new Pen(baw.box.lineColor, baw.box.lineWidth); settings.gfxData.DrawRectangle(boxPen, Rectangle.Round(boxRect)); } } if (baw.midline.visible) { float boxLeft = (float)settings.GetPixelX(baw.xPosition - baw.box.width / 2); float boxRight = (float)settings.GetPixelX(baw.xPosition + baw.box.width / 2); float midlineY = (float)settings.GetPixelY(baw.midline.position); var mindlinePen = new Pen(baw.midline.lineColor, baw.midline.lineWidth); settings.gfxData.DrawLine(mindlinePen, boxLeft, midlineY, boxRight, midlineY); } foreach (double curr in baw.points) { PointF point = new PointF(center, (float)settings.GetPixelY(curr)); MarkerTools.DrawMarker(settings.gfxData, point, MarkerShape.asterisk, 6, color); } } }