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

6.5 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.Graph/View/GraphView.xaml.cs
DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.Graph/View/TestDataView.xaml.cs
DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.Graph/View/TestDataSeriesView.xaml.cs
2026-04-16T13:53:01.641041+00:00 zai-org/GLM-5-FP8 1 8c5a8096c69954ca

Documentation: DTS.Viewer.Graph Views

1. Purpose

This module provides WPF view components for graph visualization within the DTS Viewer application. It contains three XAML code-behind classes—GraphView, TestDataView, and TestDataSeriesView—that implement corresponding interfaces from DTS.Common.Interface. The primary functionality includes rendering charts using ComponentOne WPF Chart controls and exporting test data to PDF and CSV formats with associated metadata (test setup information, gRMS tables, and PSD data).


2. Public Interface

GraphView

Implements: IGraphView

Member Signature Description
Constructor public GraphView() Initializes the XAML component via InitializeComponent().

TestDataView

Implements: ITestDataView

Member Signature Description
Constructor public TestDataView() Initializes the XAML component via InitializeComponent().

Note: Contains extensive commented-out code for mouse-driven zoom functionality (MainChart_MouseLeftButtonDown, MainChart_MouseMove, MainChart_MouseLeftButtonUp, PerformZoom, DrawReversibleRectangle), but none of this is active.


TestDataSeriesView

Implements: ITestDataSeriesView

Member Signature Description
Constructor public TestDataSeriesView() Initializes the XAML component via InitializeComponent().
SaveReportToPDF public bool SaveReportToPDF(string directory) Generates a PDF containing: test setup info, chart image, and a gRMS table with channel names, sample rates, and gRMS values. Returns true on success, false on failure.
SaveReportToCSV public bool SaveReportToCSV(string directory) Exports chart data to CSV format with frequency (Hz) and PSD values (EngineeringUnits²/Hz). Returns true on success, false on failure.
obj_DataPointChanged private void obj_DataPointChanged(object sender, EventArgs e) Event handler for data point changes. All logic is commented out.
MainChart_OnMouseWheel private void MainChart_OnMouseWheel(object sender, MouseWheelEventArgs e) Mouse wheel event handler. All logic is commented out.
MainChart_OnKeyUp private void MainChart_OnKeyUp(object sender, KeyEventArgs e) Key up event handler. Empty implementation.

AxisExtension (Static Extension Class)

Member Signature Description
GetDispMin public static double GetDispMin(this Axis axis) Calculates display minimum: axis.ActualMin + axis.Value * (axis.ActualMax - axis.ActualMin) * (1 - axis.Scale)
GetDispMax public static double GetDispMax(this Axis axis) Calculates display maximum: axis.ActualMax - (1 - axis.Value) * (axis.ActualMax - axis.ActualMin) * (1 - axis.Scale)

3. Invariants

  • SaveReportToPDF: The directory parameter must be non-null and non-whitespace; otherwise, a DirectoryNotFoundException is thrown.
  • SaveReportToCSV: The method creates the target directory if it does not exist.
  • DataContext Requirement: Both SaveReportToPDF and SaveReportToCSV require MainChart.DataContext to be castable to TestDataSeriesViewModel with a non-null GraphDataSeries property.
  • PDF Paper Size: Determined by System.Globalization.RegionInfo.CurrentRegion.IsMetric — A4 for metric regions, Letter otherwise.
  • CSV Data Alignment: The CSV export loop assumes all series in GraphDataSeries have Xvalue and Yvalue arrays of equal or greater length than the iteration index.

4. Dependencies

External Dependencies (Imports)

Namespace Purpose
DTS.Common.Interface Provides IGraphView, ITestDataView, ITestDataSeriesView interfaces
DTS.Common.Utilities.Logging Provides APILogger for logging operations
DTS.Common.Utils Provides FileUtils.GetEncoding() for text encoding
C1.WPF.Chart / C1.WPF.C1Chart / C1.WPF.C1Chart.Extended ComponentOne chart controls (C1FlexChart, Axis, ImageFormat)
C1.WPF.Pdf ComponentOne PDF generation (C1PdfDocument, PaperKind, Font, Pen)
System.Windows WPF core types (Point, Rect, Visibility, MessageBox, etc.)
System.Windows.Input Input types (MouseEventArgs, MouseWheelEventArgs, KeyEventArgs, ModifierKeys)
System.Windows.Media.Imaging Bitmap types (BitmapImage, WriteableBitmap)

Downstream Dependencies

  • Unclear from source alone — These are view components; consumers would typically be ViewModels or other presentation-layer components that reference these views, but no direct consumers are visible in the provided source.

5. Gotchas

  1. Substantial Commented-Out Code: Both TestDataView and TestDataSeriesView contain significant commented-out functionality (zoom/pan features, data point tracking). This suggests incomplete features or deprecated functionality that was never removed.

  2. Direct Concrete Type Cast: SaveReportToPDF and SaveReportToCSV cast MainChart.DataContext directly to TestDataSeriesViewModel (a concrete class) rather than an interface. This tight coupling could cause runtime exceptions if the DataContext type changes.

  3. Unsafe GraphColor Cast: In SaveReportToPDF, ds.GraphColor is cast directly to SolidColorBrush without null or type checking:

    pdf.FillRectangle((ds.GraphColor as System.Windows.Media.SolidColorBrush).Color, ...);
    

    This will fail silently or throw if GraphColor is null or a different brush type.

  4. Empty Event Handlers: MainChart_OnKeyUp is entirely empty, and obj_DataPointChanged / MainChart_OnMouseWheel have all logic commented out. These handlers may be wired up in XAML but do nothing.

  5. CSV Filename Suffix: CSV files are saved with .PSD.csv extension, indicating Power Spectral Density data, but this is not validated against actual data content.

  6. Encoding Fallback: SaveReportToCSV catches exceptions when getting encoding and falls back to Encoding.Default, which may produce inconsistent file encodings across different systems.