Esempio n. 1
0
        /// <summary>
        /// Points of each data in screen coordinate
        /// </summary>
        /// <param name="pane"></param>
        /// <returns></returns>
        virtual public PointF[] ScreenPoints(PaneBase pane)
        {
            //PointF[] points = new PointF[4];

            //points[0] = _location.TransformTopLeft(pane);
            //points[2] = _location.TransformBottomRight(pane);
            //points[1].X = points[2].X;
            //points[1].Y = points[0].Y;
            //points[3].X = points[0].X;
            //points[3].Y = points[2].Y;

            PointF[] points = new PointF[4];

            points[0] = _location.TransformTopLeft(pane);
            points[1] = _location.TransformBottomRight(pane);

            return(points);
        }
Esempio n. 2
0
        /// <summary>
        /// Render this object to the specified <see cref="Graphics"/> device.
        /// </summary>
        /// <remarks>
        /// This method is normally only called by the Draw method
        /// of the parent <see cref="GraphObjList"/> collection object.
        /// </remarks>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="PaneBase"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        public override void Draw(Graphics g, PaneBase pane, float scaleFactor)
        {
            // Convert the arrow coordinates from the user coordinate system
            // to the screen coordinate system
            PointF pix1 = Location.TransformTopLeft(pane);
            PointF pix2 = Location.TransformBottomRight(pane);

            if (pix1.X > -10000 && pix1.X < 100000 && pix1.Y > -100000 && pix1.Y < 100000 &&
                pix2.X > -10000 && pix2.X < 100000 && pix2.Y > -100000 && pix2.Y < 100000)
            {
                // calculate the length and the angle of the arrow "vector"
                double dy     = pix2.Y - pix1.Y;
                double dx     = pix2.X - pix1.X;
                float  angle  = (float)Math.Atan2(dy, dx) * 180.0F / (float)Math.PI;
                var    length = (float)Math.Sqrt(dx * dx + dy * dy);

                // Save the old transform matrix
                Matrix transform = g.Transform;
                // Move the coordinate system so it is located at the starting point
                // of this arrow
                g.TranslateTransform(pix1.X, pix1.Y);
                // Rotate the coordinate system according to the angle of this arrow
                // about the starting point
                g.RotateTransform(angle);

                // get a pen according to this arrow properties
                using (var pen = new Pen(_color, pane.ScaledPenWidth(_penWidth, scaleFactor)))
                {
                    pen.DashStyle = _style;

                    g.DrawLine(pen, 0, 0, length, 0);
                }

                // Restore the transform matrix back to its original state
                g.Transform = transform;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Render this object to the specified <see cref="Graphics"/> device.
        /// </summary>
        /// <remarks>
        /// This method is normally only called by the Draw method
        /// of the parent <see cref="GraphObjList"/> collection object.
        /// </remarks>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="PaneBase"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        public override void Draw(Graphics g, PaneBase pane, float scaleFactor)
        {
            // Convert the arrow coordinates from the user coordinate system
            // to the screen coordinate system
            PointF pix1 = Location.TransformTopLeft(pane);
            PointF pix2 = Location.TransformBottomRight(pane);

            if (pix1.X > -10000 && pix1.X < 100000 && pix1.Y > -100000 && pix1.Y < 100000 &&
                pix2.X > -10000 && pix2.X < 100000 && pix2.Y > -100000 && pix2.Y < 100000)
            {
                // get a scaled size for the arrowhead
                float scaledSize = (_size * scaleFactor);

                // calculate the length and the angle of the arrow "vector"
                double dy     = pix2.Y - pix1.Y;
                double dx     = pix2.X - pix1.X;
                float  angle  = (float)Math.Atan2(dy, dx) * 180.0F / (float)Math.PI;
                var    length = (float)Math.Sqrt(dx * dx + dy * dy);

                // Save the old transform matrix
                Matrix transform = g.Transform;
                // Move the coordinate system so it is located at the starting point
                // of this arrow
                g.TranslateTransform(pix1.X, pix1.Y);
                // Rotate the coordinate system according to the angle of this arrow
                // about the starting point
                g.RotateTransform(angle);

                // get a pen according to this arrow properties
                using (var pen = new Pen(_color, pane.ScaledPenWidth(_penWidth, scaleFactor)))
                {
                    pen.DashStyle = _style;

                    // Only show the arrowhead if required
                    if (_isArrowHead)
                    {
                        // Draw the line segment for this arrow
                        g.DrawLine(pen, 0, 0, length - scaledSize + 1, 0);

                        // Create a polygon representing the arrowhead based on the scaled
                        // size
                        var   polyPt = new PointF[4];
                        float hsize  = scaledSize / 3.0F;
                        polyPt[0].X = length;
                        polyPt[0].Y = 0;
                        polyPt[1].X = length - scaledSize;
                        polyPt[1].Y = hsize;
                        polyPt[2].X = length - scaledSize;
                        polyPt[2].Y = -hsize;
                        polyPt[3]   = polyPt[0];

                        using (var brush = new SolidBrush(_color))
                            // render the arrowhead
                            g.FillPolygon(brush, polyPt);
                    }
                    else
                    {
                        g.DrawLine(pen, 0, 0, length, 0);
                    }
                }

                // Restore the transform matrix back to its original state
                g.Transform = transform;
            }
        }