Annotation GetHoveredAnnotation(Point mouseLocation) { foreach (Annotation annotation in Chart.AnnotationRepository) { PaneAnchorPoint anchorPoint = (PaneAnchorPoint)annotation.AnchorPoint; XYDiagram diagram = ((XYDiagram)Chart.Diagram); DateTime argument = (DateTime)anchorPoint.AxisXCoordinate.AxisValue; if ((DateTime)diagram.AxisX.VisualRange.MaxValue < argument || (DateTime)diagram.AxisX.VisualRange.MinValue > argument) { continue; } ControlCoordinates coords = diagram.DiagramToPoint((DateTime)anchorPoint.AxisXCoordinate.AxisValue, (double)anchorPoint.AxisYCoordinate.AxisValue, anchorPoint.AxisXCoordinate.Axis, anchorPoint.AxisYCoordinate.Axis, anchorPoint.Pane); if (coords.Visibility == ControlCoordinatesVisibility.Visible) { RelativePosition position = (RelativePosition)annotation.ShapePosition; Point center = new Point((int)(coords.Point.X + Math.Cos(position.Angle / 180 * Math.PI) * position.ConnectorLength), (int)(coords.Point.Y - Math.Sin(position.Angle / 180 * Math.PI) * position.ConnectorLength)); int diffX = Math.Abs(center.X - mouseLocation.X); int diffY = Math.Abs(center.Y - mouseLocation.Y); if (diffX <= annotation.Width / 2 && diffY <= annotation.Height / 2) { return(annotation); } } } return(null); }
public void AddTextAnnotation(string txt, DateTime x, Double y, float fontsize, int angle, Color textcolor) { string annotationname = String.Format("a{0}", this.chart.Annotations.Count); TextAnnotation myTextAnnotation = this.chart.Annotations.AddTextAnnotation(annotationname, txt); Font font = new Font("Arial", fontsize); RelativePosition position = new RelativePosition(); myTextAnnotation.ShapePosition = position; PaneAnchorPoint anchorPoint = new PaneAnchorPoint(); myTextAnnotation.AnchorPoint = anchorPoint; position.ConnectorLength = 0; anchorPoint.AxisXCoordinate.AxisValue = x; anchorPoint.AxisYCoordinate.AxisValue = y; myTextAnnotation.TextAlignment = StringAlignment.Near; myTextAnnotation.Angle = angle; myTextAnnotation.Font = font; myTextAnnotation.TextColor = textcolor; myTextAnnotation.BackColor = Color.Transparent; myTextAnnotation.ShapeKind = ShapeKind.RoundedRectangle; myTextAnnotation.Border.Color = Color.Transparent; myTextAnnotation.ConnectorStyle = AnnotationConnectorStyle.None; }
public SCChart AddPaneAnnotation(string name, string text, string pane, string valueX, string valueY, string axisX = null, string axisY = null, AnnotationOptions options = null) { options ??= new AnnotationOptions(); options.AnchorDockPane = pane; var annotation = new TextAnnotation(); options.SetupXtraChartAnnotation(this, name, text, annotation); if (Chart.Diagram is not XYDiagram diagramXY) { throw new Exception("Panes are available only in 2D XY charts."); } var anchor = new PaneAnchorPoint(); if (!string.IsNullOrWhiteSpace(pane)) { var chartPane = diagramXY.Panes[pane]; anchor.Pane = chartPane ?? throw new Exception($"Cannot find pane '{pane}'."); } var axX = !string.IsNullOrWhiteSpace(axisX) ? diagramXY.FindAxisXByName(axisX) : diagramXY.AxisX; var axY = !string.IsNullOrWhiteSpace(axisY) ? diagramXY.FindAxisYByName(axisY) : diagramXY.AxisY; anchor.AxisXCoordinate.Axis = axX; anchor.AxisXCoordinate.AxisValue = valueX; anchor.AxisYCoordinate.Axis = axY; anchor.AxisYCoordinate.AxisValue = valueY; return(this); }
private void CreateAnnotations(StrategyDataItemInfo info) { if (Visual.Items.Count == 0) { return; } PropertyInfo pInfo = Visual.Items[0].GetType().GetProperty(info.FieldName, BindingFlags.Instance | BindingFlags.Public); PropertyInfo pAnchor = Visual.Items[0].GetType().GetProperty(info.AnnotationAnchorField, BindingFlags.Instance | BindingFlags.Public); PropertyInfo pTime = Visual.Items[0].GetType().GetProperty("Time", BindingFlags.Instance | BindingFlags.Public); XYDiagramPaneBase pane = ((XYDiagram)Chart.Diagram).DefaultPane; if (info.PanelName != "Default") { pane = ((XYDiagram)Chart.Diagram).Panes[info.PanelName]; } int index = 0; ResizeableArray <TextAnnotation> res = new ResizeableArray <TextAnnotation>(); info.DataSource = res; for (int i = 0; i < Visual.Items.Count; i++) { object obj = Visual.Items[i]; object value = pInfo.GetValue(obj); if (value == null) { index++; continue; } if (value is bool && !((bool)value)) { index++; continue; } DateTime time = (DateTime)pTime.GetValue(obj); double yValue = (double)pAnchor.GetValue(obj); string annotationText = string.Empty; if (info.HasAnnotationStringFormat) { annotationText = GetFormattedText(info.AnnotationText, obj); } else { annotationText = Convert.ToString(value); } TextAnnotation annotation = pane.Annotations.AddTextAnnotation(info.FieldName + "InPane" + info.PanelName, annotationText); res.Add(annotation); annotation.Tag = obj; annotation.ConnectorStyle = AnnotationConnectorStyle.Line; annotation.ShapeKind = ShapeKind.Rectangle; annotation.Font = new Font("Segoe UI", 6); ((RelativePosition)annotation.ShapePosition).Angle = 180; ((RelativePosition)annotation.ShapePosition).ConnectorLength = 70; PaneAnchorPoint point = new PaneAnchorPoint(); point.AxisXCoordinate.AxisValue = time; point.AxisYCoordinate.AxisValue = yValue; point.Pane = pane; annotation.AnchorPoint = point; annotation.ShapeKind = ShapeKind.Rectangle; annotation.ShapeKind = ShapeKind.Rectangle; index++; } }
protected virtual void SetupXtraChartAnnotation(TextAnnotation annotation) { AnchorDockPane = Pane ?? AnchorDockPane; //Need this to link annotation to series point in BoundDataChanged annotation.Tag = this; if (!string.IsNullOrWhiteSpace(Name)) { annotation.Name = Name; } annotation.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True; if (Angle.HasValue) { annotation.Angle = Angle.Value; } var backColor = Utils.ColorFromString(BackColor); if (backColor != Color.Empty) { annotation.BackColor = backColor; } var borderColor = Utils.ColorFromString(BorderColor); if (borderColor != Color.Empty) { annotation.Border.Color = borderColor; annotation.Border.Visibility = DevExpress.Utils.DefaultBoolean.True; } if (BorderThickness.HasValue) { annotation.Border.Thickness = BorderThickness.Value; annotation.Border.Visibility = DevExpress.Utils.DefaultBoolean.True; } if (BorderVisible.HasValue) { annotation.Border.Visibility = BorderVisible.Value ? DevExpress.Utils.DefaultBoolean.True : DevExpress.Utils.DefaultBoolean.Default; } if (FillMode.HasValue) { annotation.FillStyle.FillMode = FillMode.Value; switch (FillMode.Value) { case DevExpress.XtraCharts.FillMode.Empty: break; case DevExpress.XtraCharts.FillMode.Solid: break; case DevExpress.XtraCharts.FillMode.Gradient: if (annotation.FillStyle.Options is RectangleGradientFillOptions gradientOptions) { var backColor2 = Utils.ColorFromString(BackColor2); if (backColor2 != System.Drawing.Color.Empty) { gradientOptions.Color2 = backColor2; } if (FillGradientMode.HasValue) { gradientOptions.GradientMode = FillGradientMode.Value; } } break; case DevExpress.XtraCharts.FillMode.Hatch: if (annotation.FillStyle.Options is HatchFillOptions hatchOptions) { var backColor2 = Utils.ColorFromString(BackColor2); if (backColor2 != System.Drawing.Color.Empty) { hatchOptions.Color2 = backColor2; } if (FillHatchStyle.HasValue) { hatchOptions.HatchStyle = FillHatchStyle.Value; } } break; } } var font = Utils.StringToFont(Font, out Color textColor); if (font != null) { annotation.Font = font; } if (textColor != Color.Empty) { annotation.TextColor = textColor; } if (ConnectorStyle.HasValue) { annotation.ConnectorStyle = ConnectorStyle.Value; } if (Width.HasValue) { annotation.Width = Width.Value; annotation.AutoSize = false; } if (Height.HasValue) { annotation.Height = Height.Value; annotation.AutoSize = false; } if (Padding != null && Padding.Length == 1) { annotation.Padding.All = Padding[0]; } else if (Padding != null && Padding.Length == 4) { annotation.Padding.Left = Padding[0]; annotation.Padding.Top = Padding[1]; annotation.Padding.Right = Padding[2]; annotation.Padding.Bottom = Padding[3]; } else if (Padding != null) { throw new Exception("Invalid padding. Padding shall be an array with 1 or 4 integer values."); } var shadowColor = Utils.ColorFromString(ShadowColor); if (shadowColor != Color.Empty) { annotation.Shadow.Color = shadowColor; annotation.Shadow.Visible = true; } if (ShadowSize.HasValue) { annotation.Shadow.Size = ShadowSize.Value; annotation.Shadow.Visible = true; } if (ShapeFillet.HasValue) { annotation.ShapeFillet = ShapeFillet.Value; } if (ShapeKind.HasValue) { annotation.ShapeKind = ShapeKind.Value; } annotation.LabelMode = LabelMode; if (AnchorAngle.HasValue || AnchorConnectorLength.HasValue) { annotation.ShapePosition = new RelativePosition(AnchorAngle ?? 0.0, AnchorConnectorLength ?? 0.0); } else if (AnchorDockCorner.HasValue) { XYDiagramPane pane = null; if (!string.IsNullOrWhiteSpace(AnchorDockPane)) { if (ChartContext.Chart.Diagram is not XYDiagram2D diagramXY) { throw new Exception("Panes are available only in 2D XY charts."); } pane = diagramXY.Panes[AnchorDockPane]; if (pane == null) { throw new Exception($"Cannot find pane '{AnchorDockPane}'."); } } var freePosition = new FreePosition(); if (pane != null) { freePosition.DockTarget = pane; } freePosition.DockCorner = AnchorDockCorner.Value; if (DockInnerIndents != null && DockInnerIndents.Length == 1) { freePosition.InnerIndents.All = DockInnerIndents[0]; } else if (DockInnerIndents != null && DockInnerIndents.Length == 4) { freePosition.InnerIndents.Left = DockInnerIndents[0]; freePosition.InnerIndents.Top = DockInnerIndents[1]; freePosition.InnerIndents.Right = DockInnerIndents[2]; freePosition.InnerIndents.Bottom = DockInnerIndents[3]; } if (DockOuterIndents != null && DockOuterIndents.Length == 1) { freePosition.OuterIndents.All = DockOuterIndents[0]; } else if (DockOuterIndents != null && DockOuterIndents.Length == 4) { freePosition.OuterIndents.Left = DockOuterIndents[0]; freePosition.OuterIndents.Top = DockOuterIndents[1]; freePosition.OuterIndents.Right = DockOuterIndents[2]; freePosition.OuterIndents.Bottom = DockOuterIndents[3]; } annotation.ShapePosition = freePosition; } annotation.Text = Text; annotation.Visible = true; if (TextAlignment.HasValue) { annotation.TextAlignment = TextAlignment.Value; } if (ZOrder.HasValue) { annotation.ZOrder = ZOrder.Value; } switch (ParameterSetName) { case "Chart": annotation.AnchorPoint = new ChartAnchorPoint(X, Y); break; case "Pane": if (ChartContext.Chart.Diagram is not XYDiagram diagramXY) { throw new Exception("Panes are available only in 2D XY charts."); } var anchor = new PaneAnchorPoint(); if (!string.IsNullOrWhiteSpace(AnchorDockPane)) { var pane = diagramXY.Panes[AnchorDockPane]; anchor.Pane = pane ?? throw new Exception($"Cannot find pane '{AnchorDockPane}'."); } var axisX = !string.IsNullOrWhiteSpace(AxisX) ? diagramXY.FindAxisXByName(AxisX) : diagramXY.AxisX; var axisY = !string.IsNullOrWhiteSpace(AxisY) ? diagramXY.FindAxisYByName(AxisY) : diagramXY.AxisY; anchor.AxisXCoordinate.Axis = axisX; anchor.AxisXCoordinate.AxisValue = ValueX; anchor.AxisYCoordinate.Axis = axisY; anchor.AxisYCoordinate.AxisValue = ValueY; break; } }
// Draw sub piece range and annotation private void DrawSubPiece() { // get current using unit NowUnit ucd = _units.Find(x => x.ComponentName == "Flaw Map CD"); _totalScore = 0; DataRow[] flawRows = _dtbFlaws.Select(_dtbFlaws.DefaultView.RowFilter); ConfigHelper ch = new ConfigHelper(); string gradeConfigFile = ch.GetDefaultGradeConfigName(); DataTable gradeColumn = ch.GetDataTableOfdgvColumns(gradeConfigFile); DataTable gradeRow = ch.GetDataTableOfdgvRows(gradeConfigFile); string roiMode = ch.GetGradeNoRoiMode(gradeConfigFile); bool showScore = ch.IsGradePointEnable(gradeConfigFile); bool showGrade = ch.IsGradeMarksEnable(gradeConfigFile); if (roiMode == "Symmetrical") { foreach (DataRow drCol in gradeColumn.Rows) { foreach (DataRow drRow in gradeRow.Rows) { // Add rangearea string rangeName = String.Format("{0}{1}", drCol["Name"], drRow["Name"]); Series range = new Series(rangeName, ViewType.RangeArea); range.ShowInLegend = false; range.CrosshairEnabled = DevExpress.Utils.DefaultBoolean.False; range.ArgumentScaleType = ScaleType.Numerical; range.Points.Add(new SeriesPoint(drCol["Start"], drRow["Start"], drRow["End"])); range.Points.Add(new SeriesPoint(drCol["End"], drRow["Start"], drRow["End"])); RangeAreaSeriesView view = (RangeAreaSeriesView)range.View; view.Color = Color.Red; view.Transparency = 230; view.Marker1.Visible = false; view.Marker2.Visible = false; view.Border1.Color = Color.Transparent; view.Border2.Color = Color.Transparent; chartControl.Series.Add(range); int subPieceScore = 0; string subPieceGrade = "F"; if (showScore) { string subPieceFilter = String.Format("(CD >= {0} AND CD <= {1}) AND (MD > {2} AND MD < {3})", Convert.ToDouble(drCol["Start"]) / ucd.Conversion, Convert.ToDouble(drCol["End"]) / ucd.Conversion, (Convert.ToDouble(drRow["Start"]) / ucd.Conversion + _topOfPart), (Convert.ToDouble(drRow["End"]) / ucd.Conversion + _topOfPart)); DataRow[] subFlawRows = _dtbFlaws.Select(subPieceFilter); foreach (DataRow dr in subFlawRows) { string pointFilter = String.Format("SubpieceName = 'ROI-{0}' AND ClassName = '{1}'", rangeName, dr["FlawClass"]); subPieceScore += Convert.ToInt32(_dtbPoints.Select(pointFilter).First()["Score"]); } } if (showGrade) { string gradeFilter = String.Format("SubpieceName = 'ROI-{0}' AND Score >= {1}", rangeName, subPieceScore); DataRow[] r = _dtbGrades.Select(gradeFilter); if (_dtbGrades.Select(gradeFilter).Length > 0) { subPieceGrade = _dtbGrades.Select(gradeFilter).First()["GradeName"].ToString(); } } // Add annotation TextAnnotation annotation = new TextAnnotation(); PaneAnchorPoint paPoint = new PaneAnchorPoint(); RelativePosition relPosition = new RelativePosition(); annotation.LabelMode = true; annotation.BackColor = System.Drawing.Color.Transparent; annotation.Border.Visible = false; annotation.ConnectorStyle = AnnotationConnectorStyle.None; annotation.Font = new System.Drawing.Font("Tahoma", 8F, FontStyle.Bold); annotation.TextColor = Color.Blue; annotation.Name = rangeName; string annotationScore = ""; if (showScore) { annotationScore = String.Format(" - {0}", subPieceScore); } string annotationGrade = ""; if (showGrade) { annotationGrade = String.Format("({0})", subPieceGrade); } annotation.Text = String.Format("{0}{1}{2}", rangeName, annotationScore, annotationGrade); string annotationX = Convert.ToString(Convert.ToDouble(drCol["Start"]) + (Convert.ToDouble(drCol["End"]) - Convert.ToDouble(drCol["Start"])) * 0.3); string annotationY = Convert.ToString(Convert.ToDouble(drRow["End"]) - (Convert.ToDouble(drRow["End"]) - Convert.ToDouble(drRow["Start"])) * 0.1); paPoint.AxisXCoordinate.AxisValueSerializable = annotationX; paPoint.AxisYCoordinate.AxisValueSerializable = annotationY; annotation.AnchorPoint = paPoint; relPosition.Angle = 0; relPosition.ConnectorLength = 0; annotation.ShapePosition = relPosition; chartControl.AnnotationRepository.AddRange(new Annotation[] { annotation }); _totalScore += subPieceScore; } } } DrawDummyPoint(); // Calculate flaw quantity Dictionary<string, int> flawLegendRefDic = new Dictionary<string, int>(); int i = 0; foreach (DataGridViewRow dgvr in dgvFlawLegendDetial.Rows) { dgvr.Cells["PieceDoffNum"].Value = "0"; flawLegendRefDic.Add(dgvr.Cells["Name"].Value.ToString(), i); i++; } if (flawRows.Length > 0) { foreach (DataRow dr in flawRows) { string flawName = dr["FlawClass"].ToString(); int rowPosition = flawLegendRefDic[flawName]; int flawQuantity = Convert.ToInt32(dgvFlawLegendDetial.Rows[rowPosition].Cells["PieceDoffNum"].Value) + 1; dgvFlawLegendDetial.Rows[rowPosition].Cells["PieceDoffNum"].Value = flawQuantity.ToString(); } } }