private Annotation GetSelectedAnnotation(IEnumerable <Annotation> annotations, Point currentPosition) { Annotation selectedAnnotation = null; foreach (Annotation annotation in annotations) { var isPointInside = AnnotationManager.CheckPointInsideAnnotation(annotation, currentPosition); annotation.IsSelected = isPointInside && annotation is ShapeAnnotation; if (annotation.IsSelected) { selectedAnnotation = annotation; } else if (annotation is VerticalLineAnnotation && (annotation as VerticalLineAnnotation).AxisMarkerObject != null && (annotation as VerticalLineAnnotation).AxisMarkerObject.RotatedRect.Contains(currentPosition)) { selectedAnnotation = (annotation as VerticalLineAnnotation).AxisMarkerObject; } else if (annotation is HorizontalLineAnnotation && (annotation as HorizontalLineAnnotation).AxisMarkerObject != null && (annotation as HorizontalLineAnnotation).AxisMarkerObject.RotatedRect.Contains(currentPosition)) { selectedAnnotation = (annotation as HorizontalLineAnnotation).AxisMarkerObject; } if (selectedAnnotation == null && isPointInside) { CurrentAnnotation = annotation; } else if (selectedAnnotation != null) { CurrentAnnotation = selectedAnnotation; } } return(selectedAnnotation); }
/// <summary> /// Maps the co-ordinates values to points. /// </summary> private void MapPixelToActualValue() { double x1Value, x2Value, y1Value, y2Value; if (isSwapX) { x1Value = isAxis ? SfChart.PointToAnnotationValue(XAxis, isRotated ? new Point(0, x2) : new Point(x2, 0)) : x2; x2Value = isAxis ? SfChart.PointToAnnotationValue(XAxis, isRotated ? new Point(0, x1) : new Point(x1, 0)) : x1; } else { x1Value = isAxis ? SfChart.PointToAnnotationValue(XAxis, isRotated ? new Point(0, x1) : new Point(x1, 0)) : x1; x2Value = isAxis ? SfChart.PointToAnnotationValue(XAxis, isRotated ? new Point(0, x2) : new Point(x2, 0)) : x2; } if (isSwapY) { y2Value = isAxis ? SfChart.PointToAnnotationValue(YAxis, isRotated ? new Point(y1, 0) : new Point(0, y1)) : y1; y1Value = isAxis ? SfChart.PointToAnnotationValue(YAxis, isRotated ? new Point(y2, 0) : new Point(0, y2)) : y2; } else { y2Value = isAxis ? SfChart.PointToAnnotationValue(YAxis, isRotated ? new Point(y2, 0) : new Point(0, y2)) : y2; y1Value = isAxis ? SfChart.PointToAnnotationValue(YAxis, isRotated ? new Point(y1, 0) : new Point(0, y1)) : y1; } AnnotationManager annotationManager = chart.AnnotationManager; ShapeAnnotation annotation = annotationManager.CurrentAnnotation as ShapeAnnotation; AnnotationManager.SetPosition( annotationManager.PreviousPoints, annotation.X1, annotation.X2, annotation.Y1, annotation.Y2); AnnotationManager.SetPosition(annotationManager.CurrentPoints, x1Value, x2Value, y1Value, y2Value); annotationManager.RaiseDragStarted(); // Raise the DragStarted event annotationManager.RaiseDragDelta(); // Raise the DragDelta event if (!annotationManager.DragDeltaArgs.Cancel) { ActualX1 = x1Value; ActualY1 = y1Value; ActualX2 = x2Value; ActualY2 = y2Value; } }
private void AnnotationDrag(double xTranslate, double yTranslate) { ShapeAnnotation selectedAnnotation = (SelectedAnnotation as ShapeAnnotation); var lineAnnotation = selectedAnnotation as LineAnnotation; bool isDraggable = (selectedAnnotation.CanResize && AnnotationResizer != null) ? !AnnotationResizer.IsResizing : (lineAnnotation != null) ? !lineAnnotation.IsResizing : true; object x1, x2, y1, y2; if (selectedAnnotation.CanDrag && isDraggable) { selectedAnnotation.IsDragging = true; bool isXAxis = selectedAnnotation.DraggingMode == AxisMode.Horizontal; bool isYAxis = selectedAnnotation.DraggingMode == AxisMode.Vertical; bool isAll = selectedAnnotation.DraggingMode == AxisMode.All; if (selectedAnnotation.CoordinateUnit == CoordinateUnit.Pixel) { x1 = (isAll || isXAxis) ? Convert.ToDouble(selectedAnnotation.X1) + xTranslate : selectedAnnotation.X1; x2 = (isAll || isXAxis) ? Convert.ToDouble(selectedAnnotation.X2) + xTranslate : selectedAnnotation.X2; y1 = (isAll || isYAxis) ? Convert.ToDouble(selectedAnnotation.Y1) + yTranslate : selectedAnnotation.Y1; y2 = (isAll || isYAxis) ? Convert.ToDouble(selectedAnnotation.Y2) + yTranslate : selectedAnnotation.Y2; } else { xTranslate = selectedAnnotation.XAxis.IsInversed ? -xTranslate : xTranslate; yTranslate = selectedAnnotation.YAxis.IsInversed ? -yTranslate : yTranslate; double xAxisChange = selectedAnnotation.XAxis.PixelToCoefficientValue(xTranslate); double yAxisChange = selectedAnnotation.YAxis.PixelToCoefficientValue(yTranslate); x2 = (isAll || isXAxis) ? Annotation.ConvertToObject(CalculatePointValue(selectedAnnotation.X2, xAxisChange, true, false), selectedAnnotation.XAxis) : selectedAnnotation.X2; x1 = (isAll || isXAxis) ? Annotation.ConvertToObject(CalculatePointValue(selectedAnnotation.X1, xAxisChange, true, false), selectedAnnotation.XAxis) : selectedAnnotation.X1; y2 = (isAll || isYAxis) ? Annotation.ConvertToObject(CalculatePointValue(selectedAnnotation.Y2, yAxisChange, false, false), selectedAnnotation.YAxis) : selectedAnnotation.Y2; y1 = (isAll || isYAxis) ? Annotation.ConvertToObject(CalculatePointValue(selectedAnnotation.Y1, yAxisChange, false, false), selectedAnnotation.YAxis) : selectedAnnotation.Y1; } AnnotationManager.SetPosition( PreviousPoints, selectedAnnotation.X1, selectedAnnotation.X2, selectedAnnotation.Y1, selectedAnnotation.Y2); AnnotationManager.SetPosition(CurrentPoints, x1, x2, y1, y2); RaiseDragStarted(); // Raise DragStarted event RaiseDragDelta(); // Raise the DragDelta event if (!DragDeltaArgs.Cancel) { if (AnnotationResizer != null && !AnnotationResizer.IsResizing) { selectedAnnotation.X1 = AnnotationResizer.X1 = x1; selectedAnnotation.X2 = AnnotationResizer.X2 = x2; selectedAnnotation.Y1 = AnnotationResizer.Y1 = y1; selectedAnnotation.Y2 = AnnotationResizer.Y2 = y2; } else { selectedAnnotation.X1 = x1; selectedAnnotation.X2 = x2; selectedAnnotation.Y1 = y1; selectedAnnotation.Y2 = y2; } var axisMarker = selectedAnnotation as AxisMarker; if (axisMarker != null) { if (axisMarker.ParentAnnotation is VerticalLineAnnotation) { if (axisMarker.ParentAnnotation.XAxis.Orientation == Orientation.Horizontal) { axisMarker.ParentAnnotation.X1 = selectedAnnotation.X1; } else { axisMarker.ParentAnnotation.Y1 = selectedAnnotation.Y1; } } else { if (axisMarker.ParentAnnotation.XAxis.Orientation == Orientation.Vertical) { axisMarker.ParentAnnotation.X1 = selectedAnnotation.X1; } else { axisMarker.ParentAnnotation.Y1 = selectedAnnotation.Y1; } } } if (AnnotationResizer != null) { AnnotationResizer.MapActualValueToPixels(); } } selectedAnnotation.IsDragging = false; } }
private void OnNearThumbDragDelta(object sender, DragDeltaEventArgs e) { this.IsResizing = true; annotationManager = Chart.AnnotationManager; double x2 = 0, y2 = 0; isRotated = (XAxis != null && XAxis.Orientation == Orientation.Vertical && IsAxis); HorizontalChange = isRotated ? e.VerticalChange : e.HorizontalChange; VerticalChange = isRotated ? e.HorizontalChange : e.VerticalChange; ShapeAnnotation annotation = annotationManager.CurrentAnnotation as ShapeAnnotation; AnnotationManager.SetPosition( annotationManager.PreviousPoints, annotation.X1, annotation.X2, annotation.Y1, annotation.Y2); if (!isRotated) { if (IsHorizontal) { x2 = IsAxis ? SfChart.PointToAnnotationValue(XAxis, new Point(ActualX2 + HorizontalChange, 0)) : ActualX2 + HorizontalChange; AnnotationManager.SetPosition( annotationManager.CurrentPoints, annotation.X1, x2, annotation.Y1, annotation.Y2); } if (IsVertical) { y2 = IsAxis ? SfChart.PointToAnnotationValue(YAxis, new Point(0, ActualY2 + VerticalChange)) : ActualY2 + VerticalChange; AnnotationManager.SetPosition( annotationManager.CurrentPoints, annotation.X1, annotation.X2, annotation.Y1, y2); } } else { if (IsVertical) { x2 = IsAxis ? SfChart.PointToAnnotationValue(XAxis, new Point(0, ActualX2 + HorizontalChange)) : ActualX2 + HorizontalChange; AnnotationManager.SetPosition( annotationManager.CurrentPoints, annotation.X1, x2, annotation.Y1, annotation.Y2); } if (IsHorizontal) { y2 = IsAxis ? SfChart.PointToAnnotationValue(YAxis, new Point(ActualY2 + VerticalChange, 0)) : ActualY2 + VerticalChange; AnnotationManager.SetPosition( annotationManager.CurrentPoints, annotation.X1, annotation.X2, annotation.Y1, y2); } } annotationManager.RaiseDragStarted(); // Raise the DragStarted event annotationManager.RaiseDragDelta(); // Raise the DragDelta event if (!annotationManager.DragDeltaArgs.Cancel) { if ((!isRotated && IsHorizontal) || (isRotated && IsVertical)) { ActualX2 = x2; } if ((!isRotated && IsVertical) || (isRotated && IsHorizontal)) { ActualY2 = y2; } } }