コード例 #1
0
        protected override LayoutData CreateConfiguredLayoutData(GraphControl graphControl, ILayoutAlgorithm layout)
        {
            var layoutData = new LabelingData();

            var selection = graphControl.Selection;

            if (selection != null)
            {
                layoutData.AffectedLabels.DpKey    = SelectedLabelsKey;
                layoutData.AffectedLabels.Delegate = label => selection.IsSelected(label) || selection.IsSelected(label.Owner);
            }

            if (PlaceEdgeLabelsItem)
            {
                SetupEdgeLabelModels(graphControl);
                return(layoutData.CombineWith(
                           CreateLabelingLayoutData(
                               graphControl.Graph,
                               LabelPlacementAlongEdgeItem,
                               LabelPlacementSideOfEdgeItem,
                               LabelPlacementOrientationItem,
                               LabelPlacementDistanceItem
                               )
                           ));
            }

            return(layoutData);
        }
コード例 #2
0
        protected override LayoutData CreateConfiguredLayoutData(GraphControl graphControl, ILayoutAlgorithm layout)
        {
            var layoutData = new LabelingData();

            var selection = graphControl.Selection;

            if (selection != null)
            {
                layoutData.AffectedLabels.Source = selection.SelectedLabels;

                return(new CompositeLayoutData {
                    Items =
                    {
                        layoutData,
                        new SelectedLabelsLayoutData {
                            SelectedLabelsAtItem =
                            {
                                Delegate =
                                    item => item.Labels
                                    .Select(label => selection.IsSelected(label) || selection.IsSelected(item))
                                    .ToArray()
                            }
                        }
                    }
                });
            }

            return(layoutData);
        }
コード例 #3
0
        /// <summary>
        /// Run a layout and an analysis algorithm if wanted.
        /// </summary>
        /// <param name="incremental">Whether to run in incremental mode, i.e. only moving new items.</param>
        /// <param name="clearUndo">Whether to clear the undo queue after the layout.</param>
        /// <param name="runAlgorithm">Whether to apply the <see cref="CurrentConfig">current analysis algorithm</see>, too.</param>
        /// <returns></returns>
        private async Task RunLayout(bool incremental, bool clearUndo, bool runAlgorithm)
        {
            // the actual organic layout
            var layout = new OrganicLayout {
                Deterministic       = true,
                ConsiderNodeSizes   = true,
                Scope               = incremental ? Scope.MainlySubset : Scope.All,
                LabelingEnabled     = false,
                PreferredEdgeLength = 100,
                MinimumNodeDistance = 10
            };

            ((ComponentLayout)layout.ComponentLayout).Style = ComponentArrangementStyles.None | ComponentArrangementStyles.ModifierNoOverlap;

            OrganicLayoutData layoutData = null;

            if (incremental && incrementalNodesMapper != null)
            {
                layoutData = new OrganicLayoutData();
                layoutData.AffectedNodes.Mapper = incrementalNodesMapper;
            }
            inLayout = true;
            SetUiDisabled(true);
            // run the layout in an asynchronous, animated fashion
            await graphControl.MorphLayout(layout, TimeSpan.FromSeconds(0.5), layoutData);

            // run algorithm
            if (runAlgorithm)
            {
                // apply graph algorithms after layout
                ApplyAlgorithm();
                var algorithm = algorithmComboBox.SelectedItem as Algorithm;
                if (algorithm != null && algorithm.DisplayName.EndsWith("Centrality"))
                {
                    // since centrality changes the node sizes, node overlaps need to be removed
                    await graphControl.MorphLayout(new OrganicRemoveOverlapsStage(), TimeSpan.FromSeconds(0.2));
                }
            }

            // labeling: place labels after the layout and the analysis (which might have generated or changed labels)
            var labeling = new GenericLabeling {
                PlaceEdgeLabels = true,
                PlaceNodeLabels = false,
                Deterministic   = true
            };
            var labelingData = new LabelingData {
                EdgeLabelPreferredPlacement =
                {
                    Delegate                                            = label => {
                        var preferredPlacementDescriptor                = new PreferredPlacementDescriptor();
                        if ("Centrality".Equals(label.Tag))
                        {
                            preferredPlacementDescriptor.SideOfEdge     = LabelPlacements.OnEdge;
                        }
                        else
                        {
                            preferredPlacementDescriptor.SideOfEdge     = LabelPlacements.RightOfEdge | LabelPlacements.LeftOfEdge;
                            preferredPlacementDescriptor.DistanceToEdge = 5;
                        }
                        preferredPlacementDescriptor.Freeze();
                        return(preferredPlacementDescriptor);
                    }
                }
            };
            await graphControl.MorphLayout(labeling, TimeSpan.FromSeconds(0.2), labelingData);

            // cleanup
            if (clearUndo)
            {
                graphControl.Graph.GetUndoEngine().Clear();
            }
            // clean up data provider
            incrementalNodesMapper.Clear();

            // enable the UI's buttons
            ReleaseLocks();
            SetUiDisabled(false);
            UpdateUiState();
        }