Пример #1
0
        // primary function (accepts a style)
        public void AddScatter(double[] xs, double[] ys, Style style)
        {
            xs = xs ?? AscendingNumbers(ys.Length);
            var scatter = new Plottables.Scatter(xs, ys, style);

            plotObjects.Add(scatter);
        }
Пример #2
0
        private void RenderDataScatter(Plottables.Scatter scatter)
        {
            // convert XY pairs to an array of points scaled to pixel units
            Point[] points = new Point[scatter.xs.Length];
            for (int i = 0; i < scatter.xs.Length; i++)
            {
                int pixelX = settings.axisX.UnitToPixel(scatter.xs[i]);
                int pixelY = settings.axisY.UnitToPixel(scatter.ys[i]);
                pixelY    = settings.dataPlotHeight - pixelY;
                points[i] = new Point(pixelX, pixelY);
            }

            // draw lines
            if (points.Length > 1 && scatter.style.lineWidth > 0)
            {
                Pen linePen = new Pen(scatter.style.lineColor, scatter.style.lineWidth);
                linePen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
                linePen.EndCap   = System.Drawing.Drawing2D.LineCap.Round;
                linePen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                try
                {
                    gfxData.DrawLines(linePen, points);
                }
                catch
                {
                    Console.WriteLine("Crashed drawing lines");
                }
            }

            // draw markers
            int   markerSize  = scatter.style.markerSize;
            var   markerPen   = new Pen(scatter.style.markerColor);
            Brush markerBrush = new SolidBrush(scatter.style.markerColor);

            if (markerSize > 0)
            {
                try
                {
                    foreach (Point point in points)
                    {
                        Rectangle rect = new Rectangle(point.X - markerSize, point.Y - markerSize, markerSize * 2, markerSize * 2);
                        if (scatter.style.markerShape == Style.MarkerShape.circleFilled)
                        {
                            gfxData.FillEllipse(markerBrush, rect);
                        }
                        else if (scatter.style.markerShape == Style.MarkerShape.circleOpen)
                        {
                            gfxData.DrawEllipse(markerPen, rect);
                        }
                        else
                        {
                            Console.WriteLine("UNKNOWN SHAPE: {scatter.style.markerShape}");
                        }
                    }
                }
                catch
                {
                    Console.WriteLine($"Crashed drawing markers");
                }
            }
        }