Example #1
0
        protected virtual void DrawMarker(ChartGraphics graph, DataPoint point, int pointIndex, PointF location, MarkerStyle markerStyle, int markerSize, Brush brush, Pen borderPen)
        {
            if (this.chartArea3DEnabled)
            {
                Point3D[] array = new Point3D[1];
                location = graph.GetRelativePoint(location);
                array[0] = new Point3D(location.X, location.Y, this.seriesZCoordinate);
                this.matrix3D.TransformPoints(array);
                location.X = array[0].X;
                location.Y = array[0].Y;
                location   = graph.GetAbsolutePoint(location);
            }
            RectangleF rectangleF = new RectangleF((float)(location.X - (float)markerSize / 2.0), (float)(location.Y - (float)markerSize / 2.0), (float)markerSize, (float)markerSize);

            switch (markerStyle)
            {
            case MarkerStyle.Star4:
            case MarkerStyle.Star5:
            case MarkerStyle.Star6:
            case MarkerStyle.Star10:
            {
                int numberOfCorners = 4;
                switch (markerStyle)
                {
                case MarkerStyle.Star5:
                    numberOfCorners = 5;
                    break;

                case MarkerStyle.Star6:
                    numberOfCorners = 6;
                    break;

                case MarkerStyle.Star10:
                    numberOfCorners = 10;
                    break;
                }
                PointF[] points = graph.CreateStarPolygon(rectangleF, numberOfCorners);
                graph.FillPolygon(brush, points);
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, points);
                }
                break;
            }

            case MarkerStyle.Circle:
                graph.FillEllipse(brush, rectangleF);
                if (borderPen != null)
                {
                    graph.DrawEllipse(borderPen, rectangleF);
                }
                break;

            case MarkerStyle.Square:
                graph.FillRectangle(brush, rectangleF);
                if (borderPen != null)
                {
                    graph.DrawRectangle(borderPen, (int)Math.Round((double)rectangleF.X, 0), (int)Math.Round((double)rectangleF.Y, 0), (int)Math.Round((double)rectangleF.Width, 0), (int)Math.Round((double)rectangleF.Height, 0));
                }
                break;

            case MarkerStyle.Cross:
            {
                float    num    = (float)Math.Ceiling((float)markerSize / 4.0);
                float    num2   = (float)markerSize;
                PointF[] array4 = new PointF[12];
                array4[0].X  = (float)(location.X - num2 / 2.0);
                array4[0].Y  = (float)(location.Y + num / 2.0);
                array4[1].X  = (float)(location.X - num2 / 2.0);
                array4[1].Y  = (float)(location.Y - num / 2.0);
                array4[2].X  = (float)(location.X - num / 2.0);
                array4[2].Y  = (float)(location.Y - num / 2.0);
                array4[3].X  = (float)(location.X - num / 2.0);
                array4[3].Y  = (float)(location.Y - num2 / 2.0);
                array4[4].X  = (float)(location.X + num / 2.0);
                array4[4].Y  = (float)(location.Y - num2 / 2.0);
                array4[5].X  = (float)(location.X + num / 2.0);
                array4[5].Y  = (float)(location.Y - num / 2.0);
                array4[6].X  = (float)(location.X + num2 / 2.0);
                array4[6].Y  = (float)(location.Y - num / 2.0);
                array4[7].X  = (float)(location.X + num2 / 2.0);
                array4[7].Y  = (float)(location.Y + num / 2.0);
                array4[8].X  = (float)(location.X + num / 2.0);
                array4[8].Y  = (float)(location.Y + num / 2.0);
                array4[9].X  = (float)(location.X + num / 2.0);
                array4[9].Y  = (float)(location.Y + num2 / 2.0);
                array4[10].X = (float)(location.X - num / 2.0);
                array4[10].Y = (float)(location.Y + num2 / 2.0);
                array4[11].X = (float)(location.X - num / 2.0);
                array4[11].Y = (float)(location.Y + num / 2.0);
                Matrix matrix = new Matrix();
                matrix.RotateAt(45f, location);
                matrix.TransformPoints(array4);
                matrix.Dispose();
                graph.FillPolygon(brush, array4);
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, array4);
                }
                break;
            }

            case MarkerStyle.Diamond:
            {
                PointF[] array3 = new PointF[4];
                array3[0].X = rectangleF.X;
                array3[0].Y = (float)(rectangleF.Y + rectangleF.Height / 2.0);
                array3[1].X = (float)(rectangleF.X + rectangleF.Width / 2.0);
                array3[1].Y = rectangleF.Top;
                array3[2].X = rectangleF.Right;
                array3[2].Y = (float)(rectangleF.Y + rectangleF.Height / 2.0);
                array3[3].X = (float)(rectangleF.X + rectangleF.Width / 2.0);
                array3[3].Y = rectangleF.Bottom;
                graph.FillPolygon(brush, array3);
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, array3);
                }
                break;
            }

            case MarkerStyle.Triangle:
            {
                PointF[] array2 = new PointF[3];
                array2[0].X = rectangleF.X;
                array2[0].Y = rectangleF.Bottom;
                array2[1].X = (float)(rectangleF.X + rectangleF.Width / 2.0);
                array2[1].Y = rectangleF.Top;
                array2[2].X = rectangleF.Right;
                array2[2].Y = rectangleF.Bottom;
                graph.FillPolygon(brush, array2);
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, array2);
                }
                break;
            }

            default:
                throw new InvalidOperationException(SR.ExceptionFastPointMarkerStyleUnknown);
            }
            if (this.common.ProcessModeRegions)
            {
                this.common.HotRegionsList.AddHotRegion(graph, graph.GetRelativeRectangle(rectangleF), point, point.series.Name, pointIndex);
            }
        }
		/// <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, 
			PointF location, 
			MarkerStyle markerStyle, 
			int markerSize, 
			Brush brush,
			Pen borderPen)
		{
			// Transform 3D coordinates
			if(chartArea3DEnabled)
			{
				Point3D [] points = new Point3D[1];
				location = graph.GetRelativePoint(location);
				points[0] = new Point3D(location.X, location.Y, this.seriesZCoordinate);
				matrix3D.TransformPoints( points );
				location.X = points[0].X;
				location.Y = points[0].Y;
				location = graph.GetAbsolutePoint(location);
			}

			// Create marker bounding rectangle in pixels
			RectangleF markerBounds = new RectangleF(
				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
					PointF[]	points = graph.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.X, 0), 
							(int)Math.Round(markerBounds.Y, 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
					PointF[] points = new PointF[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
					Matrix rotationMatrix = new Matrix();
					rotationMatrix.RotateAt(45, location);
					rotationMatrix.TransformPoints(points);
					rotationMatrix.Dispose();

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

					// Draw border
					if(borderPen != null)
					{
						graph.DrawPolygon(borderPen, points);
					}
					break;
				}
				case(MarkerStyle.Diamond):
				{
					PointF[] points = new PointF[4];
					points[0].X = markerBounds.X;
					points[0].Y = markerBounds.Y + markerBounds.Height/2F;
					points[1].X = markerBounds.X + markerBounds.Width/2F;
					points[1].Y = markerBounds.Top;
					points[2].X = markerBounds.Right;
					points[2].Y = markerBounds.Y + markerBounds.Height/2F;
					points[3].X = markerBounds.X + 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):
				{
					PointF[] points = new PointF[3];
					points[0].X = markerBounds.X;
					points[0].Y = markerBounds.Bottom;
					points[1].X = markerBounds.X + 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( this.Common.ProcessModeRegions )
			{
				this.Common.HotRegionsList.AddHotRegion(
					graph.GetRelativeRectangle(markerBounds),
					point, 
					point.series.Name, 
					pointIndex );
			}
		}