Никита Кашлач 3 lat temu
rodzic
commit
999cbc1b38

+ 5 - 3
MatrixXAMLOnly/DiagramWindow.xaml

@@ -21,15 +21,17 @@
                 </Grid.ColumnDefinitions>
 
                 <StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left" Margin="50 15 0 15">
-                    <ComboBox x:Name="ComboBoxOrientation" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="14" FontWeight="SemiBold" Margin="0 0 10 0" MinWidth="120">
+                    <ComboBox x:Name="ComboBoxOrientation" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="14" FontWeight="SemiBold" Margin="0 0 10 0" MinWidth="120" MaxHeight="60">
                         <ComboBoxItem Content="По строке:"/>
                         <ComboBoxItem Content="По столбцу:"/>
                     </ComboBox>
-                    <TextBox x:Name="TextBoxNum" MinWidth="50" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="14" MaxLength="1"/>
+                    <TextBox x:Name="TextBoxNum" MinWidth="50" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="14" MaxLength="1" MaxHeight="60"/>
                 </StackPanel>
 
-                <Button x:Name="BtnCreateDiagram" Content="Построить диаграмму" Grid.Column="1" Margin="10 15 50 15" MinWidth="200" HorizontalAlignment="Right"/>
+                <Button x:Name="BtnCreateDiagram" Content="Построить диаграмму" Grid.Column="1" Margin="10 15 50 15" MinWidth="200" MaxHeight="60" HorizontalAlignment="Right" Click="BtnCreateDiagram_Click"/>
             </Grid>
         </Border>
+
+        <lvc:PieChart x:Name="PieDiagram" Grid.Row="1" LegendLocation="Bottom" Hoverable="False" DataTooltip="{x:Null}" Series="{Binding SeriesCollection}"/>
     </Grid>
 </Window>

+ 73 - 4
MatrixXAMLOnly/DiagramWindow.xaml.cs

@@ -1,4 +1,8 @@
-using System.Windows;
+using System;
+using System.Windows;
+using LiveCharts;
+using LiveCharts.Defaults;
+using LiveCharts.Wpf;
 using Matrix;
 
 namespace MatrixXAMLOnly
@@ -8,14 +12,79 @@ namespace MatrixXAMLOnly
     /// </summary>
     public partial class DiagramWindow : Window
     {
-        public DiagramWindow()
+        MyMatrix matrix;
+
+        public SeriesCollection SeriesCollection { get; set; }
+
+        public Func<ChartPoint, string> PointLabel { get; set; }
+
+        public DiagramWindow(MyMatrix matrix)
         {
             InitializeComponent();
+
+            this.matrix = matrix;
+            SeriesCollection = new SeriesCollection();
+
+            ComboBoxOrientation.SelectedIndex = 0;
+
+            PointLabel = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
+
+            DataContext = this;
         }
 
-        public DiagramWindow(MyMatrix matrix)
+        private void BtnCreateDiagram_Click(object sender, RoutedEventArgs e)
         {
-            InitializeComponent();
+            SeriesCollection.Clear();
+
+            int num;
+            try
+            {
+                num = Convert.ToInt32(TextBoxNum.Text) - 1;
+            }
+            catch
+            {
+                MessageBox.Show("Проверьте правильность введенных данных!");
+                return;
+            }
+
+
+            if (ComboBoxOrientation.SelectedIndex == 0)
+            {
+
+                if (num + 1 < 1 || num + 1 > matrix.Rows)
+                {
+                    MessageBox.Show("Указанное число превышает размерность матрицы!");
+                    return;
+                }
+
+                for (int i = 0; i < matrix.Columns; i++)
+                {
+                    SeriesCollection.Add(new PieSeries
+                    {
+                        Title = $"№{i + 1}",
+                        Values = new ChartValues<ObservableValue> { new ObservableValue(matrix.data[num, i]) },
+                        DataLabels = true
+                    });
+                }
+            }
+            else
+            {
+                if (num + 1 < 1 || num + 1 > matrix.Columns)
+                {
+                    MessageBox.Show("Указанное число превышает размерность матрицы!");
+                    return;
+                }
+
+                for (int i = 0; i < matrix.Rows; i++)
+                {
+                    SeriesCollection.Add(new PieSeries
+                    {
+                        Title = $"№{i + 1}",
+                        Values = new ChartValues<ObservableValue> { new ObservableValue(matrix.data[i, num]) },
+                        DataLabels = true
+                    });
+                }
+            }
         }
     }
 }

+ 8 - 8
MatrixXAMLOnly/MainWindow.xaml

@@ -212,7 +212,7 @@
                     <ColumnDefinition/>
                 </Grid.ColumnDefinitions>
 
