Ejemplo n.º 1
0
        public void Render(PlotDimensions dims, Bitmap bmp, bool lowQuality = false)
        {
            List <double> xList = new List <double>();
            List <double> yList = new List <double>();

            PointCount = (int)dims.DataWidth;
            for (int columnIndex = 0; columnIndex < dims.DataWidth; columnIndex++)
            {
                double x = columnIndex * dims.UnitsPerPxX + dims.XMin;
                try
                {
                    double?y = function(x);

                    if (y is null)
                    {
                        throw new NoNullAllowedException();
                    }

                    if (double.IsNaN(y.Value) || double.IsInfinity(y.Value))
                    {
                        throw new ArithmeticException("not a real number");
                    }

                    xList.Add(x);
                    yList.Add(y.Value);
                }
                catch (Exception e) //Domain error, such log(-1) or 1/0
                {
                    Debug.WriteLine($"Y({x}) failed because {e}");
                    continue;
                }
            }

            // create a temporary scatter plot and use it for rendering
            double[] xs      = xList.ToArray();
            double[] ys      = yList.ToArray();
            var      scatter = new PlottableScatter(xs, ys)
            {
                color       = color,
                lineWidth   = lineWidth,
                markerSize  = 0,
                label       = label,
                markerShape = MarkerShape.none,
                lineStyle   = lineStyle
            };

            scatter.Render(dims, bmp, lowQuality);
        }
Ejemplo n.º 2
0
        public override void Render(Settings settings)
        {
            double step            = settings.xAxisUnitsPerPixel;
            double minRenderedX    = settings.axes.limits[0];
            double maxRenderedX    = settings.axes.limits[1];
            int    maxSeriesLength = (int)Math.Ceiling((maxRenderedX - minRenderedX) / step);

            lastNumberOfPointsDisplayed = maxSeriesLength;

            List <double> xList = new List <double>();
            List <double> yList = new List <double>();

            for (int i = 0; i < maxSeriesLength; i++)
            {
                double x = i * step + minRenderedX;
                double?y;
                try
                {
                    y = function(x);
                }
                catch (Exception e) //Domain error, such log(-1) or 1/0
                {
                    Debug.WriteLine(e);
                    continue;
                }

                if (y.HasValue)
                {
                    if (double.IsNaN(y.Value) || double.IsInfinity(y.Value))
                    {// double.IsInfinity checks for positive or negative infinity
                        continue;
                    }
                    xList.Add(x);
                    yList.Add(y.Value);
                }
            }

            PlottableScatter scatter = new PlottableScatter(xList.ToArray(), yList.ToArray(), color, lineWidth, markerSize, label, null, null, 0, 0, false, markerShape, lineStyle);

            scatter.Render(settings);
        }
Ejemplo n.º 3
0
        public override void Render(Settings settings)
        {
            double step            = 1 / (settings.xAxisUnitsPerPixel * 250); // 250 may not be ideal, bigger number is more smooth, but less performant
            int    maxSeriesLength = (int)Math.Ceiling((maxX - minX) / step);

            List <double> xList = new List <double>();
            List <double> yList = new List <double>();

            for (int i = 0; i < maxSeriesLength; i++)
            {
                double x = i * step + minX;
                double?y;
                try
                {
                    y = function(x);
                }
                catch (Exception e) //Domain error, such log(-1) or 1/0
                {
                    Debug.WriteLine(e);
                    continue;
                }

                if (y.HasValue)
                {
                    xList.Add(x);
                    yList.Add(y.Value);
                }


                //Console.WriteLine($"({xs[i]},{ys[i]})");
            }


            PlottableScatter scatter = new PlottableScatter(xList.ToArray(), yList.ToArray(), color, lineWidth, markerSize, label, null, null, 0, 0, false, markerShape, lineStyle);

            scatter.Render(settings);
        }