<!-- Copyright © Northwoods Software Corporation, 2008-2026. All Rights Reserved. -->

<UserControl x:Class="TLayout.TLayout"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:go="http://schemas.nwoods.com/GoXam"
    xmlns:local="clr-namespace:TLayout">

  <UserControl.Resources>
    <local:SimpleComparer x:Key="theSimpleComparer" />

    <DataTemplate x:Key="nodeTemplate1">
      <StackPanel go:Part.SelectionAdorned="True" go:Part.SelectionElementName="ellipse">
        <Ellipse x:Name="ellipse" Fill="{Binding Path=Data.Color}" Stroke="Black" 
                 Width="40" Height="40" go:Node.PortId="" />
        <TextBlock Text="{Binding Path=Data.Key}" HorizontalAlignment="Center" />
      </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="linkTemplate1">
      <go:LinkPanel>
        <go:Link.Route>
          <go:Route Routing="Orthogonal" Curve="None" Corner="5" />
        </go:Link.Route>
        <go:LinkShape Stroke="Black" StrokeThickness="1" />
        <Path Fill="Black" go:LinkPanel.ToArrow="Standard" />
      </go:LinkPanel>
    </DataTemplate>
  </UserControl.Resources>

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="*" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="4*" />
    </Grid.RowDefinitions>

    <Border Grid.Row="0" Background="LightGray" Padding="2">
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Border Grid.Column="0" VerticalAlignment="Stretch"
              Background="AliceBlue" Margin="1" Padding="1"
              BorderBrush="Gray" BorderThickness="2" CornerRadius="2">
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
              <StackPanel>
                <TextBlock Text="TreeStyle:" FontWeight="Bold" />
                <Grid x:Name="TreeStyleRadioButtonGroup" Tag="LastParents">
                  <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                  </Grid.RowDefinitions>
                  <RadioButton Grid.Row="0"
                    Content="Layered" Checked="RadioButton_Checked" />
                  <RadioButton Grid.Row="1"
                    Content="LastParents" Checked="RadioButton_Checked" IsChecked="True" />
                  <RadioButton Grid.Row="2"
                    Content="Alternating" Checked="RadioButton_Checked" />
                  <RadioButton Grid.Row="3"
                    Content="RootOnly" Checked="RadioButton_Checked" />
                </Grid>
                <TextBlock Text="New Tree:" FontWeight="Bold" Margin="0 5 0 0" />
                <StackPanel Orientation="Horizontal">
                  <TextBlock VerticalAlignment="Center" Text="MinNodes: " />
                  <TextBox Text="20" x:Name="txtMinNodes" MaxLength="3" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock VerticalAlignment="Center" Text="MaxNodes: " />
                  <TextBox Text="50" x:Name="txtMaxNodes" MaxLength="3" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock VerticalAlignment="Center" Text="MinChildren: " />
                  <TextBox Text="3" x:Name="txtMinLinks" MaxLength="2" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock VerticalAlignment="Center" Text="MaxChildren: " />
                  <TextBox Text="5" x:Name="txtMaxLinks" MaxLength="2" />
                </StackPanel>
                <Button Content="Generate Tree" Click="GenerateTree_Click" />
              </StackPanel>
            </ScrollViewer>
          </Grid>
        </Border>

        <Border Grid.Column="1" VerticalAlignment="Stretch"
              Background="AliceBlue" Margin="1" Padding="1"
              BorderBrush="Gray" BorderThickness="2" CornerRadius="2">
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0"
                       Text="Tree Layout Properties" FontWeight="Bold" />
            <ScrollViewer Grid.Row="1">
              <StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Angle: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="AngleTextBox" Text="0" />
                  <TextBlock Text=" (0: right, 90: down, 180: left, 270: up)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Alignment: "
                             VerticalAlignment="Center" />
                  <Grid x:Name="AlignmentRadioButtonGroup" Tag="CenterChildren">
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="Auto" />
                      <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <RadioButton Grid.Row="0" Grid.Column="0"
                        Content="CenterChildren" Checked="RadioButton_Checked" IsChecked="True" />
                    <RadioButton Grid.Row="0" Grid.Column="1" 
                        Content="CenterSubtrees" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="1" Grid.Column="0"
                        Content="Start" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="1" Grid.Column="1"
                        Content="End" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="2" Grid.Column="0"
                        Content="Bus" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="2" Grid.Column="1"
                        Content="TopLeftBus" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="3" Grid.Column="0"
                        Content="BottomRightBus" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="3" Grid.Column="1"
                        Content="BusBranching" Checked="RadioButton_Checked" />
                  </Grid>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="NodeSpacing: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="NodeSpacingTextBox" Text="20" />
                  <TextBlock Text=" (negative causes overlaps)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="NodeIndent: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="NodeIndentTextBox" Text="0" />
                  <TextBlock Text=" (when Start or End; >= zero)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="NodeIndentPastParent: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="NodeIndentPastParentTextBox" Text="0" />
                  <TextBlock Text=" (fraction; 0-1)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="LayerSpacing: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="LayerSpacingTextBox" Text="50" />
                  <TextBlock Text=" (negative causes overlaps)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="LayerSpacingParentOverlap: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="LayerSpacingParentOverlapTextBox" Text="0" />
                  <TextBlock Text=" (fraction; 0-1)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Sorting: "
                             VerticalAlignment="Center" />
                  <Grid x:Name="SortingRadioButtonGroup" Tag="Ascending">
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="Auto" />
                      <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <RadioButton Grid.Row="0" Grid.Column="0"
                      Content="Forwards" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="0" Grid.Column="1"
                      Content="Reverse" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="1" Grid.Column="0"
                      Content="Ascending" Checked="RadioButton_Checked" IsChecked="True" />
                    <RadioButton Grid.Row="1" Grid.Column="1"
                      Content="Descending" Checked="RadioButton_Checked" />
                  </Grid>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Compaction: "
                             VerticalAlignment="Center" />
                  <StackPanel x:Name="CompactionRadioButtonGroup" Tag="Block"
                              Orientation="Horizontal">
                    <RadioButton Content="Block" Checked="RadioButton_Checked" IsChecked="True" />
                    <RadioButton Content="None" Checked="RadioButton_Checked" />
                  </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="BreadthLimit: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="BreadthLimitTextBox" Text="0" />
                  <TextBlock Text=" (zero means no limit)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="RowSpacing: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="RowSpacingTextBox" Text="25" />
                  <TextBlock Text=" (negative causes overlaps)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="RowIndent: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="RowIndentTextBox" Text="10" />
                  <TextBlock Text=" (>= zero)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="SetsPortSpot: "
                             VerticalAlignment="Center" />
                  <CheckBox x:Name="SetsPortSpotCheckBox"
                            IsChecked="True" />
                  <TextBlock Text=" (Route.FromSpot)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="SetsChildPortSpot: "
                             VerticalAlignment="Center" />
                  <CheckBox x:Name="SetsChildPortSpotCheckBox"
                            IsChecked="True" />
                  <TextBlock Text=" (Route.ToSpot)"
                             VerticalAlignment="Center" />
                </StackPanel>
              </StackPanel>
            </ScrollViewer>
          </Grid>
        </Border>

        <Border Grid.Column="2" VerticalAlignment="Stretch"
              Background="AliceBlue" Margin="1" Padding="1"
              BorderBrush="Gray" BorderThickness="2" CornerRadius="2">
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0"
                       Text="Alternate Layout Properties" FontWeight="Bold" />
            <ScrollViewer Grid.Row="1">
              <StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Angle: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="AlternateAngleTextBox" Text="90" />
                  <TextBlock Text=" (0: right, 90: down, 180: left, 270: up)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Alignment: "
                             VerticalAlignment="Center" />
                  <Grid x:Name="AlternateAlignmentRadioButtonGroup" Tag="CenterChildren">
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="Auto" />
                      <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <RadioButton Grid.Row="0" Grid.Column="0"
                        Content="CenterChildren" Checked="RadioButton_Checked" IsChecked="True" />
                    <RadioButton Grid.Row="0" Grid.Column="1" 
                        Content="CenterSubtrees" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="1" Grid.Column="0"
                        Content="Start" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="1" Grid.Column="1"
                        Content="End" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="2" Grid.Column="0"
                        Content="Bus" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="2" Grid.Column="1"
                        Content="TopLeftBus" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="3" Grid.Column="0"
                        Content="BottomRightBus" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="3" Grid.Column="1"
                        Content="BusBranching" Checked="RadioButton_Checked" />
                  </Grid>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="NodeSpacing: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="AlternateNodeSpacingTextBox" Text="20" />
                  <TextBlock Text=" (negative causes overlaps)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="NodeIndent: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="AlternateNodeIndentTextBox" Text="0" />
                  <TextBlock Text=" (when Start or End; >= zero)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="NodeIndentPastParent: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="AlternateNodeIndentPastParentTextBox" Text="0" />
                  <TextBlock Text=" (fraction; 0-1)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="LayerSpacing: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="AlternateLayerSpacingTextBox" Text="50" />
                  <TextBlock Text=" (negative causes overlaps)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="LayerSpacingParentOverlap: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="AlternateLayerSpacingParentOverlapTextBox" Text="0" />
                  <TextBlock Text=" (fraction; 0-1)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Sorting: "
                             VerticalAlignment="Center" />
                  <Grid x:Name="AlternateSortingRadioButtonGroup" Tag="Ascending">
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="Auto" />
                      <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <RadioButton Grid.Row="0" Grid.Column="0"
                      Content="Forwards" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="0" Grid.Column="1"
                      Content="Reverse" Checked="RadioButton_Checked" />
                    <RadioButton Grid.Row="1" Grid.Column="0"
                      Content="Ascending" Checked="RadioButton_Checked" IsChecked="True" />
                    <RadioButton Grid.Row="1" Grid.Column="1"
                      Content="Descending" Checked="RadioButton_Checked" />
                  </Grid>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Compaction: "
                             VerticalAlignment="Center" />
                  <StackPanel x:Name="AlternateCompactionRadioButtonGroup" Tag="Block"
                              Orientation="Horizontal">
                    <RadioButton Content="Block" Checked="RadioButton_Checked" IsChecked="True" />
                    <RadioButton Content="None" Checked="RadioButton_Checked" />
                  </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="BreadthLimit: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="AlternateBreadthLimitTextBox" Text="0" />
                  <TextBlock Text=" (zero means no limit)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="RowSpacing: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="AlternateRowSpacingTextBox" Text="25" />
                  <TextBlock Text=" (negative causes overlaps)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="RowIndent: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="AlternateRowIndentTextBox" Text="10" />
                  <TextBlock Text=" (>= zero)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="SetsPortSpot: "
                             VerticalAlignment="Center" />
                  <CheckBox x:Name="AlternateSetsPortSpotCheckBox"
                            IsChecked="True" />
                  <TextBlock Text=" (Route.FromSpot)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="SetsChildPortSpot: "
                             VerticalAlignment="Center" />
                  <CheckBox x:Name="AlternateSetsChildPortSpotCheckBox"
                            IsChecked="True" />
                  <TextBlock Text=" (Route.ToSpot)"
                             VerticalAlignment="Center" />
                </StackPanel>
              </StackPanel>
            </ScrollViewer>
          </Grid>
        </Border>
      </Grid>
    </Border>

    <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="5" />

    <go:Diagram x:Name="myDiagram" Grid.Row="2"
                HorizontalContentAlignment="Stretch"
                VerticalContentAlignment="Stretch"
                NodeTemplate="{StaticResource nodeTemplate1}"
                LinkTemplate="{StaticResource linkTemplate1}">
      <go:Diagram.Layout>
        <go:TreeLayout
            TreeStyle="{Binding ElementName=TreeStyleRadioButtonGroup, Path=Tag}"

            Angle="{Binding ElementName=AngleTextBox, Path=Text}"
            Alignment="{Binding ElementName=AlignmentRadioButtonGroup, Path=Tag}"
            NodeIndent="{Binding ElementName=NodeIndentTextBox, Path=Text}"
            NodeIndentPastParent="{Binding ElementName=NodeIndentPastParentTextBox, Path=Text}"
            NodeSpacing="{Binding ElementName=NodeSpacingTextBox, Path=Text}"
            LayerSpacing="{Binding ElementName=LayerSpacingTextBox, Path=Text}"
            LayerSpacingParentOverlap="{Binding ElementName=LayerSpacingParentOverlapTextBox, Path=Text}"
            Compaction="{Binding ElementName=CompactionRadioButtonGroup, Path=Tag}"
            BreadthLimit="{Binding ElementName=BreadthLimitTextBox, Path=Text}"
            RowSpacing="{Binding ElementName=RowSpacingTextBox, Path=Text}"
            RowIndent="{Binding ElementName=RowIndentTextBox, Path=Text}"
            SetsPortSpot="{Binding ElementName=SetsPortSpotCheckBox, Path=IsChecked}"
            SetsChildPortSpot="{Binding ElementName=SetsChildPortSpotCheckBox, Path=IsChecked}"
            Sorting="{Binding ElementName=SortingRadioButtonGroup, Path=Tag}"
            Comparer="{StaticResource theSimpleComparer}"

            AlternateAngle="{Binding ElementName=AlternateAngleTextBox, Path=Text}"
            AlternateAlignment="{Binding ElementName=AlternateAlignmentRadioButtonGroup, Path=Tag}"
            AlternateNodeIndent="{Binding ElementName=AlternateNodeIndentTextBox, Path=Text}"
            AlternateNodeIndentPastParent="{Binding ElementName=AlternateNodeIndentPastParentTextBox, Path=Text}"
            AlternateNodeSpacing="{Binding ElementName=AlternateNodeSpacingTextBox, Path=Text}"
            AlternateLayerSpacing="{Binding ElementName=AlternateLayerSpacingTextBox, Path=Text}"
            AlternateLayerSpacingParentOverlap="{Binding ElementName=AlternateLayerSpacingParentOverlapTextBox, Path=Text}"
            AlternateCompaction="{Binding ElementName=AlternateCompactionRadioButtonGroup, Path=Tag}"
            AlternateBreadthLimit="{Binding ElementName=AlternateBreadthLimitTextBox, Path=Text}"
            AlternateRowSpacing="{Binding ElementName=AlternateRowSpacingTextBox, Path=Text}"
            AlternateRowIndent="{Binding ElementName=AlternateRowIndentTextBox, Path=Text}"
            AlternateSetsPortSpot="{Binding ElementName=AlternateSetsPortSpotCheckBox, Path=IsChecked}"
            AlternateSetsChildPortSpot="{Binding ElementName=AlternateSetsChildPortSpotCheckBox, Path=IsChecked}"
            AlternateSorting="{Binding ElementName=AlternateSortingRadioButtonGroup, Path=Tag}"
            AlternateComparer="{StaticResource theSimpleComparer}"
          />
      </go:Diagram.Layout>
    </go:Diagram>
  </Grid>
</UserControl>