-                <Button x:Name="BtnAdditionDiagramm" Grid.Column="1" Content="Диаграмма"/>
+                <Button x:Name="BtnAdditionDiagramm" Grid.Column="1" Content="Диаграмма" Click="BtnAdditionDiagramm_Click"/>
                 <Button x:Name="BtnAdditionCalculate" Grid.Column="2" Content="Вычислить" Click="BtnAdditionCalculate_Click"/>
             </Grid>
         </Grid> <!-- Addition -->
@@ -292,7 +292,7 @@
                     <ColumnDefinition/>
                 </Grid.ColumnDefinitions>
 
-                <Button x:Name="BtnDifferenceDiagramm" Grid.Column="1" Content="Диаграмма"/>
+                <Button x:Name="BtnDifferenceDiagramm" Grid.Column="1" Content="Диаграмма" Click="BtnDifferenceDiagramm_Click"/>
                 <Button x:Name="BtnDifferenceCalculate" Grid.Column="2" Content="Вычислить" Click="BtnDifferenceCalculate_Click"/>
             </Grid>
         </Grid> <!-- Difference -->
@@ -370,7 +370,7 @@
                     <ColumnDefinition/>
                 </Grid.ColumnDefinitions>
 
-                <Button x:Name="BtnMultiplicationOnScalarnDiagramm" Grid.Column="1" Content="Диаграмма"/>
+                <Button x:Name="BtnMultiplicationOnScalarnDiagramm" Grid.Column="1" Content="Диаграмма" Click="BtnMultiplicationOnScalarnDiagramm_Click"/>
                 <Button x:Name="BtnMultiplicationOnScalarCalculate" Grid.Column="2" Content="Вычислить" Click="BtnMultiplicationOnScalarCalculate_Click"/>
             </Grid>
         </Grid> <!-- MultiplicationOnScalar -->
@@ -442,7 +442,7 @@
                     <ColumnDefinition/>
                 </Grid.ColumnDefinitions>
 
-                <Button x:Name="BtnTranspositionDiagramm" Grid.Column="1" Content="Диаграмма"/>
+                <Button x:Name="BtnTranspositionDiagramm" Grid.Column="1" Content="Диаграмма" Click="BtnTranspositionDiagramm_Click"/>
                 <Button x:Name="BtnTranspositionCalculate" Grid.Column="2" Content="Вычислить" Click="BtnTranspositionCalculate_Click"/>
             </Grid>
         </Grid> <!-- Transposition -->
@@ -514,7 +514,7 @@
                     <ColumnDefinition/>
                 </Grid.ColumnDefinitions>
 
-                <Button x:Name="BtnMultiplicationOnTransposedDiagramm" Grid.Column="1" Content="Диаграмма"/>
+                <Button x:Name="BtnMultiplicationOnTransposedDiagramm" Grid.Column="1" Content="Диаграмма" Click="BtnMultiplicationOnTransposedDiagramm_Click"/>
                 <Button x:Name="BtnMultiplicationOnTransposedCalculate" Grid.Column="2" Content="Вычислить" Click="BtnMultiplicationOnTransposedCalculate_Click"/>
             </Grid>
         </Grid> <!-- MultiplicationOnTransposed -->
@@ -601,7 +601,7 @@
                     <ColumnDefinition/>
                 </Grid.ColumnDefinitions>
 
-                <Button x:Name="BtnRowsReplaceDiagramm" Grid.Column="1" Content="Диаграмма"/>
+                <Button x:Name="BtnRowsReplaceDiagramm" Grid.Column="1" Content="Диаграмма" Click="BtnRowsReplaceDiagramm_Click"/>
                 <Button x:Name="BtnRowsReplaceCalculate" Grid.Column="2" Content="Вычислить" Click="BtnRowsReplaceCalculate_Click"/>
             </Grid>
         </Grid> <!-- RowsReplace -->
@@ -681,7 +681,7 @@
                     <ColumnDefinition/>
                 </Grid.ColumnDefinitions>
 
-                <Button x:Name="BtnRowTranspositionReplaceDiagramm" Grid.Column="1" Content="Диаграмма"/>
+                <Button x:Name="BtnRowTranspositionReplaceDiagramm" Grid.Column="1" Content="Диаграмма" Click="BtnRowTranspositionReplaceDiagramm_Click"/>
                 <Button x:Name="BtnRowTranspositionReplaceCalculate" Grid.Column="2" Content="Вычислить" Click="BtnRowTranspositionReplaceCalculate_Click"/>
             </Grid>
         </Grid> <!-- RowTranspositionReplace -->
@@ -753,7 +753,7 @@
                     <ColumnDefinition/>
                 </Grid.ColumnDefinitions>
 
-                <Button x:Name="BtnInverseeDiagramm" Grid.Column="1" Content="Диаграмма"/>
+                <Button x:Name="BtnInverseeDiagramm" Grid.Column="1" Content="Диаграмма" Click="BtnInverseeDiagramm_Click"/>
                 <Button x:Name="BtnInverseCalculate" Grid.Column="2" Content="Вычислить" Click="BtnInverseCalculate_Click"/>
             </Grid>
         </Grid> <!-- Inverse -->

