Exemplo n.º 1
0
        /// <summary>
        /// Draws the scale division label on a GDI+ surface against the provided x and y axes.
        /// </summary>
        /// <param name="g">The GDI+ surface on which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        /// 
        public void Draw(System.Drawing.Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            ArrayList yLargePositions = null;
            ArrayList ySmallPositions = null;

            yAxis.Axis.WorldTickPositions_FirstPass( yAxis.PhysicalMin, yAxis.PhysicalMax, out yLargePositions, out ySmallPositions );

            // test if we have enough y ticks
            if (yLargePositions.Count <= this.YPosition) {
                if (yLargePositions.Count > 1)
                    this.YPosition = yLargePositions.Count - 1;
                else return;
            }

            double minX = xAxis.PhysicalToWorld(xAxis.PhysicalMin,false);
            double maxX = xAxis.PhysicalToWorld(xAxis.PhysicalMax,false);

            double xOffset = this.XPosition;
            double xRef = xAxis.PhysicalMin.X;
            if (xOffset < 0)
                xRef = xAxis.PhysicalMax.X;

            if (xOffset < 1 && xOffset > 0)
                xOffset = (xAxis.PhysicalMax.X - xAxis.PhysicalMin.X) * this.XPosition;

            //*P8 	P3*==*P2==*P4
            //		 	||
            //		 	||
            //		 	|| *P7
            //       	||
            //       	||
            //  	P5*==*P1==*P6

            //Points for the main-line
            PointF p1 = new PointF(Convert.ToSingle(xRef + xOffset), 0.0f);
            PointF p2 = p1;

            PointF yTick1 = yAxis.WorldToPhysical((double)yLargePositions[yLargePositions.Count-this.YPosition],false);
            PointF yTick0 = yAxis.WorldToPhysical((double)yLargePositions[yLargePositions.Count-(this.YPosition+1)],false);

            p1.Y = yTick0.Y;
            p2.Y = yTick1.Y;

            //Points for the upper line
            PointF p3 = yTick1;
            PointF p4 = p3;
            p3.X = Convert.ToSingle(xRef + xOffset - 3);
            p4.X = Convert.ToSingle(xRef + xOffset + 3);

            //Points for the lower line
            PointF p5 = p3;
            PointF p6 = p4;
            p5.Y = yTick0.Y;
            p6.Y = yTick0.Y;

            //Label-point
            PointF p7 = p6;
            p7.Y = p7.Y + (p2.Y - p1.Y)/2;

            //Background-point
            PointF p8 = p3;
            p8.X = Convert.ToSingle((xRef + xOffset) - 14);

            double labelValue = (double)yLargePositions[yLargePositions.Count-this.YPosition] -
                (double)yLargePositions[yLargePositions.Count-(this.YPosition+1)];

            StringBuilder label = new StringBuilder();
            label.AppendFormat(this.NumberFormat, labelValue);
            float labelLength = g.MeasureString (label.ToString(), this.LabelFont).Width;

            float width = Convert.ToSingle((xRef + xOffset) + 14) - p8.X;
            float widthMin = (p7.X - p8.X) + labelLength + 2;
            if (widthMin > width)
                width = widthMin;

            float height = p1.Y-p2.Y;

            RectangleF bgRect = new RectangleF (p8.X, p8.Y, width, height);
            g.FillPath(this.BackgroundBrush, bgRect.RoundCorners(this.BackgroundCornerRadius));
            g.DrawString(label.ToString(), this.LabelFont, this.ValueBrush, p7);
            g.DrawLine( this.LinePen, (int)p1.X, (int)p1.Y, (int)p2.X, (int)p2.Y );
            g.DrawLine( this.LinePen, (int)p3.X, (int)p3.Y, (int)p4.X, (int)p4.Y );
            g.DrawLine( this.LinePen, (int)p5.X, (int)p5.Y, (int)p6.X, (int)p6.Y );
        }