Add GraphSettings

This commit is contained in:
Иван Ивашкин
2024-10-31 13:46:50 +05:00
parent 94387d0d0b
commit 96b0fbd6a3
12 changed files with 138 additions and 72 deletions

View File

@@ -18,12 +18,14 @@ namespace StructureHelper.Windows.MainGraph
public class FormulaViewModel : ViewModelBase
{
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_DESCRIPTION = "Put function description here...";
private const string DEFAULT_FORMULA = "x^2";
private const double DEFAULT_LEFT_BOUND = 0;
private const double DEFAULT_RIGHT_BOUND = 1000;
private const double DEFAULT_LEFT_BOUND = -500;
private const double DEFAULT_RIGHT_BOUND = 500;
private const int DEFAULT_STEP = 100;
private const int MAX_STEP = 1000;
public char GREATER { get; } = '\u2265';
public char LESS { get; } = '\u2264';
public char X { get; } = 'x';
@@ -145,6 +147,7 @@ namespace StructureHelper.Windows.MainGraph
Function.Name = Name;
Function.Description = Description;
Function.IsUser = true;
(Function as FormulaFunction).Step = Step;
(Function as FormulaFunction).Formula = Formula;
var window = parameter as Window;
if (LeftBound > RightBound)
@@ -152,6 +155,11 @@ namespace StructureHelper.Windows.MainGraph
MessageBox.Show($"{ERROR_BOUNDS}");
return;
}
if (Step > MAX_STEP)
{
MessageBox.Show($"{ERROR_STEP} {MAX_STEP}");
return;
}
window.DialogResult = true;
window.Close();
}

View File

@@ -213,21 +213,9 @@ namespace StructureHelper.Windows.MainGraph
}
private void DrawGraph()
{
var labels = new List<string>();
var lineSeries = new LineSeries();
var seriesCollection = new SeriesCollection();
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;
var graphSettings = SelectedFuntion.GetGraphSettings();
Labels = graphSettings.GetLabels();
SeriesCollection = graphSettings.GetSeriesCollection();
}
}
}