Ejemplo n.º 1
0
 /// <summary>
 /// Initializes an instance of this class.
 /// </summary>
 /// <param name="referencePoint">
 /// The reference point. The X and Y values refer to the units used for the vertices.
 /// </param>
 /// <param name="referencePointPosition">
 /// The position of the reference point on the scope display.
 /// The X and Y values refer to the screen graticule.
 /// </param>
 /// <param name="vertices">The vertices describing the graph.</param>
 /// <param name="xScaleFactor">The scaling factor for the horizontal (X) direction.</param>
 /// <param name="yScaleFactor">The scaling factor for the vertical (Y) direction.</param>
 /// <param name="graphType">The graph line type.</param>
 /// <param name="color">The graph color.</param>
 public ScopeGraph(PointD referencePoint, PointD referencePointPosition, IEnumerable <PointD> vertices,
                   double xScaleFactor, double yScaleFactor, ScopeLineType lineType, Color color)
 {
     ReferencePoint         = referencePoint;
     ReferencePointPosition = referencePointPosition;
     Vertices     = vertices;
     XScaleFactor = xScaleFactor;
     YScaleFactor = yScaleFactor;
     LineType     = lineType;
     Color        = color;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws a scope graph.
        /// </summary>
        private void DrawGraph(RectangleRange rectangleRange, ScopeGraph graph,
                               ScopeLineType lineType, double lineWidth)
        {
            var userToDeviceMatrix = rectangleRange.Matrix;

            var vertices               = graph.Vertices ?? new PointD[0];
            var referencePoint         = graph.ReferencePoint;
            var referencePointPosition = graph.ReferencePointPosition;
            var xScaleFactor           = graph.XScaleFactor;
            var yScaleFactor           = graph.YScaleFactor;
            var color = graph.Color;

            if (vertices.Any())
            {
                using (CreateContextState())
                {
                    Context.SetSourceColor(color);

                    // Create a new transformation matrix considering scale factors
                    // and reference point position.
                    var vertexMatrix = (Matrix)userToDeviceMatrix.Clone();
                    vertexMatrix.Translate(referencePointPosition.X, referencePointPosition.Y);
                    vertexMatrix.Scale(xScaleFactor, yScaleFactor);
                    vertexMatrix.Translate(-referencePoint.X, -referencePoint.Y);

                    using (CreateContextState(vertexMatrix))
                    {
                        Context.MoveTo(vertices.First());
                        foreach (var vertex in vertices)
                        {
                            if (lineType == ScopeLineType.Dots)
                            {
                                Context.MoveTo(vertex);
                            }
                            Context.LineTo(vertex);
                        }
                    }

                    Context.LineWidth = lineWidth;
                    if (lineType == ScopeLineType.Dots)
                    {
                        Context.LineCap = LineCap.Round;
                    }
                    Context.Stroke();
                }
            }
        }