Delete and DrawGraph command done

This commit is contained in:
Иван Ивашкин
2024-10-29 19:31:45 +05:00
parent 2a0704fc4f
commit 2738b1b7b3
17 changed files with 342 additions and 82 deletions

View File

@@ -7,11 +7,14 @@
xmlns:local="clr-namespace:StructureHelper.Windows.MainGraph" xmlns:local="clr-namespace:StructureHelper.Windows.MainGraph"
mc:Ignorable="d" mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:FormulaViewModel}" d:DataContext="{d:DesignInstance local:FormulaViewModel}"
Title="FormulaFunction" Height="320" Width="400"> Title="FormulaFunction" Height="580" Width="400">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="60"/> <RowDefinition Height="60"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="150"/>
<RowDefinition Height="60"/>
<RowDefinition Height="60"/>
<RowDefinition Height="60"/> <RowDefinition Height="60"/>
<RowDefinition Height="60"/> <RowDefinition Height="60"/>
<RowDefinition Height="50"/> <RowDefinition Height="50"/>
@@ -47,6 +50,79 @@
TextWrapping="Wrap"> TextWrapping="Wrap">
</TextBlock> </TextBlock>
<Grid Grid.Row="2"> <Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition Height="90"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.ColumnSpan="3"
Margin="5"
Text="Enter limit bounds:"
VerticalAlignment="Center"/>
<TextBlock Grid.Column="0"
Grid.Row="1"
Text="{Binding X_or_Y_text}"
VerticalAlignment="Center"
HorizontalAlignment="Right"/>
<TextBlock Grid.Column="1"
Grid.Row="1"
Text="{Binding GREATER}"
VerticalAlignment="Center"
HorizontalAlignment="Right"/>
<TextBox Grid.Column="2"
Grid.Row="1"
Text="{Binding LeftBound,
UpdateSourceTrigger=PropertyChanged,
StringFormat=\{0:n\}}"
Margin="5"/>
<TextBlock Grid.Column="0"
Grid.Row="2"
Text="{Binding X_or_Y_text}"
VerticalAlignment="Center"
HorizontalAlignment="Right"/>
<TextBlock Grid.Column="1"
Grid.Row="2"
Text="{Binding LESS}"
VerticalAlignment="Center"
HorizontalAlignment="Right"/>
<TextBox Grid.Column="2"
Grid.Row="2"
Text="{Binding RightBound,
UpdateSourceTrigger=PropertyChanged,
StringFormat=\{0:n\}}"
Margin="5"/>
</Grid>
<TextBlock Grid.Row="1"
Margin="5"
Background="LightYellow"
Text="{Binding LimitText, UpdateSourceTrigger=PropertyChanged}"
TextAlignment="Center"
FontSize="20"
TextWrapping="Wrap">
</TextBlock>
</Grid>
<Grid Grid.Row="3">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Margin="5"
Text="Step:"
VerticalAlignment="Center"/>
<TextBox Grid.Row="1" Text="{Binding Step}" Margin="5"/>
</Grid>
<Grid Grid.Row="4">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
@@ -57,7 +133,7 @@
VerticalAlignment="Center"/> VerticalAlignment="Center"/>
<TextBox Grid.Row="1" Text="{Binding Name}" Margin="5"/> <TextBox Grid.Row="1" Text="{Binding Name}" Margin="5"/>
</Grid> </Grid>
<Grid Grid.Row="3"> <Grid Grid.Row="5">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
@@ -68,8 +144,19 @@
VerticalAlignment="Center"/> VerticalAlignment="Center"/>
<TextBox Grid.Row="1" Text="{Binding Description}" Margin="5"/> <TextBox Grid.Row="1" Text="{Binding Description}" Margin="5"/>
</Grid> </Grid>
<Button Grid.Row="4" Margin="5" Content="Save" <Grid Grid.Row="6">
Command="{Binding DrawGraphCommand}" <Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Margin="5"
Text="Color:"
VerticalAlignment="Center"/>
<ComboBox Grid.Row="1" Text="{Binding Description}" Margin="5"/>
</Grid>
<Button Grid.Row="7" Margin="5" Content="Save"
Command="{Binding SaveCommand}"
CommandParameter="{Binding ElementName=FormulaFunction_win}"> CommandParameter="{Binding ElementName=FormulaFunction_win}">
</Button> </Button>
</Grid> </Grid>

