Beispiel #1
0
        /// <summary>
        /// Parses the 2d array.
        /// </summary>
        /// <param name="dataArray">The data array.</param>
        /// <param name="getRangeFromData">if set to <c>true</c> [get range from data].</param>
        /// <param name="realRange">The real range.</param>
        /// <param name="viewModel">The view model.</param>
        private static void Parse2DArray(Array dataArray, bool getRangeFromData, RealRange realRange, ref MatrixCanvasViewModel viewModel)
        {
            viewModel.RowSums = new double[dataArray.Length];

            for (int i = 0; i < dataArray.GetLength(0); i++)
            {
                for (int j = 0; j < dataArray.GetLength(1); j++)
                {
                    object val  = dataArray.GetValue(i, j);
                    double dval = Convert.ToDouble(val);
                    viewModel.DataType    = Type.GetTypeCode(val.GetType());
                    viewModel.RowSums[i] += dval;

                    if (!getRangeFromData)
                    {
                        continue;
                    }

                    realRange.Expand(dval);
                }
            }

            realRange.FixErrors();
            viewModel.DataRange = realRange;
            viewModel.Rows      = dataArray.GetLength(0);
            viewModel.Cols      = dataArray.GetLength(1);
        }
Beispiel #2
0
        /// <summary>
        /// Parses the jagged array.
        /// </summary>
        /// <param name="dataArray">The data array.</param>
        /// <param name="getRangeFromData">if set to <c>true</c> [get range from data].</param>
        /// <param name="realRange">The real range.</param>
        /// <param name="viewModel">The view model.</param>
        private static void ParseJaggedArray(Array dataArray, bool getRangeFromData, RealRange realRange, ref MatrixCanvasViewModel viewModel)
        {
            // This is a jagged array
            // First get the length of the longest row
            List <int> rowLengths = new List <int>();

            viewModel.RowSums = new double[dataArray.Length];

            for (int i = 0; i < dataArray.Length; i++)
            {
                Array row = dataArray.GetValue(i) as Array;
                if ((row == null) || (row.Rank == 0) || (row.Length == 0))
                {
                    rowLengths.Add(0);
                    continue;
                }

                if (row.Rank > 1)
                {
                    // Deeper than two dimensions - return without creating data object
                    viewModel.DataType = TypeCode.Empty;
                    break;
                }

                rowLengths.Add(row.Length);

                for (int j = 0; j < row.Length; j++)
                {
                    var val = row.GetValue(j);
                    if (viewModel.DataType == TypeCode.Empty && val != null)
                    {
                        viewModel.DataType = Type.GetTypeCode(val.GetType());
                    }

                    double dval = Convert.ToDouble(val);
                    viewModel.RowSums[i] += dval;

                    if (!getRangeFromData)
                    {
                        continue;
                    }

                    realRange.Expand(dval);
                }
            }

            realRange.FixErrors();
            viewModel.RowLengths = rowLengths.ToArray();
            viewModel.DataRange  = realRange;
            viewModel.Rows       = dataArray.Length;
            viewModel.Cols       = rowLengths.Max();
        }