Exemplo n.º 1
0
        public static void DataGrid(Settings settings)
        {
            Pen pen = new Pen(settings.grid.color, (float)settings.grid.lineWidth)
            {
                DashPattern = StyleTools.DashPattern(settings.grid.lineStyle)
            };

            // Fix rendering artifacts (diagnal lines) that appear when drawing lines that touch the edge of the Bitmap if anti-aliasing is off.
            // An alternative to tilting the line is to not let the grid line touch the edge of the bitmap (withdraw it by 1px).
            float tiltPx = (settings.misc.antiAliasData) ? 0 : .5f;

            if (settings.grid.enableVertical)
            {
                for (int i = 0; i < settings.ticks.x.tickPositionsMajor.Length; i++)
                {
                    double value             = settings.ticks.x.tickPositionsMajor[i];
                    double unitsFromAxisEdge = value - settings.axes.x.min;
                    int    xPx = (int)(unitsFromAxisEdge * settings.xAxisScale);
                    settings.gfxData.DrawLine(pen, xPx, 0, xPx + tiltPx, settings.dataSize.Height);
                }
            }

            if (settings.grid.enableHorizontal)
            {
                for (int i = 0; i < settings.ticks.y.tickPositionsMajor.Length; i++)
                {
                    double value             = settings.ticks.y.tickPositionsMajor[i];
                    double unitsFromAxisEdge = value - settings.axes.y.min;
                    int    yPx = settings.dataSize.Height - (int)(unitsFromAxisEdge * settings.yAxisScale);
                    settings.gfxData.DrawLine(pen, 0, yPx, settings.dataSize.Width, yPx + tiltPx);
                }
            }
        }
Exemplo n.º 2
0
        public PlottableAxLine(double position, bool vertical, Color color, double lineWidth, string label,
                               bool draggable, double dragLimitLower, double dragLimitUpper, LineStyle lineStyle)
        {
            this.position  = position;
            this.vertical  = vertical;
            this.color     = color;
            this.label     = label;
            this.lineStyle = lineStyle;
            pointCount     = 1;

            pen = new Pen(color, (float)lineWidth)
            {
                StartCap    = System.Drawing.Drawing2D.LineCap.Round,
                EndCap      = System.Drawing.Drawing2D.LineCap.Round,
                LineJoin    = System.Drawing.Drawing2D.LineJoin.Round,
                DashStyle   = StyleTools.DashStyle(lineStyle),
                DashPattern = StyleTools.DashPattern(lineStyle)
            };

            DragEnable(draggable);

            if (vertical)
            {
                DragLimit(x1: dragLimitLower, x2: dragLimitUpper, y1: double.NegativeInfinity, y2: double.PositiveInfinity);
            }
            else
            {
                DragLimit(x1: double.NegativeInfinity, x2: double.PositiveInfinity, y1: dragLimitLower, y2: dragLimitUpper);
            }
        }
Exemplo n.º 3
0
        public PlottableErrorBars(double[] xs, double[] ys, double[] xPositiveError, double[] xNegativeError,
                                  double[] yPositiveError, double[] yNegativeError, Color color, double lineWidth, double capSize, string label)
        {
            //check input
            if (xs.Length != ys.Length)
            {
                throw new ArgumentException("X and Y arrays must have the same length");
            }

            //save properties
            this.xs             = xs;
            this.ys             = ys;
            this.xPositiveError = SanitizeErrors(xPositiveError, xs.Length);
            this.xNegativeError = SanitizeErrors(xNegativeError, xs.Length);
            this.yPositiveError = SanitizeErrors(yPositiveError, xs.Length);
            this.yNegativeError = SanitizeErrors(yNegativeError, xs.Length);
            this.capSize        = (float)capSize;
            this.color          = color;
            this.label          = label;

            penLine = new Pen(this.color, (float)lineWidth)
            {
                StartCap    = System.Drawing.Drawing2D.LineCap.Round,
                EndCap      = System.Drawing.Drawing2D.LineCap.Round,
                LineJoin    = System.Drawing.Drawing2D.LineJoin.Round,
                DashPattern = StyleTools.DashPattern(lineStyle)
            };
        }
Exemplo n.º 4
0
        private static void DrawLegendItemLine(Config.LegendItem legendItem, Settings settings, PointF itemLocation, int padding, int stubWidth, float ySpaceBetweenItems)
        {
            if (legendItem.lineWidth == 0 || legendItem.lineStyle == LineStyle.None)
            {
                return;
            }

            float  yCenter = itemLocation.Y + ySpaceBetweenItems / 2;
            PointF xMin    = new PointF(itemLocation.X + padding, yCenter);
            PointF xMax    = new PointF(itemLocation.X + padding + stubWidth, yCenter);

            if (legendItem.lineWidth < 10)
            {
                Pen pen = new Pen(legendItem.color, (float)legendItem.lineWidth)
                {
                    DashPattern = StyleTools.DashPattern(legendItem.lineStyle)
                };
                settings.gfxLegend.DrawLine(pen, xMin, xMax);
            }
            else
            {
                Brush  brush       = new SolidBrush(legendItem.color);
                float  halfHeight  = (float)(legendItem.lineWidth / 2);
                PointF topLeft     = new PointF(xMin.X, xMin.Y - halfHeight);
                float  symbolWidth = xMax.X - xMin.X;
                settings.gfxLegend.FillRectangle(brush, topLeft.X, topLeft.Y, symbolWidth, (float)legendItem.lineWidth);
            }
        }