View File

@@ -22,10 +22,10 @@ namespace StructureHelper.Windows.MainGraph
private const double DEFAULT_LEFT_BOUND = 0; private const double DEFAULT_LEFT_BOUND = 0;
private const double DEFAULT_RIGHT_BOUND = 1000; private const double DEFAULT_RIGHT_BOUND = 1000;
private const int DEFAULT_STEP = 100; private const int DEFAULT_STEP = 100;
private RelayCommand drawGraphCommand; private RelayCommand saveCommand;
public ICommand DrawGraphCommand public ICommand SaveCommand
{ {
get => drawGraphCommand ??= new RelayCommand(o => Save(o)); get => saveCommand ??= new RelayCommand(o => Save(o));
} }
private string formula; private string formula;

View File

@@ -101,13 +101,13 @@
Background="AntiqueWhite"/> Background="AntiqueWhite"/>
</Grid> </Grid>
<lvc:CartesianChart Grid.Row="0" Grid.Column="1" <lvc:CartesianChart Grid.Row="0" Grid.Column="1"
Series="{Binding SeriesCollection}" Margin="5" Series="{Binding SeriesCollection, UpdateSourceTrigger=PropertyChanged}" Margin="5"
Zoom="Xy"> Zoom="None">
<lvc:CartesianChart.AxisY> <lvc:CartesianChart.AxisY>
<lvc:Axis Title="Y"></lvc:Axis> <lvc:Axis Title="Y"></lvc:Axis>
</lvc:CartesianChart.AxisY> </lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX> <lvc:CartesianChart.AxisX>
<lvc:Axis Title="X" Labels="{Binding Labels}"></lvc:Axis> <lvc:Axis Title="X" Labels="{Binding Labels, UpdateSourceTrigger=PropertyChanged}"></lvc:Axis>
</lvc:CartesianChart.AxisX> </lvc:CartesianChart.AxisX>
</lvc:CartesianChart> </lvc:CartesianChart>
<Grid Grid.Row="1" Grid.Column="1"> <Grid Grid.Row="1" Grid.Column="1">

View File

@@ -43,7 +43,6 @@ namespace StructureHelper.Windows.MainGraph
public void Refresh() public void Refresh()
{ {
FunctionList.Items.Refresh(); FunctionList.Items.Refresh();
DescriptionTextBlock.UpdateLayout();
} }
} }
} }

View File

