예제 #1
0
파일: Utils.cs 프로젝트: Terohnon/NPlot
        /// <summary>
        /// Returns the minimum and maximum values in a DataView.
        /// </summary>
        /// <param name="data">The DataView to search.</param>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        /// <param name="columnName">The name of the column in the row collection to search over.</param>
        /// <returns>true is min max set, false otherwise (a = null or zero length).</returns>
        public static bool DataViewArrayMinMax(DataView data,
                                               out double min, out double max, string columnName)
        {
            // double[] is a reference type and can be null, if it is then I reckon the best
            // values for min and max are also null. double is a value type so can't be set
            //	to null. So min an max return object, and we understand that if it is not null
            // it is a boxed double (same trick I use lots elsewhere in the lib). The
            // wonderful comment I didn't write at the top should explain everything.
            if (data == null || data.Count == 0)
            {
                min = 0.0;
                max = 0.0;
                return(false);
            }

            min = Utils.ToDouble((data[0])[columnName]);
            max = Utils.ToDouble((data[0])[columnName]);

            for (int i = 0; i < data.Count; ++i)
            {
                double e = Utils.ToDouble(data[i][columnName]);

                if (e < min)
                {
                    min = e;
                }

                if (e > max)
                {
                    max = e;
                }
            }

            return(true);
        }
예제 #2
0
 /// <summary>
 /// Gets data at a given index, in the given series (column number).
 /// </summary>
 /// <param name="index">index in the series to get data for</param>
 /// <param name="seriesIndex">series number (column number) to get data for.</param>
 /// <returns>the required data point.</returns>
 public double PointAt(int index, int seriesIndex)
 {
     if (seriesIndex < abscissaColumnNumber_)
     {
         return(Utils.ToDouble(rows_[index][seriesIndex]));
     }
     else
     {
         return(Utils.ToDouble(rows_[index][seriesIndex + 1]));
     }
 }
예제 #3
0
파일: Utils.cs 프로젝트: Terohnon/NPlot
        /// <summary>
        /// Returns the minimum and maximum values in a DataRowCollection.
        /// </summary>
        /// <param name="rows">The row collection to search.</param>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        /// <param name="columnName">The name of the column in the row collection to search over.</param>
        /// <returns>true is min max set, false otherwise (a = null or zero length).</returns>
        public static bool RowArrayMinMax(DataRowCollection rows,
                                          out double min, out double max, string columnName)
        {
            // double[] is a reference type and can be null, if it is then I reckon the best
            // values for min and max are also null. double is a value type so can't be set
            //	to null. So min an max return object, and we understand that if it is not null
            // it is a boxed double (same trick I use lots elsewhere in the lib). The
            // wonderful comment I didn't write at the top should explain everything.
            if (rows == null || rows.Count == 0)
            {
                min = 0.0;
                max = 0.0;
                return(false);
            }

            min = Utils.ToDouble((rows[0])[columnName]);
            max = Utils.ToDouble((rows[0])[columnName]);

            foreach (DataRow r in rows)
            {
                double e = Utils.ToDouble(r[columnName]);

                if ((min.Equals(double.NaN)) && (!e.Equals(double.NaN)))
                {
                    // if min/max are double.NaN and the current value not, then
                    // set them to the current value.
                    min = e;
                    max = e;
                }

                if (!double.IsNaN(e))
                {
                    if (e < min)
                    {
                        min = e;
                    }
                    if (e > max)
                    {
                        max = e;
                    }
                }
            }
            if (min.Equals(double.NaN))
            {
                // if min == double.NaN, then max is also double.NaN
                min = 0.0;
                max = 0.0;
                return(false);
            }

            return(true);
        }
예제 #4
0
파일: Utils.cs 프로젝트: Terohnon/NPlot
        /// <summary>
        /// Returns the minimum and maximum values in an IList. The members of the list
        /// can be of different types - any type for which the function Utils.ConvertToDouble
        /// knows how to convert into a double.
        /// </summary>
        /// <param name="a">The IList to search.</param>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        /// <returns>true if min max set, false otherwise (a == null or zero length).</returns>
        public static bool ArrayMinMax(IList a, out double min, out double max)
        {
            if (a == null || a.Count == 0)
            {
                min = 0.0;
                max = 0.0;
                return(false);
            }

            min = Utils.ToDouble(a[0]);
            max = Utils.ToDouble(a[0]);

            foreach (object o in a)
            {
                double e = Utils.ToDouble(o);

                if ((min.Equals(double.NaN)) && (!e.Equals(double.NaN)))
                {
                    // if min/max are double.NaN and the current value not, then
                    // set them to the current value.
                    min = e;
                    max = e;
                }
                if (!double.IsNaN(e))
                {
                    if (e < min)
                    {
                        min = e;
                    }
                    if (e > max)
                    {
                        max = e;
                    }
                }
            }

            if (min.Equals(double.NaN))
            {
                // if min == double.NaN, then max is also double.NaN
                min = 0.0;
                max = 0.0;
                return(false);
            }

            return(true);
        }
