/// <summary> /// Updates the annotation. /// </summary> public override void UpdateAnnotation() { if (shape != null && X1 != null && X2 != null && Y1 != null && Y2 != null) { ValidateSelection(); switch (CoordinateUnit) { case CoordinateUnit.Axis: SetAxisFromName(); if (XAxis != null && YAxis != null && ShowLine) { x1 = Annotation.ConvertData(X1, XAxis); y1 = Annotation.ConvertData(Y1, YAxis); y2 = Annotation.ConvertData(Y2, YAxis); x2 = Annotation.ConvertData(X2, XAxis); if (CoordinateUnit == CoordinateUnit.Axis && EnableClipping) { x1 = GetClippingValues(x1, XAxis); y1 = GetClippingValues(y1, YAxis); x2 = GetClippingValues(x2, XAxis); y2 = GetClippingValues(y2, YAxis); } Point point = (XAxis.Orientation == Orientation.Horizontal) ? new Point( this.Chart.ValueToPointRelativeToAnnotation(XAxis, x1), this.Chart.ValueToPointRelativeToAnnotation(YAxis, y1)) : new Point( this.Chart.ValueToPointRelativeToAnnotation(YAxis, y1), this.Chart.ValueToPointRelativeToAnnotation(XAxis, x1)); Point point2 = (XAxis.Orientation == Orientation.Horizontal) ? new Point( this.Chart.ValueToPointRelativeToAnnotation(XAxis, x2), this.Chart.ValueToPointRelativeToAnnotation(YAxis, y2)) : new Point( this.Chart.ValueToPointRelativeToAnnotation(YAxis, y2), this.Chart.ValueToPointRelativeToAnnotation(XAxis, x2)); DrawLine(point, point2, shape); } break; case CoordinateUnit.Pixel: if (ShowLine) { Point elementPoint1 = new Point(Convert.ToDouble(X1), Convert.ToDouble(Y1)); Point elementPoint2 = new Point(Convert.ToDouble(X2), Convert.ToDouble(Y2)); DrawLine(elementPoint1, elementPoint2, shape); } break; } } else if (shape != null) { ClearValues(); } }
protected override DoubleRange CalculateActualRange() { if (Minimum == null && Maximum == null) // Executes when Minimum and Maximum aren't set. { DoubleRange range = LogarithmicAxisHelper.CalculateActualRange(this, CalculateBaseActualRange(), LogarithmicBase); // Execute when include the annotion range for Auto Range if (IncludeAnnotationRange) { foreach (var annotation in (Area as SfChart).Annotations) { if (Orientation == Orientation.Vertical && annotation.CoordinateUnit == CoordinateUnit.Axis && annotation.YAxis == this) { range += new DoubleRange( Annotation.ConvertData(annotation.Y1, this), annotation is TextAnnotation ? Annotation.ConvertData(annotation.Y1, this) : annotation is ImageAnnotation ? Annotation.ConvertData((annotation as ImageAnnotation).Y2, this) : Annotation.ConvertData((annotation as ShapeAnnotation).Y2, this)); } else if (Orientation == Orientation.Horizontal && annotation.CoordinateUnit == CoordinateUnit.Axis && annotation.XAxis == this) { range += new DoubleRange( Annotation.ConvertData(annotation.X1, this), annotation is TextAnnotation ? Annotation.ConvertData(annotation.X1, this) : annotation is ImageAnnotation ? Annotation.ConvertData((annotation as ImageAnnotation).X2, this) : Annotation.ConvertData((annotation as ShapeAnnotation).X2, this)); } } } return(range); } else if (Minimum != null && Maximum != null) // Executes when Minimum and Maximum is set. { return(ActualRange); } else { // Executes when either Minimum or Maximum is set. DoubleRange range = CalculateBaseActualRange(); range = LogarithmicAxisHelper.CalculateActualRange(this, range, LogarithmicBase); if (Minimum != null) { return(new DoubleRange(ActualRange.Start, range.End)); } if (Maximum != null) { return(new DoubleRange(range.Start, ActualRange.End)); } return(range); } }
private double CalculatePointValue(object value, double change, bool isXAxis, bool isAngleInPhone) { ShapeAnnotation selectedAnnotation = (SelectedAnnotation is ShapeAnnotation) ? (SelectedAnnotation as ShapeAnnotation) : null; change = isAngleInPhone ? change * -1 : change; if (isXAxis) { return(Annotation.ConvertData(value, selectedAnnotation.XAxis) + change); } return(Annotation.ConvertData(value, selectedAnnotation.YAxis) - change); }
protected override DoubleRange CalculateActualRange() { if (Minimum == null && Maximum == null) // Executes when Minimum and Maximum aren't set. { DoubleRange range = base.CalculateActualRange(); if (Orientation == Orientation.Horizontal && IncludeAnnotationRange && Area != null) { foreach (var annotation in (Area as SfChart).Annotations) { if (annotation.CoordinateUnit == CoordinateUnit.Axis && annotation.XAxis == this) { range += new DoubleRange( (Annotation.ConvertData(annotation.X1, this) == 0d ? range.Start : Annotation.ConvertData(annotation.X1, this)), (annotation is TextAnnotation ? (Annotation.ConvertData(annotation.X1, this) == 0d ? range.Start : Annotation.ConvertData(annotation.X1, this)) : annotation is ImageAnnotation ? (Annotation.ConvertData((annotation as ImageAnnotation).X2, this) == 0d ? range.Start : Annotation.ConvertData((annotation as ImageAnnotation).X2, this)) : (Annotation.ConvertData((annotation as ShapeAnnotation).X2, this) == 0d ? range.Start : Annotation.ConvertData((annotation as ShapeAnnotation).X2, this)))); } } } return(range); } else if (Minimum != null && Maximum != null) // Executes when Minimum and Maximum are set. { return(ActualRange); } else { // Executes when either Minimum or Maximum. DoubleRange range = base.CalculateActualRange(); if (Minimum != null) { return(new DoubleRange(ActualRange.Start, double.IsNaN(range.End) ? ActualRange.Start + 1 : range.End)); } else if (Maximum != null) { return(new DoubleRange(double.IsNaN(range.Start) ? ActualRange.End - 1 : range.Start, ActualRange.End)); } return(range); } }
internal void HeightWidthChanged() { switch (CoordinateUnit) { case CoordinateUnit.Axis: this.ImageHeight = Annotation.ConvertData(this.Y2, this.YAxis); this.ImageWidth = Annotation.ConvertData(this.X2, this.XAxis); break; } UpdateAnnotation(); if (Chart != null && this.CoordinateUnit == CoordinateUnit.Axis && CanUpdateRange(this.X2, this.Y2)) { Chart.ScheduleUpdate(); } }
/// <summary> /// Updates the annotation /// </summary> public override void UpdateAnnotation() { if (_image != null && X1 != null && Y1 != null) { Point textPosition = new Point(); Size desiredSize; Rect heightAndWidthRect; RotateTransform rotate = new RotateTransform { Angle = this.Angle }; Point positionedPoint = new Point(0, 0); TextElement.Visibility = Visibility.Visible; switch (CoordinateUnit) { case CoordinateUnit.Axis: base.UpdateAnnotation(); if (XAxis != null && YAxis != null) { ImageHeight = Annotation.ConvertData(Y2, YAxis); ImageWidth = Annotation.ConvertData(X2, XAxis); if (CoordinateUnit == CoordinateUnit.Axis && EnableClipping) { x1 = GetClippingValues(x1, XAxis); y1 = GetClippingValues(y1, YAxis); ImageWidth = GetClippingValues(ImageWidth, XAxis); ImageHeight = GetClippingValues(ImageHeight, YAxis); } Point point = (XAxis.Orientation == Orientation.Horizontal) ? new Point( this.Chart.ValueToPointRelativeToAnnotation(XAxis, x1), this.Chart.ValueToPointRelativeToAnnotation(YAxis, y1)) : new Point( this.Chart.ValueToPointRelativeToAnnotation(YAxis, y1), this.Chart.ValueToPointRelativeToAnnotation(XAxis, x1)); Point point2 = (XAxis.Orientation == Orientation.Horizontal) ? new Point( Chart.ValueToPointRelativeToAnnotation(XAxis, ImageWidth), this.Chart.ValueToPointRelativeToAnnotation(YAxis, ImageHeight)) : new Point( this.Chart.ValueToPointRelativeToAnnotation(YAxis, ImageHeight), Chart.ValueToPointRelativeToAnnotation(XAxis, ImageWidth)); point.Y = (double.IsNaN(point.Y)) ? 0 : point.Y; point.X = (double.IsNaN(point.X)) ? 0 : point.X; point2.Y = (double.IsNaN(point2.Y)) ? 0 : point2.Y; point2.X = (double.IsNaN(point2.X)) ? 0 : point2.X; heightAndWidthRect = new Rect(point, point2); _image.Height = heightAndWidthRect.Height; _image.Width = heightAndWidthRect.Width; AnnotationElement.Height = heightAndWidthRect.Height; AnnotationElement.Width = heightAndWidthRect.Width; Point ensurePoint = this.EnsurePoint(point, point2); desiredSize = new Size(heightAndWidthRect.Width, heightAndWidthRect.Height); positionedPoint = GetElementPosition( new Size(heightAndWidthRect.Width, heightAndWidthRect.Height), ensurePoint); TextElement.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); if (X2 != null && Y2 != null) { textPosition = GetTextPosition(desiredSize, new Point(0, 0), new Size(TextElement.DesiredSize.Width, TextElement.DesiredSize.Height)); Canvas.SetLeft(TextElement, textPosition.X); Canvas.SetTop(TextElement, textPosition.Y); Canvas.SetLeft(AnnotationElement, positionedPoint.X); Canvas.SetTop(AnnotationElement, positionedPoint.Y); } else { _image.Height = 0; _image.Width = 0; if (ContentTemplate != null) { AnnotationElement.Height = TextElement.DesiredSize.Height; AnnotationElement.Width = TextElement.DesiredSize.Width; textPosition = GetTextPositionWithX1Y1(point, new Size(TextElement.DesiredSize.Width, TextElement.DesiredSize.Height)); Canvas.SetLeft(TextElement, 0); Canvas.SetTop(TextElement, 0); Canvas.SetLeft(AnnotationElement, textPosition.X); Canvas.SetTop(AnnotationElement, textPosition.Y); } } Point centerPoint = new Point( positionedPoint.X + (AnnotationElement.Width / 2), positionedPoint.Y + (AnnotationElement.Height / 2)); Rect rotated = this.RotateElement(this.Angle, AnnotationElement); AnnotationElement.RenderTransformOrigin = new Point(0.5, 0.5); AnnotationElement.RenderTransform = rotate; if (this.Angle > 0) { RotatedRect = new Rect( centerPoint.X - (rotated.Width / 2), centerPoint.Y - (rotated.Height / 2), rotated.Width, rotated.Height); } else { RotatedRect = new Rect( centerPoint.X - (AnnotationElement.Width / 2), centerPoint.Y - (AnnotationElement.Height / 2), AnnotationElement.Width, AnnotationElement.Height); } } break; case CoordinateUnit.Pixel: Point elementPoint1 = new Point(Convert.ToDouble(X1), Convert.ToDouble(Y1)); Point elementPoint2 = new Point(Convert.ToDouble(X2), Convert.ToDouble(Y2)); heightAndWidthRect = new Rect(elementPoint1, elementPoint2); _image.Height = heightAndWidthRect.Height; _image.Width = heightAndWidthRect.Width; AnnotationElement.Height = heightAndWidthRect.Height; AnnotationElement.Width = heightAndWidthRect.Width; #if __IOS__ || __ANDROID__ positionedPoint = GetElementPosition(_imageBorder, elementPoint1); #else positionedPoint = GetElementPosition(_image, elementPoint1); #endif desiredSize = new Size(_image.Width, _image.Height); TextElement.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); if (X2 != null && Y2 != null) { textPosition = GetTextPosition( desiredSize, new Point(0, 0), new Size(TextElement.DesiredSize.Width, TextElement.DesiredSize.Height)); Canvas.SetLeft(AnnotationElement, positionedPoint.X); Canvas.SetTop(AnnotationElement, positionedPoint.Y); Canvas.SetLeft(TextElement, textPosition.X); Canvas.SetTop(TextElement, textPosition.Y); } else { _image.Height = 0; _image.Width = 0; if (ContentTemplate != null) { AnnotationElement.Height = TextElement.DesiredSize.Height; AnnotationElement.Width = TextElement.DesiredSize.Width; textPosition = GetTextPositionWithX1Y1(elementPoint1, new Size(TextElement.DesiredSize.Width, TextElement.DesiredSize.Height)); Canvas.SetLeft(TextElement, 0); Canvas.SetTop(TextElement, 0); Canvas.SetLeft(AnnotationElement, textPosition.X); Canvas.SetTop(AnnotationElement, textPosition.Y); } } Rect _rotated = this.RotateElement(this.Angle, AnnotationElement); AnnotationElement.RenderTransformOrigin = new Point(0.5, 0.5); AnnotationElement.RenderTransform = rotate; Point _centerPoint = new Point( positionedPoint.X + (AnnotationElement.Width / 2), positionedPoint.Y + (AnnotationElement.Height / 2)); if (this.Angle > 0) { RotatedRect = new Rect( _centerPoint.X - (_rotated.Width / 2), _centerPoint.Y - (_rotated.Height / 2), _rotated.Width, _rotated.Height); } else { RotatedRect = new Rect( _centerPoint.X - (AnnotationElement.Width / 2), _centerPoint.Y - (AnnotationElement.Height / 2), AnnotationElement.Width, AnnotationElement.Height); } break; } } else if (_image != null) { _image.Height = 0; _image.Width = 0; AnnotationElement.ClearValue(Canvas.LeftProperty); AnnotationElement.ClearValue(Canvas.TopProperty); TextElement.Visibility = Visibility.Collapsed; } }
/// <summary> /// Updates the annotation /// </summary> public override void UpdateAnnotation() { if (shape != null) { ValidateSelection(); switch (CoordinateUnit) { case CoordinateUnit.Axis: SetAxisFromName(); if (XAxis != null && YAxis != null) { if (Chart.AnnotationManager != null && ShowAxisLabel && !Chart.ChartAnnotationCanvas.Children.Contains(AxisMarkerObject.MarkerCanvas)) { Chart.AnnotationManager.AddOrRemoveAnnotations(AxisMarkerObject, false); } if (XAxis.Orientation == Orientation.Vertical) { if (X1 == null) { break; } y1 = (Y1 == null) ? YAxis.VisibleRange.Start : Annotation.ConvertData(Y1, YAxis); y2 = (Y2 == null) ? YAxis.VisibleRange.End : Annotation.ConvertData(Y2, YAxis); X2 = X1; x1 = Annotation.ConvertData(X1, XAxis); x2 = Annotation.ConvertData(X2, XAxis); if (ShowAxisLabel) { SetAxisMarkerValue(X1, X2, YAxis.VisibleRange.Start, YAxis.VisibleRange.End, AxisMode.Horizontal); } this.DraggingMode = AxisMode.Horizontal; } else { if (Y1 == null) { break; } x1 = (X1 == null) ? XAxis.VisibleRange.Start : Annotation.ConvertData(X1, XAxis); x2 = (X2 == null) ? XAxis.VisibleRange.End : Annotation.ConvertData(X2, XAxis); Y2 = Y1; y1 = Annotation.ConvertData(Y1, YAxis); y2 = Annotation.ConvertData(Y2, YAxis); if (ShowAxisLabel) { SetAxisMarkerValue(XAxis.VisibleRange.Start, XAxis.VisibleRange.End, Y1, Y2, AxisMode.Vertical); } this.DraggingMode = AxisMode.Vertical; } if (ShowAxisLabel) { AxisMarkerObject.UpdateAnnotation(); } if (ShowLine) { if (CoordinateUnit == CoordinateUnit.Axis && EnableClipping) { x1 = GetClippingValues(x1, XAxis); y1 = GetClippingValues(y1, YAxis); x2 = GetClippingValues(x2, XAxis); y2 = GetClippingValues(y2, YAxis); } Point point = (XAxis.Orientation == Orientation.Horizontal) ? new Point( this.Chart.ValueToPointRelativeToAnnotation(XAxis, x1) - XAxis.ActualPlotOffset, this.Chart.ValueToPointRelativeToAnnotation(YAxis, y1)) : new Point( this.Chart.ValueToPointRelativeToAnnotation(YAxis, y1) - YAxis.ActualPlotOffset, this.Chart.ValueToPointRelativeToAnnotation(XAxis, x1)); Point point2 = (XAxis.Orientation == Orientation.Horizontal) ? new Point( Chart.ValueToPointRelativeToAnnotation(XAxis, x2) + XAxis.ActualPlotOffset, this.Chart.ValueToPointRelativeToAnnotation(YAxis, y2)) : new Point( this.Chart.ValueToPointRelativeToAnnotation(YAxis, y2) + YAxis.ActualPlotOffset, Chart.ValueToPointRelativeToAnnotation(XAxis, x2)); DrawLine(point, point2, shape); } } break; case CoordinateUnit.Pixel: if (ShowLine && this.Chart != null && this.Chart.AnnotationManager != null && Y1 != null) { this.DraggingMode = AxisMode.Vertical; if (Y1 == null) { Y1 = 0; } Y2 = Y1; X1 = (X1 == null) ? 0 : X1; X2 = (X2 == null || Convert.ToDouble(X2) == 0) ? this.Chart.DesiredSize.Width : X2; Point elementPoint1 = new Point(Convert.ToDouble(X1), Convert.ToDouble(Y1)); Point elementPoint2 = new Point(Convert.ToDouble(X2), Convert.ToDouble(Y2)); DrawLine(elementPoint1, elementPoint2, shape); } break; } if ((XAxis != null && XAxis.Orientation == Orientation.Vertical && X1 == null) || Y1 == null) { ClearValues(); if (ShowAxisLabel) { AxisMarkerObject.ClearValue(AxisMarker.X1Property); AxisMarkerObject.ClearValue(AxisMarker.X2Property); AxisMarkerObject.ClearValue(AxisMarker.Y1Property); AxisMarkerObject.ClearValue(AxisMarker.Y2Property); } } } }
protected override DoubleRange CalculateActualRange() { if (ActualRange.IsEmpty) // Executes when Minimum and Maximum aren't set. { DoubleRange range = base.CalculateActualRange(); // Execute when include the annotion range for Auto Range if (IncludeAnnotationRange) { foreach (var annotation in (Area as SfChart).Annotations) { if (Orientation == Orientation.Vertical && annotation.CoordinateUnit == CoordinateUnit.Axis && annotation.YAxis == this) { range += new DoubleRange( Annotation.ConvertData(annotation.Y1, this), annotation is TextAnnotation ? Annotation.ConvertData(annotation.Y1, this) : annotation is ImageAnnotation ? Annotation.ConvertData((annotation as ImageAnnotation).Y2, this) : Annotation.ConvertData((annotation as ShapeAnnotation).Y2, this)); } else if (Orientation == Orientation.Horizontal && annotation.CoordinateUnit == CoordinateUnit.Axis && annotation.XAxis == this) { range += new DoubleRange( Annotation.ConvertData(annotation.X1, this), annotation is TextAnnotation ? Annotation.ConvertData(annotation.X1, this) : annotation is ImageAnnotation ? Annotation.ConvertData((annotation as ImageAnnotation).X2, this) : Annotation.ConvertData((annotation as ShapeAnnotation).X2, this)); } } } return(range); } else if (Minimum != null && Maximum != null) // Executes when Minimum and Maximum are set. { return(ActualRange); } else { // Executes when either Minimum or Maximum is set. DoubleRange range = base.CalculateActualRange(); if (StartRangeFromZero && range.Start > 0) { return(new DoubleRange(0, range.End)); } else if (Minimum != null) { return(new DoubleRange(ActualRange.Start, double.IsNaN(range.End) ? ActualRange.Start + 1 : range.End)); } else if (Maximum != null) { return(new DoubleRange(double.IsNaN(range.Start) ? ActualRange.End - 1 : range.Start, ActualRange.End)); } else { if (IncludeAnnotationRange) { foreach (var annotation in (Area as SfChart).Annotations) { if (Orientation == Orientation.Vertical && annotation.CoordinateUnit == CoordinateUnit.Axis && annotation.YAxis == this) { range += new DoubleRange( Annotation.ConvertData(annotation.Y1, this), annotation is TextAnnotation ? Annotation.ConvertData(annotation.Y1, this) : annotation is ImageAnnotation ? Annotation.ConvertData((annotation as ImageAnnotation).Y2, this) : Annotation.ConvertData((annotation as ShapeAnnotation).Y2, this)); } else if (Orientation == Orientation.Horizontal && annotation.CoordinateUnit == CoordinateUnit.Axis && annotation.XAxis == this) { range += new DoubleRange( Annotation.ConvertData(annotation.X1, this), annotation is TextAnnotation ? Annotation.ConvertData(annotation.X1, this) : annotation is ImageAnnotation ? Annotation.ConvertData((annotation as ImageAnnotation).X2, this) : Annotation.ConvertData((annotation as ShapeAnnotation).X2, this)); } } } return(range); } } }