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

6.3 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-16T11:14:59.450875+00:00 zai-org/GLM-5-FP8 1 8c5a8096c69954ca

Documentation: DTS.Viewer.Graph Views

1. Purpose

This module provides WPF view components for rendering and exporting graphical test data within the DTS Viewer application. It contains three XAML code-behind classes—GraphView, TestDataView, and TestDataSeriesView—that implement view interfaces from DTS.Common.Interface. The primary functionality resides in TestDataSeriesView, which supports exporting chart data to PDF reports and CSV files (specifically for Power Spectral Density data). The module integrates with ComponentOne charting and PDF libraries for visualization and document generation.


2. Public Interface

GraphView

Signature: public partial class GraphView : IGraphView

  • GraphView() - Default constructor. Calls InitializeComponent() to load the XAML-defined UI. No other behavior.

TestDataView

Signature: public partial class TestDataView : ITestDataView

  • TestDataView() - Default constructor. Calls InitializeComponent(). Contains extensive commented-out zoom functionality (mouse handlers, reversible frame drawing) that is not active.

TestDataSeriesView

Signature: public partial class TestDataSeriesView : ITestDataSeriesView

  • TestDataSeriesView() - Default constructor. Calls InitializeComponent().

  • bool SaveReportToPDF(string directory) - Generates a PDF report containing:

    • Test setup name and test ID from the first data series
    • Chart image rendered as PNG and embedded
    • A tabular summary of channel names, sample rates, and gRMS values with color indicators
    • Returns true on success, false on exception. Throws DirectoryNotFoundException if directory is null/whitespace (caught internally).
  • bool SaveReportToCSV(string directory) - Exports PSD (Power Spectral Density) data to CSV format:

    • Header row: "Frequency" followed by channel names
    • Units row: "Hz" followed by engineering units in format {units}^2/Hz
    • Data rows: X values (frequency) and corresponding Y values for each channel
    • Returns true on success, false on exception.
  • void MainChart_OnMouseWheel(object sender, MouseWheelEventArgs e) - Event handler (currently empty implementation; zoom logic commented out).

  • void MainChart_OnKeyUp(object sender, KeyEventArgs e) - Event handler (empty implementation).

  • void obj_DataPointChanged(object sender, EventArgs e) - Event handler (currently empty; data point label update logic commented out).


AxisExtension (Static Helper Class)

Signature: public static class AxisExtension

  • double GetDispMin(this Axis axis) - Extension method calculating display minimum based on ActualMin, Value, ActualMax, and Scale.

  • double GetDispMax(this Axis axis) - Extension method calculating display maximum based on ActualMin, Value, ActualMax, and Scale.


3. Invariants

  • PDF Paper Size: Determined by System.Globalization.RegionInfo.CurrentRegion.IsMetric — uses PaperKind.A4 for metric regions, PaperKind.Letter otherwise.
  • Data Series Access: SaveReportToPDF and SaveReportToCSV assume MainChart.DataContext is castable to TestDataSeriesViewModel with a non-null GraphDataSeries property.
  • Data Series Uniformity: CSV export assumes all data series have equal-length Xvalue and Yvalue arrays (loop condition checks all series).
  • Color Casting: PDF export assumes ds.GraphColor is castable to System.Windows.Media.SolidColorBrush.
  • File Naming: Both export methods generate filenames using the current DateTime with specific formatting patterns.

4. Dependencies

This module depends on:

  • DTS.Common.Interface — Provides IGraphView, ITestDataView, ITestDataSeriesView interfaces
  • DTS.Common.Utilities.Logging — Provides APILogger for logging operations and exceptions
  • DTS.Common.Utils — Provides FileUtils.GetEncoding(int)
  • C1.WPF.Chart — ComponentOne FlexChart library
  • C1.WPF.C1Chart — ComponentOne chart components (Axis, ImageFormat)
  • C1.WPF.C1Chart.Extended — Extended chart functionality
  • C1.WPF.Pdf — ComponentOne PDF generation (C1PdfDocument, PaperKind, Font, Pen)
  • System.Windows — WPF core (UI elements, input, media)
  • System.IO — File and directory operations

What depends on this module:

  • Unknown from source alone — The interfaces (IGraphView, ITestDataView, ITestDataSeriesView) suggest consumption by a presentation layer or DI container, but concrete consumers are not visible in these files.

5. Gotchas

  1. Extensive Dead Code: Both TestDataView and TestDataSeriesView contain large blocks of commented-out functionality including zoom/pan features, mouse event handling, and data point tracking. This suggests incomplete refactoring or feature rollback.

  2. Tight ViewModel Coupling: SaveReportToPDF and SaveReportToCSV directly cast MainChart.DataContext to the concrete TestDataSeriesViewModel type rather than using an interface, creating tight coupling.

  3. Silent Failure Pattern: Both export methods catch all exceptions, log them, and return false without rethrowing. Callers receive no exception details beyond the boolean result.

  4. Encoding Fallback: SaveReportToCSV attempts to get a specific encoding by code page, falling back to Encoding.Default on failure. This could cause inconsistent file encoding across different systems.

  5. File Path Construction: Both methods construct file paths using string concatenation with "\\" rather than Path.Combine() for the filename portion (though Path.Combine is used elsewhere).

  6. Empty Event Handlers: MainChart_OnKeyUp and MainChart_OnMouseWheel are wired but have empty or commented-out implementations — unclear if they are placeholders or remnants.

  7. AxisExtension Usage Unclear: The AxisExtension class provides zoom-related calculations, but no code in these files appears to call these methods.