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

<UserControl x:Class="LDLayout.LDLayout"
    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:LDLayout">

  <UserControl.Resources>
    <local:StringEnumConverter x:Key="theStringEnumConverter" />

    <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="Normal" Curve="None" />
        </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" />
        </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>
            <TextBlock Grid.Row="0" Text="Graph Generator" FontWeight="Bold" />
            <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
              <StackPanel>
                <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>
                <Button Content="Generate Graph" Click="GenerateGraph_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="Layered Digraph Layout Properties" FontWeight="Bold" />
            <ScrollViewer Grid.Row="1">
              <StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Direction: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="DirectionTextBox" Text="0" />
                  <TextBlock Text=" (0: right, 90: down, 180: left, 270: up)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="LayerSpacing: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="LayerSpacingTextBox" Text="25" />
                  <TextBlock Text=" (>= 1)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="ColumnSpacing: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="ColumnSpacingTextBox" Text="25" />
                  <TextBlock Text=" (>= 1; smaller is slower)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Cycle Remove: "
                             VerticalAlignment="Center" />
                  <StackPanel x:Name="CycleRemoveRadioButtonGroup" Tag="DepthFirst"
                              Orientation="Horizontal">
                    <RadioButton Content="DepthFirst" Checked="RadioButton_Checked" IsChecked="True" />
                    <RadioButton Content="Greedy" Checked="RadioButton_Checked" />
                  </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Layering: "
                             VerticalAlignment="Center" />
                  <StackPanel x:Name="LayeringRadioButtonGroup" Tag="OptimalLinkLength"
                              Orientation="Horizontal">
                    <RadioButton Content="OptimalLinkLength" Checked="RadioButton_Checked" IsChecked="True" />
                    <RadioButton Content="LongestPathSink" Checked="RadioButton_Checked" />
                    <RadioButton Content="LongestPathSource" Checked="RadioButton_Checked" />
                  </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Initialize: "
                             VerticalAlignment="Center" />
                  <StackPanel x:Name="InitializeRadioButtonGroup" Tag="DepthFirstOut"
                              Orientation="Horizontal">
                    <RadioButton Content="DepthFirstOut" Checked="RadioButton_Checked" IsChecked="True" />
                    <RadioButton Content="DepthFirstIn" Checked="RadioButton_Checked" />
                    <RadioButton Content="Naive" Checked="RadioButton_Checked" />
                  </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Iterations: "
                             VerticalAlignment="Center" />
                  <TextBox x:Name="IterationsTextBox" Text="4" />
                  <TextBlock Text=" (>= zero)"
                             VerticalAlignment="Center" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Aggressive: "
                             VerticalAlignment="Center" />
                  <StackPanel x:Name="AggressiveRadioButtonGroup" Tag="Less"
                              Orientation="Horizontal">
                    <RadioButton Content="None" Checked="RadioButton_Checked" />
                    <RadioButton Content="Less" Checked="RadioButton_Checked" IsChecked="True" />
                    <RadioButton Content="More" Checked="RadioButton_Checked" />
                  </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Pack: "
                             VerticalAlignment="Center" />
                  <StackPanel x:Name="PackCheckBoxGroup" Tag="7"
                              Orientation="Horizontal">
                    <CheckBox Content="Expand" Tag="1" IsChecked="True"
                              Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" />
                    <CheckBox Content="Straighten" Tag="2" IsChecked="True"
                              Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" />
                    <CheckBox Content="Median" Tag="4" IsChecked="True"
                              Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" />
                  </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="SetsPortSpots: "
                             VerticalAlignment="Center" />
                  <CheckBox x:Name="SetsPortSpotsCheckBox"
                            IsChecked="True" />
                </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:LayeredDigraphLayout
            Direction="{Binding ElementName=DirectionTextBox, Path=Text}"
            LayerSpacing="{Binding ElementName=LayerSpacingTextBox, Path=Text}"
            ColumnSpacing="{Binding ElementName=ColumnSpacingTextBox, Path=Text}"
            CycleRemoveOption="{Binding ElementName=CycleRemoveRadioButtonGroup, Path=Tag}"
            LayeringOption="{Binding ElementName=LayeringRadioButtonGroup, Path=Tag}"
            InitializeOption="{Binding ElementName=InitializeRadioButtonGroup, Path=Tag}"
            Iterations="{Binding ElementName=IterationsTextBox, Path=Text}"
            AggressiveOption="{Binding ElementName=AggressiveRadioButtonGroup, Path=Tag}"
            PackOption="{Binding ElementName=PackCheckBoxGroup, Path=Tag,
                                 Converter={StaticResource theStringEnumConverter}}"
            SetsPortSpots="{Binding ElementName=SetsPortSpotsCheckBox, Path=IsChecked}"
          />
      </go:Diagram.Layout>
    </go:Diagram>
  </Grid>
</UserControl>
