Example #1
0
        internal OutputsViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            ModuleState moduleState,
            SamplingDesigns samplingDesigns
            )
        {
            _appState    = appState;
            _appSettings = appSettings;
            _moduleState = moduleState;
            _simulation  = appState.Target.AssertSome();

            _outputsSelectedSampleViewModel  = new OutputsSelectedSampleViewModel(appState, appService, moduleState);
            _outputsFilteredSamplesViewModel = new OutputsFilteredSamplesViewModel(appState, appService, moduleState, samplingDesigns);
            _outputsEvidenceViewModel        = new OutputsEvidenceViewModel(appState, appService, moduleState);

            var output = _simulation.SimConfig.SimOutput;

            _outputNames = output.DependentVariables
                           .Map(e => e.Name)
                           .OrderBy(n => n.ToUpperInvariant())
                           .ToArr();

            _moduleState.OutputsState.SelectedOutputName ??= _outputNames.Head();

            _selectedOutputName = _outputNames.IndexOf(
                _moduleState.OutputsState.SelectedOutputName
                );

            PlotController = new();
            PlotController.Bind(
                new OxyMouseDownGesture(OxyMouseButton.Left),
                new DelegatePlotCommand <OxyMouseDownEventArgs>(HandleOutputsMouseDown)
                );
            PlotController.Bind(
                new OxyMouseDownGesture(OxyMouseButton.Left, OxyModifierKeys.Control),
                new DelegatePlotCommand <OxyMouseDownEventArgs>(HandleOutputsMouseDown)
                );

            Outputs = new();

            var horizontalAxis = new LinearAxis
            {
                Position = AxisPosition.Bottom,
                Title    = output.IndependentVariable.Name,
                Unit     = output.IndependentVariable.Unit
            };

            Outputs.Axes.Add(horizontalAxis);

            var verticalAxis = new LinearAxis
            {
                Position = AxisPosition.Left
            };

            Outputs.Axes.Add(verticalAxis);

            Outputs.ApplyThemeToPlotModelAndAxes();

            PopulateAll();

            ToggleSeriesType = ReactiveCommand.Create(HandleToggleSeriesType);
            ResetAxes        = ReactiveCommand.Create(HandleResetAxes);

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

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

                moduleState.OutputsState
                .ObservableForProperty(os => os.SelectedOutputName)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveOutputsStateSelectedOutputName
                        )
                    ),

                moduleState.OutputsState
                .ObservableForProperty(os => os.ObservationsReferences)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveOutputsStateObservationsReferences
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.FilterConfig)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateFilterConfig
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.Outputs)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputs
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.OutputFilters)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputFilters
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.SelectedOutputName)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveSelectedOutputName
                        )
                    )

                );
        }