Beispiel #1
0
        public static void Distribution(PlotDimensions dims, Bitmap bmp, bool lowQuality, Population pop, Random rand,
                                        double popLeft, double popWidth, Color color, Position position, LineStyle lineStyle)
        {
            // adjust edges to accomodate special positions
            if (position == Position.Hide)
            {
                return;
            }
            if (position == Position.Left || position == Position.Right)
            {
                popWidth /= 2;
            }
            if (position == Position.Right)
            {
                popLeft += popWidth;
            }

            // contract edges slightly to encourage padding between elements
            double edgePaddingFrac = 0.2;

            popLeft  += popWidth * edgePaddingFrac;
            popWidth -= (popWidth * edgePaddingFrac) * 2;

            double[] ys = DataGen.Range(pop.minus3stDev, pop.plus3stDev, dims.UnitsPerPxY);
            if (ys.Length == 0)
            {
                return;
            }
            double[] ysFrac = pop.GetDistribution(ys);

            PointF[] points = new PointF[ys.Length];
            for (int i = 0; i < ys.Length; i++)
            {
                float x = (float)dims.GetPixelX(popLeft + popWidth * ysFrac[i]);
                float y = (float)dims.GetPixelY(ys[i]);
                points[i] = new PointF(x, y);
            }

            using (Graphics gfx = GDI.Graphics(bmp, lowQuality))
                using (Pen pen = GDI.Pen(color, 1, lineStyle, true))
                {
                    gfx.DrawLines(pen, points);
                }
        }
        public override AxisLimits2D GetLimits()
        {
            double max = double.NegativeInfinity;
            double min = double.PositiveInfinity;

            foreach (double x in DataGen.Range(-10, 10, .1))
            {
                double?y = function(x);
                if (y != null)
                {
                    max = Math.Max(max, y.Value);
                    min = Math.Min(min, y.Value);
                }
            }

            double[] limits = { -10, 10, min, max };

            return(new Config.AxisLimits2D(limits));
        }
        public static void Distribution(Settings settings, Population pop, Random rand, double popLeft, double popWidth, Color color, Position position, LineStyle lineStyle)
        {
            // adjust edges to accomodate special positions
            if (position == Position.Hide)
            {
                return;
            }
            if (position == Position.Left || position == Position.Right)
            {
                popWidth /= 2;
            }
            if (position == Position.Right)
            {
                popLeft += popWidth;
            }

            // contract edges slightly to encourage padding between elements
            double edgePaddingFrac = 0.2;

            popLeft  += popWidth * edgePaddingFrac;
            popWidth -= (popWidth * edgePaddingFrac) * 2;

            Pen pen = GDI.Pen(color, 1, lineStyle, true);

            double[] ys     = DataGen.Range(pop.minus3stDev, pop.plus3stDev, settings.yAxisUnitsPerPixel);
            double[] ysFrac = pop.GetDistribution(ys);

            PointF[] points = new PointF[ys.Length];
            for (int i = 0; i < ys.Length; i++)
            {
                float x = (float)settings.GetPixelX(popLeft + popWidth * ysFrac[i]);
                float y = (float)settings.GetPixelY(ys[i]);
                points[i] = new PointF(x, y);
            }

            if (points.Length > 1)
            {
                settings.gfxData.DrawLines(pen, points);
            }
        }