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

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

  <UserControl.Resources>
    <!-- Used as Comparer -->
    <local:AreaComparer x:Key="AreaComp" />

    <DataTemplate x:Key="RectangularTemplate">
      <StackPanel go:Part.SelectionAdorned="True"
                  go:Node.LocationSpot="Center"
                  go:Part.Text="{Binding Path=Data.Key}"
                  go:Node.Location="{Binding Path=Data.Location}">
        <Rectangle Fill="{Binding Path=Data.Color}"
                   Stroke="Black" StrokeThickness="1"
                   Width="{Binding Path=Data.Width}"
                   Height="{Binding Path=Data.Height}"
                   go:Node.PortId="" />
      </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="EllipticalTemplate">
      <StackPanel go:Part.SelectionAdorned="True"
                  go:Node.LocationSpot="Center"
                  go:Part.Text="{Binding Path=Data.Key}"
                  go:Node.Location="{Binding Path=Data.Location}">
        <Ellipse Fill="{Binding Path=Data.Color}"
                 Stroke="Black" StrokeThickness="1"
                 Width="{Binding Path=Data.Width}"
                 Height="{Binding Path=Data.Height}"
                 go:Node.PortId="" />
      </StackPanel>
    </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>

        <!-- Data properties -->
        <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="New Graph" FontWeight="Bold" />
            <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
              <!-- Data properties -->
              <StackPanel Orientation="Vertical" Grid.Row="2" Grid.Column="2">
                <StackPanel Orientation="Vertical">
                  <StackPanel Orientation="Horizontal">
                    <TextBlock Text="# of nodes: " />
                    <TextBox Text="16" x:Name="NodeNumTextBox" MaxLength="3" />
                  </StackPanel>
                  <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Node Size: " />
                    <TextBox Text="25" x:Name="WidthTextBox" />
                    <TextBlock Text="x" />
                    <TextBox Text="25" x:Name="HeightTextBox" />
                  </StackPanel>
                </StackPanel>
                <CheckBox x:Name="RandomSizesCheckBox" Content="Random sizes &lt;= 65" IsChecked="True" />
                <CheckBox x:Name="RectangularNodesCheckBox" Content="Rectangular Nodes (vs. circular)" IsChecked="True" />
                <!-- Link stuff -->
                <CheckBox x:Name="CyclicGraphCheckBox" Content="Graph is simple ring" IsChecked="False" />
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="# of links from node between " />
                  <TextBox x:Name="MinLinksTextBox" Text="1" />
                  <TextBlock Text="and" />
                  <TextBox x:Name="MaxLinksTextBox" Text="2" />
                </StackPanel>
                <!-- updates data -->
                <Button Content="Rebuild Model" Click="BuildModel" Height="24" HorizontalAlignment="Left" />
              </StackPanel>
            </ScrollViewer>
          </Grid>
        </Border>

        <!-- Layout Properties -->
        <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="Circular Layout Properties" FontWeight="Bold" />
            <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
              <StackPanel Orientation="Vertical">
                <!-- 1st -->
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Radius: " />
                  <TextBox Text="NaN" x:Name="RadiusBox" />
                  <TextBlock Text="(along X axis; NaN or > 0)" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Aspect Ratio: " />
                  <TextBox Text="1" x:Name="AspectBox" />
                  <TextBlock Text="(1 is circular; > 0)" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Start Angle: " />
                  <TextBox Text="0" x:Name="StartBox" />
                  <TextBlock Text="(angle at first element)" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Sweep Angle: " />
                  <TextBox Text="360" x:Name="SweepBox" />
                  <TextBlock Text="(degrees occupied; &gt;= 1, &lt;= 360)" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Spacing: " />
                  <TextBox Text="6" x:Name="SpacingBox" />
                  <TextBlock Text="(actual spacing also depends on Radius)" />
                </StackPanel>

                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Arrangement: " />
                  <StackPanel Orientation="Vertical" x:Name="ArrGroup" Tag="ConstantSpacing">
                    <RadioButton Checked="Button_Checked" Content="ConstantDistance" IsChecked="False" />
                    <RadioButton Checked="Button_Checked" Content="ConstantAngle" IsChecked="False" />
                    <RadioButton Checked="Button_Checked" Content="ConstantSpacing" IsChecked="True" />
                    <RadioButton Checked="Button_Checked" Content="Packed" IsChecked="False" />
                  </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Node diameter: " />
                  <StackPanel Orientation="Vertical" x:Name="DiamGroup" Tag="Pythagorean">
                    <RadioButton Checked="Button_Checked" Content="Pythagorean" IsChecked="True" />
                    <RadioButton Checked="Button_Checked" Content="Circular" IsChecked="False" />
                  </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Direction: " />
                  <StackPanel Orientation="Vertical" x:Name="DirGroup" Tag="Clockwise">
                    <RadioButton Checked="Button_Checked" Content="Clockwise" IsChecked="True" />
                    <RadioButton Checked="Button_Checked" Content="Counterclockwise" IsChecked="False" />
                    <RadioButton Checked="Button_Checked" Content="BidirectionalLeft" IsChecked="False" />
                    <RadioButton Checked="Button_Checked" Content="BidirectionalRight" IsChecked="False" />
                  </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Sorting: " />
                  <StackPanel Orientation="Vertical" x:Name="SortGroup" Tag="Forwards">
                    <RadioButton Checked="Button_Checked" Content="Forwards" IsChecked="False" />
                    <RadioButton Checked="Button_Checked" Content="Reverse" IsChecked="False" />
                    <RadioButton Checked="Button_Checked" Content="Ascending" IsChecked="False" />
                    <RadioButton Checked="Button_Checked" Content="Descending" IsChecked="False" />
                    <RadioButton Checked="Button_Checked" Content="Optimized" IsChecked="True" />
                  </StackPanel>
                </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" Padding="5"
                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                NodeTemplate="{StaticResource RectangularTemplate}">
      <go:Diagram.Layout>
        <go:CircularLayout
          Arrangement="{Binding ElementName=ArrGroup, Path=Tag}"
          AspectRatio="{Binding ElementName=AspectBox, Path=Text}"
          Comparer="{StaticResource AreaComp}"
          Direction="{Binding ElementName=DirGroup, Path=Tag}"
          NodeDiameterFormula="{Binding ElementName=DiamGroup, Path=Tag}"
          Radius="{Binding ElementName=RadiusBox, Path=Text}"
          Sorting="{Binding ElementName=SortGroup, Path=Tag}"
          Spacing="{Binding ElementName=SpacingBox, Path=Text}"
          StartAngle="{Binding ElementName=StartBox, Path=Text}"
          SweepAngle="{Binding ElementName=SweepBox, Path=Text}" />
      </go:Diagram.Layout>
    </go:Diagram>
  </Grid>
</UserControl>