Exemplo n.º 5
0
 public Plot(int width = 800, int height = 600)
 {
     if (width <= 0 || height <= 0)
     {
         throw new ArgumentException("width and height must each be greater than 0");
     }
     StyleTools.SetStyle(this, ScottPlot.Style.Default);
     Resize(width, height);
 }
Exemplo n.º 6
0
        private static void DrawLegendItemLine(Config.LegendItem legendItem, Settings settings, Point itemLocation, int padding, int stubWidth, float legendFontLineHeight)
        {
            if (legendItem.lineWidth == 0 || legendItem.lineStyle == LineStyle.None)
            {
                return;
            }

            Pen pen = new Pen(legendItem.color, (float)legendItem.lineWidth)
            {
                DashPattern = StyleTools.DashPattern(legendItem.lineStyle)
            };

            settings.gfxLegend.DrawLine(pen,
                                        itemLocation.X + padding, itemLocation.Y + legendFontLineHeight / 2,
                                        itemLocation.X + padding + stubWidth, itemLocation.Y + legendFontLineHeight / 2);
        }
Exemplo n.º 7
0
        public PlottableVLine(double position, Color color, double lineWidth, string label,
                              bool draggable, double dragLimitLower, double dragLimitUpper, LineStyle lineStyle)
        {
            this.position  = position;
            this.color     = color;
            this.label     = label;
            this.lineStyle = lineStyle;

            pen = new Pen(color, (float)lineWidth)
            {
                StartCap    = System.Drawing.Drawing2D.LineCap.Round,
                EndCap      = System.Drawing.Drawing2D.LineCap.Round,
                LineJoin    = System.Drawing.Drawing2D.LineJoin.Round,
                DashPattern = StyleTools.DashPattern(lineStyle)
            };

            DragEnabled = draggable;

            SetLimits(x1: dragLimitLower, x2: dragLimitUpper, y1: double.NegativeInfinity, y2: double.PositiveInfinity);
        }
Exemplo n.º 8
0
        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 = new Pen(color)
            {
                DashPattern = StyleTools.DashPattern(lineStyle)
            };

            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);
            }
            settings.gfxData.DrawLines(pen, points);
        }
Exemplo n.º 9
0
 public void Style(Style style)
 {
     StyleTools.SetStyle(this, style);
 }
Exemplo n.º 10
0
        public PlottableScatter(double[] xs, double[] ys, Color color, double lineWidth, double markerSize, string label,
                                double[] errorX, double[] errorY, double errorLineWidth, double errorCapSize, bool stepDisplay, MarkerShape markerShape, LineStyle lineStyle)
        {
            if ((xs == null) || (ys == null))
            {
                throw new Exception("X and Y data cannot be null");
            }

            if (xs.Length != ys.Length)
            {
                throw new Exception("Xs and Ys must have same length");
            }

            if (errorY != null)
            {
                for (int i = 0; i < errorY.Length; i++)
                {
                    if (errorY[i] < 0)
                    {
                        errorY[i] = -errorY[i];
                    }
                }
            }

            if (errorX != null)
            {
                for (int i = 0; i < errorX.Length; i++)
                {
                    if (errorX[i] < 0)
                    {
                        errorX[i] = -errorX[i];
                    }
                }
            }

            this.xs             = xs;
            this.ys             = ys;
            this.color          = color;
            this.lineWidth      = lineWidth;
            this.markerSize     = (float)markerSize;
            this.label          = label;
            this.errorX         = errorX;
            this.errorY         = errorY;
            this.errorLineWidth = (float)errorLineWidth;
            this.errorCapSize   = (float)errorCapSize;
            this.stepDisplay    = stepDisplay;
            this.markerShape    = markerShape;
            this.lineStyle      = lineStyle;

            pointCount = xs.Length;

            if (xs.Length != ys.Length)
            {
                throw new ArgumentException("X and Y arrays must have the same length");
            }

            if ((errorX != null) && (xs.Length != errorX.Length))
            {
                throw new ArgumentException("errorX must be the same length as the original data");
            }

            if ((errorY != null) && (xs.Length != errorY.Length))
            {
                throw new ArgumentException("errorY must be the same length as the original data");
            }

            penLine = new Pen(color, (float)lineWidth)
            {
                StartCap    = System.Drawing.Drawing2D.LineCap.Round,
                EndCap      = System.Drawing.Drawing2D.LineCap.Round,
                LineJoin    = System.Drawing.Drawing2D.LineJoin.Round,
                DashStyle   = StyleTools.DashStyle(lineStyle),
                DashPattern = StyleTools.DashPattern(lineStyle)
            };

            penLineError = new Pen(color, (float)errorLineWidth)
            {
                StartCap = System.Drawing.Drawing2D.LineCap.Round,
                EndCap   = System.Drawing.Drawing2D.LineCap.Round,
                LineJoin = System.Drawing.Drawing2D.LineJoin.Round
            };

            brush = new SolidBrush(color);
        }