protected override void OnChartDragEntered(Point mousePos, object originalSource) { if (EnableSegmentDragging) { FrameworkElement element = originalSource as FrameworkElement; ColumnSegment columnSegment = null; if (element != null) { if (element.Tag is ColumnSegment) { columnSegment = element.Tag as ColumnSegment; } } if (columnSegment == null) { return; } double segmentPosition = YValues[Segments.IndexOf(columnSegment)]; if (IsActualTransposed) { UpdateDragSpliter(element, columnSegment, segmentPosition < 0 ? "Left" : "Right"); } else { UpdateDragSpliter(element, columnSegment, segmentPosition < 0 ? "Bottom" : "Top"); } base.OnChartDragEntered(mousePos, originalSource); } }
/// <summary> /// This method used to get the chart data index at an SfChart co-ordinates /// </summary> /// <param name="index"></param> /// <returns></returns> internal override int GetDataPointIndex(Point point) { Canvas canvas = Area.GetAdorningCanvas(); double left = Area.ActualWidth - canvas.ActualWidth; double top = Area.ActualHeight - canvas.ActualHeight; point.X = point.X - left + Area.Margin.Left; point.Y = point.Y - top + Area.Margin.Top; foreach (var segment in Segments) { Path path = segment.GetRenderedVisual() as Path; bool isHit = false; var pathData = path.Data as PathGeometry; if (pathData != null) { isHit = pathData.Bounds.Contains(point); } if (isHit) { return(Segments.IndexOf(segment)); } } return(-1); }
/// <summary> /// Called when [series mouse up]. /// </summary> /// <param name="source">The source.</param> /// <param name="position">The position.</param> protected internal override void OnSeriesMouseUp(object source, Point position) { FrameworkElement element = source as FrameworkElement; if (SelectionMode == SelectionMode.MouseClick) { if (element == null || !(element.Tag is ChartSegment3D)) { return; } var segment = element.Tag as ChartSegment3D; int currentIndex = -1; if (this.IsSideBySide || segment.Series is CircularSeriesBase3D) { currentIndex = Segments.IndexOf(segment); } else { this.dataPoint = this.GetDataPoint(position); if (this.dataPoint != null) { currentIndex = dataPoint.Index; } } this.OnMouseDownSelection(currentIndex); } }
private void SetScatterDraggingSegment(FrameworkElement frameworkElement, ref bool isAdornment) { // Empty point support only given for the interior case and not for symbol case. if (frameworkElement.Tag is EmptyPointSegment || frameworkElement.DataContext is EmptyPointSegment) { return; } if (frameworkElement.Tag is ScatterSegment || frameworkElement.DataContext is ScatterSegment) { draggingSegment = GetDraggingSegment(frameworkElement) as ScatterSegment; if (ActualXAxis is CategoryAxis && !(ActualXAxis as CategoryAxis).IsIndexed) { SegmentIndex = ActualData.IndexOf(draggingSegment.Item); } else { SegmentIndex = Segments.IndexOf(draggingSegment); } } else { isAdornment = true; // Get the selected adornment index and select the adornment marker SegmentIndex = ChartExtensionUtils.GetAdornmentIndex(frameworkElement); if (SegmentIndex > -1) { draggingSegment = Segments[SegmentIndex] as ScatterSegment; } } }
/// <summary> /// Virtual Method for ExplodeRadius /// </summary> protected override void SetExplodeRadius() { if (Segments.Count > 0) { foreach (DoughnutSegment segment in Segments) { int index = Segments.IndexOf(segment); UpdateSegments(index, NotifyCollectionChangedAction.Replace); } } }
/// <summary> /// Virtual method for ExplodeAll /// </summary> protected override void SetExplodeAll() { if (Segments.Count > 0) { foreach (PieSegment segment in Segments) { int index = Segments.IndexOf(segment); segment.IsExploded = true; UpdateSegments(index, NotifyCollectionChangedAction.Replace); } } }
public int MoveSegment2NextPosition(Segment segment) { var orderId = -1; foreach (var seg in Segments.OrderBy(t => t.OrderId)) { orderId++; seg.OrderId = orderId; } var oldIndex = Segments[Segments.IndexOf(segment)].OrderId; if (oldIndex == Segments.Count - 1) { return(oldIndex); } Segments.First(t => t.OrderId == oldIndex + 1).OrderId = oldIndex; segment.OrderId = oldIndex + 1; return(segment.OrderId); }
/// <summary> /// Method implementation for ExplodeIndex /// </summary> /// <param name="i"></param> protected override void SetExplodeIndex(int i) { if (Segments.Count > 0) { foreach (DoughnutSegment segment in Segments) { int index = !double.IsNaN(GroupTo) ? Segments.IndexOf(segment) : ActualData.IndexOf(segment.Item); if (i == index) { segment.IsExploded = !segment.IsExploded; UpdateSegments(i, NotifyCollectionChangedAction.Remove); } else if (i == -1) { segment.IsExploded = false; UpdateSegments(i, NotifyCollectionChangedAction.Remove); } } } }
/// <summary> /// This method used to get the chart data index at an SfChart co-ordinates /// </summary> /// <param name="index"></param> /// <returns></returns> internal override int GetDataPointIndex(Point point) { Canvas canvas = Area.GetAdorningCanvas(); double left = Area.ActualWidth - canvas.ActualWidth; double top = Area.ActualHeight - canvas.ActualHeight; point.X = point.X - left - Area.SeriesClipRect.Left + Area.Margin.Left; point.Y = point.Y - top - Area.SeriesClipRect.Top + Area.Margin.Top; foreach (var segment in Segments) { Ellipse ellipse = segment.GetRenderedVisual() as Ellipse; if (ellipse != null && EllipseContainsPoint(ellipse, point)) { return(Segments.IndexOf(segment)); } } return(-1); }
/// <summary> /// Updates the series when mouse moved. /// </summary> /// <param name="element">The Element</param> /// <param name="pos">The Position</param> internal void OnMouseMoveSelection(FrameworkElement element, Point pos) { if (element == null || !(element.Tag is ChartSegment3D)) { return; } var segment = element.Tag as ChartSegment3D; int currentIndex = -1; if (this.IsSideBySide || segment.Series is CircularSeriesBase3D) { currentIndex = Segments.IndexOf(segment); } else { this.dataPoint = this.GetDataPoint(pos); if (this.dataPoint != null) { currentIndex = dataPoint.Index; } } bool seriesSelection = this.Area.EnableSeriesSelection && (segment.Series.IsSideBySide || segment.Series is ScatterSeries3D || segment.Series is CircularSeriesBase3D || (!segment.Series.IsSideBySide && ((!this.Area.EnableSegmentSelection) || (this.Area.EnableSegmentSelection && currentIndex == -1)))); if (seriesSelection) { int index = this.Area.Series.IndexOf(segment.Series as ChartSeries3D); if (index > -1) { bool isCancel = this.RaiseSelectionChanging(index, this.Area.SeriesSelectedIndex); if (!isCancel) { this.Area.SeriesSelectedIndex = index; this.Area.PreviousSelectedSeries = this; } } } else if (this.Area.EnableSegmentSelection) { if (currentIndex > -1) { bool isCancel = this.RaiseSelectionChanging(currentIndex, this.SelectedIndex); if (!isCancel) { if (this.Area.SelectionStyle == SelectionStyle3D.Single) { this.SelectedIndex = currentIndex; } else { SelectedSegmentsIndexes.Add(currentIndex); } this.Area.PreviousSelectedSeries = this; } } } }
private void ActivateDragging(Point mousePos, object element) { try { if (previewRect != null) { return; } var rectangle = element as Rectangle; if (rectangle == null || !EnableSegmentDragging) { return; } var rangeColumnSegment = rectangle.Tag as RangeColumnSegment; if (rangeColumnSegment == null) { return; } initialHeight = Canvas.GetTop(rectangle); var brush = rectangle.Fill as SolidColorBrush; previewRect = new Rectangle { Fill = brush != null ? new SolidColorBrush( Color.FromArgb( brush.Color.A, (byte)(brush.Color.R * 0.6), (byte)(brush.Color.G * 0.6), (byte)(brush.Color.B * 0.6))) : rectangle.Fill, Opacity = 0.5, Stroke = rectangle.Stroke, StrokeThickness = rectangle.StrokeThickness }; previewRect.SetValue(Canvas.LeftProperty, Canvas.GetLeft(rectangle)); previewRect.SetValue(Canvas.TopProperty, initialHeight); previewRect.Height = rectangle.ActualHeight; previewRect.Width = rectangle.ActualWidth; SeriesPanel.Children.Add(previewRect); SegmentIndex = Segments.IndexOf(rectangle.Tag as ChartSegment); draggingMode = GetSegmentMousePosition(rangeColumnSegment, mousePos); selectedSegment = rangeColumnSegment; initialHeight = IsActualTransposed ? mousePos.X : mousePos.Y; initialValue = Area.PointToValue(ActualYAxis, mousePos); var dragEventArgs = new ChartDragStartEventArgs { BaseXValue = GetActualXValue(SegmentIndex) }; RaiseDragStart(dragEventArgs); if (dragEventArgs.Cancel) { ResetDraggingElements("Cancel", true); } #if NETFX_CORE Focus(FocusState.Keyboard); #endif UnHoldPanning(false); } catch { ResetDraggingElements("Exception", true); } }
/// <summary> /// Creates the segments of WaterfallSeries. /// </summary> public override void CreateSegments() { List <double> xValues = GetXValues(); double median = 0d; DoubleRange sbsInfo = this.GetSideBySideInfo(this); median = sbsInfo.Delta / 2; double origin = ActualXAxis != null ? ActualXAxis.Origin : 0; if (ActualXAxis != null && ActualXAxis.Origin == 0 && ActualYAxis is LogarithmicAxis && (ActualYAxis as LogarithmicAxis).Minimum != null) { origin = (double)(ActualYAxis as LogarithmicAxis).Minimum; } if (xValues != null) { double x1, x2, y1, y2; ClearUnUsedSegments(this.DataCount); ClearUnUsedAdornments(this.DataCount); for (int i = 0; i < this.DataCount; i++) { if (i < this.DataCount) { // Calculate the waterfall segment rendering values. OnCalculateSegmentValues( out x1, out x2, out y1, out y2, i, origin, xValues[i]); WaterfallSegment segment = null; bool isSum = false; if (i < Segments.Count) { segment = Segments[i] as WaterfallSegment; segment.SetData(x1, y1, x2, y2); segment.XData = xValues[i]; segment.YData = YValues[i]; segment.Item = ActualData[i]; if (segment.SegmentType == WaterfallSegmentType.Sum) { isSum = true; } // Update sum segment values. OnUpdateSumSegmentValues(segment, i, isSum, origin); segment.BindProperties(); } else { segment = new WaterfallSegment(x1, y1, x2, y2, this) { XData = xValues[i], YData = YValues[i], Item = ActualData[i] }; // Raise segment created event. isSum = RaiseSegmentCreatedEvent(segment, i); // Update sum segment values. OnUpdateSumSegmentValues(segment, i, isSum, origin); Segments.Add(segment); } #region Adornment calculation if (AdornmentsInfo != null) { if (segment.SegmentType == WaterfallSegmentType.Sum) { if (Segments.IndexOf(segment) > 0 && AllowAutoSum) { if (this.AdornmentsInfo.AdornmentsPosition == AdornmentsPosition.TopAndBottom) { AddColumnAdornments(xValues[i], segment.WaterfallSum, x1, segment.WaterfallSum / 2, i, median); } else if (segment.WaterfallSum >= 0) { AddColumnAdornments(xValues[i], segment.WaterfallSum, x1, segment.Top, i, median); } else { AddColumnAdornments(xValues[i], segment.WaterfallSum, x1, segment.Bottom, i, median); } } else { if (this.AdornmentsInfo.AdornmentsPosition == AdornmentsPosition.TopAndBottom) { AddColumnAdornments(xValues[i], YValues[i], x1, y1 + (y2 - y1) / 2, i, median); } else if (YValues[i] >= 0) { AddColumnAdornments(xValues[i], YValues[i], x1, segment.Top, i, median); } else { AddColumnAdornments(xValues[i], YValues[i], x1, segment.Bottom, i, median); } } } else if (this.AdornmentsInfo.AdornmentsPosition == AdornmentsPosition.Top) { if (segment.SegmentType == WaterfallSegmentType.Positive) { AddColumnAdornments(xValues[i], YValues[i], x1, y1, i, median); } else { AddColumnAdornments(xValues[i], YValues[i], x1, y2, i, median); } } else if (this.AdornmentsInfo.AdornmentsPosition == AdornmentsPosition.Bottom) { if (segment.SegmentType == WaterfallSegmentType.Positive) { AddColumnAdornments(xValues[i], YValues[i], x1, y2, i, median); } else { AddColumnAdornments(xValues[i], YValues[i], x1, y1, i, median); } } else { AddColumnAdornments(xValues[i], YValues[i], x1, y1 + (y2 - y1) / 2, i, median); } } #endregion } } } this.ActualArea.IsUpdateLegend = true; }
/// <summary> /// Updates the drag spliter low. /// </summary> /// <param name="rect">The rect.</param> protected virtual void UpdateDragSpliterLow(Rectangle rect) { int index = Segments.IndexOf(rect.Tag as ChartSegment); var args = new RangeSegmentEnterEventArgs() { XValue = GetActualXValue(index), SegmentIndex = index, CanDrag = true, HighValue = HighValues[index], LowValue = LowValues[index] }; RaiseDragEnter(args); if (!args.CanDrag) { return; } if (DragSpliterLow == null) { DragSpliterLow = new ContentControl(); SeriesPanel.Children.Add(DragSpliterLow); if (IsActualTransposed) { DragSpliterLow.Template = ChartDictionaries.GenericCommonDictionary["DragSpliterLeft"] as ControlTemplate; } else { DragSpliterLow.Template = ChartDictionaries.GenericCommonDictionary["DragSpliterTop"] as ControlTemplate; } } double canvasLeft, canvasTop, spliterHeight, spliterWidth, margin; if (IsActualTransposed) { canvasTop = Canvas.GetTop(rect); double height = rect.Height; margin = height / 3; spliterHeight = height - margin * 2; DragSpliterLow.Margin = new Thickness(0, margin, 0, margin); canvasLeft = Canvas.GetLeft(rect) + margin / 3; spliterWidth = spliterHeight / 5; } else { double bottom = Canvas.GetTop(rect) + rect.Height; double width = rect.Width; margin = width / 3; spliterWidth = width - margin * 2; DragSpliterLow.Margin = new Thickness(margin, 0, margin, 0); canvasLeft = Canvas.GetLeft(rect); canvasTop = bottom - 7; spliterHeight = spliterWidth / 5; } DragSpliterLow.SetValue(Canvas.LeftProperty, canvasLeft); DragSpliterLow.SetValue(Canvas.TopProperty, canvasTop); DragSpliterLow.Height = spliterHeight; DragSpliterLow.Width = spliterWidth; }
/// <summary> /// Animates the <see cref="ScatterSeries3D"/>. /// </summary> internal override void Animate() { int i = 0; Random rand = new Random(); // WPF-25124 Animation not working properly when resize the window. if (this.AnimationStoryboard != null) { AnimationStoryboard.Stop(); if (!this.canAnimate) { this.ResetAdornmentAnimationState(); return; } } this.AnimationStoryboard = new Storyboard(); ScatterSegment3D segment = null; foreach (ChartSegment scatterSegment in this.Segments) { if (scatterSegment is EmptyPointSegment) { continue; } segment = scatterSegment as ScatterSegment3D; if (double.IsNaN(segment.Y)) { continue; } int randomValue = Segments.IndexOf(segment) == 0 ? 0 : rand.Next(1, 20); TimeSpan beginTime = TimeSpan.FromMilliseconds(randomValue * 20); var dblAnimationKeyFrames = new DoubleAnimationUsingKeyFrames(); var keyFrame = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 0d }; dblAnimationKeyFrames.KeyFrames.Add(keyFrame); keyFrame = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(AnimationDuration), Value = segment.ScatterHeight }; var keySpline = new KeySpline { ControlPoint1 = new Point(0.64, 0.84), ControlPoint2 = new Point(0.67, 0.95) }; keyFrame.KeySpline = keySpline; dblAnimationKeyFrames.KeyFrames.Add(keyFrame); Storyboard.SetTargetProperty(dblAnimationKeyFrames, "ScatterSegment3D.ScatterHeight"); dblAnimationKeyFrames.EnableDependentAnimation = true; Storyboard.SetTarget(dblAnimationKeyFrames, segment); AnimationStoryboard.Children.Add(dblAnimationKeyFrames); dblAnimationKeyFrames = new DoubleAnimationUsingKeyFrames(); keyFrame = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 0d }; dblAnimationKeyFrames.KeyFrames.Add(keyFrame); keyFrame = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(AnimationDuration), Value = segment.ScatterWidth }; keySpline = new KeySpline { ControlPoint1 = new Point(0.64, 0.84), ControlPoint2 = new Point(0.67, 0.95) }; keyFrame.KeySpline = keySpline; dblAnimationKeyFrames.KeyFrames.Add(keyFrame); Storyboard.SetTargetProperty(dblAnimationKeyFrames, "ScatterSegment3D.ScatterWidth"); dblAnimationKeyFrames.EnableDependentAnimation = true; Storyboard.SetTarget(dblAnimationKeyFrames, segment); AnimationStoryboard.Children.Add(dblAnimationKeyFrames); if (this.AdornmentsInfo != null && AdornmentsInfo.ShowLabel) { UIElement label = this.AdornmentsInfo.LabelPresenters[i]; label.Opacity = 0; DoubleAnimation animation = new DoubleAnimation() { To = 1, From = 0, BeginTime = TimeSpan.FromSeconds(beginTime.TotalSeconds + (beginTime.Seconds * 90) / 100), Duration = TimeSpan.FromSeconds((AnimationDuration.TotalSeconds * 50) / 100) }; Storyboard.SetTargetProperty(animation, "FrameworkElement.Opacity"); Storyboard.SetTarget(animation, label); AnimationStoryboard.Children.Add(animation); } i++; } AnimationStoryboard.Begin(); }
public int IndexOf(DcColumn col) // Return index of the specified column in this path { return(Segments.IndexOf(col)); }
protected internal override void OnSeriesMouseUp(object source, Point position) { var element = source as FrameworkElement; var segment = element != null ? element.Tag as ChartSegment : null; int index = -1; if (ExplodeOnMouseClick && allowExplode && mouseUnderSegment == segment) { if (segment != null && segment.Series is AccumulationSeriesBase) { index = segment.Series is CircularSeriesBase && !double.IsNaN(((CircularSeriesBase)segment.Series).GroupTo) ? Segments.IndexOf(segment) : ActualData.IndexOf(segment.Item); } else if (Adornments.Count > 0) { index = ChartExtensionUtils.GetAdornmentIndex(source); } var newIndex = index; var oldIndex = ExplodeIndex; if (newIndex != oldIndex) { ExplodeIndex = newIndex; } else if (ExplodeIndex >= 0) { ExplodeIndex = -1; } allowExplode = false; } }