/// <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 phenologyColumnName = FindPhenologyStageColumn(data); if (phenologyColumnName != null && data.Columns.Contains(xFieldName)) { string[] names = DataTableUtilities.GetColumnAsStrings(data, phenologyColumnName); DateTime[] dates = DataTableUtilities.GetColumnAsDates(data, xFieldName); if (names.Length == dates.Length) { 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 = dates[i]; line.y1 = double.MinValue; line.x2 = dates[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 = dates[i]; text.y = double.MinValue; text.textRotation = 270; annotations.Add(text); } } } } } }
/// <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 phenologyColumnName = FindPhenologyStageColumn(data); if (phenologyColumnName != null && data.Table.Columns.Contains(xFieldName)) { string[] names = DataTableUtilities.GetColumnAsStrings(data, phenologyColumnName); DateTime[] dates = DataTableUtilities.GetColumnAsDates(data, xFieldName); if (names.Length == dates.Length) { for (int i = 0; i < names.Length; i++) { if (names[i] != "?") { // Add a line annotation. LineAnnotation line = new LineAnnotation(); line.colour = Color.Black; line.type = LineType.Dot; line.x1 = dates[i]; line.y1 = double.MinValue; line.x2 = dates[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 = dates[i]; text.y = double.MinValue; text.textRotation = 270; annotations.Add(text); } } } } } }
private static void AddAnnotation(List <Annotation> annotations, List <object> x, Color baseColour, Dictionary <string, Color> colourMap, int startIndex, string startName, int i) { 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); }
/// <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; } } } } } } }
/// <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 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); } } } } } }