// 20160119 public void Generate(string name, List <DataPoint> dataPointList) { this.name = name; this.dataPointList = dataPointList; plotAttributesList = new List <PlotAttributes>(); foreach (DataPoint dataPoint in dataPointList) { PlotAttributes plotAttributes = new PlotAttributes(); plotAttributesList.Add(plotAttributes); } }
private void PlotSeries(DataSeries dataSeries, Graphics g) { for (int ii = 0; ii < dataSeries.DataPointList.Count; ii++) { DataPoint currentPoint = dataSeries.DataPointList[ii]; DataPoint nextPoint = null; if ((ii + 1) < dataSeries.DataPointList.Count) { nextPoint = dataSeries.DataPointList[ii + 1]; } PlotAttributes plotAttributes = dataSeries.PlotAttributesList[ii]; PlotPoint(currentPoint, nextPoint, plotAttributes, g); } }
// Generates a data series without error bars, and with default plot attributes public void Generate(string name, List <double> horizontalData, List <double> verticalData) { this.name = name; dataPointList = new List <DataPoint>(); plotAttributesList = new List <PlotAttributes>(); if (horizontalData.Count != verticalData.Count) { return; } for (int ii = 0; ii < horizontalData.Count; ii++) { DataPoint dataPoint = new DataPoint(); dataPoint.X = horizontalData[ii]; dataPoint.Y = verticalData[ii]; dataPointList.Add(dataPoint); PlotAttributes plotAttributes = new PlotAttributes(); plotAttributesList.Add(plotAttributes); } }
private void PlotPoint(DataPoint currentPoint, DataPoint nextPoint, PlotAttributes plotAttributes, Graphics g) { using (SolidBrush pointBrush = new SolidBrush(Color.White)) { // To Do: More here - add connection to the next point, different symbols etc. float plotX = GetPlotXAtX(currentPoint.X); float plotY = GetPlotYAtY(currentPoint.Y); pointBrush.Color = plotAttributes.PointColor; if (plotAttributes.Connect) { using (Pen linePen = new Pen(plotAttributes.LineColor)) { linePen.Width = (float)(plotAttributes.RelativeLineWidth * Math.Max(plotWidth, plotHeight)); if (nextPoint != null) { float nextPlotX = GetPlotXAtX(nextPoint.X); float nextPlotY = GetPlotYAtY(nextPoint.Y); DrawLine(g, linePen, plotX, plotY, nextPlotX, nextPlotY); } } } if (plotAttributes.PointVisible) { if (plotAttributes.PlotSymbol == PlotSymbol.Disc) { float pointSize = (float)(2 * plotAttributes.RelativePointSize * Math.Max(plotWidth, plotHeight)); if (((currentPoint.X - xMin) > -double.Epsilon) && ((xMax - currentPoint.X) > -double.Epsilon) && ((currentPoint.Y - yMin) > -double.Epsilon) && ((yMax - currentPoint.Y) > -double.Epsilon)) { DrawEllipse(g, pointBrush, plotX, plotY, pointSize); } } } if (plotAttributes.HorizontalErrorBarVisible) { float horizontalErrorPlotXMin = GetPlotXAtX(currentPoint.X - currentPoint.ErrorLeft); float horizontalErrorPlotXMax = GetPlotXAtX(currentPoint.X + currentPoint.ErrorRight); float horizontalErrorPlotY = GetPlotYAtY(currentPoint.Y); using (Pen errorPen = new Pen(plotAttributes.ErrorBarColor)) { DrawLine(g, errorPen, horizontalErrorPlotXMin, horizontalErrorPlotY, horizontalErrorPlotXMax, horizontalErrorPlotY); if (plotAttributes.UseHorizontalErrorBarSerifs) { float serifLength = (float)(plotAttributes.RelativeErrorBarSerifLength * Math.Max(plotWidth, plotHeight)); float serifYMin = GetPlotYAtY(currentPoint.Y) - serifLength; float serifYMax = GetPlotYAtY(currentPoint.Y) + serifLength; DrawLine(g, errorPen, horizontalErrorPlotXMin, serifYMin, horizontalErrorPlotXMin, serifYMax); DrawLine(g, errorPen, horizontalErrorPlotXMax, serifYMin, horizontalErrorPlotXMax, serifYMax); } } } if (plotAttributes.VerticalErrorBarVisible) { float verticalErrorPlotYMin = GetPlotYAtY(currentPoint.Y - currentPoint.ErrorBottom); float verticalErrorPlotYMax = GetPlotYAtY(currentPoint.Y + currentPoint.ErrorTop); float verticalErrorPlotX = GetPlotXAtX(currentPoint.X); using (Pen errorPen = new Pen(plotAttributes.ErrorBarColor)) { DrawLine(g, errorPen, verticalErrorPlotX, verticalErrorPlotYMin, verticalErrorPlotX, verticalErrorPlotYMax); if (plotAttributes.UseVerticalErrorBarSerifs) { float serifLength = (float)(plotAttributes.RelativeErrorBarSerifLength * Math.Max(plotWidth, plotHeight)); float serifXMin = GetPlotXAtX(currentPoint.X) - serifLength; float serifXMax = GetPlotXAtX(currentPoint.X) + serifLength; DrawLine(g, errorPen, serifXMin, verticalErrorPlotYMin, serifXMax, verticalErrorPlotYMin); DrawLine(g, errorPen, serifXMin, verticalErrorPlotYMax, serifXMax, verticalErrorPlotYMax); } } } } }