import * as d3 from 'd3'; import { GraphData, SankeyOptions } from '../index'; import { EventBus } from '../core/events/EventBus'; import { SummaryService } from './calculation/SummaryService'; import { GraphService } from './calculation/GraphService'; import { Logger } from "../utils/Logger"; import { DataService } from "./data/DataService"; import { ConfigurationService } from "./ConfigurationService"; type D3SVGSelection = d3.Selection; type D3DivSelection = d3.Selection; export interface GraphNest { strokes: { [year: number]: { [fuel: string]: { [sector: string]: number; }; }; }; tops: { [year: number]: { [fuel: string]: number; }; }; heights: { [year: number]: { [sector: string]: number; }; }; waste: { [year: number]: { [sector: string]: number; }; }; } /** * Animation Control Service - Advanced Timeline Management & Smooth Transitions * * ARCHITECTURAL RESPONSIBILITY: Temporal Visualization Control & User Interaction * * This service implements sophisticated animation control patterns for temporal energy * visualizations, managing smooth year-to-year transitions, timeline navigation, * milestone events, and user interaction with historical energy data. * * TEMPORAL VISUALIZATION PATTERNS: * 1. **Timeline Navigation**: Seamless movement through 200+ years of energy history * 2. **State Management**: Centralized animation state with event-driven updates * 3. **Smooth Transitions**: D3.js-powered animations with configurable timing * 4. **Milestone Integration**: Interactive historical event markers and dialogs * 5. **User Controls**: Play/pause/seek controls with keyboard accessibility * 6. **Loop Management**: Configurable animation looping for presentations * * ANIMATION ARCHITECTURE: * - **Timeline State**: Current year, animation status, timing controls * - **Transition Management**: Smooth interpolation between energy data years * - **Interactive Controls**: Slider, buttons, and keyboard input handling * - **Milestone System**: Historical event markers with contextual information * - **Performance Optimization**: Efficient DOM updates and animation scheduling * * USER INTERACTION DESIGN: * - Intuitive timeline slider with year selection * - Responsive play/pause controls * - Keyboard navigation (arrow keys, space bar) * - Milestone hover/click interactions * - Configurable playback speed controls * * EVENT-DRIVEN INTEGRATION: * Communicates with other services via event bus for coordinated visual updates, * ensuring synchronized animation across all visualization components. */ export declare class AnimationService { private configService; private summaryCalculationService; private graphCalculationService; private dataService; private options; private eventBus; private logger; private state; private svg; private tooltip; private graphs; private graphNest; private sliderWidth; constructor(configService: ConfigurationService, summaryCalculationService: SummaryService, graphCalculationService: GraphService, dataService: DataService, options: SankeyOptions, eventBus: EventBus, logger: Logger); /** * Receives pre-built data structures and sets up animation system */ setupAnimation(graphs: GraphData[], graphNest: GraphNest, svg: D3SVGSelection, tooltip: D3DivSelection): void; /** * Sets up slider, year labels, tick marks, and milestone interactions */ private setupTimelineControls; /** * Creates milestone markers and dialog interactions */ private setupMilestones; /** * Handles milestone dot clicks and dialog positioning */ private setupMilestoneDialogs; /** * Creates dialog element with same styling and behavior */ private createMilestoneDialog; /** * Set up play/pause button controls */ private setupPlayControls; /** * Set up year display element */ private setupYearDisplay; /** * Set Year - Programmatic Timeline Navigation with Coordinated Updates * * NAVIGATION RESPONSIBILITY: Move visualization to specific year with system-wide coordination * * This method implements the core temporal navigation functionality, orchestrating * synchronized updates across all visualization components when changing years. * Essential for both user interaction (slider) and programmatic control (API). * * COORDINATED UPDATE SEQUENCE: * 1. **State Validation**: Verify target year exists in available data * 2. **State Update**: Update internal animation state to new year * 3. **UI Synchronization**: Update slider position to reflect state * 4. **Visualization Update**: Trigger complex chart transition animations * 5. **Visual Indicators**: Update timeline position indicators * 6. **Display Update**: Update year text display elements * 7. **Event Broadcasting**: Notify other services of year change * * ANIMATION INTEGRATION: * Seamlessly integrates with animation playback - can be called during * active animation for smooth seeking or by user interaction for direct navigation. * * PERFORMANCE CONSIDERATIONS: * Efficiently updates only necessary DOM elements and triggers minimal * re-calculations by leveraging pre-computed mathematical data structures. */ setYear(year: number): void; /** * Handles the complex animation transitions between years */ private animatePeriod; /** * Updates the position and content of the year indicator above the slider */ private updateSliderIndicator; private calculateIndicatorPosition; private applyIndicatorPosition; private updateYearDisplay; /** * Start Animation Playback - Temporal Visualization Timeline Control * * PLAYBACK RESPONSIBILITY: Initiate automated year-by-year progression through energy data * * This method starts the animation loop that automatically advances through years * of energy data, creating a cinematic progression through US energy history. * Essential for presentation mode and automated demonstration of energy trends. * * ANIMATION LIFECYCLE MANAGEMENT: * 1. **Guard Clause**: Prevent multiple simultaneous animations * 2. **State Update**: Set animation flag for system-wide coordination * 3. **UI Update**: Change play button to pause state for user feedback * 4. **Timer Initialization**: Start interval-based animation loop * 5. **Event Broadcasting**: Notify other services animation has started * * TIMING MECHANISM: * Uses JavaScript setInterval() for consistent frame timing at configured speed. * Timer interval determined by this.state.speed (milliseconds between years). * Each timer tick calls nextFrame() for year progression logic. * * USER INTERACTION INTEGRATION: * Updates visual play button state to indicate animation status, * providing immediate visual feedback for user understanding. */ play(): void; /** * Pause Animation Playback - Temporal Visualization Control * * PAUSE RESPONSIBILITY: Stop automated timeline progression while preserving current position * * This method halts the animation loop while maintaining the current year position, * enabling users to pause for detailed examination of specific time periods. * Critical for interactive exploration and presentation control. * * PAUSE LIFECYCLE MANAGEMENT: * 1. **Guard Clause**: Ensure animation is actually running before stopping * 2. **State Update**: Clear animation flag for system coordination * 3. **UI Update**: Restore play button state for user interface consistency * 4. **Timer Cleanup**: Properly clear interval timer to prevent memory leaks * 5. **Event Broadcasting**: Notify other services animation has stopped * * RESOURCE MANAGEMENT: * Properly clears JavaScript interval timer to prevent continued execution * and potential memory leaks during long-running visualization sessions. */ pause(): void; /** * Move to next frame in animation * Stop at end instead of looping */ private nextFrame; /** * Set animation speed AnimationService.setSpeed() */ setSpeed(speed: number): void; /** * Check if animation is currently playing */ isPlaying(): boolean; /** * Get current year */ getCurrentYear(): number; /** * Move to next year */ nextYear(): void; /** * Move to previous year */ previousYear(): void; /** * Clean up animation resources */ cleanup(): void; } export {}; //# sourceMappingURL=AnimationService.d.ts.map