private void UpdateChart() { var precVal = (Math.Abs(_toX) + Math.Abs(_fromX)) * _sliderValue / 200; ChartData.Clear(); ChartBiRootData.Clear(); ChartFalsiRootData.Clear(); for (var i = _fromX; i < _toX; i += precVal) { ChartData.Add(new KeyValuePair <double, double>(i, FunctionSelectorSelectedItem.GetValue(i))); } int step = RootsCollection.Count > 100 ? Convert.ToInt32(_divisionRate) / 10 : 1; IntervalDivNoteBind = step == 1 ? "" : Locale["#IntervalDivNote"].Replace("&arg;", step.ToString()); RaisePropertyChanged(() => IntervalDivNoteBind); foreach ( var root in RootsCollection.Where( (root, i) => (i % step == 0) && (root.SourceId == FunctionSelectorSelectedItem.Id) && (root.X > _fromX) && (root.X < _toX))) { if (root.Method_Used == "Bi") { ChartBiRootData.Add(new KeyValuePair <double, double>(root.X, root.Y)); } else { ChartFalsiRootData.Add(new KeyValuePair <double, double>(root.X, root.Y)); } } ProgressBarVisibility = Visibility.Collapsed; }
private async void SubmitData() { double from, to, approx, divRate = 1; if (!double.TryParse(FromXValueBind, out from) || !double.TryParse(ToXValueBind, out to) || !double.TryParse(ApproxValueBind, out approx)) { MessageBox.Show(Locale["#ValuesParseException"], Locale["#RecommendDiffrentArgs"], MessageBoxButton.OK, MessageBoxImage.Error); return; } if (from >= to) { MessageBox.Show(Locale["#IntervalEndpointsException"], Locale["#RecommendDiffrentArgs"], MessageBoxButton.OK, MessageBoxImage.Error); return; } if (IsIntervalDivisionEnabled && !double.TryParse(DivisionRateBind, out divRate)) { MessageBox.Show(Locale["#IntervalDivParseException"], Locale["#RecommendDiffrentArgs"], MessageBoxButton.OK, MessageBoxImage.Error); return; } ProgressBarVisibility = (int)divRate != 1 ? Visibility.Visible : Visibility.Collapsed; _fromX = from; _toX = to; //Add results to the list. int noRootsCounter = 0, maxIterCounter = 0, divisionsSuccesses = 0; var intervalStep = Math.Abs(from - to) / divRate; var roots = await Task.Run(() => { List <FunctionRoot> output = new List <FunctionRoot>(); for (var i = from; i < to; i += intervalStep) { //Prepare argument. var arg = new GetFunctionRootArgs { FromX = i, ToX = i + intervalStep, Approx = approx, MaxIterations = _maxIterations }; try { output.Add(MathCore.GetFunctionRootBi(FunctionSelectorSelectedItem, arg)); divisionsSuccesses++; } catch (Exception e) { //if this function return true , it means that values on the interval's borders are of the same sign if (CatchFunction(e, ref maxIterCounter, ref noRootsCounter, "Bi")) { continue; } } try { output.Add(MathCore.GetFunctionRootFalsi(FunctionSelectorSelectedItem, arg)); divisionsSuccesses++; } catch (Exception e) { CatchFunction(e, ref maxIterCounter, ref noRootsCounter, "Falsi"); } } return(output); }); foreach (var functionRoot in roots) { RootsCollection.Add(functionRoot); } if (maxIterCounter > 0 || noRootsCounter > 0) { MessageBox.Show(Locale["#DividedIntervalRaport"] .Replace("&s1;", divisionsSuccesses.ToString()) .Replace("&s2;", maxIterCounter.ToString()) .Replace("&s3;", noRootsCounter.ToString()), Locale["#DividedIntervalRaport1"], MessageBoxButton.OK, MessageBoxImage.Information); } //Update DataGrid's groups definitions. RootsView = new ListCollectionView(RootsCollection); //Once we are done we can render the chart. UpdateChart(); }