private void SetAnimation() { storyBoard?.Stop(Selected); if ((EdgesPath?.Count ?? 0) == 0) { return; } storyBoard = new Storyboard(); DoubleAnimationUsingKeyFrames leftAnimation = new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames topAnimation = new DoubleAnimationUsingKeyFrames(); leftAnimation.RepeatBehavior = RepeatBehavior.Forever; topAnimation.RepeatBehavior = RepeatBehavior.Forever; Storyboard.SetTargetName(leftAnimation, Selected.Name); Storyboard.SetTargetProperty(leftAnimation, new PropertyPath("(0)", Canvas.LeftProperty)); Storyboard.SetTargetName(topAnimation, Selected.Name); Storyboard.SetTargetProperty(topAnimation, new PropertyPath("(0)", Canvas.TopProperty)); double sumDist = EdgesPath.Sum(edge => Distance(edge)); double sumTime = 0; foreach (var edge in EdgesPath) { leftAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(Nodes[edge.Begin].X, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, (int)sumTime)))); topAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(Nodes[edge.Begin].Y, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, (int)sumTime)))); sumTime += (Distance(edge) / sumDist) * (animTimeSpan * EdgesPath.Count); leftAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(Nodes[edge.End].X, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, (int)sumTime)))); topAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(Nodes[edge.End].Y, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, (int)sumTime)))); } leftAnimation.Freeze(); topAnimation.Freeze(); storyBoard.Children.Add(leftAnimation); storyBoard.Children.Add(topAnimation); storyBoard.Begin(Selected, true); }
private void SmartGraphPathParentChanged() { GraphVM previous = Graph; Graph = GraphPath?.Parent; if (Graph != null && Graph == previous) { return; } previous = Graph; Nodes.Clear(); Edges.Clear(); NodesNames.Clear(); EdgesPath.Clear(); NodesPathOrder.Clear(); if (Graph == null) { return; } positioner = new CircleGraphPositioner(Graph); double actualWidth = ActualWidth; double actualHeight = ActualHeight; foreach (var node in Graph.Nodes) { Nodes[node] = CalculatePosition(node, NodesMargin, actualWidth, actualHeight); NodesNames[node] = CalculatePosition(node, NamesMargin, actualWidth, actualHeight); } foreach (var edge in Graph.Edges) { Edges.Add(edge); } ++ChangeCount; }
private void SmartGraphPathCahnged() { EdgesPath.Clear(); NodesPathOrder.Clear(); if (GraphPath == null) { return; } int index = 0; NodesPathOrder.Add(GraphPath.Edges.First().Begin, index++); foreach (var edge in GraphPath.Edges) { EdgesPath.Add(edge); NodesPathOrder.Add(edge.End, index++); } ++ChangeCount; SetAnimation(); }