@@ -16,11 +16,26 @@ namespace StructureHelper.Windows.MainGraph
{ {
public class GraphViewModel : ViewModelBase public class GraphViewModel : ViewModelBase
{ {
public SeriesCollection SeriesCollection { get; set; } private SeriesCollection seriesCollection;
public List<string> Labels { get; set; } private List<string> labels;
public SeriesCollection SeriesCollection
{
get => seriesCollection;
set
{
seriesCollection = value;
OnPropertyChanged(nameof(seriesCollection));
}
}
public List<string> Labels
{
get => labels;
set
{
labels = value;
OnPropertyChanged(nameof(labels));
}
}
private IOneVariableFunction selectedFunction; private IOneVariableFunction selectedFunction;
public IOneVariableFunction SelectedFuntion public IOneVariableFunction SelectedFuntion
{ {
@@ -31,6 +46,7 @@ namespace StructureHelper.Windows.MainGraph
set set
{ {
selectedFunction = value; selectedFunction = value;
DrawGraph();
OnPropertyChanged(nameof(SelectedFuntion)); OnPropertyChanged(nameof(SelectedFuntion));
} }
} }
@@ -89,6 +105,9 @@ namespace StructureHelper.Windows.MainGraph
var f2 = new FormulaFunction(); var f2 = new FormulaFunction();
f2.Name = "Формульная системная функция"; f2.Name = "Формульная системная функция";
f2.Formula = "x^2"; f2.Formula = "x^2";
f2.Step = 100;
f2.MinArg = -1000;
f2.MaxArg = 1000;
f2.IsUser = false; f2.IsUser = false;
f2.Description = "Описание формульной системной функции"; f2.Description = "Описание формульной системной функции";
@@ -106,6 +125,7 @@ namespace StructureHelper.Windows.MainGraph
if (tableView.ShowDialog() == true) if (tableView.ShowDialog() == true)
{ {
Functions.Add(tableViewModel.Function); Functions.Add(tableViewModel.Function);
SelectedFuntion = tableViewModel.Function;
} }
} }
private void AddFormula() private void AddFormula()
@@ -116,6 +136,7 @@ namespace StructureHelper.Windows.MainGraph
if (formulaView.ShowDialog() == true) if (formulaView.ShowDialog() == true)
{ {
Functions.Add(formulaViewModel.Function); Functions.Add(formulaViewModel.Function);
SelectedFuntion = formulaViewModel.Function;
} }
} }
private void Edit(object parameter) private void Edit(object parameter)
@@ -139,9 +160,9 @@ namespace StructureHelper.Windows.MainGraph
formulaView.DataContext = formulaViewModel; formulaView.DataContext = formulaViewModel;
formulaView.ShowDialog(); formulaView.ShowDialog();
SelectedFuntion = formulaViewModel.Function; SelectedFuntion = formulaViewModel.Function;
} }
var graphView = parameter as GraphView; //var graphView = parameter as GraphView;
graphView.Refresh(); //graphView.Refresh();
} }
private void Delete() private void Delete()
{ {
@@ -175,12 +196,18 @@ namespace StructureHelper.Windows.MainGraph
} }
private void Tree() private void Tree()
{ {
var func = Database.GetFunctionTree(); if (SelectedFuntion is null)
{
return;
}
//var testFunction = Database.GetFunctionTree();
//var treeGraphVM = new TreeGraphViewModel(testFunction);
var treeGraphVM = new TreeGraphViewModel(func); var treeGraphVM = new TreeGraphViewModel(SelectedFuntion);
var treeGraph = new TreeGraphView(); var treeGraph = new TreeGraphView();
treeGraph.DataContext = treeGraphVM; treeGraph.DataContext = treeGraphVM;
treeGraphVM.TreeGraphView_win = treeGraph;
treeGraph.ShowDialog(); treeGraph.ShowDialog();
} }
private void DrawGraph() private void DrawGraph()
@@ -196,6 +223,7 @@ namespace StructureHelper.Windows.MainGraph
} }
lineSeries.Values = chartValues; lineSeries.Values = chartValues;
Labels = labels; Labels = labels;
seriesCollection.Add(lineSeries);
SeriesCollection = seriesCollection; SeriesCollection = seriesCollection;
} }
} }

View File

@@ -8,7 +8,7 @@
mc:Ignorable="d" mc:Ignorable="d"
ResizeMode="CanResize" ResizeMode="CanResize"
d:DataContext="{d:DesignInstance local:TableViewModel}" d:DataContext="{d:DesignInstance local:TableViewModel}"
Title="TableFunction" Height="500" Width="400" Title="TableFunction" Height="560" Width="400"
MaxWidth="400" MaxWidth="400"
MinWidth="400"> MinWidth="400">
<Grid> <Grid>
@@ -18,6 +18,7 @@
<RowDefinition Height="50"/> <RowDefinition Height="50"/>
<RowDefinition Height="60"/> <RowDefinition Height="60"/>
<RowDefinition Height="60"/> <RowDefinition Height="60"/>
<RowDefinition Height="60"/>
<RowDefinition Height="50"/> <RowDefinition Height="50"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Grid.Column="0" Margin="5"> <Grid Grid.Column="0" Margin="5">
@@ -105,8 +106,19 @@
VerticalAlignment="Center"/> VerticalAlignment="Center"/>
<TextBox Grid.Row="1" Text="{Binding Description}" Margin="5"/> <TextBox Grid.Row="1" Text="{Binding Description}" Margin="5"/>
</Grid> </Grid>
<Button Grid.Row="5" Margin="5" Content="Save" <Grid Grid.Row="5">
Command="{Binding DrawGraphCommand}" <Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Margin="5"
Text="Color:"
VerticalAlignment="Center"/>
<ComboBox Grid.Row="1" Text="{Binding Description}" Margin="5"/>
</Grid>
<Button Grid.Row="6" Margin="5" Content="Save"
Command="{Binding SaveCommand}"
CommandParameter="{Binding ElementName=TableFunction_win}"> CommandParameter="{Binding ElementName=TableFunction_win}">
</Button> </Button>
</Grid> </Grid>

View File

