public static void Box(Settings settings, Population pop, Random rand, double popLeft, double popWidth, Color color, Position position, BoxFormat boxFormat, HorizontalAlignment errorAlignment = HorizontalAlignment.Right)
        {
            // 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;
            }

            double errorMaxPx, errorMinPx;
            double yPxTop, yPxBase;
            double yPx;

            if (boxFormat == BoxFormat.StdevStderrMean)
            {
                errorMaxPx = settings.GetPixelY(pop.mean + pop.stDev);
                errorMinPx = settings.GetPixelY(pop.mean - pop.stDev);
                yPxTop     = settings.GetPixelY(pop.mean + pop.stdErr);
                yPxBase    = settings.GetPixelY(pop.mean - pop.stdErr);
                yPx        = settings.GetPixelY(pop.mean);
            }
            else if (boxFormat == BoxFormat.OutlierQuartileMedian)
            {
                errorMaxPx = settings.GetPixelY(pop.maxNonOutlier);
                errorMinPx = settings.GetPixelY(pop.minNonOutlier);
                yPxTop     = settings.GetPixelY(pop.Q3);
                yPxBase    = settings.GetPixelY(pop.Q1);
                yPx        = settings.GetPixelY(pop.median);
            }
            else
            {
                throw new NotImplementedException();
            }

            // make cap width a fraction of available space
            double capWidthFrac = .38;
            double capWidth     = popWidth * capWidthFrac;

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

            popLeft  += popWidth * edgePaddingFrac;
            popWidth -= (popWidth * edgePaddingFrac) * 2;
            double leftPx  = settings.GetPixelX(popLeft);
            double rightPx = settings.GetPixelX(popLeft + popWidth);

            Pen   pen   = new Pen(Color.Black, 1);
            Brush brush = new SolidBrush(color);

            // draw the box
            RectangleF rect = new RectangleF((float)leftPx, (float)yPxTop, (float)(rightPx - leftPx), (float)(yPxBase - yPxTop));

            settings.gfxData.FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height);
            settings.gfxData.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);

            // draw the line in the center
            settings.gfxData.DrawLine(pen, rect.X, (float)yPx, rect.X + rect.Width, (float)yPx);

            // determine location of errorbars and caps
            double capPx1, capPx2, errorPxX;

            switch (errorAlignment)
            {
            case HorizontalAlignment.Center:
                double centerX = popLeft + popWidth / 2;
                errorPxX = settings.GetPixelX(centerX);
                capPx1   = settings.GetPixelX(centerX - capWidth / 2);
                capPx2   = settings.GetPixelX(centerX + capWidth / 2);
                break;

            case HorizontalAlignment.Right:
                errorPxX = settings.GetPixelX(popLeft + popWidth);
                capPx1   = settings.GetPixelX(popLeft + popWidth - capWidth / 2);
                capPx2   = settings.GetPixelX(popLeft + popWidth);
                break;

            case HorizontalAlignment.Left:
                errorPxX = settings.GetPixelX(popLeft);
                capPx1   = settings.GetPixelX(popLeft);
                capPx2   = settings.GetPixelX(popLeft + capWidth / 2);
                break;

            default:
                throw new NotImplementedException();
            }

            // draw errorbars and caps
            settings.gfxData.DrawLine(pen, (float)errorPxX, (float)errorMinPx, (float)errorPxX, rect.Y + rect.Height);
            settings.gfxData.DrawLine(pen, (float)errorPxX, (float)errorMaxPx, (float)errorPxX, rect.Y);
            settings.gfxData.DrawLine(pen, (float)capPx1, (float)errorMinPx, (float)capPx2, (float)errorMinPx);
            settings.gfxData.DrawLine(pen, (float)capPx1, (float)errorMaxPx, (float)capPx2, (float)errorMaxPx);
        }
