src/GenFx.Wpf/Controls/MetricsChart.xaml.cs
/// <summary>
/// Refreshes all of the plot model's series.
/// </summary>
Refreshes all of the plot model's series.
Refreshes all of the plot model ' s series .
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
        private void RefreshAllSeries()
        {
            GeneticAlgorithm? algorithm = null;
            Population? population = null;
            IEnumerable<Metric>? selectedMetrics = null;
            this.Dispatcher.Invoke(() =>
            {
                algorithm = this.Algorithm;
                population = this.Population;
                selectedMetrics = this.SelectedMetrics;
            });
            this.PlotModel.Series.Clear();
            if (algorithm != null && population != null)
            {
                IEnumerable<Metric> metrics = selectedMetrics ?? algorithm.Metrics;
                foreach (Metric metric in metrics)
                {
                    LineSeries series = new LineSeries
                    {
                        Title = DisplayNameHelper.GetDisplayName(metric),
                        ToolTip = DisplayNameHelper.GetDisplayNameWithTypeInfo(metric),
                        DataFieldX = nameof(MetricResult.GenerationIndex),
                        DataFieldY = nameof(MetricResult.ResultValue)
                    };
                    ObservableCollection<MetricResult> results = metric.GetResults(population.Index);
                    series.ItemsSource = results;
                    MetricResult firstResult = results.FirstOrDefault();
                    if (firstResult != null)
                    {
                        bool exceptionThrown = false;
                        try
                        {
                            Convert.ToDouble(firstResult.ResultValue, CultureInfo.CurrentCulture);
                        }
                        catch (Exception)
                        {
                            exceptionThrown = true;
                        }
                        if (!exceptionThrown)
                        {
                            this.PlotModel.Series.Add(series);
                        }
                    }
                }
            }
            this.RefreshPlot();
        }
[ System . Diagnostics . CodeAnalysis . SuppressMessage ( " " , " " ) ] private void RefreshAllSeries ( ) { GeneticAlgorithm ? algorithm = null ; Population ? population = null ; IEnumerable < Metric > ? selectedMetrics = null ; this . Dispatcher . Invoke ( ( ) => { algorithm = this . Algorithm ; population = this . Population ; selectedMetrics = this . SelectedMetrics ; } ) ; this . PlotModel . Series . Clear ( ) ; if ( algorithm != null && population != null ) { IEnumerable < Metric > metrics = selectedMetrics ?? algorithm . Metrics ; foreach ( Metric metric in metrics ) { LineSeries series = new LineSeries { Title = DisplayNameHelper . GetDisplayName ( metric ) , ToolTip = DisplayNameHelper . GetDisplayNameWithTypeInfo ( metric ) , DataFieldX = nameof ( MetricResult . GenerationIndex ) , DataFieldY = nameof ( MetricResult . ResultValue ) } ; ObservableCollection < MetricResult > results = metric . GetResults ( population . Index ) ; series . ItemsSource = results ; MetricResult firstResult = results . FirstOrDefault ( ) ; if ( firstResult != null ) { bool exceptionThrown = false ; try { Convert . ToDouble ( firstResult . ResultValue , CultureInfo . CurrentCulture ) ; } catch ( Exception ) { exceptionThrown = true ; } if ( ! exceptionThrown ) { this . PlotModel . Series . Add ( series ) ; } } } } this . RefreshPlot ( ) ; }
Refreshes all of the plot model's series.
Refreshes all of the plot model ' s series .
// Verify the results contain values of types that can be converted to double // for the chart to plot.