@@ -18,12 +18,12 @@ namespace StructureHelper.Windows.MainGraph
{ {
private const string DEFAULT_NAME = "Put function name here..."; private const string DEFAULT_NAME = "Put function name here...";
private const string DEFAULT_DESCRIPTION = "Put function description here..."; private const string DEFAULT_DESCRIPTION = "Put function description here...";
private RelayCommand drawGraphCommand; private RelayCommand saveCommand;
private RelayCommand addPointCommand; private RelayCommand addPointCommand;
private RelayCommand deletePointCommand; private RelayCommand deletePointCommand;
public ICommand DrawGraphCommand public ICommand SaveCommand
{ {
get => drawGraphCommand ??= new RelayCommand(o => Save(o)); get => saveCommand ??= new RelayCommand(o => Save(o));
} }
public ICommand AddPointCommand public ICommand AddPointCommand
{ {

View File

@@ -35,14 +35,14 @@
<TextBox Grid.Column="1" Text="{Binding Argument}" <TextBox Grid.Column="1" Text="{Binding Argument}"
Margin="5"/> Margin="5"/>
<Button Grid.Column="2" Margin="5" Content="Get value" <Button Grid.Column="2" Margin="5" Content="Get value"
Command="{Binding DrawGraphCommand}"> Command="{Binding GetValueCommand}">
</Button> </Button>
</Grid> </Grid>
</Grid> </Grid>
<ScrollViewer Grid.Row="1" Margin="5" > <ScrollViewer Grid.Row="1" Margin="5" >
<TextBlock <TextBlock
Background="LightYellow" Background="LightYellow"
Text="{Binding Trace}" Text="{Binding Trace, UpdateSourceTrigger=PropertyChanged}"
TextAlignment="Center" TextAlignment="Center"
FontSize="20" FontSize="20"
TextWrapping="Wrap"> TextWrapping="Wrap">
@@ -67,7 +67,7 @@
HorizontalAlignment="Right"/> HorizontalAlignment="Right"/>
<TextBlock Grid.Column="1" <TextBlock Grid.Column="1"
Background="AliceBlue" Background="AliceBlue"
Text="{Binding Value}" Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}"
FontWeight="DemiBold" FontWeight="DemiBold"
Margin="5"/> Margin="5"/>
</Grid> </Grid>

View File

@@ -28,12 +28,20 @@ namespace StructureHelper.Windows.TreeGraph
public double Value public double Value
{ {
get => value; get => value;
set => this.value = value; set
{
this.value = value;
OnPropertyChanged(nameof(Value));
}
} }
public string Trace public string Trace
{ {
get => trace; get => trace;
set => trace = value; set
{
trace = value;
OnPropertyChanged(nameof(Trace));
}
} }
private RelayCommand _getValueCommand; private RelayCommand _getValueCommand;
public ICommand GetValueCommand public ICommand GetValueCommand
@@ -47,7 +55,7 @@ namespace StructureHelper.Windows.TreeGraph
private void GetValue() private void GetValue()
{ {
Value = Function.GetByX(Argument); Value = Function.GetByX(Argument);
Trace = "скорее всего переменная внутри функции"; Trace = "Calculation logic";
} }
} }
} }

View File

@@ -9,13 +9,16 @@ namespace StructureHelper.Windows.TreeGraph
{ {
public class LimViewModel : ViewModelBase public class LimViewModel : ViewModelBase
{ {
private bool isArg = false;
public char GREATER { get; } = '\u2265'; public char GREATER { get; } = '\u2265';
public char LESS { get; } = '\u2264'; public char LESS { get; } = '\u2264';
public char IN { get; } = '\u2208'; public char IN { get; } = '\u2208';
public char LEFT_BOUND { get; } = '['; public char LEFT_BOUND { get; } = '[';
public char RIGHT_BOUND { get; } = ']'; public char RIGHT_BOUND { get; } = ']';
public char SEMICOLON { get; } = ';'; public char SEMICOLON { get; } = ';';
private string x_or_y_text = "x"; private const string X = "x";
private const string Y = "y";
private string x_or_y_text;
private string limitText; private string limitText;
public string X_or_Y_text public string X_or_Y_text
{ {
@@ -53,8 +56,17 @@ namespace StructureHelper.Windows.TreeGraph
OnPropertyChanged(nameof(RightBound)); OnPropertyChanged(nameof(RightBound));
} }
} }
public LimViewModel() public LimViewModel(bool isArg)
{ {
this.isArg = isArg;
if (isArg)
{
X_or_Y_text = X;
}
else
{
X_or_Y_text = Y;
}
LimitText = $"{X_or_Y_text}" + $"{IN}" + $"{LEFT_BOUND}" + $"{LeftBound}" + $"{SEMICOLON}" + $"{rightBound}" + $"{RIGHT_BOUND}"; LimitText = $"{X_or_Y_text}" + $"{IN}" + $"{LEFT_BOUND}" + $"{LeftBound}" + $"{SEMICOLON}" + $"{rightBound}" + $"{RIGHT_BOUND}";
} }
} }

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Windows.TreeGraph
{
public class Node
{
public ObservableCollection<Node> Nodes { get; set; }
public string Name { get; set; }
}
}

