Exemplo n.º 1
0
        public void InitializeCharts()
        {
            if (!(AppSS.FirstReferencedWindow is MainWindow mw))
            {
                throw new Exception($"{this.GetType()} could not get a reference of {typeof(MainWindow)}");
            }

            PointPlotSummaryEvalPlot_CartesianChart = mw.PointPlotSummaryEvalPlot_CartesianChart;
            //PointPlotSummaryEvalPlot_CartesianChart.LegendLocation = LegendLocation.Top;
            PointPlotSummaryEvalPlot_CartesianChart.ChartLegend       = null;
            PointPlotSummaryEvalPlot_CartesianChart.DisableAnimations = true;

            PointPlotSummaryEvalPlot_CartesianChart.AxisY.Add(new Axis()
            {
                Title          = "Objective Function Eval",
                LabelFormatter = inD => BaseWPFStaticMembers.DoubleToEngineering(inD, "3"),
                Foreground     = mw.Resources["EmsPanelBorder_Green"] as SolidColorBrush,
            });
            PointPlotSummaryEvalPlot_CartesianChart.AxisX.Add(new Axis()
            {
                Title = "Optimization Point",
            });
            PointPlotSummaryEvalPlot_CartesianChart.Series.Add(new LineSeries()
            {
                //Title = "Objective Function Eval",
                Values          = new ChartValues <double>(),
                PointForeground = mw.Resources["EmsPanelBorder_Green"] as SolidColorBrush,
                Foreground      = mw.Resources["EmsPanelBorder_Green"] as SolidColorBrush,
                Stroke          = mw.Resources["EmsPanelBorder_Green"] as SolidColorBrush,
                StrokeThickness = 1d,
                Fill            = new SolidColorBrush()
                {
                    Opacity = 0d
                },
                PointGeometrySize = 5d,
                LineSmoothness    = 0d,
            });


            if (!(AppSS.I.GetDescendantOfElement_ByTag("CalculatingEvalPlot_CartesianChart", mw.Window_CustomOverlay) is CartesianChart calEvalPlot))
            {
                throw new Exception($"{this.GetType()} could not get find CalculatingEvalPlot_CartesianChart when searching by Tag.");
            }
            CalculatingEvalPlot_CartesianChart             = calEvalPlot;
            CalculatingEvalPlot_CartesianChart.ChartLegend = null;
            //CalculatingEvalPlot_CartesianChart.LegendLocation = LegendLocation.Top;
            CalculatingEvalPlot_CartesianChart.DisableAnimations = true;

            CalculatingEvalPlot_CartesianChart.AxisY.Add(new Axis()
            {
                Title          = "Objective Function Eval",
                LabelFormatter = inD => BaseWPFStaticMembers.DoubleToEngineering(inD, "3"),
                Foreground     = mw.Resources["EmsPanelBorder_Green"] as SolidColorBrush,
            });
            CalculatingEvalPlot_CartesianChart.AxisX.Add(new Axis()
            {
                Title = "Optimization Point",
            });
            CalculatingEvalPlot_CartesianChart.Series.Add(new LineSeries()
            {
                //Title = "Objective Function Eval",
                Values          = new ChartValues <double>(),
                PointForeground = mw.Resources["EmsPanelBorder_Green"] as SolidColorBrush,
                Foreground      = mw.Resources["EmsPanelBorder_Green"] as SolidColorBrush,
                Stroke          = mw.Resources["EmsPanelBorder_Green"] as SolidColorBrush,
                StrokeThickness = 1d,
                Fill            = new SolidColorBrush()
                {
                    Opacity = 0d
                },
                PointGeometrySize = 5d,
                LineSmoothness    = 0d,
            });



            ProblemConfigDetailPlot_CartesianChart = mw.ProblemConfigDetailPlot_CartesianChart;
            ProblemConfigDetailPlot_CartesianChart.LegendLocation    = LegendLocation.Top;
            ProblemConfigDetailPlot_CartesianChart.DisableAnimations = true;
            //ProblemConfigDetailPlot_CartesianChart.AxisY[0].LabelFormatter = inD => $"{inD:+0.0e+00;-0.0e+00;0.0}";

            // Makes them visible
            PointPlotSummaryEvalPlot_CartesianChart.Visibility = Visibility.Visible;
            CalculatingEvalPlot_CartesianChart.Visibility      = Visibility.Visible;
            ProblemConfigDetailPlot_CartesianChart.Visibility  = Visibility.Visible;

            NlOptPointDetails_CartesianChart = mw.NlOptPointDetails_CartesianChart;
            NlOptPointDetails_CartesianChart.DisableAnimations = true;
            NlOptPointDetails_CartesianChart.DataTooltip       = new DefaultTooltip()
            {
                SelectionMode = TooltipSelectionMode.OnlySender
            };
            NlOptPointDetails_CartesianChart.HideLegend();

            NlOptPointDetails_CartesianChart.AxisX.Add(new Axis()
            {
                Labels = new List <string>(),
            });

            NlOptPointDetails_CartesianChart.AxisY.Add(new Axis()
            {
                Title          = "Count of Elements",
                LabelFormatter = inD => BaseWPFStaticMembers.DoubleToEngineering(inD, "3"),
                Position       = AxisPosition.LeftBottom,
                Foreground     = mw.Resources["EmsPanelBorder_Gray"] as SolidColorBrush,
            });

            NlOptPointDetails_CartesianChart.Series.Add(new ColumnSeries()
            {
                Values          = new ChartValues <int>(),
                Foreground      = mw.Resources["EmsPanelBackground_Gray"] as SolidColorBrush,
                Stroke          = mw.Resources["EmsPanelBorder_Gray"] as SolidColorBrush,
                StrokeThickness = 1d,
                Fill            = mw.Resources["EmsPanelBackground_Gray"] as SolidColorBrush,
                ScalesYAt       = 0,
                ScalesXAt       = 0,
            });
        }