+ 144 - 4
MatrixXAMLOnly/MainWindow.xaml.cs

@@ -20,10 +20,6 @@ namespace MatrixXAMLOnly
         {
             InitializeComponent();
 
-            DiagramWindow wnd = new DiagramWindow();
-            wnd.Show();
-            Close();
-
             BtnAddition.Content = "Сложение матриц";
             BtnDifference.Content = "Вычитание матриц";
             BtnMultiplicationOnScalar.Content = "Умножение матрицы \nна скаляр";
@@ -407,6 +403,24 @@ namespace MatrixXAMLOnly
             GridAdditionScndTerm.Children.Add(CreateMatrix(rowCount, columnCount, false));
             GridAdditionResult.Children.Add(CreateMatrix(rowCount, columnCount, true));
         }
+
+        private void BtnAdditionDiagramm_Click(object sender, RoutedEventArgs e)
+        {
+            int rowCount = ((Grid)GridAdditionResult.Children[0]).RowDefinitions.Count;
+            int columnCount = ((Grid)GridAdditionResult.Children[0]).ColumnDefinitions.Count;
+
+            double[,] result = new double[rowCount, columnCount];
+            for (int i = 0; i < rowCount; i++)
+            {
+                for (int j = 0; j < columnCount; j++)
+                {
+                    result[i, j] = Convert.ToDouble(((Grid)GridAdditionResult.Children[0]).Children.Cast<TextBox>().First(e => Grid.GetColumn(e) == j && Grid.GetRow(e) == i).Text);
+                }
+            }
+
+            DiagramWindow wnd = new DiagramWindow(new MyMatrix(result));
+            wnd.Show();
+        }
         #endregion
 
         #region Difference
@@ -471,6 +485,24 @@ namespace MatrixXAMLOnly
                 }
             }
         }
+
+        private void BtnDifferenceDiagramm_Click(object sender, RoutedEventArgs e)
+        {
+            int rowCount = ((Grid)GridDifferenceResult.Children[0]).RowDefinitions.Count;
+            int columnCount = ((Grid)GridDifferenceResult.Children[0]).ColumnDefinitions.Count;
+
+            double[,] result = new double[rowCount, columnCount];
+            for (int i = 0; i < rowCount; i++)
+            {
+                for (int j = 0; j < columnCount; j++)
+                {
+                    result[i, j] = Convert.ToDouble(((Grid)GridDifferenceResult.Children[0]).Children.Cast<TextBox>().First(e => Grid.GetColumn(e) == j && Grid.GetRow(e) == i).Text);
+                }
+            }
+
+            DiagramWindow wnd = new DiagramWindow(new MyMatrix(result));
+            wnd.Show();
+        }
         #endregion
 
         #region MultiplicationOnScalar
@@ -541,6 +573,24 @@ namespace MatrixXAMLOnly
                 }
             }
         }
+
+        private void BtnMultiplicationOnScalarnDiagramm_Click(object sender, RoutedEventArgs e)
+        {
+            int rowCount = ((Grid)GridMultiplicationOnScalarResult.Children[0]).RowDefinitions.Count;
+            int columnCount = ((Grid)GridMultiplicationOnScalarResult.Children[0]).ColumnDefinitions.Count;
+
+            double[,] result = new double[rowCount, columnCount];
+            for (int i = 0; i < rowCount; i++)
+            {
+                for (int j = 0; j < columnCount; j++)
+                {
+                    result[i, j] = Convert.ToDouble(((Grid)GridMultiplicationOnScalarResult.Children[0]).Children.Cast<TextBox>().First(e => Grid.GetColumn(e) == j && Grid.GetRow(e) == i).Text);
+                }
+            }
+
+            DiagramWindow wnd = new DiagramWindow(new MyMatrix(result));
+            wnd.Show();
+        }
         #endregion
 
         #region Transposition
@@ -600,6 +650,24 @@ namespace MatrixXAMLOnly
                 }
             }
         }
+
+        private void BtnTranspositionDiagramm_Click(object sender, RoutedEventArgs e)
+        {
+            int rowCount = ((Grid)GridTransposed.Children[0]).RowDefinitions.Count;
+            int columnCount = ((Grid)GridTransposed.Children[0]).ColumnDefinitions.Count;
+
+            double[,] result = new double[rowCount, columnCount];
+            for (int i = 0; i < rowCount; i++)
+            {
+                for (int j = 0; j < columnCount; j++)
+                {
+                    result[i, j] = Convert.ToDouble(((Grid)GridTransposed.Children[0]).Children.Cast<TextBox>().First(e => Grid.GetColumn(e) == j && Grid.GetRow(e) == i).Text);
+                }
+            }
+
+            DiagramWindow wnd = new DiagramWindow(new MyMatrix(result));
+            wnd.Show();
+        }
         #endregion
 
         #region MultiplicationOnTransposed