View File

@@ -18,7 +18,8 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="50"/> <RowDefinition Height="50"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TreeView Grid.Row="0" <TreeView Name="FunctionTreeView"
Grid.Row="0"
Grid.Column="0" Grid.Column="0"
Margin="5" Margin="5"
ItemsSource="{Binding FirstGeneration}"> ItemsSource="{Binding FirstGeneration}">
@@ -81,7 +82,7 @@
</Grid> </Grid>
<lvc:CartesianChart Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" <lvc:CartesianChart Grid.Row="0" Grid.Column="1" Grid.RowSpan="2"
Series="{Binding SeriesCollection}" Margin="5" Series="{Binding SeriesCollection}" Margin="5"
Zoom="Xy"> Zoom="None">
<lvc:CartesianChart.AxisY> <lvc:CartesianChart.AxisY>
<lvc:Axis Title="Y"></lvc:Axis> <lvc:Axis Title="Y"></lvc:Axis>
</lvc:CartesianChart.AxisY> </lvc:CartesianChart.AxisY>

View File

@@ -1,4 +1,6 @@
using NLog.Common; using LiveCharts.Wpf;
using LiveCharts;
using NLog.Common;
using StructureHelper.Infrastructure; using StructureHelper.Infrastructure;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Functions; using StructureHelperCommon.Models.Functions;
@@ -14,7 +16,9 @@ namespace StructureHelper.Windows.TreeGraph
{ {
public class TreeGraphViewModel : ViewModelBase public class TreeGraphViewModel : ViewModelBase
{ {
readonly ReadOnlyCollection<TreeViewItemViewModel> _firstGeneration; private SeriesCollection seriesCollection;
private List<string> labels;
readonly ObservableCollection<TreeViewItemViewModel> _firstGeneration;
readonly TreeViewItemViewModel _rootFunction; readonly TreeViewItemViewModel _rootFunction;
readonly ICommand _searchCommand; readonly ICommand _searchCommand;
private RelayCommand _getYCommand; private RelayCommand _getYCommand;
@@ -22,7 +26,44 @@ namespace StructureHelper.Windows.TreeGraph
private RelayCommand _limCommand; private RelayCommand _limCommand;
private RelayCommand _editCommand; private RelayCommand _editCommand;
private RelayCommand _deleteCommand; private RelayCommand _deleteCommand;
public ReadOnlyCollection<TreeViewItemViewModel> FirstGeneration private TreeGraphView _treeGraphView_win;
private IOneVariableFunction selectedFunction;
public IOneVariableFunction SelectedFuntion
{
get
{
return selectedFunction;
}
set
{
selectedFunction = value;
OnPropertyChanged(nameof(SelectedFuntion));
}
}
public SeriesCollection SeriesCollection
{
get => seriesCollection;
set
{
seriesCollection = value;
OnPropertyChanged(nameof(seriesCollection));
}
}
public List<string> Labels
{
get => labels;
set
{
labels = value;
OnPropertyChanged(nameof(labels));
}
}
public TreeGraphView TreeGraphView_win
{
get => _treeGraphView_win;
set => _treeGraphView_win = value;
}
public ObservableCollection<TreeViewItemViewModel> FirstGeneration
{ {
get => _firstGeneration; get => _firstGeneration;
} }
@@ -46,22 +87,27 @@ namespace StructureHelper.Windows.TreeGraph
{ {
get => _deleteCommand ??= new RelayCommand(o => Delete()); get => _deleteCommand ??= new RelayCommand(o => Delete());
} }
private ObservableCollection<IOneVariableFunction> functions;
public ObservableCollection<IOneVariableFunction> Functions { get; set; }
public ObservableCollection<Node> Nodes { get; set; }
public TreeGraphViewModel(IOneVariableFunction rootFunction) public TreeGraphViewModel(IOneVariableFunction rootFunction)
{ {
_rootFunction = new TreeViewItemViewModel(rootFunction); _rootFunction = new TreeViewItemViewModel(rootFunction, this);
_firstGeneration = new ReadOnlyCollection<TreeViewItemViewModel>( _firstGeneration = new ObservableCollection<TreeViewItemViewModel>
new TreeViewItemViewModel[] (
{ new ObservableCollection<TreeViewItemViewModel>()
_rootFunction {
}); _rootFunction,
}
);
} }
private void GetY() private void GetY()
{ {
var vm = new GetValueViewModel(new TableFunction()); var selectedTreeViewItem = TreeGraphView_win.FunctionTreeView.SelectedItem as TreeViewItemViewModel;
if (selectedTreeViewItem is null)
{
return;
}
SelectedFuntion = selectedTreeViewItem.Function;
var vm = new GetValueViewModel(SelectedFuntion);
var v = new GetValueView(); var v = new GetValueView();
v.DataContext = vm; v.DataContext = vm;
v.ShowDialog(); v.ShowDialog();
@@ -88,7 +134,20 @@ namespace StructureHelper.Windows.TreeGraph
} }
private void Limit(object parameter) private void Limit(object parameter)
{ {
var vm = new LimViewModel(); LimViewModel vm = null;
var type = parameter as string;
if (type.Equals("x"))
{
vm = new LimViewModel(true);
}
else if (type.Equals("y"))
{
vm = new LimViewModel(false);
}
else
{
return;
}
var v = new LimView(); var v = new LimView();
v.DataContext = vm; v.DataContext = vm;
v.ShowDialog(); v.ShowDialog();
@@ -99,11 +158,39 @@ namespace StructureHelper.Windows.TreeGraph
} }
private void Delete() private void Delete()
{ {
var selectedTreeViewItem = TreeGraphView_win.FunctionTreeView.SelectedItem as TreeViewItemViewModel;
if (selectedTreeViewItem is null)
{
return;
}
var selectedTreeViewItemParent = selectedTreeViewItem.Parent;
if (selectedTreeViewItemParent is null)
{
return;
}
selectedTreeViewItemParent.Children.Remove(selectedTreeViewItem);
} }
private void RefreshTree() public void DrawGraph()
{ {
var labels = new List<string>();
var lineSeries = new LineSeries();
var seriesCollection = new SeriesCollection();
var chartValues = new ChartValues<double>();
var selectedTreeViewItem = TreeGraphView_win.FunctionTreeView.SelectedItem as TreeViewItemViewModel;
if (selectedTreeViewItem is null)
{
return;
}
SelectedFuntion = selectedTreeViewItem.Function;
foreach (GraphPoint graphPoint in SelectedFuntion.Table)
{
labels.Add(Math.Round(graphPoint.X, 2).ToString());
chartValues.Add(Math.Round(graphPoint.Y));
}
lineSeries.Values = chartValues;
Labels = labels;
seriesCollection.Add(lineSeries);
SeriesCollection = seriesCollection;
} }
} }
} }

