Draw() public method

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.
return void
Ejemplo n.º 1
0
        /// <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));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws the marker on a plot surface.
        /// </summary>
        /// <param name="g">graphics 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 void Draw(IGraphics g, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            PointF point = new PointF(
                xAxis.WorldToPhysical(x_, true).X,
                yAxis.WorldToPhysical(y_, true).Y);

            marker_.Draw(g, (int)point.X, (int)point.Y);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Draws the 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 override void Draw(IGraphics g, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            SequenceAdapter data =
                new SequenceAdapter(DataSource, DataMember, OrdinateData, AbscissaData);

            TextDataAdapter textData =
                new TextDataAdapter(DataSource, DataMember, TextData);

            // first plot the marker
            // we can do this cast, since the constructor accepts only this type!
            for (int i = 0; i < data.Count; ++i)
            {
                try
                {
                    PointD pt = data[i];
                    if (!Double.IsNaN(pt.X) && !Double.IsNaN(pt.Y))
                    {
                        PointF xPos = xAxis.WorldToPhysical(pt.X, false);
                        PointF yPos = yAxis.WorldToPhysical(pt.Y, false);
                        Marker.Draw(g, (int)xPos.X, (int)yPos.Y);
                        if (textData[i] != "")
                        {
                            SizeF size = g.MeasureString(textData[i], Font);
                            switch (LabelTextPosition)
                            {
                            case LabelPositions.Above:
                                g.DrawString(textData[i], Font, Brushes.Black,
                                             new PointF(xPos.X - size.Width / 2, yPos.Y - size.Height - Marker.Size * 2 / 3));
                                break;

                            case LabelPositions.Below:
                                g.DrawString(textData[i], Font, Brushes.Black, new PointF(xPos.X - size.Width / 2, yPos.Y + Marker.Size * 2 / 3));
                                break;

                            case LabelPositions.Left:
                                g.DrawString(textData[i], Font, Brushes.Black,
                                             new PointF(xPos.X - size.Width - Marker.Size * 2 / 3, yPos.Y - size.Height / 2));
                                break;

                            case LabelPositions.Right:
                                g.DrawString(textData[i], Font, Brushes.Black, new PointF(xPos.X + Marker.Size * 2 / 3, yPos.Y - size.Height / 2));
                                break;
                            }
                        }
                    }
                }
                catch
                {
                    throw new NPlotException("Error in TextPlot.Draw");
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Draws a representation of this plot in the legend.
 /// </summary>
 /// <param name="g">The graphics surface on which to draw.</param>
 /// <param name="startEnd">A rectangle specifying the bounds of the area in the legend set aside for drawing.</param>
 public void DrawInLegend(Graphics g, Rectangle startEnd)
 {
     if (marker_.Size > 0)
     {
         marker_.Draw(g, (startEnd.Left + startEnd.Right) / 2, (startEnd.Top + startEnd.Bottom) / 2);
     }
     else if (marker_.Pen.Width > 0)
     {
         g.DrawLine(marker_.Pen,
                    (startEnd.Left + startEnd.Right) / 2, (startEnd.Top + startEnd.Bottom - marker_.Pen.Width) / 2,
                    (startEnd.Left + startEnd.Right) / 2, (startEnd.Top + startEnd.Bottom + marker_.Pen.Width) / 2);
     }
 }