Exemplo n.º 1
0
        /// <summary>
        /// Go through each <see cref="CurveItem"/> object in the collection,
        /// calling the <see cref="PointPairList.GetRange"/> member to
        /// determine the minimum and maximum values in the
        /// <see cref="CurveItem.Points"/> list of data value pairs.  If the curves include
        /// a stack bar, handle within the current GetRange method. In the event that no
        /// data are available, a default range of min=0.0 and max=1.0 are returned.
        /// If the Y axis has a valid data range and the Y2 axis not, then the Y2
        /// range will be a duplicate of the Y range.  Vice-versa for the Y2 axis
        /// having valid data when the Y axis does not.
        /// If any <see cref="CurveItem"/> in the list has a missing
        /// <see cref="PointPairList"/>, a new empty one will be generated.
        /// </summary>
        /// <param name="xMinVal">The minimun X value in the data range for all curves
        /// in this collection</param>
        /// <param name="xMaxVal">The maximun X value in the data range for all curves
        /// in this collection</param>
        /// <param name="yMinVal">The minimun Y (left Y axis) value in the data range
        /// for all curves in this collection</param>
        /// <param name="yMaxVal">The maximun Y (left Y axis) value in the data range
        /// for all curves in this collection</param>
        /// <param name="y2MinVal">The minimun Y2 (right Y axis) value in the data range
        /// for all curves in this collection</param>
        /// <param name="y2MaxVal">The maximun Y2 (right Y axis) value in the data range
        /// for all curves in this collection</param>
        /// <param name="bIgnoreInitial">ignoreInitial is a boolean value that
        /// affects the data range that is considered for the automatic scale
        /// ranging (see <see cref="GraphPane.IsIgnoreInitial"/>).  If true, then initial
        /// data points where the Y value is zero are not included when
        /// automatically determining the scale <see cref="Axis.Min"/>,
        /// <see cref="Axis.Max"/>, and <see cref="Axis.Step"/> size.  All data after
        /// the first non-zero Y value are included.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        public void GetRange(out double xMinVal, out double xMaxVal,
                             out double yMinVal, out double yMaxVal,
                             out double y2MinVal, out double y2MaxVal,
                             bool bIgnoreInitial, GraphPane pane)
        {
            double tXMinVal,
                   tXMaxVal,
                   tYMinVal,
                   tYMaxVal;

            // initialize the values to outrageous ones to start
            xMinVal = yMinVal = y2MinVal = tXMinVal = tYMinVal = Double.MaxValue;
            xMaxVal = yMaxVal = y2MaxVal = tXMaxVal = tYMaxVal = Double.MinValue;
            maxPts  = 1;

            PointPairList sumList = null;

            // Loop over each curve in the collection and examine any that are not a stack bar
            foreach (CurveItem curve in this)
            {
                if (curve.IsBar && pane.BarType == BarType.Stack)
                {
                    if (sumList == null)
                    {
                        sumList = (PointPairList)curve.Points.Clone();
                    }
                    else if (pane.BarBase == BarBase.X)
                    {
                        sumList.SumY(curve.Points);
                    }
                    else
                    {
                        sumList.SumX(curve.Points);
                    }

                    sumList.GetRange(ref tXMinVal, ref tXMaxVal,
                                     ref tYMinVal, ref tYMaxVal, bIgnoreInitial,
                                     false, true);
                }
                else
                {
                    // Call the GetRange() member function for the current
                    // curve to get the min and max values
                    curve.GetRange(ref tXMinVal, ref tXMaxVal,
                                   ref tYMinVal, ref tYMaxVal, bIgnoreInitial, pane);
                }

                bool isYOrd = ((pane.Y2Axis.IsOrdinal || pane.Y2Axis.IsText) && curve.IsY2Axis) ||
                              ((pane.YAxis.IsOrdinal || pane.YAxis.IsText) && !curve.IsY2Axis);
                bool isXOrd = pane.XAxis.IsOrdinal || pane.XAxis.IsText;

                // For ordinal Axes, the data range is just 1 to Npts
                if (isYOrd)
                {
                    tYMinVal = 1.0;
                    tYMaxVal = curve.NPts;
                }
                if (isXOrd)
                {
                    tXMinVal = 1.0;
                    tXMaxVal = curve.NPts;
                }

                // Bar types always include the Y=0 value
                if (curve.IsBar)
                {
                    if (pane.BarBase == BarBase.X)
                    {
                        if (tYMinVal > 0)
                        {
                            tYMinVal = 0;
                        }
                        else if (tYMaxVal < 0)
                        {
                            tYMaxVal = 0;
                        }

                        if (!isXOrd)
                        {
                            tXMinVal -= pane.ClusterScaleWidth / 2.0;
                            tXMaxVal += pane.ClusterScaleWidth / 2.0;
                        }
                    }
                    else
                    {
                        if (tXMinVal > 0)
                        {
                            tXMinVal = 0;
                        }
                        else if (tXMaxVal < 0)
                        {
                            tXMaxVal = 0;
                        }

                        if (!isYOrd)
                        {
                            tYMinVal -= pane.ClusterScaleWidth / 2.0;
                            tYMaxVal += pane.ClusterScaleWidth / 2.0;
                        }
                    }
                }

                // determine which curve has the maximum number of points
                if (curve.NPts > maxPts)
                {
                    maxPts = curve.NPts;
                }

                // If the min and/or max values from the current curve
                // are the absolute min and/or max, then save the values
                // Also, differentiate between Y and Y2 values
                if (curve.IsY2Axis)
                {
                    if (tYMinVal < y2MinVal)
                    {
                        y2MinVal = tYMinVal;
                    }
                    if (tYMaxVal > y2MaxVal)
                    {
                        y2MaxVal = tYMaxVal;
                    }
                }
                else
                {
                    if (tYMinVal < yMinVal)
                    {
                        yMinVal = tYMinVal;
                    }
                    if (tYMaxVal > yMaxVal)
                    {
                        yMaxVal = tYMaxVal;
                    }
                }

                if (tXMinVal < xMinVal)
                {
                    xMinVal = tXMinVal;
                }
                if (tXMaxVal > xMaxVal)
                {
                    xMaxVal = tXMaxVal;
                }
            }

            // Define suitable default ranges in the event that
            // no data were available
            if (xMinVal >= Double.MaxValue || xMaxVal <= Double.MinValue)
            {
                xMinVal = 0;
                xMaxVal = 1;
            }

            if (yMinVal >= Double.MaxValue || yMaxVal <= Double.MinValue)
            {
                if (y2MinVal < Double.MaxValue && y2MaxVal > Double.MinValue)
                {
                    yMinVal = y2MinVal;
                    yMaxVal = y2MaxVal;
                }
                else
                {
                    yMinVal = 0;
                    yMaxVal = 1;
                }
            }

            if (y2MinVal >= Double.MaxValue || y2MaxVal <= Double.MinValue)
            {
                if (yMinVal < Double.MaxValue && yMaxVal > Double.MinValue)
                {
                    y2MinVal = yMinVal;
                    y2MaxVal = yMaxVal;
                }
                else
                {
                    y2MinVal = 0;
                    y2MaxVal = 1;
                }
            }
            //check for single values which may	be	larger than the	totals,	because totals have been
            // reduced by	negative values.  If any	are found, adjust max/min values accordingly		   rpk
            if (pane.BarType == BarType.Stack)
            {
                foreach (CurveItem curve in this)
                {
                    if (curve.IsBar)
                    {
                        curve.Points.GetRange(ref tXMinVal, ref tXMaxVal,
                                              ref tYMinVal, ref tYMaxVal, bIgnoreInitial, false, true);

                        if (curve.IsY2Axis)
                        {
                            if (tYMinVal < y2MinVal)
                            {
                                y2MinVal = tYMinVal;
                            }
                            if (tYMaxVal > y2MaxVal)
                            {
                                y2MaxVal = tYMaxVal;
                            }
                        }
                        else
                        {
                            if (tYMinVal < yMinVal)
                            {
                                yMinVal = tYMinVal;
                            }
                            if (tYMaxVal > yMaxVal)
                            {
                                yMaxVal = tYMaxVal;
                            }
                        }

                        if (tXMinVal < xMinVal)
                        {
                            xMinVal = tXMinVal;
                        }
                        if (tXMaxVal > xMaxVal)
                        {
                            xMaxVal = tXMaxVal;
                        }
                    }
                }
            }

            //create reasonable min/max values for bartype = percentStack
            bool hasNegative = false;

            if (pane.BarType == BarType.PercentStack)
            {
                foreach (CurveItem curve in this)
                {
                    if (curve.IsBar)
                    {
                        foreach (PointPair point in curve.Points)
                        {
                            if (point.X < 0 || point.Y < 0)
                            {
                                hasNegative = true;
                                if (pane.BarBase == BarBase.X)
                                {
                                    yMinVal = -100;
                                    yMaxVal = 100;
                                }
                                else
                                {
                                    xMinVal = -100;
                                    xMaxVal = 100;
                                }
                                break;
                            }
                        }
                    }
                    if (hasNegative)
                    {
                        break;
                    }
                }
                if (!hasNegative)
                {
                    if (pane.BarBase == BarBase.X)
                    {
                        yMinVal = 0;
                        yMaxVal = 100;
                    }
                    else
                    {
                        xMinVal = 0;
                        xMaxVal = 100;
                    }
                }
            }
        }