Beispiel #1
0
        /// <summary>This refreshes data being displayed on the graphs, based on the value of the startYear and showYear values  </summary>
        /// <param name="table">The data set</param>
        /// <param name="startDate">The start date</param>
        /// <param name="endDate">The end date</param>
        /// <param name="updateYears">Update the years</param>
        private void DisplayGraphRadiation(DataTable table, DateTime startDate, DateTime endDate, bool updateYears)
        {
            try
            {
                if (table != null && table.Rows.Count > 0)
                {
                    DateTime[] dailyDates   = DataTableUtilities.GetColumnAsDates(table, "Date", startDate, endDate);
                    double[]   dailyRain    = DataTableUtilities.GetColumnAsDoubles(table, "rain", startDate, endDate);
                    double[]   dailyRadn    = DataTableUtilities.GetColumnAsDoubles(table, "radn", startDate, endDate);
                    double[]   dailyMaxRadn = DataTableUtilities.GetColumnAsDoubles(table, "Qmax", startDate, endDate);

                    if (dailyRadn.Length != 0)
                    {
                        this.PopulateRadiationGraph("Radiation", dailyDates, dailyRain, dailyRadn, dailyMaxRadn);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Unable to display Detailed Graphs due to insufficient data: " + e.Message.ToString());
            }
        }
Beispiel #2
0
 /// <summary>Gets a column of data from a view.</summary>
 /// <param name="data">The table</param>
 /// <param name="fieldName">Name of the field.</param>
 /// <returns>The column of data.</returns>
 private IEnumerable GetDataFromView(DataView data, string fieldName)
 {
     if (fieldName != null && data != null && data.Table.Columns.Contains(fieldName))
     {
         if (data.Table.Columns[fieldName].DataType == typeof(DateTime))
         {
             return(DataTableUtilities.GetColumnAsDates(data, fieldName));
         }
         else if (data.Table.Columns[fieldName].DataType == typeof(string))
         {
             return(DataTableUtilities.GetColumnAsStrings(data, fieldName));
         }
         else if (data.Table.Columns[fieldName].DataType == typeof(int))
         {
             return(DataTableUtilities.GetColumnAsIntegers(data, fieldName));
         }
         else
         {
             return(DataTableUtilities.GetColumnAsDoubles(data, fieldName));
         }
     }
     return(null);
 }
        /// <summary>Called by the graph presenter to get a list of all annotations to put on the graph.</summary>
        /// <param name="annotations">A list of annotations to add to.</param>
        public void GetAnnotationsToPutOnGraph(List <Annotation> annotations)
        {
            Graph parentGraph = Parent.Parent as Graph;

            if (data != null && ColumnName != null && xFieldName != null)
            {
                string columnName = FindColumn(data);
                if (columnName != null && data.Columns.Contains(xFieldName))
                {
                    string[]      names = DataTableUtilities.GetColumnAsStrings(data, columnName);
                    List <object> x;
                    Type          columnType = data.Columns[xFieldName].DataType;
                    if (columnType == typeof(DateTime))
                    {
                        x = DataTableUtilities.GetColumnAsDates(data, xFieldName).Cast <object>().ToList();
                    }
                    else if (columnType == typeof(int))
                    {
                        x = DataTableUtilities.GetColumnAsIntegers(data, xFieldName).Cast <object>().ToList();
                    }
                    else if (columnType == typeof(double))
                    {
                        x = DataTableUtilities.GetColumnAsDoubles(data, xFieldName).Cast <object>().ToList();
                    }
                    else
                    {
                        throw new Exception($"Error in EventNamesOnGraph {Name}: unknown column type '{columnType.FullName}' in column '{xFieldName}'");
                    }

                    if (names.Length == x.Count)
                    {
                        var    baseColour = Color.LightBlue;
                        var    colourMap  = new Dictionary <string, Color>();
                        int    startIndex = -1;
                        string startName  = string.Empty;
                        for (int i = 0; i < names.Length; i++)
                        {
                            if (startIndex == -1)
                            {
                                startIndex = i;
                                startName  = names[i];
                            }
                            else if (names[i] != startName)
                            {
                                if (!string.IsNullOrEmpty(startName))
                                {
                                    // Add a line annotation.
                                    AddAnnotation(annotations, x, baseColour, colourMap, startIndex, startName, i);
                                }
                                startName  = names[i];
                                startIndex = i;
                            }
                        }
                        if (startIndex != -1)
                        {
                            AddAnnotation(annotations, x, baseColour, colourMap, startIndex, startName, names.Length);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>Called by the graph presenter to get a list of all annotations to put on the graph.</summary>
        public IEnumerable <IAnnotation> GetAnnotations()
        {
            List <IAnnotation> annotations = new List <IAnnotation>();
            Graph parentGraph = Parent.Parent as Graph;

            if (data != null && ColumnName != null && xFieldName != null)
            {
                string phenologyColumnName = FindPhenologyStageColumn(data);
                if (phenologyColumnName != null && data.Columns.Contains(xFieldName))
                {
                    string[]      names = DataTableUtilities.GetColumnAsStrings(data, phenologyColumnName);
                    List <object> x;
                    Type          columnType = data.Columns[xFieldName].DataType;
                    if (columnType == typeof(DateTime))
                    {
                        x = DataTableUtilities.GetColumnAsDates(data, xFieldName).Cast <object>().ToList();
                    }
                    else if (columnType == typeof(int))
                    {
                        x = DataTableUtilities.GetColumnAsIntegers(data, xFieldName).Cast <object>().ToList();
                    }
                    else if (columnType == typeof(double))
                    {
                        x = DataTableUtilities.GetColumnAsDoubles(data, xFieldName).Cast <object>().ToList();
                    }
                    else
                    {
                        throw new Exception($"Error in EventNamesOnGraph {Name}: unknown column type '{columnType.FullName}' in column '{xFieldName}'");
                    }

                    if (names.Length == x.Count)
                    {
                        for (int i = 0; i < names.Length; i++)
                        {
                            if (names[i] != "?" && !string.IsNullOrEmpty(names[i]))
                            {
                                // Add a line annotation.
                                LineAnnotation line = new LineAnnotation();
                                line.colour = Color.Black;
                                line.type   = LineType.Dot;
                                line.x1     = x[i];
                                line.y1     = double.MinValue;
                                line.x2     = x[i];
                                line.y2     = double.MaxValue;
                                annotations.Add(line);

                                // Add a text annotation.

                                TextAnnotation text = new TextAnnotation();
                                text.text      = names[i];
                                text.colour    = Color.Black;
                                text.leftAlign = true;
                                text.x         = x[i];

                                text.y            = double.MinValue;
                                text.textRotation = 270;
                                annotations.Add(text);
                            }
                        }
                    }
                }
            }
            return(annotations);
        }
        /// <summary>Called by the graph presenter to get a list of all annotations to put on the graph.</summary>
        /// <param name="annotations">A list of annotations to add to.</param>
        public void GetAnnotationsToPutOnGraph(List <Annotation> annotations)
        {
            Graph parentGraph = Parent.Parent as Graph;

            if (data != null && ColumnName != null && xFieldName != null)
            {
                string columnName = FindColumn(data);
                if (columnName != null && data.Columns.Contains(xFieldName))
                {
                    string[]      names = DataTableUtilities.GetColumnAsStrings(data, columnName);
                    List <object> x;
                    Type          columnType = data.Columns[xFieldName].DataType;
                    if (columnType == typeof(DateTime))
                    {
                        x = DataTableUtilities.GetColumnAsDates(data, xFieldName).Cast <object>().ToList();
                    }
                    else if (columnType == typeof(int))
                    {
                        x = DataTableUtilities.GetColumnAsIntegers(data, xFieldName).Cast <object>().ToList();
                    }
                    else if (columnType == typeof(double))
                    {
                        x = DataTableUtilities.GetColumnAsDoubles(data, xFieldName).Cast <object>().ToList();
                    }
                    else
                    {
                        throw new Exception($"Error in EventNamesOnGraph {Name}: unknown column type '{columnType.FullName}' in column '{xFieldName}'");
                    }

                    if (names.Length == x.Count)
                    {
                        var    baseColour = Color.LightBlue;
                        var    colourMap  = new Dictionary <string, Color>();
                        int    startIndex = -1;
                        string startName  = string.Empty;
                        for (int i = 0; i < names.Length; i++)
                        {
                            if (names[i] != "?" && !string.IsNullOrEmpty(names[i]))
                            {
                                if (startIndex == -1)
                                {
                                    startIndex = i;
                                    startName  = names[i];
                                }
                                else if (names[i] != startName)
                                {
                                    // Add a line annotation.
                                    var bar = new LineAnnotation();
                                    if (colourMap.ContainsKey(startName))
                                    {
                                        bar.colour = colourMap[startName];
                                    }
                                    else
                                    {
                                        bar.colour = ColourUtilities.ChangeColorBrightness(baseColour, colourMap.Count * 0.2);
                                        colourMap.Add(startName, bar.colour);
                                    }
                                    bar.type            = LineType.Dot;
                                    bar.x1              = x[startIndex];
                                    bar.y1              = double.MinValue;
                                    bar.x2              = x[i - 1];
                                    bar.y2              = double.MaxValue;
                                    bar.InFrontOfSeries = false;
                                    bar.ToolTip         = startName;
                                    annotations.Add(bar);

                                    startName  = names[i];
                                    startIndex = i;
                                }
                            }
                        }
                    }
                }
            }
        }