@@ -660,6 +728,24 @@ namespace MatrixXAMLOnly
                 }
             }
         }
+
+        private void BtnMultiplicationOnTransposedDiagramm_Click(object sender, RoutedEventArgs e)
+        {
+            int rowCount = ((Grid)GridMultiplicationOnTransposedResult.Children[0]).RowDefinitions.Count;
+            int columnCount = ((Grid)GridMultiplicationOnTransposedResult.Children[0]).ColumnDefinitions.Count;
+
+            double[,] result = new double[rowCount, columnCount];
+            for (int i = 0; i < rowCount; i++)
+            {
+                for (int j = 0; j < columnCount; j++)
+                {
+                    result[i, j] = Convert.ToDouble(((Grid)GridMultiplicationOnTransposedResult.Children[0]).Children.Cast<TextBox>().First(e => Grid.GetColumn(e) == j && Grid.GetRow(e) == i).Text);
+                }
+            }
+
+            DiagramWindow wnd = new DiagramWindow(new MyMatrix(result));
+            wnd.Show();
+        }
         #endregion
 
         #region RowReplace
@@ -719,6 +805,24 @@ namespace MatrixXAMLOnly
                 }
             }
         }
+
+        private void BtnRowsReplaceDiagramm_Click(object sender, RoutedEventArgs e)
+        {
+            int rowCount = ((Grid)GridRowsReplaceResult.Children[0]).RowDefinitions.Count;
+            int columnCount = ((Grid)GridRowsReplaceResult.Children[0]).ColumnDefinitions.Count;
+
+            double[,] result = new double[rowCount, columnCount];
+            for (int i = 0; i < rowCount; i++)
+            {
+                for (int j = 0; j < columnCount; j++)
+                {
+                    result[i, j] = Convert.ToDouble(((Grid)GridRowsReplaceResult.Children[0]).Children.Cast<TextBox>().First(e => Grid.GetColumn(e) == j && Grid.GetRow(e) == i).Text);
+                }
+            }
+
+            DiagramWindow wnd = new DiagramWindow(new MyMatrix(result));
+            wnd.Show();
+        }
         #endregion
 
         #region RowTranspositionReplace
@@ -807,6 +911,24 @@ namespace MatrixXAMLOnly
             }
             
         }
+
+        private void BtnRowTranspositionReplaceDiagramm_Click(object sender, RoutedEventArgs e)
+        {
+            int rowCount = ((Grid)GridRowTranspositionReplaceResult.Children[0]).RowDefinitions.Count;
+            int columnCount = ((Grid)GridRowTranspositionReplaceResult.Children[0]).ColumnDefinitions.Count;
+
+            double[,] result = new double[rowCount, columnCount];
+            for (int i = 0; i < rowCount; i++)
+            {
+                for (int j = 0; j < columnCount; j++)
+                {
+                    result[i, j] = Convert.ToDouble(((Grid)GridRowTranspositionReplaceResult.Children[0]).Children.Cast<TextBox>().First(e => Grid.GetColumn(e) == j && Grid.GetRow(e) == i).Text);
+                }
+            }
+
+            DiagramWindow wnd = new DiagramWindow(new MyMatrix(result));
+            wnd.Show();
+        }
         #endregion
 
         #region Inverse
@@ -875,6 +997,24 @@ namespace MatrixXAMLOnly
                 }
             }
         }
+
+        private void BtnInverseeDiagramm_Click(object sender, RoutedEventArgs e)
+        {
+            int rowCount = ((Grid)GridInverseResult.Children[0]).RowDefinitions.Count;
+            int columnCount = ((Grid)GridInverseResult.Children[0]).ColumnDefinitions.Count;
+
+            double[,] result = new double[rowCount, columnCount];
+            for (int i = 0; i < rowCount; i++)
+            {
+                for (int j = 0; j < columnCount; j++)
+                {
+                    result[i, j] = Convert.ToDouble(((Grid)GridInverseResult.Children[0]).Children.Cast<TextBox>().First(e => Grid.GetColumn(e) == j && Grid.GetRow(e) == i).Text);
+                }
+            }
+
+            DiagramWindow wnd = new DiagramWindow(new MyMatrix(result));
+            wnd.Show();
+        }
         #endregion
     }
 }

+ 0 - 1
MatrixXAMLOnly/Matrix.cs

@@ -228,7 +228,6 @@ namespace Matrix
             // Применить формулу: умножить число, обратное определителю матрицы A, на союзную матрицу
             MyMatrix inverseMatrix = 1 / matrix.GetDeterminante() * friendMatrix;
 
-
             return inverseMatrix;
         }