Add GraphSettings
This commit is contained in:
@@ -18,12 +18,14 @@ namespace StructureHelper.Windows.MainGraph
|
|||||||
public class FormulaViewModel : ViewModelBase
|
public class FormulaViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
private const string ERROR_BOUNDS = "The left bound must be less than the right bound";
|
private const string ERROR_BOUNDS = "The left bound must be less than the right bound";
|
||||||
|
private const string ERROR_STEP = "The number of steps should not be more than";
|
||||||
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 const string DEFAULT_FORMULA = "x^2";
|
private const string DEFAULT_FORMULA = "x^2";
|
||||||
private const double DEFAULT_LEFT_BOUND = 0;
|
private const double DEFAULT_LEFT_BOUND = -500;
|
||||||
private const double DEFAULT_RIGHT_BOUND = 1000;
|
private const double DEFAULT_RIGHT_BOUND = 500;
|
||||||
private const int DEFAULT_STEP = 100;
|
private const int DEFAULT_STEP = 100;
|
||||||
|
private const int MAX_STEP = 1000;
|
||||||
public char GREATER { get; } = '\u2265';
|
public char GREATER { get; } = '\u2265';
|
||||||
public char LESS { get; } = '\u2264';
|
public char LESS { get; } = '\u2264';
|
||||||
public char X { get; } = 'x';
|
public char X { get; } = 'x';
|
||||||
@@ -145,6 +147,7 @@ namespace StructureHelper.Windows.MainGraph
|
|||||||
Function.Name = Name;
|
Function.Name = Name;
|
||||||
Function.Description = Description;
|
Function.Description = Description;
|
||||||
Function.IsUser = true;
|
Function.IsUser = true;
|
||||||
|
(Function as FormulaFunction).Step = Step;
|
||||||
(Function as FormulaFunction).Formula = Formula;
|
(Function as FormulaFunction).Formula = Formula;
|
||||||
var window = parameter as Window;
|
var window = parameter as Window;
|
||||||
if (LeftBound > RightBound)
|
if (LeftBound > RightBound)
|
||||||
@@ -152,6 +155,11 @@ namespace StructureHelper.Windows.MainGraph
|
|||||||
MessageBox.Show($"{ERROR_BOUNDS}");
|
MessageBox.Show($"{ERROR_BOUNDS}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (Step > MAX_STEP)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"{ERROR_STEP} {MAX_STEP}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
window.DialogResult = true;
|
window.DialogResult = true;
|
||||||
window.Close();
|
window.Close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,21 +213,9 @@ namespace StructureHelper.Windows.MainGraph
|
|||||||
}
|
}
|
||||||
private void DrawGraph()
|
private void DrawGraph()
|
||||||
{
|
{
|
||||||
var labels = new List<string>();
|
var graphSettings = SelectedFuntion.GetGraphSettings();
|
||||||
var lineSeries = new LineSeries();
|
Labels = graphSettings.GetLabels();
|
||||||
var seriesCollection = new SeriesCollection();
|
SeriesCollection = graphSettings.GetSeriesCollection();
|
||||||
var chartValues = new ChartValues<double>();
|
|
||||||
foreach (GraphPoint graphPoint in SelectedFuntion.Table)
|
|
||||||
{
|
|
||||||
labels.Add(Math.Round(graphPoint.X, 2).ToString());
|
|
||||||
chartValues.Add(Math.Round(graphPoint.Y));
|
|
||||||
}
|
|
||||||
lineSeries.Values = chartValues;
|
|
||||||
lineSeries.Stroke = Brushes.Blue;
|
|
||||||
lineSeries.Fill = Brushes.Transparent;
|
|
||||||
Labels = labels;
|
|
||||||
seriesCollection.Add(lineSeries);
|
|
||||||
SeriesCollection = seriesCollection;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,17 +213,9 @@ namespace StructureHelper.Windows.TreeGraph
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SelectedFuntion = selectedTreeViewItem.Function;
|
SelectedFuntion = selectedTreeViewItem.Function;
|
||||||
foreach (GraphPoint graphPoint in SelectedFuntion.Table)
|
var graphSettings = SelectedFuntion.GetGraphSettings();
|
||||||
{
|
Labels = graphSettings.GetLabels();
|
||||||
labels.Add(Math.Round(graphPoint.X, 2).ToString());
|
SeriesCollection = graphSettings.GetSeriesCollection();
|
||||||
chartValues.Add(Math.Round(graphPoint.Y));
|
|
||||||
}
|
|
||||||
lineSeries.Values = chartValues;
|
|
||||||
lineSeries.Stroke = Brushes.Blue;
|
|
||||||
lineSeries.Fill = Brushes.Transparent;
|
|
||||||
Labels = labels;
|
|
||||||
seriesCollection.Add(lineSeries);
|
|
||||||
SeriesCollection = seriesCollection;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using System.Windows.Media;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using StructureHelperCommon.Services;
|
||||||
|
|
||||||
namespace StructureHelperCommon.Infrastructures.Interfaces
|
namespace StructureHelperCommon.Infrastructures.Interfaces
|
||||||
{
|
{
|
||||||
@@ -46,9 +47,9 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
|
|||||||
{
|
{
|
||||||
return function.GetByX(xValue);
|
return function.GetByX(xValue);
|
||||||
}
|
}
|
||||||
public virtual SeriesCollection GetSeriesCollection()
|
public virtual GraphSettings GetGraphSettings()
|
||||||
{
|
{
|
||||||
return function.GetSeriesCollection();
|
return function.GetGraphSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using LiveCharts;
|
using LiveCharts;
|
||||||
using StructureHelperCommon.Infrastructures.Enums;
|
using StructureHelperCommon.Infrastructures.Enums;
|
||||||
using StructureHelperCommon.Models.Functions;
|
using StructureHelperCommon.Models.Functions;
|
||||||
|
using StructureHelperCommon.Services;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
@@ -21,13 +22,12 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
|
|||||||
public FunctionType Type { get; set; }
|
public FunctionType Type { 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 double MinArg { get; set; }
|
public double MinArg { get; set; }
|
||||||
public double MaxArg { get; set; }
|
public double MaxArg { get; set; }
|
||||||
public Color Color { get; set; }
|
public Color Color { 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);
|
||||||
public SeriesCollection GetSeriesCollection();
|
public GraphSettings GetGraphSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using LiveCharts;
|
using LiveCharts;
|
||||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Services;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -30,9 +31,19 @@ namespace StructureHelperCommon.Models.Functions.Decorator
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
public override SeriesCollection GetSeriesCollection()
|
public override GraphSettings GetGraphSettings()
|
||||||
{
|
{
|
||||||
return base.GetSeriesCollection();
|
var graphSettings = base.GetGraphSettings();
|
||||||
|
var graphLimitGraphPoint = new List<GraphPoint>();
|
||||||
|
foreach (GraphPoint point in graphSettings.GraphPoints)
|
||||||
|
{
|
||||||
|
if (point.X > leftBound && point.X < rightBound)
|
||||||
|
{
|
||||||
|
graphLimitGraphPoint.Add(point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
graphSettings.GraphPoints = graphLimitGraphPoint;
|
||||||
|
return graphSettings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using LiveCharts;
|
using LiveCharts;
|
||||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Services;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -10,13 +11,13 @@ namespace StructureHelperCommon.Models.Functions.Decorator
|
|||||||
{
|
{
|
||||||
public class LimYDecorator : FunctionDecorator
|
public class LimYDecorator : FunctionDecorator
|
||||||
{
|
{
|
||||||
private double leftBound;
|
private double downBound;
|
||||||
private double rightBound;
|
private double upBound;
|
||||||
public LimYDecorator(IOneVariableFunction function, double leftBound, double rightBound) : base(function)
|
public LimYDecorator(IOneVariableFunction function, double downBound, double upBound) : base(function)
|
||||||
{
|
{
|
||||||
Name = $"y\u2208[{leftBound};{rightBound}]";
|
Name = $"y\u2208[{downBound};{upBound}]";
|
||||||
this.leftBound = leftBound;
|
this.downBound = downBound;
|
||||||
this.rightBound = rightBound;
|
this.upBound = upBound;
|
||||||
}
|
}
|
||||||
public override bool Check()
|
public override bool Check()
|
||||||
{
|
{
|
||||||
@@ -25,15 +26,25 @@ namespace StructureHelperCommon.Models.Functions.Decorator
|
|||||||
public override double GetByX(double xValue)
|
public override double GetByX(double xValue)
|
||||||
{
|
{
|
||||||
var y = base.GetByX(xValue);
|
var y = base.GetByX(xValue);
|
||||||
if (y > leftBound && y < rightBound)
|
if (y > downBound && y < upBound)
|
||||||
{
|
{
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
public override SeriesCollection GetSeriesCollection()
|
public override GraphSettings GetGraphSettings()
|
||||||
{
|
{
|
||||||
return base.GetSeriesCollection();
|
var graphSettings = base.GetGraphSettings();
|
||||||
|
var graphLimitGraphPoint = new List<GraphPoint>();
|
||||||
|
foreach (GraphPoint point in graphSettings.GraphPoints)
|
||||||
|
{
|
||||||
|
if (point.Y > downBound && point.Y < upBound)
|
||||||
|
{
|
||||||
|
graphLimitGraphPoint.Add(point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
graphSettings.GraphPoints = graphLimitGraphPoint;
|
||||||
|
return graphSettings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using LiveCharts;
|
using LiveCharts;
|
||||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Services;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -24,9 +25,14 @@ namespace StructureHelperCommon.Models.Functions.Decorator
|
|||||||
{
|
{
|
||||||
return base.GetByX(factor * xValue);
|
return base.GetByX(factor * xValue);
|
||||||
}
|
}
|
||||||
public override SeriesCollection GetSeriesCollection()
|
public override GraphSettings GetGraphSettings()
|
||||||
{
|
{
|
||||||
return base.GetSeriesCollection();
|
var graphSettings = base.GetGraphSettings();
|
||||||
|
foreach(GraphPoint point in graphSettings.GraphPoints)
|
||||||
|
{
|
||||||
|
point.Y = GetByX(point.X);
|
||||||
|
}
|
||||||
|
return graphSettings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using LiveCharts;
|
using LiveCharts;
|
||||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using StructureHelperCommon.Services;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -24,9 +25,14 @@ namespace StructureHelperCommon.Models.Functions.Decorator
|
|||||||
{
|
{
|
||||||
return factor * base.GetByX(xValue);
|
return factor * base.GetByX(xValue);
|
||||||
}
|
}
|
||||||
public override SeriesCollection GetSeriesCollection()
|
public override GraphSettings GetGraphSettings()
|
||||||
{
|
{
|
||||||
return base.GetSeriesCollection();
|
var graphSettings = base.GetGraphSettings();
|
||||||
|
foreach (GraphPoint point in graphSettings.GraphPoints)
|
||||||
|
{
|
||||||
|
point.Y = GetByX(point.X);
|
||||||
|
}
|
||||||
|
return graphSettings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Documents;
|
using System.Windows.Documents;
|
||||||
|
using StructureHelperCommon.Services;
|
||||||
|
using LiveCharts.Wpf;
|
||||||
|
|
||||||
namespace StructureHelperCommon.Models.Functions
|
namespace StructureHelperCommon.Models.Functions
|
||||||
{
|
{
|
||||||
@@ -24,18 +26,6 @@ namespace StructureHelperCommon.Models.Functions
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Description { get ; set; }
|
public string Description { get ; set; }
|
||||||
public int Step { 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();
|
||||||
@@ -86,23 +76,19 @@ namespace StructureHelperCommon.Models.Functions
|
|||||||
public double GetByX(double xValue)
|
public double GetByX(double xValue)
|
||||||
{
|
{
|
||||||
double yValue = 0;
|
double yValue = 0;
|
||||||
yValue = Math.Round(Math.Pow(xValue, 2), 2); //Временное тестовой выражение квадратичной параболы, будет разбор выражения
|
yValue = Math.Round(Math.Pow(xValue, 2), 2); //Временно выражение квадратичной параболы, будет разбор выражения
|
||||||
return yValue;
|
return yValue;
|
||||||
}
|
}
|
||||||
private List<GraphPoint> CalculateTable()
|
public GraphSettings GetGraphSettings()
|
||||||
{
|
{
|
||||||
var table = new List<GraphPoint>();
|
var graphSettings = new GraphSettings(Color, Color);
|
||||||
var stepLenght = Math.Abs(MaxArg - MinArg) / Step;
|
var stepLenght = Math.Abs(MaxArg - MinArg) / Step;
|
||||||
for (double x = MinArg; x < MaxArg; x += stepLenght)
|
for (double x = MinArg; x < MaxArg; x += stepLenght)
|
||||||
{
|
{
|
||||||
var graphPoint = new GraphPoint(x, GetByX(x));
|
var graphPoint = new GraphPoint(x, GetByX(x));
|
||||||
table.Add(graphPoint);
|
graphSettings.GraphPoints.Add(graphPoint);
|
||||||
}
|
}
|
||||||
return table;
|
return graphSettings;
|
||||||
}
|
|
||||||
public SeriesCollection GetSeriesCollection()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using System.Windows.Media;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using StructureHelperCommon.Services;
|
||||||
|
|
||||||
namespace StructureHelperCommon.Models.Functions
|
namespace StructureHelperCommon.Models.Functions
|
||||||
{
|
{
|
||||||
@@ -57,7 +58,6 @@ namespace StructureHelperCommon.Models.Functions
|
|||||||
public object Clone()
|
public object Clone()
|
||||||
{
|
{
|
||||||
var tableFunction = new TableFunction();
|
var tableFunction = new TableFunction();
|
||||||
|
|
||||||
//Здесь будет стратегия
|
//Здесь будет стратегия
|
||||||
tableFunction.Type = Type;
|
tableFunction.Type = Type;
|
||||||
tableFunction.Name = $"{Name} {COPY}";
|
tableFunction.Name = $"{Name} {COPY}";
|
||||||
@@ -74,12 +74,20 @@ namespace StructureHelperCommon.Models.Functions
|
|||||||
{
|
{
|
||||||
//Реализовать взятие значения из таблицы и интерполяцию по таблице
|
//Реализовать взятие значения из таблицы и интерполяцию по таблице
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
return 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SeriesCollection GetSeriesCollection()
|
public GraphSettings GetGraphSettings()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var graphSettings = new GraphSettings(Color, Color);
|
||||||
|
foreach(GraphPoint point in Table)
|
||||||
|
{
|
||||||
|
var graphPoint = new GraphPoint(point.X, GetByX(point.X));
|
||||||
|
graphSettings.GraphPoints.Add(graphPoint);
|
||||||
|
}
|
||||||
|
return graphSettings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
49
StructureHelperCommon/Services/GraphSettings.cs
Normal file
49
StructureHelperCommon/Services/GraphSettings.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using LiveCharts;
|
||||||
|
using LiveCharts.Wpf;
|
||||||
|
using StructureHelperCommon.Models.Functions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace StructureHelperCommon.Services
|
||||||
|
{
|
||||||
|
public class GraphSettings
|
||||||
|
{
|
||||||
|
private Color _strokeColor;
|
||||||
|
private Color _fillColor;
|
||||||
|
private List<string> _labels = new List<string>();
|
||||||
|
private SeriesCollection _seriesCollection = new SeriesCollection();
|
||||||
|
private LineSeries _lineSeries { get; set; } = new LineSeries();
|
||||||
|
private ChartValues<double> _chartValues { get; set; } = new ChartValues<double>();
|
||||||
|
public List<GraphPoint> GraphPoints { get; set; } = new List<GraphPoint>();
|
||||||
|
public GraphSettings(Color strokeColor, Color fillColor)
|
||||||
|
{
|
||||||
|
_strokeColor = strokeColor;
|
||||||
|
_fillColor = fillColor;
|
||||||
|
}
|
||||||
|
public List<string> GetLabels()
|
||||||
|
{
|
||||||
|
foreach (GraphPoint point in GraphPoints)
|
||||||
|
{
|
||||||
|
_labels.Add(Math.Round(point.X, 2).ToString());
|
||||||
|
}
|
||||||
|
return _labels;
|
||||||
|
}
|
||||||
|
public SeriesCollection GetSeriesCollection()
|
||||||
|
{
|
||||||
|
foreach (GraphPoint point in GraphPoints)
|
||||||
|
{
|
||||||
|
_chartValues.Add(Math.Round(point.Y, 2));
|
||||||
|
}
|
||||||
|
_lineSeries.Values = _chartValues;
|
||||||
|
_lineSeries.Stroke = Brushes.Blue; //Заменить на поле Color
|
||||||
|
_lineSeries.Fill = Brushes.Transparent; //Заменить на поле Color
|
||||||
|
_seriesCollection.Add(_lineSeries);
|
||||||
|
return _seriesCollection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user