diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs index e89e198..9556dfb 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/MindViewModel.cs @@ -37,7 +37,7 @@ namespace AIStudio.Wpf.Flowchart } - private MindType _mindType = Mind.MindType.Directory; + private MindType _mindType = Mind.MindType.FishBone; public MindType MindType { get @@ -55,10 +55,10 @@ namespace AIStudio.Wpf.Flowchart base.Init(); MindNode level1node = new MindNode(DiagramViewModel, Mind.NodeLevel.Level1, MindType) { Text = "思维导图" }; - level1node.Left = 220; - level1node.Top = 15; + //level1node.Left = 220; + //level1node.Top = 15; DiagramViewModel.DirectAddItemCommand.Execute(level1node); - //DiagramViewModel.CenterMoveCommand.Execute(level1node); + DiagramViewModel.CenterMoveCommand.Execute(level1node); MindNode level2node1_1 = new MindNode(DiagramViewModel, Mind.NodeLevel.Level2, MindType) { Text = "分支主题1" }; level1node.AddChild(level2node1_1); diff --git a/AIStudio.Wpf.Mind/Helpers/FishBoneLayout.cs b/AIStudio.Wpf.Mind/Helpers/FishBoneLayout.cs index 260bbf7..2b50fce 100644 --- a/AIStudio.Wpf.Mind/Helpers/FishBoneLayout.cs +++ b/AIStudio.Wpf.Mind/Helpers/FishBoneLayout.cs @@ -14,6 +14,10 @@ namespace AIStudio.Wpf.Mind.Helpers { public void Appearance(MindNode mindNode) { + if (mindNode == null) return; + + mindNode.GetLevel1Node().LayoutUpdating = true; + switch (mindNode.NodeLevel) { case NodeLevel.Level1: @@ -31,6 +35,7 @@ namespace AIStudio.Wpf.Mind.Helpers mindNode.ColorViewModel.LineColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf); mindNode.FontViewModel.FontColor = Colors.White; mindNode.FontViewModel.FontSize = 15; + mindNode.Spacing = new SizeBase(50, 15); mindNode.ShapeViewModel.SinkMarker.PathStyle = ArrowPathStyle.None; mindNode.ShapeViewModel.SinkMarker.SizeStyle = ArrowSizeStyle.VerySmall; @@ -84,6 +89,8 @@ namespace AIStudio.Wpf.Mind.Helpers break; } } + + mindNode.GetLevel1Node().LayoutUpdating = false; } @@ -108,17 +115,23 @@ namespace AIStudio.Wpf.Mind.Helpers if (mindNode.NodeLevel == NodeLevel.Level1) { var tops = mindNode.Children.Where((p, index) => index % 2 == 0).ToList(); - tops.ForEach(p => p.ConnectorOrientation = ConnectorOrientation.Top); + tops.ForEach(p => p.ConnectorOrientation = ConnectorOrientation.BottomLeft); var topsizes = tops.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray(); var bottoms = mindNode.Children.Where((p, index) => index % 2 == 1).ToList(); - bottoms.ForEach(p => p.ConnectorOrientation = ConnectorOrientation.Bottom); + bottoms.ForEach(p => p.ConnectorOrientation = ConnectorOrientation.TopLeft); var bottomsizes = bottoms.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray(); - sizewithSpacing = new SizeBase(sizewithSpacing.Width + Math.Max(topsizes.Sum(p => p.Width), bottomsizes.Sum(p => p.Width)), sizewithSpacing.Height + topsizes.Max(p => p.Height) + bottomsizes.Max(p => p.Height)); + sizewithSpacing = new SizeBase(sizewithSpacing.Width + Math.Max(topsizes.Sum(p => p.Width), bottomsizes.Sum(p => p.Width)), sizewithSpacing.Height + topsizes.Max(p => p.Height) + bottomsizes.Max(p => p.Height)); } - else + else if (mindNode.NodeLevel == NodeLevel.Level2) { var childrensizes = mindNode.Children.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray(); - sizewithSpacing = new SizeBase(sizewithSpacing.Width + childrensizes.Sum(p => p.Width), sizewithSpacing.Height + childrensizes.Sum(p => p.Height)); + var lastchildsize = childrensizes.LastOrDefault(); + sizewithSpacing = new SizeBase(sizewithSpacing.Width + childrensizes.Sum(p => p.Width) + lastchildsize.Height / 2 - lastchildsize.Width, sizewithSpacing.Height + childrensizes.Sum(p => p.Height)); + } + else if (mindNode.NodeLevel == NodeLevel.Level3) + { + var childrensizes = mindNode.Children.Select(p => MeasureOverride(p, mindNode.IsExpanded && isExpanded)).ToArray(); + sizewithSpacing = new SizeBase(Math.Max(sizewithSpacing.Width, sizewithSpacing.Width * 0.5 + childrensizes.Max(p => p.Width)), sizewithSpacing.Height + childrensizes.Sum(p => p.Height)); } } mindNode.DesiredSize = isExpanded ? sizewithSpacing : new SizeBase(0, 0); @@ -129,26 +142,56 @@ namespace AIStudio.Wpf.Mind.Helpers public void ArrangeOverride(MindNode mindNode) { - double left = mindNode.MiddlePosition.X - Math.Max(mindNode.DesiredSize.Width, mindNode.Children.Sum(p => p.DesiredSize.Width)) / 2; - double top = mindNode.MiddlePosition.Y + mindNode.ItemHeight / 2 + mindNode.Spacing.Height; - if (mindNode.Children?.Count > 0) + if (mindNode.NodeLevel == NodeLevel.Level1) { - foreach (var child in mindNode.Children) + var tops = mindNode.Children.Where(p => p.ConnectorOrientation == ConnectorOrientation.BottomLeft).ToList(); + double topleft = mindNode.MiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width; + double toptop = mindNode.MiddlePosition.Y - mindNode.ItemHeight / 2 - mindNode.Spacing.Height; + + if (mindNode.Children?.Count > 0) { - child.Left = left + child.DesiredSize.Width / 2 - child.ItemWidth / 2 + child.Offset.X; - child.Top = top + child.Spacing.Height + child.Offset.Y; - child.DesiredPosition = child.Position; - left += child.DesiredSize.Width; + foreach (var child in tops) + { + child.Left = topleft + child.Spacing.Width + child.Offset.X; + child.Top = toptop - child.ItemHeight - child.Spacing.Height + child.Offset.Y; + child.DesiredPosition = child.Position; + topleft += child.DesiredSize.Width; - ArrangeOverride(child); + ArrangeOverride(child); - var connect = mindNode.Root?.Items.OfType().FirstOrDefault(p => p.SourceConnectorInfo?.DataItem == mindNode && p.SinkConnectorInfoFully?.DataItem == child); - connect?.SetSourcePort(mindNode.BottomConnector); - connect?.SetSinkPort(child.TopConnector); - connect.Visible = child.Visible; + //var connect = mindNode.Root?.Items.OfType().FirstOrDefault(p => p.SourceConnectorInfo?.DataItem == mindNode && p.SinkConnectorInfoFully?.DataItem == child); + //connect?.SetSourcePort(mindNode.BottomConnector); + //connect?.SetSinkPort(child.TopConnector); + //connect.Visible = child.Visible; + } + } + + var bottoms = mindNode.Children.Where(p => p.ConnectorOrientation == ConnectorOrientation.TopLeft).ToList(); + double bottomleft = mindNode.MiddlePosition.X + mindNode.ItemWidth / 2 + mindNode.Spacing.Width; + double bottomtop = mindNode.MiddlePosition.Y + mindNode.ItemHeight / 2 + mindNode.Spacing.Height; + + if (mindNode.Children?.Count > 0) + { + foreach (var child in bottoms) + { + child.Left = bottomleft + child.Spacing.Width + child.Offset.X; + child.Top = bottomtop + child.ItemHeight + child.Spacing.Height + child.Offset.Y; + child.DesiredPosition = child.Position; + bottomleft += child.DesiredSize.Width; + + ArrangeOverride(child); + + //var connect = mindNode.Root?.Items.OfType().FirstOrDefault(p => p.SourceConnectorInfo?.DataItem == mindNode && p.SinkConnectorInfoFully?.DataItem == child); + //connect?.SetSourcePort(mindNode.BottomConnector); + //connect?.SetSinkPort(child.TopConnector); + //connect.Visible = child.Visible; + } } } + else if (mindNode.NodeLevel == NodeLevel.Level2) + { + } } }