View File

@@ -12,35 +12,40 @@ namespace StructureHelper.Windows.TreeGraph
{ {
public class TreeViewItemViewModel : ViewModelBase public class TreeViewItemViewModel : ViewModelBase
{ {
readonly ReadOnlyCollection<TreeViewItemViewModel> _children; readonly ObservableCollection<TreeViewItemViewModel> _children;
readonly TreeViewItemViewModel _parent; readonly TreeViewItemViewModel _parent;
readonly IOneVariableFunction _functions; readonly IOneVariableFunction _function;
readonly TreeGraphViewModel _treeGraphViewModel;
bool _isExpanded; bool _isExpanded;
bool _isSelected; bool _isSelected;
public TreeViewItemViewModel(IOneVariableFunction function) : this(function, null) public TreeViewItemViewModel(IOneVariableFunction function, TreeGraphViewModel treeGraphViewModel) : this(function, null, treeGraphViewModel)
{ {
} }
private TreeViewItemViewModel(IOneVariableFunction function, TreeViewItemViewModel parent) private TreeViewItemViewModel(IOneVariableFunction function, TreeViewItemViewModel parent, TreeGraphViewModel treeGraphViewModel)
{ {
_functions = function; _function = function;
_parent = parent; _parent = parent;
_children = new ReadOnlyCollection<TreeViewItemViewModel> _treeGraphViewModel = treeGraphViewModel;
_children = new ObservableCollection<TreeViewItemViewModel>
( (
_functions.Functions _function.Functions
.Select(x => new TreeViewItemViewModel(x, this)) .Select(x => new TreeViewItemViewModel(x, this, treeGraphViewModel))
.ToList<TreeViewItemViewModel>() .ToList<TreeViewItemViewModel>()
); );
} }
public ReadOnlyCollection<TreeViewItemViewModel> Children public IOneVariableFunction Function
{
get { return _function; }
}
public ObservableCollection<TreeViewItemViewModel> Children
{ {
get { return _children; } get { return _children; }
} }
public string Name public string Name
{ {
get { return _functions.Name; } get { return _function.Name; }
} }
public bool IsExpanded public bool IsExpanded
{ {
@@ -65,6 +70,7 @@ namespace StructureHelper.Windows.TreeGraph
if (value != _isSelected) if (value != _isSelected)
{ {
_isSelected = value; _isSelected = value;
_treeGraphViewModel.DrawGraph();
OnPropertyChanged(nameof(IsSelected)); OnPropertyChanged(nameof(IsSelected));
} }
} }

View File

@@ -20,6 +20,8 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
public string Name { get; set; } public string Name { get; set; }
public string Description { get; set; } public string Description { get; set; }
public List<GraphPoint> Table { get; set; } public List<GraphPoint> Table { get; set; }
public double MinArg { get; set; }
public double MaxArg { get; set; }
public ObservableCollection<IOneVariableFunction> Functions { get; set; } public ObservableCollection<IOneVariableFunction> Functions { get; set; }
public bool Check(); public bool Check();
public double GetByX(double xValue); public double GetByX(double xValue);

View File

@@ -21,12 +21,27 @@ namespace StructureHelperCommon.Models.Functions
public string Group { get; set; } public string Group { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Description { get ; set; } public string Description { get ; set; }
public List<GraphPoint> Table { get; set; } public int Step { get; set; }
private List<GraphPoint> table;
public List<GraphPoint> Table
{
get
{
return CalculateTable();
}
set
{
table = value;
}
}
public string Formula { get; set; } public string Formula { get; set; }
public Guid Id => throw new NotImplementedException(); public Guid Id => throw new NotImplementedException();
public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>(); public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>();
public double MinArg { get; set; }
public double MaxArg { get; set; }
public FormulaFunction(bool isUser = false) public FormulaFunction(bool isUser = false)
{ {
Type = FunctionType.FormulaFunction; Type = FunctionType.FormulaFunction;
@@ -58,12 +73,28 @@ namespace StructureHelperCommon.Models.Functions
formulaFunction.Formula = Formula; formulaFunction.Formula = Formula;
formulaFunction.IsUser = true; formulaFunction.IsUser = true;
formulaFunction.Group = GROUP_TYPE_2; formulaFunction.Group = GROUP_TYPE_2;
formulaFunction.Step = Step;
formulaFunction.MinArg = MinArg;
formulaFunction.MaxArg = MaxArg;
return formulaFunction; return formulaFunction;
} }
public double GetByX(double xValue) public double GetByX(double xValue)
{ {
throw new NotImplementedException(); double yValue = 0;
yValue = Math.Round(Math.Pow(xValue, 2), 2); //Временное тестовой выражение квадратичной параболы, будет разбор выражения
return yValue;
}
public List<GraphPoint> CalculateTable()
{
var table = new List<GraphPoint>();
var stepLenght = Math.Abs(MaxArg - MinArg) / Step;
for (double x = MinArg; x < MaxArg; x += stepLenght)
{
var graphPoint = new GraphPoint(x, GetByX(x));
table.Add(graphPoint);
}
return table;
} }
} }
} }

View File

@@ -27,6 +27,8 @@ namespace StructureHelperCommon.Models.Functions
public Guid Id => throw new NotImplementedException(); public Guid Id => throw new NotImplementedException();
public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>(); public ObservableCollection<IOneVariableFunction> Functions { get; set; } = new ObservableCollection<IOneVariableFunction>();
public double MinArg { get; set; }
public double MaxArg { get; set; }
public TableFunction(bool isUser = false) public TableFunction(bool isUser = false)
{ {