NPlot.PhysicalAxis.GetBoundingBox C# (CSharp) Метод

GetBoundingBox() публичный Метод

Returns the smallest rectangle that completely contains all parts of the axis [including ticks and label].
public GetBoundingBox ( ) : Rectangle
Результат System.Drawing.Rectangle
        public virtual Rectangle GetBoundingBox()
        {
            using (System.Drawing.Bitmap scratchArea = new System.Drawing.Bitmap(1, 1))
            {
                using (Graphics g = Graphics.FromImage(scratchArea))
                {
                    Rectangle bounds;
                    Draw(g, out bounds);
                    return bounds;
                }
            }
        }

Usage Example

Пример #1
0
        private void DeterminePhysicalAxesToDraw( Rectangle bounds, 
			Axis xAxis1, Axis xAxis2, Axis yAxis1, Axis yAxis2,
			out PhysicalAxis pXAxis1, out PhysicalAxis pXAxis2, 
			out PhysicalAxis pYAxis1, out PhysicalAxis pYAxis2 )
        {
            System.Drawing.Rectangle cb = bounds;

            pXAxis1 = new PhysicalAxis( xAxis1,
                new Point( cb.Left, cb.Bottom ), new Point( cb.Right, cb.Bottom ) );
            pYAxis1 = new PhysicalAxis( yAxis1,
                new Point( cb.Left, cb.Bottom ), new Point( cb.Left, cb.Top ) );
            pXAxis2 = new PhysicalAxis( xAxis2,
                new Point( cb.Left, cb.Top), new Point( cb.Right, cb.Top) );
            pYAxis2 = new PhysicalAxis( yAxis2,
                new Point( cb.Right, cb.Bottom ), new Point( cb.Right, cb.Top ) );

            int bottomIndent = padding_;
            if (!pXAxis1.Axis.Hidden)
            {
                // evaluate its bounding box
                Rectangle bb = pXAxis1.GetBoundingBox();
                // finally determine its indentation from the bottom
                bottomIndent = bottomIndent + bb.Bottom - cb.Bottom;
            }

            int leftIndent = padding_;
            if (!pYAxis1.Axis.Hidden)
            {
                // evaluate its bounding box
                Rectangle bb = pYAxis1.GetBoundingBox();
                // finally determine its indentation from the left
                leftIndent = leftIndent - bb.Left + cb.Left;
            }

            int topIndent = padding_;
            float scale = this.DetermineScaleFactor( bounds.Width, bounds.Height );
            int titleHeight;
            if (this.AutoScaleTitle)
            {
                titleHeight = Utils.ScaleFont(titleFont_, scale).Height;
            }
            else
            {
                titleHeight = titleFont_.Height;
            }

            //count number of new lines in title.
            int nlCount = 0;
            for (int i=0; i<title_.Length; ++i)
            {
                if (title_[i] == '\n')
                    nlCount += 1;
            }
            titleHeight = (int)( ((float)nlCount*0.75 + 1.0f) * (float)titleHeight);

            if (!pXAxis2.Axis.Hidden)
            {
                // evaluate its bounding box
                Rectangle bb = pXAxis2.GetBoundingBox();
                topIndent = topIndent - bb.Top + cb.Top;

                // finally determine its indentation from the top
                // correct top indendation to take into account plot title
                if (title_ != "" )
                {
                    topIndent += (int)(titleHeight * 1.3f);
                }
            }

            int rightIndent = padding_;
            if (!pYAxis2.Axis.Hidden)
            {
                // evaluate its bounding box
                Rectangle bb = pYAxis2.GetBoundingBox();

                // finally determine its indentation from the right
                rightIndent = (int)(rightIndent + bb.Right-cb.Right);
            }

            // now we have all the default calculated positions and we can proceed to
            // "move" the axes to their right places

            // primary axes (bottom, left)
            pXAxis1.PhysicalMin = new Point( cb.Left+leftIndent, cb.Bottom-bottomIndent );
            pXAxis1.PhysicalMax = new Point( cb.Right-rightIndent, cb.Bottom-bottomIndent );
            pYAxis1.PhysicalMin = new Point( cb.Left+leftIndent, cb.Bottom-bottomIndent );
            pYAxis1.PhysicalMax = new Point( cb.Left+leftIndent, cb.Top+topIndent );

            // secondary axes (top, right)
            pXAxis2.PhysicalMin = new Point( cb.Left+leftIndent, cb.Top+topIndent );
            pXAxis2.PhysicalMax = new Point( cb.Right-rightIndent, cb.Top+topIndent );
            pYAxis2.PhysicalMin = new Point( cb.Right-rightIndent, cb.Bottom-bottomIndent );
            pYAxis2.PhysicalMax = new Point( cb.Right-rightIndent, cb.Top+topIndent );
        }
All Usage Examples Of NPlot.PhysicalAxis::GetBoundingBox