Files
2026-04-17 14:55:32 -04:00

167 lines
7.5 KiB
Markdown

---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.ChartOptions/ViewModel/ChartOptionsViewModel.cs
generated_at: "2026-04-16T11:18:03.613000+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "7f2f2e90f6f17587"
---
# Documentation: ChartOptionsViewModel
## 1. Purpose
`ChartOptionsViewModel` is a Prism-based view model that manages user-configurable chart display options within the DTS Viewer application. It serves as an intermediary between chart option UI controls and the underlying chart rendering system, handling unit type selection (EU, mV, ADC), axis range configuration, cursor visibility, and PDF export functionality. The module supports multiple parent contexts including `IViewerMainViewModel` and `IPSDReportMainViewModel`, with different default configurations based on the parent type.
---
## 2. Public Interface
### Constructor
```csharp
public ChartOptionsViewModel(
IChartOptionsView view,
IRegionManager regionManager,
IEventAggregator eventAggregator,
IUnityContainer unityContainer)
```
Initializes the view model, sets up the view's DataContext, creates interaction requests, and subscribes to `ChartAxisChangedEvent`.
---
### Properties
| Property | Type | Access | Description |
|----------|------|--------|-------------|
| `Parent` | `IBaseViewModel` | get/set | Reference to the parent view model; used for event filtering. |
| `NotificationRequest` | `InteractionRequest<Notification>` | get | Prism interaction request for notifications. |
| `ConfirmationRequest` | `InteractionRequest<Confirmation>` | get | Prism interaction request for confirmations. |
| `View` | `IBaseView` | get/set | The associated view interface. |
| `Model` | `IChartOptionsModel` | get/set | The chart options model; resolves from container on set. Raises `OnPropertyChanged("Model")`. |
| `ContextSearchRegion` | `object` | get/set | Unused in visible code. |
| `IsMenuIncluded` | `bool` | get/set | Hides base property. |
| `IsNavigationIncluded` | `bool` | get/set | Hides base property. |
| `IsBusy` | `bool` | get/set | Hides base property. |
| `IsDirty` | `bool` | get | Always returns default value; never assigned. |
| `ChartOptionsVisability` | `bool` | get/set | Controls visibility of chart options UI. Raises property changed notification. |
| `ClearMarkersCommand` | `DelegateCommand` | get | Lazy-initialized command that calls `ClearMarkersMethod()`. |
---
### Methods
```csharp
public override void Initialize()
```
Empty override; performs no operations.
```csharp
public override void Initialize(object parameter)
```
Initializes the view model with a parent context. Subscribes to events, resolves the model from Unity container, and configures defaults based on parameter type:
- If `parameter is IViewerMainViewModel`: Sets `Model.DecimateData = true`
- If `parameter is Tuple<IBaseViewModel, string>` where `Item1` is `IPSDReportMainViewModel`: Configures based on `chartType` string ("Graph" vs other)
```csharp
public void ShowMinMaxCursor(bool value)
```
Publishes `CursorShowMinMaxChangedEvent` with the given boolean value.
```csharp
public void ResetZoomMethod()
```
Sets `Model.YRange` to `YRangeScaleEnum.AutoRange` and publishes `ResetZoomChangedEvent` with `true`.
```csharp
public void ResetTMethod()
```
Publishes `ResetZoomChangedEvent` with `false`.
```csharp
public void SaveToPDFMethod()
```
Publishes `SaveToPDFRequestedEvent` with the stored `Directory` path.
```csharp
public void PublishChanges()
```
Publishes `ChartOptionsChangedEvent` with a `ChartOptionsChangedEventArg` containing `ParentVM`, `Model`, and `ChartType`.
```csharp
public void ShowCusor(bool value)
```
Publishes `CursorShowChangedEvent` with the given boolean value.
```csharp
public new void OnPropertyChanged(string propertyName)
```
Raises the `PropertyChanged` event for the specified property name.
---
### Events
```csharp
public new event PropertyChangedEventHandler PropertyChanged
```
Hides the base class event; raised by `OnPropertyChanged`.
---
## 3. Invariants
1. **Model Resolution**: `Model` must be resolved from `IUnityContainer` before use; it is not resolved in the constructor but in `Initialize(object parameter)`.
2. **Event Filtering**: All received events are filtered by comparing `args?.ParentVM` to `Parent`. Events from other parent contexts are ignored.
3. **Publish Guard Pattern**: When programmatically modifying `Model` properties in response to events (e.g., in `OnChartAxisChangedEvent`), `Model.CanPublishChanges` must be set to `false` before modifications and restored to `true` afterward to prevent recursive event publishing.
4. **Log Scale Constraint**: When `chartType == "Graph"`, `Model.MinFixedY` is set to `1e-12` because log scale cannot handle zero.
5. **Unit Type Fallback**: If channels do not support ADC or mV (determined by `AllChannelsSupportADC` / `AllChannelsSupportmV`), the `Model.UnitType` is automatically reset to `ChartUnitTypeEnum.EU`.
---
## 4. Dependencies
### This Module Depends On
| Namespace | Types Used |
|-----------|------------|
| `DTS.Common.Base` | `BaseViewModel<T>`, `IBaseViewModel` |
| `DTS.Common.Enums.Viewer` | `ChartUnitTypeEnum`, `YRangeScaleEnum`, `FilterOptionEnum` |
| `DTS.Common.Enums.Hardware` | `HardwareConstants.IsTSRAIRSerialNumber()` |
| `DTS.Common.Events` | `ChartAxisChangedEvent`, `CursorsAlailableChangedEvent`, `GraphSelectedChannelsNotification`, `CursorShowMinMaxChangedEvent`, `ResetZoomChangedEvent`, `SaveToPDFRequestedEvent`, `ChartOptionsChangedEvent`, `CursorShowChangedEvent`, `CursorsClearChangedEvent` |
| `DTS.Common.Interface` | `IChartOptionsViewModel`, `IChartOptionsModel`, `IChartOptionsView`, `IBaseView`, `IViewerMainViewModel`, `IPSDReportMainViewModel`, `ITestChannel` |
| `DTS.Common.Interactivity` | `InteractionRequest<T>`, `Notification`, `Confirmation` |
| `Prism.Events` | `IEventAggregator` |
| `Prism.Regions` | `IRegionManager` |
| `Prism.Commands` | `DelegateCommand` |
| `Unity` | `IUnityContainer` |
### Modules That Depend On This Module
Cannot be determined from source alone; would require analysis of consumers of `IChartOptionsViewModel`.
---
## 5. Gotchas
1. **Copy-Paste Error in XML Comment**: The constructor's XML documentation states "Creates a new instance of the TestSummaryViewModel" — this is incorrect; the class is `ChartOptionsViewModel`.
2. **Typo: `ChartOptionsVisability`**: Property name should be `ChartOptionsVisibility`.
3. **Typo: `ShowCusor`**: Method name should be `ShowCursor`.
4. **Typo: `OnCursorsAlailableChanged`**: Event handler and event name `CursorsAlailableChangedEvent` should be `CursorsAvailableChanged`.
5. **Hidden Base Members**: Multiple properties (`IsMenuIncluded`, `IsNavigationIncluded`, `IsBusy`, `IsDirty`, `ConfirmationRequest`, `Model`, `PropertyChanged`, `OnPropertyChanged`) use the `new` keyword to hide base class members. This may cause unexpected behavior when casting to base types.
6. **Unused `IsDirty` Property**: The property has only a getter and is never assigned a value, making it perpetually `false` (default).
7. **Commented-Out Constructor Code**: Lines 55-57 are commented out, suggesting initialization logic was moved to `Initialize(object parameter)`.
8. **Hardcoded Magic Strings**: Axis comparison uses literal strings `"Y"` and `"X"` in `OnChartAxisChangedEvent`; `chartType` comparison uses literal `"Graph"`.
9. **ADC/mV Support Detection**: Both `AllChannelsSupportADC` and `AllChannelsSupportmV` use identical logic (checking for TSR AIR serial numbers). The comment indicates this is a temporary implementation that may need future refinement for calculated channels.