Esempio n. 1
0
        private static TraceDataPlotState ToState(_TraceDataPlotStateDTO tdpsDTO)
        {
            var traceDataPlotState = new TraceDataPlotState
            {
                IsVisible                    = tdpsDTO.IsVisible,
                ViewHeight                   = tdpsDTO.ViewHeight,
                IsSeriesTypeLine             = tdpsDTO.IsSeriesTypeLine,
                IsAxesOriginLockedToZeroZero = tdpsDTO.IsAxesOriginLockedToZeroZero,
                XMinimum = tdpsDTO.XMinimum,
                XMaximum = tdpsDTO.XMaximum,
                YMinimum = tdpsDTO.YMinimum,
                YMaximum = tdpsDTO.YMaximum
            };

            if (tdpsDTO.DepVarConfigState != default)
            {
                traceDataPlotState.DepVarConfigState.SelectedElementName =
                    tdpsDTO.DepVarConfigState.SelectedElementName;

                traceDataPlotState.DepVarConfigState.MRUElementNames =
                    tdpsDTO.DepVarConfigState.MRUElementNames.IsNullOrEmpty()
            ? default
            : tdpsDTO.DepVarConfigState.MRUElementNames.ToArr();

                traceDataPlotState.DepVarConfigState.SelectedInsetElementName =
                    tdpsDTO.DepVarConfigState.SelectedInsetElementName;

                traceDataPlotState.DepVarConfigState.SupplementaryElementNames =
                    tdpsDTO.DepVarConfigState.SupplementaryElementNames.IsNullOrEmpty()
            ? default
            : tdpsDTO.DepVarConfigState.SupplementaryElementNames.ToArr();

                if (tdpsDTO.DepVarConfigState.InactiveSupplementaryElementNames != default)
                {
                    foreach (var kvp in tdpsDTO.DepVarConfigState.InactiveSupplementaryElementNames)
                    {
                        traceDataPlotState.DepVarConfigState.InactiveSupplementaryElementNames.Add(kvp.Key, kvp.Value.ToArr());
                    }
                }

                traceDataPlotState.DepVarConfigState.ObservationsReferences =
                    tdpsDTO.DepVarConfigState.ObservationsReferences.IsNullOrEmpty()
            ? default
            : tdpsDTO.DepVarConfigState.ObservationsReferences.ToArr();

                traceDataPlotState.DepVarConfigState.IsScaleLogarithmic = tdpsDTO.DepVarConfigState.IsScaleLogarithmic;
            }

            return(traceDataPlotState);
        }
Esempio n. 2
0
        public TraceDataPlotViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            TraceDataPlotState traceDataPlotState
            )
        {
            _appState    = appState;
            _appSettings = appSettings;
            _simulation  = _appState.Target.AssertSome("No simulation");
            State        = traceDataPlotState;

            _depVarConfigViewModel = new DepVarConfigViewModel(
                _simulation.SimConfig.SimOutput,
                _appState.SimEvidence,
                appService,
                traceDataPlotState.DepVarConfigState
                );

            _isSeriesTypeLine             = traceDataPlotState.IsSeriesTypeLine;
            _isAxesOriginLockedToZeroZero = traceDataPlotState.IsAxesOriginLockedToZeroZero;

            _xAbsoluteMinimum = _isAxesOriginLockedToZeroZero ? 0.0 : double.MinValue;
            _xMinimum         = traceDataPlotState.XMinimum ?? (_isAxesOriginLockedToZeroZero ? 0.0 : double.NaN);
            _xMaximum         = traceDataPlotState.XMaximum ?? double.NaN;

            _yAbsoluteMinimum = _isAxesOriginLockedToZeroZero ? 0.0 : double.MinValue;
            _yMinimum         = traceDataPlotState.YMinimum ?? (_isAxesOriginLockedToZeroZero ? 0.0 : double.NaN);
            _yMaximum         = traceDataPlotState.YMaximum ?? double.NaN;

            ToggleSeriesType = ReactiveCommand.Create(HandleToggleSeriesType);

            ToggleLockAxesOriginToZeroZero = ReactiveCommand.Create(HandleToggleIsAxesOriginLockedToZeroZero);

            ResetAxisRanges = ReactiveCommand.Create(HandleResetAxisRanges);

            RemoveChart = ReactiveCommand.Create(HandleRemoveChart);

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _plotModel = new PlotModel
            {
                Background     = OxyColors.Transparent,
                LegendPosition = LegendPosition.BottomRight
            };

            _traceHorizontalAxis = new LinearAxis
            {
                Position       = AxisPosition.Bottom,
                MinimumPadding = 0,
                MaximumPadding = 0.06,
            };
            _traceHorizontalAxis.AxisChanged += (s, e) => { if (_reactiveSafeInvoke.React)
                                                            {
                                                                HandleAxisChanged();
                                                            }
            };
            _plotModel.Axes.Add(_traceHorizontalAxis);

            _traceVerticalAxis = new LinearAxis
            {
                Position       = AxisPosition.Left,
                MinimumPadding = 0,
                MaximumPadding = 0.06,
                Key            = nameof(_traceVerticalAxis),
            };
            _traceVerticalAxis.AxisChanged += (s, e) => { if (_reactiveSafeInvoke.React)
                                                          {
                                                              HandleAxisChanged();
                                                          }
            };
            _traceInsetAxis = new LinearAxis
            {
                Position       = AxisPosition.Right,
                MinimumPadding = 0,
                MaximumPadding = 0,
                TickStyle      = TickStyle.Inside,
                LabelFormatter = x => null,
                StartPosition  = 0.4,
                EndPosition    = 0.6,
                Key            = nameof(_traceInsetAxis),
            };

            _traceLogVerticalAxis = new LogarithmicAxis
            {
                Position       = AxisPosition.Left,
                MinimumPadding = 0,
                MaximumPadding = 0.06,
                Key            = nameof(_traceLogVerticalAxis)
            };
            _traceLogVerticalAxis.AxisChanged += (s, e) => { if (_reactiveSafeInvoke.React)
                                                             {
                                                                 HandleAxisChanged();
                                                             }
            };
            _traceLogInsetAxis = new LogarithmicAxis
            {
                Position       = AxisPosition.Right,
                MinimumPadding = 0,
                MaximumPadding = 0.06,
                TickStyle      = TickStyle.Inside,
                LabelFormatter = x => null,
                StartPosition  = 0.4,
                EndPosition    = 0.6,
                Key            = nameof(_traceLogInsetAxis)
            };

            ApplyTheme();

            _subscriptions = new CompositeDisposable(

                _appSettings
                .GetWhenPropertyChanged()
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <string?>(ObserveAppSettingsPropertyChange)
                    ),

                traceDataPlotState
                .ObservableForProperty(x => x.IsVisible)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(ObserveTraceDataPlotStateIsVisible)
                    ),

                traceDataPlotState.DepVarConfigState
                .GetWhenPropertyChanged()
                .Subscribe(
                    ObserveDepVarConfigStatePropertyChanged
                    ),

                this
                .ObservableForProperty(vm => vm.DataSet)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(ObserveDataSet)
                    )

                );
        }