From 5712a85f3834e978ee823d53979f8b984cd09353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=98=D0=B2=D0=B0=D1=88=D0=BA?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Thu, 19 Dec 2024 13:13:55 +0500 Subject: [PATCH] Add graph service --- .../Windows/Graphs/GraphService.cs | 2 +- .../Windows/Graphs/GraphVisualProps.cs | 1 - .../Windows/MainGraph/GraphView.xaml | 10 +++++-- .../Windows/MainGraph/GraphViewModel.cs | 28 +++++++++++++++++-- .../Windows/TreeGraph/TreeGraphView.xaml | 6 +++- .../Windows/TreeGraph/TreeGraphViewModel.cs | 19 +++++++++++-- .../Models/Functions/FormulaFunction.cs | 1 - .../Services/GraphSettings.cs | 16 +++++++++-- 8 files changed, 70 insertions(+), 13 deletions(-) diff --git a/StructureHelper/Windows/Graphs/GraphService.cs b/StructureHelper/Windows/Graphs/GraphService.cs index 4fcd557..d7b8fe4 100644 --- a/StructureHelper/Windows/Graphs/GraphService.cs +++ b/StructureHelper/Windows/Graphs/GraphService.cs @@ -22,7 +22,7 @@ namespace StructureHelper.Windows.Graphs lineSeries.LineSmoothness = visualProps.LineSmoothness; lineSeries.PointGeometry = DefaultGeometries.Circle; lineSeries.PointGeometrySize = visualProps.StrokeSize; - Color lineColor = (lineSeries.Stroke as SolidColorBrush)?.Color ?? Colors.Black; + Color lineColor = (lineSeries.Stroke as SolidColorBrush)?.Color ?? Colors.LightGray; //lineSeries.Fill = new SolidColorBrush(lineColor) { Opacity = visualProps.Opacity }; lineSeries.Fill = new SolidColorBrush(lineColor) { Opacity = visualProps.Opacity }; diff --git a/StructureHelper/Windows/Graphs/GraphVisualProps.cs b/StructureHelper/Windows/Graphs/GraphVisualProps.cs index 5556372..ad43329 100644 --- a/StructureHelper/Windows/Graphs/GraphVisualProps.cs +++ b/StructureHelper/Windows/Graphs/GraphVisualProps.cs @@ -49,7 +49,6 @@ namespace StructureHelper.Windows.Graphs OnPropertyChanged(nameof(Opacity)); } } - public GraphVisualProps() { MaxLineSmoothness = 1d; diff --git a/StructureHelper/Windows/MainGraph/GraphView.xaml b/StructureHelper/Windows/MainGraph/GraphView.xaml index e9206f2..a403c4d 100644 --- a/StructureHelper/Windows/MainGraph/GraphView.xaml +++ b/StructureHelper/Windows/MainGraph/GraphView.xaml @@ -20,6 +20,7 @@ + - + + @@ -153,7 +157,7 @@ Command="{Binding TreeCommand}" Background="AntiqueWhite"/> - @@ -163,7 +167,7 @@ - + diff --git a/StructureHelper/Windows/MainGraph/GraphViewModel.cs b/StructureHelper/Windows/MainGraph/GraphViewModel.cs index 6a476b0..d0cad49 100644 --- a/StructureHelper/Windows/MainGraph/GraphViewModel.cs +++ b/StructureHelper/Windows/MainGraph/GraphViewModel.cs @@ -1,6 +1,7 @@ using LiveCharts; using LiveCharts.Wpf; using StructureHelper.Infrastructure; +using StructureHelper.Windows.Graphs; using StructureHelper.Windows.TreeGraph; using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Interfaces; @@ -17,15 +18,26 @@ namespace StructureHelper.Windows.MainGraph { public class GraphViewModel : ViewModelBase { + private LineSeries lineSeries; private SeriesCollection seriesCollection; private List labels; + private GraphVisualProps visualProps = new(); + public LineSeries LineSeries + { + get => lineSeries; + set + { + lineSeries = value; + OnPropertyChanged(nameof(lineSeries)); + } + } public SeriesCollection SeriesCollection { get => seriesCollection; set { seriesCollection = value; - OnPropertyChanged(nameof(seriesCollection)); + OnPropertyChanged(nameof(SeriesCollection)); } } public List Labels @@ -37,6 +49,15 @@ namespace StructureHelper.Windows.MainGraph OnPropertyChanged(nameof(labels)); } } + public GraphVisualProps VisualProps + { + get => visualProps; + set + { + visualProps = value; + DrawGraph(); + } + } private IOneVariableFunction selectedFunction; public IOneVariableFunction SelectedFuntion { @@ -219,7 +240,10 @@ namespace StructureHelper.Windows.MainGraph { var graphSettings = SelectedFuntion.GetGraphSettings(); Labels = graphSettings.GetLabels(); - SeriesCollection = graphSettings.GetSeriesCollection(); + LineSeries = graphSettings.GetLineSeries(); + GraphService.SetVisualProps(LineSeries, VisualProps); + SeriesCollection = new SeriesCollection(); + SeriesCollection.Add(LineSeries); } } } diff --git a/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml b/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml index 822f88d..05930ab 100644 --- a/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml +++ b/StructureHelper/Windows/TreeGraph/TreeGraphView.xaml @@ -16,6 +16,7 @@ + - + + diff --git a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs index e5a23bc..5850979 100644 --- a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs +++ b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs @@ -13,11 +13,13 @@ using System.Threading.Tasks; using System.Windows.Input; using StructureHelperCommon.Models.Functions.Decorator; using System.Windows.Media; +using StructureHelper.Windows.Graphs; namespace StructureHelper.Windows.TreeGraph { public class TreeGraphViewModel : ViewModelBase { + private LineSeries lineSeries; private SeriesCollection seriesCollection; private List labels; readonly ObservableCollection _firstGeneration; @@ -47,7 +49,7 @@ namespace StructureHelper.Windows.TreeGraph set { seriesCollection = value; - OnPropertyChanged(nameof(seriesCollection)); + OnPropertyChanged(nameof(SeriesCollection)); } } public List Labels @@ -59,6 +61,15 @@ namespace StructureHelper.Windows.TreeGraph OnPropertyChanged(nameof(labels)); } } + public LineSeries LineSeries + { + get => lineSeries; + set + { + lineSeries = value; + OnPropertyChanged(nameof(lineSeries)); + } + } public TreeGraphView TreeGraphView_win { get => _treeGraphView_win; @@ -68,6 +79,7 @@ namespace StructureHelper.Windows.TreeGraph { get => _firstGeneration; } + public GraphVisualProps VisualProps { get; } = new GraphVisualProps(); public ICommand GetYCommand { get => _getYCommand ??= new RelayCommand(o => GetY()); @@ -215,7 +227,10 @@ namespace StructureHelper.Windows.TreeGraph SelectedFuntion = selectedTreeViewItem.Function; var graphSettings = SelectedFuntion.GetGraphSettings(); Labels = graphSettings.GetLabels(); - SeriesCollection = graphSettings.GetSeriesCollection(); + LineSeries = graphSettings.GetLineSeries(); + GraphService.SetVisualProps(LineSeries, VisualProps); + SeriesCollection = new SeriesCollection(); + SeriesCollection.Add(LineSeries); } } } diff --git a/StructureHelperCommon/Models/Functions/FormulaFunction.cs b/StructureHelperCommon/Models/Functions/FormulaFunction.cs index e4f8ef0..27eb451 100644 --- a/StructureHelperCommon/Models/Functions/FormulaFunction.cs +++ b/StructureHelperCommon/Models/Functions/FormulaFunction.cs @@ -103,7 +103,6 @@ namespace StructureHelperCommon.Models.Functions { double yValue = 0; current_xValue = xValue; - Check(); yValue = Math.Round(Expression.CalculateValue(new double[] { xValue }), 2); return yValue; } diff --git a/StructureHelperCommon/Services/GraphSettings.cs b/StructureHelperCommon/Services/GraphSettings.cs index e4ef243..d571e14 100644 --- a/StructureHelperCommon/Services/GraphSettings.cs +++ b/StructureHelperCommon/Services/GraphSettings.cs @@ -33,7 +33,7 @@ namespace StructureHelperCommon.Services } return _labels; } - public SeriesCollection GetSeriesCollection() + public LineSeries GetLineSeries() { foreach (GraphPoint point in GraphPoints) { @@ -41,9 +41,21 @@ namespace StructureHelperCommon.Services } _lineSeries.Values = _chartValues; _lineSeries.Stroke = new SolidColorBrush(_strokeColor); + _lineSeries.Fill = Brushes.Transparent; + return _lineSeries; + } + /*public SeriesCollection GetSeriesCollection() + { + foreach (GraphPoint point in GraphPoints) + { + _chartValues.Add(Math.Round(point.Y, 2)); + } + _lineSeries.Values = _chartValues; + _lineSeries.Stroke = new SolidColorBrush(_strokeColor); + _lineSeries.Fill = Brushes.Transparent; _seriesCollection.Add(_lineSeries); return _seriesCollection; - } + }*/ } }