Exemplo n.º 1
0
        /// <summary>
        /// Draws a marker that represents a data point in FastPoint series.
        /// </summary>
        /// <param name="graph">Chart graphics used to draw the marker.</param>
        /// <param name="point">Series data point drawn.</param>
        /// <param name="pointIndex">Data point index in the series.</param>
        /// <param name="location">Marker location in pixels.</param>
        /// <param name="markerStyle">Marker style.</param>
        /// <param name="markerSize">Marker size in pixels.</param>
        /// <param name="brush">Brush used to fill marker shape.</param>
        /// <param name="borderPen">Marker border pen.</param>
        virtual protected void DrawMarker(
            ChartGraphics graph,
            DataPoint point,
            int pointIndex,
            SKPoint location,
            MarkerStyle markerStyle,
            int markerSize,
            SKPaint brush,
            SKPaint borderPen)
        {
            // Transform 3D coordinates
            if (chartArea3DEnabled)
            {
                Point3D[] points = new Point3D[1];
                location  = graph.GetRelativePoint(location);
                points[0] = new Point3D(location.X, location.Y, seriesZCoordinate);
                matrix3D.TransformPoints(points);
                location.X = points[0].X;
                location.Y = points[0].Y;
                location   = graph.GetAbsolutePoint(location);
            }

            // Create marker bounding rectangle in pixels
            SKRect markerBounds = new(
                location.X - markerSize / 2f, location.Y - markerSize / 2f, markerSize, markerSize);

            // Draw Marker
            switch (markerStyle)
            {
            case (MarkerStyle.Star4):
            case (MarkerStyle.Star5):
            case (MarkerStyle.Star6):
            case (MarkerStyle.Star10):
            {
                // Set number of corners
                int cornerNumber = 4;
                if (markerStyle == MarkerStyle.Star5)
                {
                    cornerNumber = 5;
                }
                else if (markerStyle == MarkerStyle.Star6)
                {
                    cornerNumber = 6;
                }
                else if (markerStyle == MarkerStyle.Star10)
                {
                    cornerNumber = 10;
                }

                // Get star polygon
                SKPoint[] points = ChartGraphics.CreateStarPolygon(markerBounds, cornerNumber);

                // Fill shape
                graph.FillPolygon(brush, points);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, points);
                }
                break;
            }

            case (MarkerStyle.Circle):
            {
                graph.FillEllipse(brush, markerBounds);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawEllipse(borderPen, markerBounds);
                }

                break;
            }

            case (MarkerStyle.Square):
            {
                graph.FillRectangle(brush, markerBounds);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawRectangle(
                        borderPen,
                        (int)Math.Round(markerBounds.Left, 0),
                        (int)Math.Round(markerBounds.Top, 0),
                        (int)Math.Round(markerBounds.Width, 0),
                        (int)Math.Round(markerBounds.Height, 0));
                }

                break;
            }

            case (MarkerStyle.Cross):
            {
                // Calculate cross line width and size
                float crossLineWidth = (float)Math.Ceiling(markerSize / 4F);
                float crossSize      = markerSize;      // * (float)Math.Sin(45f/180f*Math.PI)

                // Calculate cross coordinates
                SKPoint[] points = new SKPoint[12];
                points[0].X = location.X - crossSize / 2F;
                points[0].Y = location.Y + crossLineWidth / 2F;
                points[1].X = location.X - crossSize / 2F;
                points[1].Y = location.Y - crossLineWidth / 2F;

                points[2].X = location.X - crossLineWidth / 2F;
                points[2].Y = location.Y - crossLineWidth / 2F;
                points[3].X = location.X - crossLineWidth / 2F;
                points[3].Y = location.Y - crossSize / 2F;
                points[4].X = location.X + crossLineWidth / 2F;
                points[4].Y = location.Y - crossSize / 2F;

                points[5].X = location.X + crossLineWidth / 2F;
                points[5].Y = location.Y - crossLineWidth / 2F;
                points[6].X = location.X + crossSize / 2F;
                points[6].Y = location.Y - crossLineWidth / 2F;
                points[7].X = location.X + crossSize / 2F;
                points[7].Y = location.Y + crossLineWidth / 2F;

                points[8].X  = location.X + crossLineWidth / 2F;
                points[8].Y  = location.Y + crossLineWidth / 2F;
                points[9].X  = location.X + crossLineWidth / 2F;
                points[9].Y  = location.Y + crossSize / 2F;
                points[10].X = location.X - crossLineWidth / 2F;
                points[10].Y = location.Y + crossSize / 2F;
                points[11].X = location.X - crossLineWidth / 2F;
                points[11].Y = location.Y + crossLineWidth / 2F;

                // Rotate cross coordinates 45 degrees
                SKMatrix rotationMatrix = SKMatrix.CreateRotationDegrees(45, location.X, location.Y);
                rotationMatrix.TransformPoints(points);

                // Fill shape
                graph.FillPolygon(brush, points);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, points);
                }
                break;
            }

            case (MarkerStyle.Diamond):
            {
                SKPoint[] points = new SKPoint[4];
                points[0].X = markerBounds.Left;
                points[0].Y = markerBounds.Top + markerBounds.Height / 2F;
                points[1].X = markerBounds.Left + markerBounds.Width / 2F;
                points[1].Y = markerBounds.Top;
                points[2].X = markerBounds.Right;
                points[2].Y = markerBounds.Top + markerBounds.Height / 2F;
                points[3].X = markerBounds.Left + markerBounds.Width / 2F;
                points[3].Y = markerBounds.Bottom;

                graph.FillPolygon(brush, points);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, points);
                }
                break;
            }

            case (MarkerStyle.Triangle):
            {
                SKPoint[] points = new SKPoint[3];
                points[0].X = markerBounds.Left;
                points[0].Y = markerBounds.Bottom;
                points[1].X = markerBounds.Top + markerBounds.Width / 2F;
                points[1].Y = markerBounds.Top;
                points[2].X = markerBounds.Right;
                points[2].Y = markerBounds.Bottom;

                graph.FillPolygon(brush, points);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, points);
                }
                break;
            }

            default:
            {
                throw (new InvalidOperationException(SR.ExceptionFastPointMarkerStyleUnknown));
            }
            }

            // Process selection regions
            if (Common.ProcessModeRegions)
            {
                Common.HotRegionsList.AddHotRegion(
                    graph.GetRelativeRectangle(markerBounds),
                    point,
                    point.series.Name,
                    pointIndex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draw chart line using horisontal and vertical lines.
        /// </summary>
        /// <param name="graph">Graphics object.</param>
        /// <param name="common">The Common elements object</param>
        /// <param name="point">Point to draw the line for.</param>
        /// <param name="series">Point series.</param>
        /// <param name="points">Array of points coordinates.</param>
        /// <param name="pointIndex">Index of point to draw.</param>
        /// <param name="tension">Line tension</param>
        override protected void DrawLine(
            ChartGraphics graph,
            CommonElements common,
            DataPoint point,
            Series series,
            SKPoint[] points,
            int pointIndex,
            float tension)
        {
            // Start drawing from the second point
            if (pointIndex <= 0)
            {
                return;
            }

            // Darw two lines
            SKPoint point1 = points[pointIndex - 1];
            SKPoint point2 = new(points[pointIndex].X, points[pointIndex - 1].Y);
            SKPoint point3 = points[pointIndex];

            graph.DrawLineRel(point.Color, point.BorderWidth, point.BorderDashStyle, graph.GetRelativePoint(point1), graph.GetRelativePoint(point2), series.ShadowColor, series.ShadowOffset);
            graph.DrawLineRel(point.Color, point.BorderWidth, point.BorderDashStyle, graph.GetRelativePoint(point2), graph.GetRelativePoint(point3), series.ShadowColor, series.ShadowOffset);

            if (common.ProcessModeRegions)
            {
                // Create grapics path object for the line
                // Split line into 2 segments.
                SKPath path = new();
                try
                {
                    path.AddLine(point2, point3);
                    if (!point2.Equals(point3))
                    {
                        // path.Widen(new Pen(point.Color, point.BorderWidth + 2));
                    }
                }
                catch (OutOfMemoryException)
                {
                    // SKPath.Widen incorrectly throws OutOfMemoryException
                    // catching here and reacting by not widening
                }
                catch (ArgumentException)
                {
                    // Ignore
                }

                float[]   coord      = new float[path.PointCount * 2];
                SKPoint[] pathPoints = path.Points;

                // Allocate array of floats
                SKPoint pointNew;
                for (int i = 0; i < path.PointCount; i++)
                {
                    pointNew         = graph.GetRelativePoint(pathPoints[i]);
                    coord[2 * i]     = pointNew.X;
                    coord[2 * i + 1] = pointNew.Y;
                }

                common.HotRegionsList.AddHotRegion(
                    path,
                    false,
                    coord,
                    point,
                    series.Name,
                    pointIndex);
                path.Dispose();
                // Create grapics path object for the line
                path = new SKPath();
                try
                {
                    path.AddLine(point1, point2);
                    //path.Widen(new Pen(point.Color, point.BorderWidth + 2));
                }
                catch (OutOfMemoryException)
                {
                    // SKPath.Widen incorrectly throws OutOfMemoryException
                    // catching here and reacting by not widening
                }
                catch (ArgumentException)
                {
                    // Ignore
                }

                // Allocate array of floats
                coord      = new float[path.PointCount * 2];
                pathPoints = path.Points;
                for (int i = 0; i < path.PointCount; i++)
                {
                    pointNew         = graph.GetRelativePoint(pathPoints[i]);
                    coord[2 * i]     = pointNew.X;
                    coord[2 * i + 1] = pointNew.Y;
                }

                common.HotRegionsList.AddHotRegion(
                    path,
                    false,
                    coord,
                    series.Points[pointIndex - 1],
                    series.Name,
                    pointIndex - 1);
                path.Dispose();
            }
        }