mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
xx
This commit is contained in:
@@ -37,7 +37,7 @@ namespace AIStudio.Wpf.Flowchart
|
||||
}
|
||||
|
||||
|
||||
private MindType _mindType = Mind.MindType.Organizational;
|
||||
private MindType _mindType = Mind.MindType.Directory;
|
||||
public MindType MindType
|
||||
{
|
||||
get
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Helpers
|
||||
{
|
||||
public class GetTextDisplayWidthHelper
|
||||
{
|
||||
public static Double GetTextDisplayWidth(Label label)
|
||||
{
|
||||
|
||||
return GetTextDisplayWidth(label.Content.ToString(), label.FontFamily, label.FontStyle, label.FontWeight, label.FontStretch, label.FontSize);
|
||||
|
||||
}
|
||||
|
||||
public static Double GetTextDisplayWidth(string str, FontFamily fontFamily, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, double fontSize)
|
||||
{
|
||||
|
||||
var formattedText = new FormattedText(
|
||||
str,
|
||||
CultureInfo.CurrentUICulture,
|
||||
FlowDirection.LeftToRight,
|
||||
new Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
|
||||
fontSize,
|
||||
Brushes.Black
|
||||
);
|
||||
|
||||
Size size = new Size(formattedText.Width, formattedText.Height);
|
||||
|
||||
return size.Width;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = left + child.Spacing.Width + child.Offset.X;
|
||||
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;
|
||||
|
||||
155
AIStudio.Wpf.Mind/Helpers/FishBoneLayout.cs
Normal file
155
AIStudio.Wpf.Mind/Helpers/FishBoneLayout.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Algorithms;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
using AIStudio.Wpf.Mind.ViewModels;
|
||||
|
||||
namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
public class FishBoneLayout : IMindLayout
|
||||
{
|
||||
public void Appearance(MindNode mindNode)
|
||||
{
|
||||
switch (mindNode.NodeLevel)
|
||||
{
|
||||
case NodeLevel.Level1:
|
||||
{
|
||||
mindNode.ItemWidth = 110;
|
||||
mindNode.ItemHeight = 40;
|
||||
mindNode.ClearConnectors();
|
||||
|
||||
var port = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Right, true) { XRatio = 1, YRatio = 0.5 };
|
||||
mindNode.AddConnector(port);
|
||||
|
||||
mindNode.IsInnerConnector = true;
|
||||
|
||||
mindNode.ColorViewModel.FillColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
|
||||
mindNode.ColorViewModel.LineColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
|
||||
mindNode.FontViewModel.FontColor = Colors.White;
|
||||
mindNode.FontViewModel.FontSize = 15;
|
||||
mindNode.ShapeViewModel.SinkMarker.PathStyle = ArrowPathStyle.None;
|
||||
mindNode.ShapeViewModel.SinkMarker.SizeStyle = ArrowSizeStyle.VerySmall;
|
||||
|
||||
break;
|
||||
}
|
||||
case NodeLevel.Level2:
|
||||
{
|
||||
mindNode.ItemWidth = 80;
|
||||
mindNode.ItemHeight = 25;
|
||||
mindNode.ClearConnectors();
|
||||
|
||||
var port1 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.BottomLeft, true) { XRatio = 0, YRatio = 1 };
|
||||
mindNode.AddConnector(port1);
|
||||
var port2 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Top, true) { XRatio = 0.25, YRatio = 0 };
|
||||
mindNode.AddConnector(port2);
|
||||
|
||||
var port3 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.TopLeft, true) { XRatio = 0, YRatio = 0 };
|
||||
mindNode.AddConnector(port3);
|
||||
var port4 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Bottom, true) { XRatio = 0.25, YRatio = 1 };
|
||||
mindNode.AddConnector(port4);
|
||||
|
||||
mindNode.IsInnerConnector = true;
|
||||
|
||||
mindNode.ColorViewModel.LineColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
|
||||
mindNode.ShapeViewModel.SinkMarker.PathStyle = ArrowPathStyle.None;
|
||||
mindNode.ShapeViewModel.SinkMarker.SizeStyle = ArrowSizeStyle.VerySmall;
|
||||
break;
|
||||
}
|
||||
case NodeLevel.Level3:
|
||||
{
|
||||
mindNode.ItemWidth = 80;
|
||||
mindNode.ItemHeight = 25;
|
||||
mindNode.ClearConnectors();
|
||||
|
||||
var port1 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.BottomLeft, true) { XRatio = 0, YRatio = 1 };
|
||||
mindNode.AddConnector(port1);
|
||||
var port2 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Top, true) { XRatio = 0.25, YRatio = 0 };
|
||||
mindNode.AddConnector(port2);
|
||||
|
||||
var port3 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.TopLeft, true) { XRatio = 0, YRatio = 0 };
|
||||
mindNode.AddConnector(port3);
|
||||
var port4 = new FullyCreatedConnectorInfo(mindNode.Root, mindNode, ConnectorOrientation.Bottom, true) { XRatio = 0.25, YRatio = 1 };
|
||||
mindNode.AddConnector(port4);
|
||||
|
||||
mindNode.IsInnerConnector = true;
|
||||
mindNode.ColorViewModel.LineColor.Color = Color.FromRgb(0x73, 0xa1, 0xbf);
|
||||
mindNode.ShapeViewModel.SinkMarker.PathStyle = ArrowPathStyle.None;
|
||||
mindNode.ShapeViewModel.SinkMarker.SizeStyle = ArrowSizeStyle.VerySmall;
|
||||
mindNode.CornerRadius = new System.Windows.CornerRadius(0);
|
||||
mindNode.BorderThickness = new System.Windows.Thickness(0, 0, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void LayoutUpdated(MindNode mindNode)
|
||||
{
|
||||
if (mindNode == null) return;
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = true;
|
||||
var size = MeasureOverride(mindNode);
|
||||
ArrangeOverride(mindNode);
|
||||
|
||||
mindNode.Root.BringToFrontCommand.Execute(new SelectableDesignerItemViewModelBase[] { mindNode });
|
||||
|
||||
mindNode.GetLevel1Node().LayoutUpdating = false;
|
||||
}
|
||||
|
||||
public SizeBase MeasureOverride(MindNode mindNode, bool isExpanded = true)
|
||||
{
|
||||
var sizewithSpacing = mindNode.SizeWithSpacing;
|
||||
if (mindNode.Children?.Count > 0)
|
||||
{
|
||||
if (mindNode.NodeLevel == NodeLevel.Level1)
|
||||
{
|
||||
var tops = mindNode.Children.Where((p, index) => index % 2 == 0).ToList();
|
||||
tops.ForEach(p => p.ConnectorOrientation = ConnectorOrientation.Top);
|
||||
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);
|
||||
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));
|
||||
}
|
||||
else
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
mindNode.DesiredSize = isExpanded ? sizewithSpacing : new SizeBase(0, 0);
|
||||
mindNode.Visible = isExpanded;
|
||||
|
||||
return mindNode.DesiredSize;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
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;
|
||||
|
||||
ArrangeOverride(child);
|
||||
|
||||
var connect = mindNode.Root?.Items.OfType<ConnectionViewModel>().FirstOrDefault(p => p.SourceConnectorInfo?.DataItem == mindNode && p.SinkConnectorInfoFully?.DataItem == child);
|
||||
connect?.SetSourcePort(mindNode.BottomConnector);
|
||||
connect?.SetSinkPort(child.TopConnector);
|
||||
connect.Visible = child.Visible;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -112,7 +112,7 @@ namespace AIStudio.Wpf.Mind.Helpers
|
||||
{
|
||||
foreach (var child in mindNode.Children)
|
||||
{
|
||||
child.Left = left + child.DesiredSize.Width / 2 - child.ItemWidth + child.Spacing.Width + child.Offset.X;
|
||||
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;
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Algorithms;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using AIStudio.Wpf.Mind.Helpers;
|
||||
|
||||
@@ -585,6 +586,12 @@ namespace AIStudio.Wpf.Mind.ViewModels
|
||||
}
|
||||
break;
|
||||
}
|
||||
case nameof(Text):
|
||||
{
|
||||
ItemWidth = Math.Max(ItemWidth, GetTextDisplayWidthHelper.GetTextDisplayWidth(Text, new FontFamily(FontViewModel.FontFamily), FontViewModel.FontStyle, FontViewModel.FontWeight, FontViewModel.FontStretch, FontViewModel.FontSize) + 30);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user