Exemplo n.º 2
0
        public void UpdateChart(CartesianChart inChart, List <ChartDisplayData> inData)
        {
            // Checks if chart is already invalidated...

            // Completely clears the chart's series
            inChart.Series.Clear();
            inChart.AxisY.Clear();

            // Get all visible pairs
            IEnumerable <ChartDisplayData_Series> allVisible = inData.SelectMany(a => a.SeriesData).Where(a => a.IsVisible);

            //double lf_getClosest(double inValue, double inShift)
            //{
            //    double target = inValue + inShift;
            //    string s = $"{target:+0.0e+000;-0.0e+000}";
            //    string[] chunks = s.Split(new[] {'e'});
            //    return double.Parse($"{chunks[0]}e{chunks[1]}");
            //}

            int counter = 0;

            foreach (ChartDisplayData_Series chartDisplayData_SeriesAxisPair in allVisible)
            {
                //double min = chartDisplayData_SeriesAxisPair.Min;
                //double max = chartDisplayData_SeriesAxisPair.Max;
                //int lineCount = 10;
                //double shift = (max - min) / lineCount;
                //double axisMin = lf_getClosest(min, -shift);
                //double axisMax = lf_getClosest(max, shift);

                // Creates an Axis to handle this list
                inChart.AxisY.Add(new Axis()
                {
                    Title          = chartDisplayData_SeriesAxisPair.Series.Title,
                    LabelFormatter = inD => BaseWPFStaticMembers.DoubleToEngineering(inD, "3"),
                    Position       = chartDisplayData_SeriesAxisPair.IsPairSelected_AxisOnLeftSide ? AxisPosition.LeftBottom : AxisPosition.RightTop,
                    Foreground     = chartDisplayData_SeriesAxisPair.Series.Stroke,

                    //MaxValue = axisMax,
                    //MinValue = axisMin,
                    //Separator = new Separator(){Step = (axisMax - axisMin)/lineCount}
                });

                // Adds this series to the list
                inChart.Series.Add(chartDisplayData_SeriesAxisPair.Series);

                // Tells the series to plot in the right axis
                chartDisplayData_SeriesAxisPair.Series.ScalesYAt = counter;


                counter++;
            }


            // Matches the axis' colors


            //inChart.Dispatcher.Invoke(() =>
            //{
            //    if (inChart == null)
            //    {
            //        int a = 0;
            //        a++;
            //    }

            //    inChart.Update();
            //    inChart.InvalidateArrange();
            //    inChart.UpdateLayout();
            //});

            // TODO: Check assigned color and try to match the color of the axes with the color of the series
            //int b = 0;
            //b++;
        }