protected override IAnimation CreateViewportAnimation(RectD targetBounds) { if (nodes.Count == 0) { return(base.CreateViewportAnimation(targetBounds)); } if (!nodes.All(node => Graph.Contains(node))) { throw new InvalidOperationException("Cannot zoom to nodes that are not in the graph"); } var layoutGraph = this.LayoutGraph; var bounds = nodes .Select(node => layoutGraph.GetBoundingBox(layoutGraph.GetCopiedNode(node))) .Aggregate(RectD.Empty, (rect1, rect2) => rect1 + rect2.ToRectD()); var viewportAnimation = new ViewportAnimation(this.GraphControl, bounds, this.Duration) { // The insets are not symmetric since we must compensate the space of the scrollbars TargetViewMargins = new InsetsD(20, 20, 36, 36), MaximumTargetZoom = 1 }; return(viewportAnimation); }
/// <summary> /// Called after the layout has been calculated. /// </summary> /// <remarks> /// Applies the layout in an animation and cleans up. Calls OnDone to raise the Done event after the animation has been completed. /// </remarks> /// <param name="graph">The graph to apply the layout to.</param> /// <param name="moduleContext">The module context.</param> /// <param name="compoundEdit">The undo edit which wraps the layout. It was created in <see cref="StartWithIGraph"/> and will be closed here.</param> protected virtual async Task LayoutDone(IGraph graph, ILookup moduleContext, ICompoundEdit compoundEdit) { if (abortDialog != null) { if (abortDialog.IsVisible) { abortDialog.Close(); } abortDialog = null; } GraphControl view = moduleContext.Lookup <GraphControl>(); if (LayoutMorphingEnabled && view != null) { var morphingAnimation = graph.CreateLayoutAnimation(layoutGraph, TimeSpan.FromSeconds(1)); Rectangle2D box = LayoutGraphUtilities.GetBoundingBox(layoutGraph, layoutGraph.GetNodeCursor(), layoutGraph.GetEdgeCursor()); RectD targetBounds = box.ToRectD(); ViewportAnimation vpAnim = new ViewportAnimation(view, targetBounds, TimeSpan.FromSeconds(1)) { MaximumTargetZoom = 1.0d, TargetViewMargins = view.ContentMargins }; var animations = new List <IAnimation>(); animations.Add(morphingAnimation); animations.Add(CreateTableAnimations()); if (ViewPortMorphingEnabled) { animations.Add(vpAnim); } TableLayoutConfigurator.CleanUp(graph); Animator animator = new Animator(view); await animator.Animate(animations.CreateParallelAnimation().CreateEasedAnimation()); try { compoundEdit.Commit(); view.UpdateContentRect(); } finally { OnDone(new LayoutEventArgs()); } } else { layoutGraph.CommitLayoutToOriginalGraph(); RestoreTableLayout(); compoundEdit.Commit(); if (view != null) { view.UpdateContentRect(); } OnDone(new LayoutEventArgs()); } }