예제 #5
0
            /// <summary>
            /// Gets the ith point in the candle adapter
            /// </summary>
            /// <param name="i">index of datapoint to get</param>
            /// <returns>the datapoint.</returns>
            public PointOLHC this[int i]
            {
                get
                {
                    // try a fast track first
                    if (useDoublesArrays_)
                    {
                        return(new PointOLHC(
                                   abscissaDataArray_[i],
                                   openDataArray_[i],
                                   lowDataArray_[i],
                                   highDataArray_[i],
                                   closeDataArray_[i]));
                    }

                    // is the data coming from a data source?
                    else if (rows_ != null)
                    {
                        double x     = Utils.ToDouble(((DataRow)(rows_[i]))[(string)abscissaData_]);
                        double open  = Utils.ToDouble(((DataRow)(rows_[i]))[(string)openData_]);
                        double low   = Utils.ToDouble(((DataRow)(rows_[i]))[(string)lowData_]);
                        double high  = Utils.ToDouble(((DataRow)(rows_[i]))[(string)highData_]);
                        double close = Utils.ToDouble(((DataRow)(rows_[i]))[(string)closeData_]);

                        return(new PointOLHC(x, open, low, high, close));
                    }

                    // the data is coming from individual arrays.
                    else if (abscissaData_ is Array && openData_ is Array && lowData_ is Array && highData_ is Array && closeData_ is Array)
                    {
                        double x     = Utils.ToDouble(((Array)abscissaData_).GetValue(i));
                        double open  = Utils.ToDouble(((Array)openData_).GetValue(i));
                        double low   = Utils.ToDouble(((Array)lowData_).GetValue(i));
                        double high  = Utils.ToDouble(((Array)highData_).GetValue(i));
                        double close = Utils.ToDouble(((Array)closeData_).GetValue(i));

                        return(new PointOLHC(x, open, low, high, close));
                    }

                    else
                    {
                        throw new NPlotException("not implemented yet");
                    }
                }
            }
예제 #6
0
 /// <summary>
 /// Gets the ith data value.
 /// </summary>
 /// <param name="i">sequence number of data to get.</param>
 /// <returns>ith data value.</returns>
 public double Get(int i)
 {
     return(Utils.ToDouble((rows_[i])[columnName_]));
 }
예제 #7
0
 /// <summary>
 /// Gets the ith data value.
 /// </summary>
 /// <param name="i">sequence number of data to get.</param>
 /// <returns>ith data value.</returns>
 public double Get(int i)
 {
     return(Utils.ToDouble(data_[i]));
 }
예제 #8
0
            /// <summary>
            /// Returns an x-axis that is suitable for drawing the data.
            /// </summary>
            /// <returns>A suitable x-axis.</returns>
            public Axis SuggestXAxis()
            {
                double min;
                double max;
                double minStep = 0.0;

                if (this.rows_ == null)
                {
                    Utils.ArrayMinMax((System.Collections.IList) this.abscissaData_, out min, out max);

                    if (((System.Collections.IList)abscissaData_).Count > 1)
                    {
                        double first  = Utils.ToDouble(((Array)abscissaData_).GetValue(0));
                        double second = Utils.ToDouble(((Array)abscissaData_).GetValue(1));
                        minStep = Math.Abs(second - first);
                    }
                    if (((System.Collections.IList)abscissaData_).Count > 2)
                    {
                        double first  = Utils.ToDouble(((Array)abscissaData_).GetValue(1));
                        double second = Utils.ToDouble(((Array)abscissaData_).GetValue(2));
                        if (Math.Abs(second - first) < minStep)
                        {
                            minStep = Math.Abs(second - first);
                        }
                    }
                    if (((System.Collections.IList)abscissaData_)[0] is DateTime)
                    {
                        return(new DateTimeAxis(min - minStep / 2.0, max + minStep / 2.0));
                    }
                    else
                    {
                        return(new LinearAxis(min - minStep / 2.0, max + minStep / 2.0));
                    }
                }
                else
                {
                    Utils.RowArrayMinMax(this.rows_, out min, out max, (string)this.abscissaData_);

                    if (rows_.Count > 1)
                    {
                        double first  = Utils.ToDouble(rows_[0][(string)abscissaData_]);
                        double second = Utils.ToDouble(rows_[1][(string)abscissaData_]);
                        minStep = Math.Abs(second - first);
                    }
                    if (rows_.Count > 2)
                    {
                        double first  = Utils.ToDouble(rows_[1][(string)abscissaData_]);
                        double second = Utils.ToDouble(rows_[2][(string)abscissaData_]);
                        if (Math.Abs(second - first) < minStep)
                        {
                            minStep = Math.Abs(second - first);
                        }
                    }

                    if ((rows_[0])[(string)abscissaData_] is DateTime)
                    {
                        return(new DateTimeAxis(min - minStep / 2.0, max + minStep / 2.0));
                    }
                    else
                    {
                        return(new LinearAxis(min - minStep / 2.0, max + minStep / 2.0));
                    }
                }
            }