public LayoutInfo CalculateLayout()
        {
            var vertexCenters = CalculateVertexCenters();
            var edgeRoutes    = CalculateEdgeRoutes(vertexCenters);

            var diagramNodeRects = vertexCenters
                                   .Where(i => i.Key is DiagramNodeLayoutVertex)
                                   .Select(i => (diagramNode: ((DiagramNodeLayoutVertex)i.Key).DiagramNode, center: i.Value))
                                   .ToDictionary(
                i => i.diagramNode.Id,
                i => Rect2D.CreateFromCenterAndSize(i.center, i.diagramNode.Size));

            return(new LayoutInfo(diagramNodeRects, edgeRoutes));
        }
예제 #2
0
        public IDictionary <ModelNodeId, Rect2D> Calculate(IEnumerable <IDiagramNode> nodes, IEnumerable <IDiagramConnector> connectors)
        {
            var diagramNodeToLayoutVertexMap    = new Map <ModelNodeId, DiagramNodeLayoutVertex>();
            var diagramConnectorToLayoutPathMap = new Map <ModelRelationshipId, LayoutPath>();

            var layoutVertices = nodes.Select(i => CreateLayoutVertex(i, diagramNodeToLayoutVertexMap)).OrderBy(i => i.DiagramNode.AddedAt).ThenBy(i => i.Name)
                                 .ToList();
            var layoutPaths = connectors.Select(i => CreateLayoutPath(i, diagramNodeToLayoutVertexMap, diagramConnectorToLayoutPathMap)).ToList();

            var relativeLayout         = RelativeLayoutCalculator.Calculate(layoutVertices, layoutPaths);
            var layoutVertexToPointMap = AbsolutePositionCalculator.GetVertexCenters(relativeLayout, HorizontalGap, VerticalGap);

            return(diagramNodeToLayoutVertexMap.ToDictionary(
                       i => i.Key,
                       i => Rect2D.CreateFromCenterAndSize(layoutVertexToPointMap.Get(i.Value), i.Value.Size)));
        }
        private void CheckThatParentsAreCentered(LayoutVertexToPointMap vertexCenters)
        {
            foreach (var vertex in ProperLayoutGraph.Vertices)
            {
                if (ProperLayoutGraph.HasPrimaryChildren(vertex))
                {
                    var childrenBlockRect = ProperLayoutGraph.GetPrimaryChildren(vertex)
                                            .Select(i => Rect2D.CreateFromCenterAndSize(vertexCenters.Get(i), i.Size))
                                            .Union();

                    if (!vertexCenters.Get(vertex).X.IsEqualWithTolerance(childrenBlockRect.Center.X))
                    {
                        throw new Exception($"{vertex} is not centered to its children.");
                    }
                }
            }
        }
예제 #4
0
        public Rect2D GetRect(LayoutVertexBase vertex)
        {
            var center = Get(vertex);

            return(Rect2D.CreateFromCenterAndSize(center, vertex.Size));
        }