import * as d3 from 'd3'; import { GraphStroke, YearTotals } from '../index'; import { EventBus } from '../core/events/EventBus'; import { ConfigurationService } from './ConfigurationService'; import { SummaryService } from './calculation/SummaryService'; import { GraphService } from './calculation/GraphService'; import { DataService } from "./data/DataService"; type D3SVGSelection = d3.Selection; type D3DivSelection = d3.Selection; /** * Chart Rendering Service - D3.js SVG Generation & Visual Rendering Engine * * ARCHITECTURAL RESPONSIBILITY: Mathematical Data → Visual SVG Transformation * * This service implements sophisticated D3.js patterns to transform mathematical energy flow * calculations into interactive SVG visualizations. It manages the complete visual rendering * pipeline from raw data to user-ready interactive charts. * * D3.JS DESIGN PATTERNS IMPLEMENTED: * 1. **Selection Patterns**: Efficient DOM element selection and manipulation * 2. **Data Binding**: Binding energy data to SVG elements with enter/update/exit patterns * 3. **Method Chaining**: Fluent D3 API usage for concise and readable code * 4. **Event Handling**: Mouse interactions with tooltip integration * 5. **Transition Management**: Smooth animations for year-to-year transitions * 6. **Scale Management**: Coordinate transformations and responsive scaling * * SVG GENERATION ARCHITECTURE: * - **Fuel Boxes**: Left column showing energy sources (solar, coal, etc.) * - **Sector Boxes**: Right column showing consumption sectors (residential, industrial, etc.) * - **Flow Paths**: connecting fuel sources to consumption sectors * - **Labels & Text**: Dynamic text elements with data-driven content * - **Tooltips**: Interactive information overlays with precise positioning * * VISUAL RENDERING PIPELINE: * Mathematical Data → D3 Selections → SVG Elements → Interactive Features → User Interface * * PERFORMANCE OPTIMIZATIONS: * - Efficient DOM manipulation using D3 selections * - Minimal DOM re-creation during year transitions * - Event delegation for tooltip management * - CSS class-based styling for performance * - Cached line generator for path creation */ export declare class RenderingService { private configService; private summaryCalculationService; private graphCalculationService; private dataService; private eventBus; private lineGenerator; constructor(configService: ConfigurationService, summaryCalculationService: SummaryService, graphCalculationService: GraphService, dataService: DataService, eventBus: EventBus); /** * Draws the animated header elements (year and energy units) as separate SVG overlays */ drawHeader(): void; /** * Creates the energy usage SVG overlay in the title section */ private createEnergyUsageOverlay; /** * Creates the year SVG overlay in the year section */ private createYearOverlay; /** * Draw Fuel Source Labels - Left Column Energy Source Visualization * * RENDERING RESPONSIBILITY: Create dynamic fuel source labels with proportional positioning * * This method implements D3.js text element creation for fuel source identification. * Label positions are calculated dynamically based on energy totals to maintain * accurate visual alignment with proportional fuel box heights. * * D3.JS TEXT RENDERING PATTERNS: * - Dynamic content from configuration and energy data * - Conditional visibility based on energy values (hidden if zero) * - Data attributes for animation and programmatic access * - CSS classes for styling and state management * * PROPORTIONAL POSITIONING ALGORITHM: * Y-position calculated dynamically: TOP_Y + cumulative_energy_heights + gaps * Ensures perfect alignment between fuel labels and their corresponding flow origins */ drawLeftLabels(svg: D3SVGSelection, totals: YearTotals): void; /** * Draw Energy Sector Boxes & Labels - Right Column Consumption Visualization * * RENDERING RESPONSIBILITY: Create interactive sector boxes with labels and totals * * This method implements the most complex D3.js element creation patterns, generating * rectangular sector boxes with multi-line labels and dynamic energy totals. * Demonstrates advanced SVG composition with nested text elements. * * ADVANCED D3.JS PATTERNS DEMONSTRATED: * 1. **Conditional Positioning**: Different algorithms for electricity vs. sector boxes * 2. **Complex Text Composition**: Multi-line labels using tspan elements * 3. **Dynamic Sizing**: Proportional box heights based on energy consumption * 4. **Data-Driven Visibility**: Conditional hiding based on energy values * 5. **Nested Element Creation**: Text elements with multiple tspan children * 6. **Special Case Handling**: Residential/Commercial label splitting * * SVG ELEMENT ARCHITECTURE: * Each sector generates: Rectangle (visual box) + Text (label + total + waste) * - Rectangle: Proportionally sized based on energy consumption * - Text Label: Human-readable sector name with special formatting * - Energy Total: Numeric display of energy consumption value * - Waste Total: Thermodynamic losses for electricity-consuming sectors */ drawBoxes(svg: D3SVGSelection, totals: YearTotals): void; /** * Draw Interactive Energy Flow Paths - Advanced D3.js SVG Path Rendering * * RENDERING RESPONSIBILITY: Transform Mathematical Flow Data → Interactive SVG Paths * * This method implements the most sophisticated D3.js rendering patterns in the entire * visualization system, creating interactive paths that represent energy * flows between fuel sources and consumption sectors. * * ADVANCED D3.JS PATTERNS IMPLEMENTED: * 1. **Complex Path Generation**: Mathematical GraphStroke data → SVG path strings * 2. **Interactive Event Binding**: Mouse event handlers for tooltip interactions * 3. **Dynamic Content Creation**: Data-driven SVG element creation with unique attributes * 4. **Transition Management**: Smooth fade-in/fade-out tooltip animations * 5. **Context-Aware Selection**: Targeting existing fuel group containers * 6. **Performance Optimization**: Efficient DOM manipulation and event delegation * * ENERGY FLOW VISUALIZATION ARCHITECTURE: * Each energy flow (Fuel → Sector) becomes an SVG element with: * - Geometry calculated by GraphService * - Stroke width proportional to energy quantity (visual data encoding) * - Interactive tooltip showing detailed energy values on hover * - CSS classes enabling styling and animation hooks * - Data attributes for programmatic access and filtering * * TOOLTIP INTERACTION DESIGN: * - Mouseover: 200ms fade-in with energy flow details * - Mouseout: 500ms fade-out for smooth visual transitions * - Dynamic positioning: Follows cursor with offset for readability * - Content formatting: "Fuel → Sector" with numerical energy value * * SVG PATH GENERATION PIPELINE: * Mathematical Coordinates → parseLineData() → SVG Path String → Interactive Path Element */ drawFlows(svg: D3SVGSelection, yearIndex: number, tooltip: D3DivSelection): void; /** * Clear chart content */ clearChart(svg: D3SVGSelection): void; drawInitialChart(svg: D3SVGSelection, tooltip: D3DivSelection): boolean; /** * Highlight specific fuel flows */ highlightFuel(svg: D3SVGSelection, fuelName: string): void; /** * Reset highlighting */ resetHighlight(svg: D3SVGSelection): void; parseLineData(stroke: GraphStroke): string; } export {}; //# sourceMappingURL=RenderingService.d.ts.map