import * as d3 from 'd3'; import { GraphData, GraphPoint } from '../../index'; import { DataService } from "../data/DataService"; import { ConfigurationService } from "../ConfigurationService"; import { SummaryService } from "../calculation/SummaryService"; /** * Graph Service * * Performs complex mathematical calculations for energy flow positioning and routing. * Handles the sophisticated algorithms needed to calculate Sankey diagram paths, * including triple nested loops for flow positioning and waste heat calculations. * * Key Algorithms: * - Complex flow positioning with mathematical precision * - Waste heat cloning and distribution calculations * - Multi-layer caching system for performance optimization * - D3 line generation for smooth rendering * - Graph data structure management and optimization */ export declare class GraphService { private configService; private dataService; private summaryCalculationService; graphs: GraphData[]; constructor(configService: ConfigurationService, // Will inject when available dataService: DataService, summaryCalculationService: SummaryService); /** * Extract expensive calculation to separate method (same logic as original) */ private buildGraphs; /** * Calculate Flow Y-Coordinates - Complex Triple Nested Loop Algorithm * * COMPUTATIONAL COMPLEXITY: O(n³) - Years × Fuels × Sectors * This is the most mathematically sophisticated method in the entire energy visualization system, * handling precise flow positioning, coordinate calculations, and waste heat thermodynamics. * * ALGORITHM STRUCTURE - THREE NESTED LEVELS: * * Level 1 (i): Years Loop - Process each chronological data point * └─ Creates GraphStroke arrays for energy flow paths * └─ Manages vertical offset tracking for precise positioning * * Level 2 (j): Fuels Loop - Process each energy source type * └─ Special handling for electricity (j=0) vs. primary fuels (j>0) * └─ Calculates fuel-specific positioning and offsets * * Level 3 (k): Sectors Loop - Process each consumption category * └─ Creates GraphStroke objects for each Fuel → Sector flow * └─ Applies complex coordinate mathematics for positioning * * CRITICAL COORDINATE MATHEMATICS: * 1. Y-Coordinate Positioning: Uses cumulative offset tracking * 2. Stroke Width Calculation: Energy value × SCALE factor * 3. Control Points: mathematics for smooth flow * 4. Waste Heat Cloning: Deep object cloning with thermodynamic calculations * * WASTE HEAT PHYSICS IMPLEMENTATION: * Implements the fundamental thermodynamic principle that electricity generation * produces waste heat according to Carnot efficiency limits. Each electricity * flow gets a corresponding waste heat flow with identical path geometry. * * COORDINATE SYSTEM DETAILS: * - SCALE (0.02): Converts energy units (Quads) to pixel heights * - ELEC_BOX coordinates: Special positioning for electricity flows * - SR3: Slope ratio for smooth transitions (slope = height/3) * - PATH_GAP: Visual spacing between parallel flow paths * - LEFT_GAP: Spacing between fuel source boxes * * PERFORMANCE OPTIMIZATIONS: * - Method inlining: Configuration constants cached locally * - Direct array indexing: Eliminates object property lookups * - In-place calculations: Minimizes temporary object creation * * MATHEMATICAL PRECISION REQUIREMENTS: * All calculations must maintain sub-pixel precision to ensure: * - Smooth flow animations during year transitions * - Perfect alignment between interconnected flows * - Accurate proportional representation of energy values * - Thermodynamically correct waste heat positioning */ calculateGraphY(): void; calculateGraphX(): void; /** * Method Inlined calculateGraphXUps() - eliminates repeated property access */ private calculateGraphXUps; /** * Method Inlined calculateGraphXDowns() - eliminates repeated property access */ private calculateGraphXDowns; /** * Method Inlined spaceUpsAndDowns() - eliminates repeated property access */ spaceUpsAndDowns(): void; /** * Waste heat processing */ processWasteHeatFlows(): void; /** * Method Inlined sortGraphUp() - eliminates repeated array access */ private sortGraphUp; /** * Method Inlined sortGraphDown() - eliminates repeated array access */ private sortGraphDown; sigfig2(n: number | string | undefined | null): number; createLine(): d3.Line; } //# sourceMappingURL=GraphService.d.ts.map