Ejemplo n.º 1
0
        /// <summary>
        /// Calculate the <see cref="RectangleF"/> that will be used to define the bounding rectangle of
        /// the GasGaugeNeedle.
        /// </summary>
        /// <remarks>This rectangle always lies inside of the <see cref="Chart.Rect"/>, and it is
        /// normally a square so that the pie itself is not oval-shaped.</remarks>
        /// <param name="g">
        /// A graphic device object to be drawn into. This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects. This is calculated and
        /// passed down by the parent <see cref="ZedGraph.GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <param name="chartRect">The <see cref="RectangleF"/> (normally the <see cref="Chart.Rect"/>)
        /// that bounds this pie.</param>
        /// <returns></returns>
        public static RectangleF CalcRectangle(Graphics g, GraphPane pane, float scaleFactor, RectangleF chartRect)
        {
            RectangleF nonExpRect = chartRect;

            nonExpRect.Height -= pane.GasGaugeRegionWidth / 2;
            nonExpRect.Width  -= pane.GasGaugeRegionWidth;

            float width = nonExpRect.Width;
            float height;

            double sineVal = Math.Sin((Math.PI / 180) * ((pane.Angle - 180) / 2));

            //take at least half a circle
            if (pane.Angle <= 180)
            {
                height = (width / 2);
            }
            else
            {
                height             = (float)((width / 2) + ((width / 2) * sineVal));
                nonExpRect.Height -= (float)(pane.GasGaugeRegionWidth / 2 * sineVal);
            }

            height *= 1.05f;

            float ratio = width / height;

            if ((ratio * nonExpRect.Height) > nonExpRect.Width)
            {
                //Scale based on width
                nonExpRect.Height = nonExpRect.Width;
            }
            else
            {
                //Scale based on heights
                nonExpRect.Width  = nonExpRect.Height * ratio;
                nonExpRect.Height = nonExpRect.Width;
            }

            //define the place on the pane
            nonExpRect.X = (pane.Rect.Width - nonExpRect.Width) / 2;
            nonExpRect.Y = pane.Chart.Rect.Top + pane.GasGaugeRegionWidth / 2;

            GasGaugeRegion.CalculateGasGuageParameters(pane);

            foreach (CurveItem curve in pane.CurveList)
            {
                if (curve is GasGaugeRegion)
                {
                    GasGaugeRegion gg = (GasGaugeRegion)curve;
                    gg._boundingRectangle = nonExpRect;
                }
            }

            return(nonExpRect);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculate the <see cref="RectangleF"/> that will be used to define the bounding rectangle of
        /// the GasGaugeNeedle.
        /// </summary>
        /// <remarks>This rectangle always lies inside of the <see cref="Chart.Rect"/>, and it is
        /// normally a square so that the pie itself is not oval-shaped.</remarks>
        /// <param name="g">
        /// A graphic device object to be drawn into. This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects. This is calculated and
        /// passed down by the parent <see cref="ZedGraph.GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <param name="chartRect">The <see cref="RectangleF"/> (normally the <see cref="Chart.Rect"/>)
        /// that bounds this pie.</param>
        /// <returns></returns>
        public static RectangleF CalcRectangle(Graphics g, GraphPane pane, float scaleFactor, RectangleF chartRect)
        {
            RectangleF nonExpRect = chartRect;

            if ((2 * nonExpRect.Height) > nonExpRect.Width)
            {
                //Scale based on width
                float percentS = ((nonExpRect.Height * 2) - nonExpRect.Width) / (nonExpRect.Height * 2);
                nonExpRect.Height = ((nonExpRect.Height * 2) - ((nonExpRect.Height * 2) * percentS));
            }
            else
            {
                nonExpRect.Height = nonExpRect.Height * 2;
            }

            nonExpRect.Width = nonExpRect.Height;

            float xDelta = (chartRect.Width / 2) - (nonExpRect.Width / 2);

            //Align Horizontally
            nonExpRect.X += xDelta;

            //nonExpRect.Y += -(float)0.025F * nonExpRect.Height;
            //nonExpRect.Y += ((chartRect.Height) - (nonExpRect.Height / 2)) - 10.0f;

            nonExpRect.Inflate(-(float)0.05F * nonExpRect.Height, -(float)0.05 * nonExpRect.Width);

            GasGaugeRegion.CalculateGasGuageParameters(pane);

            foreach (CurveItem curve in pane.CurveList)
            {
                if (curve is GasGaugeRegion)
                {
                    GasGaugeRegion gg = (GasGaugeRegion)curve;
                    gg._boundingRectangle = nonExpRect;
                }
            }

            return(nonExpRect);
        }