예제 #2
0
        private static void Box(PlotDimensions dims, Bitmap bmp, bool lowQuality, Population pop, Random rand,
                                double popLeft, double popWidth, Color color, byte alpha, Position position, BoxFormat boxFormat,
                                HorizontalAlignment errorAlignment = HorizontalAlignment.Right)
        {
            // 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;
            }

            double errorMaxPx, errorMinPx;
            double yPxTop, yPxBase;
            double yPx;

            if (boxFormat == BoxFormat.StdevStderrMean)
            {
                errorMaxPx = dims.GetPixelY(pop.mean + pop.stDev);
                errorMinPx = dims.GetPixelY(pop.mean - pop.stDev);
                yPxTop     = dims.GetPixelY(pop.mean + pop.stdErr);
                yPxBase    = dims.GetPixelY(pop.mean - pop.stdErr);
                yPx        = dims.GetPixelY(pop.mean);
            }
            else if (boxFormat == BoxFormat.OutlierQuartileMedian)
            {
                errorMaxPx = dims.GetPixelY(pop.maxNonOutlier);
                errorMinPx = dims.GetPixelY(pop.minNonOutlier);
                yPxTop     = dims.GetPixelY(pop.Q3);
                yPxBase    = dims.GetPixelY(pop.Q1);
                yPx        = dims.GetPixelY(pop.median);
            }
            else
            {
                throw new NotImplementedException();
            }

            // make cap width a fraction of available space
            double capWidthFrac = .38;
            double capWidth     = popWidth * capWidthFrac;

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

            popLeft  += popWidth * edgePaddingFrac;
            popWidth -= (popWidth * edgePaddingFrac) * 2;
            double     leftPx  = dims.GetPixelX(popLeft);
            double     rightPx = dims.GetPixelX(popLeft + popWidth);
            RectangleF rect    = new RectangleF(
                x: (float)leftPx,
                y: (float)yPxTop,
                width: (float)(rightPx - leftPx),
                height: (float)(yPxBase - yPxTop));

            // determine location of errorbars and caps
            double capPx1, capPx2, errorPxX;

            switch (errorAlignment)
            {
            case HorizontalAlignment.Center:
                double centerX = popLeft + popWidth / 2;
                errorPxX = dims.GetPixelX(centerX);
                capPx1   = dims.GetPixelX(centerX - capWidth / 2);
                capPx2   = dims.GetPixelX(centerX + capWidth / 2);
                break;

            case HorizontalAlignment.Right:
                errorPxX = dims.GetPixelX(popLeft + popWidth);
                capPx1   = dims.GetPixelX(popLeft + popWidth - capWidth / 2);
                capPx2   = dims.GetPixelX(popLeft + popWidth);
                break;

            case HorizontalAlignment.Left:
                errorPxX = dims.GetPixelX(popLeft);
                capPx1   = dims.GetPixelX(popLeft);
                capPx2   = dims.GetPixelX(popLeft + capWidth / 2);
                break;

            default:
                throw new NotImplementedException();
            }

            using (Graphics gfx = GDI.Graphics(bmp, dims, lowQuality))
                using (Pen pen = GDI.Pen(Color.Black))
                    using (Brush brush = GDI.Brush(Color.FromArgb(alpha, color)))
                    {
                        // draw the box
                        gfx.FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height);
                        gfx.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);

                        // draw the line in the center
                        gfx.DrawLine(pen, rect.X, (float)yPx, rect.X + rect.Width, (float)yPx);

                        // draw errorbars and caps
                        gfx.DrawLine(pen, (float)errorPxX, (float)errorMinPx, (float)errorPxX, rect.Y + rect.Height);
                        gfx.DrawLine(pen, (float)errorPxX, (float)errorMaxPx, (float)errorPxX, rect.Y);
                        gfx.DrawLine(pen, (float)capPx1, (float)errorMinPx, (float)capPx2, (float)errorMinPx);
                        gfx.DrawLine(pen, (float)capPx1, (float)errorMaxPx, (float)capPx2, (float)errorMaxPx);
                    }
        }