/// <summary> /// Create a <see cref="Pen" /> object based on the properties of this /// <see cref="LineBase" />. /// </summary> /// <param name="pane">The owner <see cref="GraphPane" /> of this /// <see cref="LineBase" />. /// </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> /// <param name="dataValue">The data value to be used for a value-based /// color gradient. This is only applicable if <see cref="Fill.Type">GradientFill.Type</see> /// is one of <see cref="FillType.GradientByX"/>, /// <see cref="FillType.GradientByY"/>, <see cref="FillType.GradientByZ"/>, /// or <see cref="FillType.GradientByColorValue" />. /// </param> /// <returns>A <see cref="Pen" /> object with the properties of this <see cref="LineBase" /> /// </returns> public Pen GetPen(PaneBase pane, float scaleFactor, IPointPair dataValue) { var color = Color; if (GradientFill.IsGradientValueType) { color = GradientFill.GetGradientColor(dataValue); } var pen = new Pen(color, pane.ScaledPenWidth(Width, scaleFactor)) { DashStyle = Style }; if (Style != DashStyle.Custom) { return(pen); } if (DashOff <= 1e-10 || DashOn <= 1e-10) { pen.DashStyle = DashStyle.Solid; } else { pen.DashStyle = DashStyle.Custom; pen.DashPattern = new[] { DashOn, DashOff }; } return(pen); }
/// <summary> /// Create a <see cref="Pen" /> object based on the properties of this /// <see cref="LineBase" />. /// </summary> /// <param name="pane">The owner <see cref="GraphPane" /> of this /// <see cref="LineBase" />. /// </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> /// <param name="dataValue">The data value to be used for a value-based /// color gradient. This is only applicable if <see cref="Fill.Type">GradientFill.Type</see> /// is one of <see cref="FillType.GradientByX"/>, /// <see cref="FillType.GradientByY"/>, <see cref="FillType.GradientByZ"/>, /// or <see cref="FillType.GradientByColorValue" />. /// </param> /// <returns>A <see cref="Pen" /> object with the properties of this <see cref="LineBase" /> /// </returns> public Pen GetPen(PaneBase pane, float scaleFactor, PointPair dataValue) { Color color = _color; if (_gradientFill.IsGradientValueType) { color = _gradientFill.GetGradientColor(dataValue); } Pen pen = new Pen(color, pane.ScaledPenWidth(_width, scaleFactor)); pen.DashStyle = _style; if (_style == DashStyle.Custom) { if (_dashOff > 1e-10 && _dashOn > 1e-10) { pen.DashStyle = DashStyle.Custom; float[] pattern = new float[2]; pattern[0] = _dashOn; pattern[1] = _dashOff; pen.DashPattern = pattern; } else { pen.DashStyle = DashStyle.Solid; } } return(pen); }
/// <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> override public void Draw(Graphics g, PaneBase pane, float scaleFactor) { // Convert the arrow coordinates from the user coordinate system // to the screen coordinate system PointF pix1 = this.Location.TransformTopLeft(pane); PointF pix2 = this.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; float 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 Pen 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; } }
/// <summary> /// Create a <see cref="Pen" /> object based on the properties of this /// <see cref="LineBase" />. /// </summary> /// <param name="pane">The owner <see cref="GraphPane" /> of this /// <see cref="LineBase" />. /// </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> /// <param name="dataValue">The data value to be used for a value-based /// color gradient. This is only applicable if <see cref="Fill.Type">GradientFill.Type</see> /// is one of <see cref="FillType.GradientByX"/>, /// <see cref="FillType.GradientByY"/>, <see cref="FillType.GradientByZ"/>, /// or <see cref="FillType.GradientByColorValue" />. /// </param> /// <returns>A <see cref="Pen" /> object with the properties of this <see cref="LineBase" /> /// </returns> public Pen GetPen(PaneBase pane, float scaleFactor, PointPair dataValue) { Color color = _color; if (_gradientFill.IsGradientValueType) { color = _gradientFill.GetGradientColor(dataValue); } Pen pen = new Pen(color, pane.ScaledPenWidth(_width, scaleFactor)); pen.DashStyle = _style; if (_style == DashStyle.Custom) { CustomDashes.SetupPen(pen, this, dataValue); } return(pen); }
/// <summary> /// Create a <see cref="Pen" /> object based on the properties of this /// <see cref="LineBase" />. /// </summary> /// <param name="pane">The owner <see cref="GraphPane" /> of this /// <see cref="LineBase" />. /// </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> /// <param name="dataValue">The data value to be used for a value-based /// color gradient. This is only applicable if <see cref="Fill.Type">GradientFill.Type</see> /// is one of <see cref="FillType.GradientByX"/>, /// <see cref="FillType.GradientByY"/>, <see cref="FillType.GradientByZ"/>, /// or <see cref="FillType.GradientByColorValue" />. /// </param> /// <returns>A <see cref="Pen" /> object with the properties of this <see cref="LineBase" /> /// </returns> public Pen GetPen( PaneBase pane, float scaleFactor, PointPair dataValue ) { Color color = _color; if ( _gradientFill.IsGradientValueType ) color = _gradientFill.GetGradientColor( dataValue ); Pen pen = new Pen( color, pane.ScaledPenWidth( _width, scaleFactor ) ); pen.DashStyle = _style; if ( _style == DashStyle.Custom ) { CustomDashes.SetupPen(pen, this, dataValue); } return pen; }
/// <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; } }
/// <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; } }
public Pen GetPen( PaneBase pane, float scaleFactor, PointPair dataValue ) { Color color = _color; if ( _gradientFill.IsGradientValueType ) color = _gradientFill.GetGradientColor( dataValue ); Pen pen = new Pen( color, pane.ScaledPenWidth( _width, scaleFactor ) ); pen.DashStyle = _style; if ( _style == DashStyle.Custom ) { if ( _dashOff > 1e-10 && _dashOn > 1e-10 ) { pen.DashStyle = DashStyle.Custom; float[] pattern = new float[2]; pattern[0] = _dashOn; pattern[1] = _dashOff; pen.DashPattern = pattern; } else pen.DashStyle = DashStyle.Solid; } return pen; }
/// <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; } }