NPlot.Marker.Draw C# (CSharp) 메소드

Draw() 공개 메소드

Draws the marker at the given position
public Draw ( Graphics g, int x, int y ) : void
g System.Drawing.Graphics The graphics surface on which to draw.
x int The [physical] x position to draw the marker.
y int The [physical] y position to draw the marker.
리턴 void
        public void Draw( Graphics g, int x, int y )
        {
            switch (markerType_)
            {

                case MarkerType.Cross1:
                    g.DrawLine( pen_, x-h_, y+h_, x+h_, y-h_ );
                    g.DrawLine( pen_, x+h_, y+h_, x-h_, y-h_ );
                    break;

                case MarkerType.Cross2:
                    g.DrawLine( pen_, x, y-h_, x, y+h_ );
                    g.DrawLine( pen_, x-h_, y, x+h_, y );
                    break;

                case MarkerType.Circle:
                    g.DrawEllipse( pen_, x-h_, y-h_, size_, size_ );
                    if ( this.filled_ )
                    {
                        g.FillEllipse( brush_, x-h_, y-h_, size_, size_ );
                    }
                    break;

                case MarkerType.Square:
                    g.DrawRectangle( pen_, x-h_, y-h_, size_, size_ );
                    if ( this.filled_ )
                    {
                        g.FillRectangle( brush_, x-h_, y-h_, size_, size_ );
                    }
                    break;

                case MarkerType.Triangle:
                case MarkerType.TriangleDown:
                {
                    Point p1 = new Point( x-h_, y-h_ );
                    Point p2 = new Point( x, y+h_ );
                    Point p3 = new Point( x+h_, y-h_ );
                    Point [] pts = new Point [3] { p1, p2, p3 };
                    GraphicsPath gp = new GraphicsPath();
                    gp.AddPolygon( pts );
                    g.DrawPath( pen_, gp );
                    if (this.filled_)
                    {
                        g.FillPath( brush_, gp );
                    }
                    break;
                }
                case MarkerType.TriangleUp:
                {
                    Point p1 = new Point( x-h_, y+h_ );
                    Point p2 = new Point( x, y-h_ );
                    Point p3 = new Point( x+h_, y+h_ );
                    Point [] pts = new Point [3] { p1, p2, p3 };
                    GraphicsPath gp = new GraphicsPath();
                    gp.AddPolygon( pts );
                    g.DrawPath( pen_, gp );
                    if (this.filled_)
                    {
                        g.FillPath( brush_, gp );
                    }
                    break;
                }
                case MarkerType.FilledCircle:
                    g.DrawEllipse( pen_, x-h_, y-h_, size_, size_ );
                    g.FillEllipse( brush_, x-h_, y-h_, size_, size_ );
                    break;

                case MarkerType.FilledSquare:
                    g.DrawRectangle( pen_, x-h_, y-h_, size_, size_ );
                    g.FillRectangle( brush_, x-h_, y-h_, size_, size_ );
                    break;

                case MarkerType.FilledTriangle:
                {
                    Point p1 = new Point( x-h_, y-h_ );
                    Point p2 = new Point( x, y+h_ );
                    Point p3 = new Point( x+h_, y-h_ );
                    Point [] pts = new Point [3] { p1, p2, p3 };
                    GraphicsPath gp = new GraphicsPath();
                    gp.AddPolygon( pts );
                    g.DrawPath( pen_, gp );
                    g.FillPath( brush_, gp );
                    break;
                }
                case MarkerType.Diamond:
                {
                    Point p1 = new Point( x-h_, y );
                    Point p2 = new Point( x, y-h_ );
                    Point p3 = new Point( x+h_, y );
                    Point p4 = new Point( x, y+h_ );
                    Point [] pts = new Point [4] { p1, p2, p3, p4 };
                    GraphicsPath gp = new GraphicsPath();
                    gp.AddPolygon( pts );
                    g.DrawPath( pen_, gp );
                    if (this.filled_)
                    {
                        g.FillPath( brush_, gp );
                    }
                    break;
                }
                case MarkerType.Flag:
                case MarkerType.FlagUp:
                {
                    Point p1 = new Point( x, y );
                    Point p2 = new Point( x, y-size_ );
                    Point p3 = new Point( x+size_, y-size_+size_/3 );
                    Point p4 = new Point( x, y-size_+2*size_/3 );
                    g.DrawLine( pen_, p1, p2 );
                    Point [] pts = new Point [3] { p2, p3, p4 };
                    GraphicsPath gp = new GraphicsPath();
                    gp.AddPolygon( pts );
                    g.DrawPath( pen_, gp );
                    if (this.filled_)
                    {
                        g.FillPath( brush_, gp );
                    }
                    break;
                }
                case MarkerType.FlagDown:
                {
                    Point p1 = new Point( x, y );
                    Point p2 = new Point( x, y+size_ );
                    Point p3 = new Point( x+size_, y+size_-size_/3 );
                    Point p4 = new Point( x, y+size_-2*size_/3 );
                    g.DrawLine( pen_, p1, p2 );
                    Point [] pts = new Point [3] { p2, p3, p4 };
                    GraphicsPath gp = new GraphicsPath();
                    gp.AddPolygon( pts );
                    g.DrawPath( pen_, gp );
                    if (this.filled_)
                    {
                        g.FillPath( brush_, gp );
                    }
                    break;
                }
                case MarkerType.None:
                    break;
            }
        }

Usage Example

예제 #1
0
파일: PointPlot.cs 프로젝트: Terohnon/NPlot
        /// <summary>
        /// Draws the point plot on a GDI+ surface against the provided x and y axes.
        /// </summary>
        /// <param name="g">The GDI+ surface on which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public virtual void Draw(Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            SequenceAdapter data_ =
                new SequenceAdapter(this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData);

            float leftCutoff_  = xAxis.PhysicalMin.X - marker_.Size;
            float rightCutoff_ = xAxis.PhysicalMax.X + marker_.Size;

            for (int i = 0; i < data_.Count; ++i)
            {
                var p1 = data_[i];

                if (!Double.IsNaN(p1.X) && !Double.IsNaN(p1.Y))
                {
                    PointF xPos = xAxis.WorldToPhysical(p1.X, false);
                    if (float.IsNaN(xPos.X) || xPos.X < leftCutoff_ || rightCutoff_ < xPos.X)
                    {
                        continue;
                    }

                    PointF yPos = yAxis.WorldToPhysical(p1.Y, false);
                    if (float.IsNaN(yPos.Y))
                    {
                        continue;
                    }
                    marker_.Draw(g, (int)xPos.X, (int)yPos.Y);
                    if (marker_.DropLine)
                    {
                        PointD yMin   = new PointD(p1.X, Math.Max(0.0f, yAxis.Axis.WorldMin));
                        PointF yStart = yAxis.WorldToPhysical(yMin.Y, false);
                        g.DrawLine(marker_.Pen, new Point((int)xPos.X, (int)yStart.Y), new Point((int)xPos.X, (int)yPos.Y));
                    }
                }
            }
        }
All Usage Examples Of NPlot.Marker::Draw