energy-visualization-sankey 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +497 -0
- package/babel.config.cjs +28 -0
- package/coverage/clover.xml +6 -0
- package/coverage/coverage-final.json +1 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +101 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +0 -0
- package/demo-caching.js +68 -0
- package/dist/core/Sankey.d.ts +294 -0
- package/dist/core/Sankey.d.ts.map +1 -0
- package/dist/core/events/EventBus.d.ts +195 -0
- package/dist/core/events/EventBus.d.ts.map +1 -0
- package/dist/core/types/events.d.ts +42 -0
- package/dist/core/types/events.d.ts.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/sankey.esm.js +5212 -0
- package/dist/sankey.esm.js.map +1 -0
- package/dist/sankey.standalone.esm.js +9111 -0
- package/dist/sankey.standalone.esm.js.map +1 -0
- package/dist/sankey.standalone.min.js +2 -0
- package/dist/sankey.standalone.min.js.map +1 -0
- package/dist/sankey.standalone.umd.js +9119 -0
- package/dist/sankey.standalone.umd.js.map +1 -0
- package/dist/sankey.umd.js +5237 -0
- package/dist/sankey.umd.js.map +1 -0
- package/dist/sankey.umd.min.js +2 -0
- package/dist/sankey.umd.min.js.map +1 -0
- package/dist/services/AnimationService.d.ts +229 -0
- package/dist/services/AnimationService.d.ts.map +1 -0
- package/dist/services/ConfigurationService.d.ts +173 -0
- package/dist/services/ConfigurationService.d.ts.map +1 -0
- package/dist/services/InteractionService.d.ts +377 -0
- package/dist/services/InteractionService.d.ts.map +1 -0
- package/dist/services/RenderingService.d.ts +152 -0
- package/dist/services/RenderingService.d.ts.map +1 -0
- package/dist/services/calculation/GraphService.d.ts +111 -0
- package/dist/services/calculation/GraphService.d.ts.map +1 -0
- package/dist/services/calculation/SummaryService.d.ts +149 -0
- package/dist/services/calculation/SummaryService.d.ts.map +1 -0
- package/dist/services/data/DataService.d.ts +167 -0
- package/dist/services/data/DataService.d.ts.map +1 -0
- package/dist/services/data/DataValidationService.d.ts +48 -0
- package/dist/services/data/DataValidationService.d.ts.map +1 -0
- package/dist/types/index.d.ts +189 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/Logger.d.ts +88 -0
- package/dist/utils/Logger.d.ts.map +1 -0
- package/jest.config.cjs +20 -0
- package/package.json +68 -0
- package/rollup.config.js +131 -0
- package/scripts/performance-validation-real.js +411 -0
- package/scripts/validate-optimization.sh +147 -0
- package/scripts/visual-validation-real-data.js +374 -0
- package/src/core/Sankey.ts +1039 -0
- package/src/core/events/EventBus.ts +488 -0
- package/src/core/types/events.ts +80 -0
- package/src/index.ts +35 -0
- package/src/services/AnimationService.ts +983 -0
- package/src/services/ConfigurationService.ts +497 -0
- package/src/services/InteractionService.ts +920 -0
- package/src/services/RenderingService.ts +484 -0
- package/src/services/calculation/GraphService.ts +616 -0
- package/src/services/calculation/SummaryService.ts +394 -0
- package/src/services/data/DataService.ts +380 -0
- package/src/services/data/DataValidationService.ts +155 -0
- package/src/styles/controls.css +184 -0
- package/src/styles/sankey.css +211 -0
- package/src/types/index.ts +220 -0
- package/src/utils/Logger.ts +105 -0
- package/tests/numerical-validation.test.js +575 -0
- package/tests/setup.js +53 -0
- package/tsconfig.json +54 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { EventBus } from '@/core/events/EventBus';
|
|
2
|
+
import { DataService } from "@/services/data/DataService";
|
|
3
|
+
import { AnimationService } from "@/services/AnimationService";
|
|
4
|
+
import { Logger } from "@/utils/Logger";
|
|
5
|
+
type D3SVGSelection = d3.Selection<SVGSVGElement, unknown, HTMLElement, any>;
|
|
6
|
+
type D3DivSelection = d3.Selection<HTMLDivElement, unknown, HTMLElement, any>;
|
|
7
|
+
interface InteractionState {
|
|
8
|
+
isMouseDown: boolean;
|
|
9
|
+
lastMousePosition: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
};
|
|
13
|
+
selectedElement: Element | null;
|
|
14
|
+
isDragging: boolean;
|
|
15
|
+
touchStartTime: number;
|
|
16
|
+
keyboardShortcutsEnabled: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface InteractionHandlers {
|
|
19
|
+
onElementHover?: (element: Element, event: MouseEvent) => void;
|
|
20
|
+
onElementClick?: (element: Element, event: MouseEvent) => void;
|
|
21
|
+
onKeyboardNavigation?: (key: string, event: KeyboardEvent) => void;
|
|
22
|
+
onSliderInteraction?: (value: number, event: Event) => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Interaction Service - Advanced User Interface & Accessibility Management
|
|
26
|
+
*
|
|
27
|
+
* ARCHITECTURAL RESPONSIBILITY: Comprehensive User Interaction & Accessibility Framework
|
|
28
|
+
*
|
|
29
|
+
* This service implements sophisticated interaction patterns for multi-platform energy
|
|
30
|
+
* visualization, providing seamless mouse, touch, keyboard, and accessibility support.
|
|
31
|
+
* Ensures inclusive design principles and responsive user experience across all devices.
|
|
32
|
+
*
|
|
33
|
+
* ADVANCED INTERACTION PATTERNS:
|
|
34
|
+
* 1. **Multi-Modal Input**: Mouse, touch, and keyboard with context switching
|
|
35
|
+
* 2. **Event Delegation**: Efficient handling of dynamic SVG elements
|
|
36
|
+
* 3. **Accessibility Integration**: WCAG 2.1 compliance with screen reader support
|
|
37
|
+
* 4. **Cross-Platform Compatibility**: Desktop, tablet, and mobile optimization
|
|
38
|
+
* 5. **Performance Optimization**: Event debouncing and efficient listener management
|
|
39
|
+
* 6. **State Management**: Centralized interaction state for coordinated responses
|
|
40
|
+
*
|
|
41
|
+
* USER EXPERIENCE ARCHITECTURE:
|
|
42
|
+
* - **Mouse Interactions**: Precise hover, click, and drag operations
|
|
43
|
+
* - **Touch Interactions**: Gesture recognition with mobile-optimized responses
|
|
44
|
+
* - **Keyboard Navigation**: Full accessibility with arrow keys, space, enter
|
|
45
|
+
* - **Screen Reader Support**: ARIA labels and semantic markup integration
|
|
46
|
+
* - **Visual Feedback**: Immediate response to all user interactions
|
|
47
|
+
*
|
|
48
|
+
* ACCESSIBILITY FEATURES:
|
|
49
|
+
* - Keyboard-only navigation through all interactive elements
|
|
50
|
+
* - Screen reader compatibility with descriptive ARIA labels
|
|
51
|
+
* - High contrast support and focus management
|
|
52
|
+
* - Mobile accessibility with proper touch target sizing
|
|
53
|
+
* - Semantic HTML structure for assistive technologies
|
|
54
|
+
*
|
|
55
|
+
* EVENT-DRIVEN INTEGRATION:
|
|
56
|
+
* Communicates through event bus for loose coupling with other services,
|
|
57
|
+
* enabling coordinated responses without direct dependencies.
|
|
58
|
+
*/
|
|
59
|
+
export declare class InteractionService {
|
|
60
|
+
private animationControlService;
|
|
61
|
+
private dataService;
|
|
62
|
+
private eventBus;
|
|
63
|
+
private logger;
|
|
64
|
+
private state;
|
|
65
|
+
private handlers;
|
|
66
|
+
private eventListeners;
|
|
67
|
+
constructor(animationControlService: AnimationService, dataService: DataService, eventBus: EventBus, logger: Logger);
|
|
68
|
+
/**
|
|
69
|
+
* Initialize Comprehensive Multi-Platform User Interactions
|
|
70
|
+
*
|
|
71
|
+
* INITIALIZATION RESPONSIBILITY: Complete interaction system setup across all input modalities
|
|
72
|
+
*
|
|
73
|
+
* This method orchestrates the setup of all user interaction capabilities, creating
|
|
74
|
+
* a comprehensive interface layer that supports mouse, touch, keyboard, and accessibility
|
|
75
|
+
* interactions for the energy visualization.
|
|
76
|
+
*
|
|
77
|
+
* MULTI-MODAL INTERACTION INITIALIZATION:
|
|
78
|
+
* 1. **Mouse Interactions**: Hover effects, click handling, drag operations
|
|
79
|
+
* 2. **Touch Interactions**: Mobile gestures with responsive feedback
|
|
80
|
+
* 3. **Keyboard Navigation**: Full accessibility with arrow key navigation
|
|
81
|
+
* 4. **Slider Controls**: Timeline interaction with precise positioning
|
|
82
|
+
* 5. **Button Controls**: Play/pause and control button event handling
|
|
83
|
+
* 6. **Accessibility Features**: WCAG 2.1 compliance with screen reader support
|
|
84
|
+
*
|
|
85
|
+
* CROSS-PLATFORM COMPATIBILITY:
|
|
86
|
+
* Automatically detects device capabilities (touch support, keyboard availability)
|
|
87
|
+
* and adapts interaction patterns for optimal user experience on each platform.
|
|
88
|
+
*
|
|
89
|
+
* EVENT SYSTEM INTEGRATION:
|
|
90
|
+
* Broadcasts initialization completion to coordinate with other services,
|
|
91
|
+
* enabling system-wide awareness of interaction capability readiness.
|
|
92
|
+
*/
|
|
93
|
+
initializeInteractions(svg: D3SVGSelection, tooltip: D3DivSelection): void;
|
|
94
|
+
/**
|
|
95
|
+
* Set up mouse event handlers
|
|
96
|
+
* Provides hover effects, click handling, and drag support
|
|
97
|
+
*/
|
|
98
|
+
private setupMouseInteractions;
|
|
99
|
+
/**
|
|
100
|
+
* Set up touch event handlers
|
|
101
|
+
* Provides mobile-friendly touch interactions
|
|
102
|
+
*/
|
|
103
|
+
private setupTouchInteractions;
|
|
104
|
+
/**
|
|
105
|
+
* Enable keyboard navigation shortcuts
|
|
106
|
+
*
|
|
107
|
+
* **Accessibility Enhancement Responsibility:**
|
|
108
|
+
* - WCAG 2.1 AA compliance for keyboard navigation
|
|
109
|
+
* - Document-level keyboard event delegation
|
|
110
|
+
* - Form input safety (prevents interference)
|
|
111
|
+
* - Global shortcut system activation
|
|
112
|
+
*
|
|
113
|
+
* **Keyboard Navigation Architecture:**
|
|
114
|
+
* - Document Event Delegation: Single handler for all keyboard events
|
|
115
|
+
* - Input Safety: Excludes form fields from shortcut processing
|
|
116
|
+
* - State Management: Prevents duplicate handler registration
|
|
117
|
+
* - Event System Integration: Coordinates with EventBus
|
|
118
|
+
*
|
|
119
|
+
* **Performance Optimization:**
|
|
120
|
+
* - Single document listener (efficient delegation pattern)
|
|
121
|
+
* - Early return for duplicate activation
|
|
122
|
+
* - Form input filtering (performance + UX)
|
|
123
|
+
*
|
|
124
|
+
* **Accessibility Standards:**
|
|
125
|
+
* - Follows ARIA keyboard navigation patterns
|
|
126
|
+
* - Provides alternative to mouse interaction
|
|
127
|
+
* - Ensures consistent cross-platform behavior
|
|
128
|
+
*/
|
|
129
|
+
enableKeyboardNavigation(): void;
|
|
130
|
+
/**
|
|
131
|
+
* Disable keyboard navigation
|
|
132
|
+
*
|
|
133
|
+
* **Resource Management Responsibility:**
|
|
134
|
+
* - Graceful keyboard navigation shutdown
|
|
135
|
+
* - State cleanup coordination
|
|
136
|
+
* - Memory leak prevention (handlers cleaned by cleanup())
|
|
137
|
+
*
|
|
138
|
+
* **Accessibility Pattern:**
|
|
139
|
+
* - Allows dynamic keyboard navigation toggling
|
|
140
|
+
* - Maintains system state consistency
|
|
141
|
+
* - Prepares for service disposal
|
|
142
|
+
*/
|
|
143
|
+
disableKeyboardNavigation(): void;
|
|
144
|
+
/**
|
|
145
|
+
* Handle keyboard navigation events
|
|
146
|
+
*
|
|
147
|
+
* **Keyboard Shortcuts Responsibility:**
|
|
148
|
+
* - Comprehensive animation control via keyboard
|
|
149
|
+
* - Standard accessibility key mapping
|
|
150
|
+
* - Cross-platform keyboard compatibility
|
|
151
|
+
* - Event delegation and custom handler integration
|
|
152
|
+
*
|
|
153
|
+
* **Standard Keyboard Mappings (WCAG 2.1 AA):**
|
|
154
|
+
* - Space/Enter: Play/Pause toggle (standard media controls)
|
|
155
|
+
* - Arrow Left/Right: Year navigation (standard timeline controls)
|
|
156
|
+
* - Home/End: First/Last year navigation (standard list navigation)
|
|
157
|
+
* - Escape: Pause/Stop action (standard escape behavior)
|
|
158
|
+
*
|
|
159
|
+
* **Event-Driven Architecture Integration:**
|
|
160
|
+
* - Emits structured keyboard events to EventBus
|
|
161
|
+
* - Captures modifier keys (Ctrl, Shift, Alt) for advanced interactions
|
|
162
|
+
* - Integrates with AnimationService for timeline control
|
|
163
|
+
* - Supports custom keyboard handlers via callback pattern
|
|
164
|
+
*
|
|
165
|
+
* **Accessibility Design Principles:**
|
|
166
|
+
* - Follows operating system keyboard conventions
|
|
167
|
+
* - Provides equivalent functionality to mouse interactions
|
|
168
|
+
* - Preventable default behavior (event.preventDefault())
|
|
169
|
+
* - Comprehensive modifier key support for power users
|
|
170
|
+
*/
|
|
171
|
+
private handleKeyboardNavigation;
|
|
172
|
+
/**
|
|
173
|
+
* Set up slider interactions
|
|
174
|
+
*
|
|
175
|
+
* **Timeline Control Responsibility:**
|
|
176
|
+
* - Direct year selection via range slider
|
|
177
|
+
* - Real-time year value feedback
|
|
178
|
+
* - Smooth animation coordination
|
|
179
|
+
* - Event-driven timeline synchronization
|
|
180
|
+
*
|
|
181
|
+
* **User Control Patterns:**
|
|
182
|
+
* - HTML5 range input integration (native accessibility)
|
|
183
|
+
* - Continuous value updates (smooth interaction)
|
|
184
|
+
* - Animation service coordination (timeline sync)
|
|
185
|
+
* - Custom event emission (extensibility)
|
|
186
|
+
*
|
|
187
|
+
* **Accessibility Features:**
|
|
188
|
+
* - Native keyboard support (arrow keys, page up/down)
|
|
189
|
+
* - Screen reader compatibility (range slider semantics)
|
|
190
|
+
* - Touch-friendly interaction (mobile/tablet support)
|
|
191
|
+
* - Visual feedback during interaction
|
|
192
|
+
*
|
|
193
|
+
* **Performance Considerations:**
|
|
194
|
+
* - Direct DOM element access (cached reference)
|
|
195
|
+
* - Efficient value parsing (parseFloat optimization)
|
|
196
|
+
* - Event delegation pattern (single handler)
|
|
197
|
+
*/
|
|
198
|
+
private setupSliderInteractions;
|
|
199
|
+
/**
|
|
200
|
+
* Set up button interactions
|
|
201
|
+
*
|
|
202
|
+
* **Control Button Responsibility:**
|
|
203
|
+
* - Play/pause animation control
|
|
204
|
+
* - Speed adjustment controls
|
|
205
|
+
* - Animation state management
|
|
206
|
+
* - User feedback coordination
|
|
207
|
+
*
|
|
208
|
+
* **User Interface Patterns:**
|
|
209
|
+
* - Primary action button (play/pause toggle)
|
|
210
|
+
* - Secondary action buttons (speed controls)
|
|
211
|
+
* - Event delegation for button groups
|
|
212
|
+
* - State-aware button behavior
|
|
213
|
+
*
|
|
214
|
+
* **Accessibility Integration:**
|
|
215
|
+
* - Click event handling (mouse + keyboard activation)
|
|
216
|
+
* - Focus management (keyboard navigation)
|
|
217
|
+
* - Screen reader button semantics
|
|
218
|
+
* - Touch-friendly tap targets
|
|
219
|
+
*
|
|
220
|
+
* **Animation Control Architecture:**
|
|
221
|
+
* - Direct AnimationService integration
|
|
222
|
+
* - State synchronization (playing/paused)
|
|
223
|
+
* - Speed control coordination
|
|
224
|
+
* - Event emission for system coordination
|
|
225
|
+
*/
|
|
226
|
+
private setupButtonInteractions;
|
|
227
|
+
/**
|
|
228
|
+
* Set up accessibility features
|
|
229
|
+
*
|
|
230
|
+
* **WCAG 2.1 AA Compliance Responsibility:**
|
|
231
|
+
* - ARIA labels and semantic roles
|
|
232
|
+
* - Keyboard focus management
|
|
233
|
+
* - Screen reader support
|
|
234
|
+
* - Visual focus indicators
|
|
235
|
+
* - Interactive element accessibility
|
|
236
|
+
*
|
|
237
|
+
* **Accessibility Standards Implementation:**
|
|
238
|
+
* - SVG accessibility (role="img", aria-label)
|
|
239
|
+
* - Keyboard navigation (tabindex, focus/blur)
|
|
240
|
+
* - Control accessibility (slider, button roles)
|
|
241
|
+
* - Focus indicators (visual outline feedback)
|
|
242
|
+
* - Screen reader descriptions (meaningful labels)
|
|
243
|
+
*
|
|
244
|
+
* **Universal Design Principles:**
|
|
245
|
+
* - Perceivable: Visual focus indicators, semantic structure
|
|
246
|
+
* - Operable: Keyboard navigation, touch targets
|
|
247
|
+
* - Understandable: Clear labels, consistent behavior
|
|
248
|
+
* - Robust: Cross-platform compatibility, assistive technology support
|
|
249
|
+
*
|
|
250
|
+
* **Focus Management Architecture:**
|
|
251
|
+
* - Logical tab order (sequential navigation)
|
|
252
|
+
* - Visual focus indicators (CSS outline styling)
|
|
253
|
+
* - Focus trap prevention (proper event handling)
|
|
254
|
+
* - Screen reader announcements (ARIA integration)
|
|
255
|
+
*/
|
|
256
|
+
private setupAccessibilityFeatures;
|
|
257
|
+
/**
|
|
258
|
+
* Handle element hover events
|
|
259
|
+
*
|
|
260
|
+
* **Visual Feedback Responsibility:**
|
|
261
|
+
* - Interactive element highlighting
|
|
262
|
+
* - Hover state management
|
|
263
|
+
* - Multi-element coordination (exclusive hover)
|
|
264
|
+
* - Event-driven hover notifications
|
|
265
|
+
*
|
|
266
|
+
* **User Experience Patterns:**
|
|
267
|
+
* - Visual Affordance: Immediate hover feedback via CSS classes
|
|
268
|
+
* - Exclusive Interaction: Single element hover state (removes others)
|
|
269
|
+
* - Event Context: Rich hover event data (element type, fuel, sector)
|
|
270
|
+
* - Mouse Position: Coordinates for tooltip positioning
|
|
271
|
+
*
|
|
272
|
+
* **Interaction Architecture:**
|
|
273
|
+
* - CSS Class-Based Styling: .hovered class for visual feedback
|
|
274
|
+
* - Event Bus Integration: Structured hover events for system coordination
|
|
275
|
+
* - Custom Handler Support: Extensible hover behavior
|
|
276
|
+
* - Element Classification: Flow vs Box element detection
|
|
277
|
+
*
|
|
278
|
+
* **Performance Considerations:**
|
|
279
|
+
* - Efficient DOM querying (.hovered class removal)
|
|
280
|
+
* - Minimal DOM manipulation (add/remove classes)
|
|
281
|
+
* - Event data extraction (cached attribute access)
|
|
282
|
+
*/
|
|
283
|
+
private handleElementHover;
|
|
284
|
+
/**
|
|
285
|
+
* Handle element click events
|
|
286
|
+
*
|
|
287
|
+
* **Selection Management Responsibility:**
|
|
288
|
+
* - Element selection state management
|
|
289
|
+
* - Exclusive selection pattern (single selection)
|
|
290
|
+
* - Visual selection feedback
|
|
291
|
+
* - Event-driven selection notifications
|
|
292
|
+
*
|
|
293
|
+
* **User Interaction Patterns:**
|
|
294
|
+
* - Click-to-Select: Primary selection mechanism
|
|
295
|
+
* - Exclusive Selection: Single element selected at a time
|
|
296
|
+
* - Visual Feedback: .selected class for styling
|
|
297
|
+
* - Context Preservation: Rich click event data
|
|
298
|
+
*
|
|
299
|
+
* **State Management Architecture:**
|
|
300
|
+
* - CSS Class-Based Selection: .selected class for visual state
|
|
301
|
+
* - DOM State Management: Clear previous selections
|
|
302
|
+
* - Event Data Capture: Element type, fuel, sector, coordinates
|
|
303
|
+
* - Extensible Handler Support: Custom click behavior
|
|
304
|
+
*
|
|
305
|
+
* **Integration Benefits:**
|
|
306
|
+
* - Analytics Support: Click tracking and user behavior
|
|
307
|
+
* - Tooltip Coordination: Click-based detailed information display
|
|
308
|
+
* - Custom Behavior: Application-specific selection actions
|
|
309
|
+
*/
|
|
310
|
+
private handleElementClick;
|
|
311
|
+
/**
|
|
312
|
+
* Set custom interaction handlers
|
|
313
|
+
*/
|
|
314
|
+
setInteractionHandlers(handlers: InteractionHandlers): void;
|
|
315
|
+
/**
|
|
316
|
+
* Helper method to add event listener and track for cleanup
|
|
317
|
+
*/
|
|
318
|
+
private addEventListener;
|
|
319
|
+
/**
|
|
320
|
+
* Clean up all interactions and event listeners
|
|
321
|
+
*
|
|
322
|
+
* **Resource Management Responsibility:**
|
|
323
|
+
* - Complete memory cleanup and leak prevention
|
|
324
|
+
* - Event listener disposal
|
|
325
|
+
* - State reset and consistency
|
|
326
|
+
* - DOM class cleanup
|
|
327
|
+
*
|
|
328
|
+
* **Memory Management Architecture:**
|
|
329
|
+
* - Event Listener Cleanup: Remove all tracked listeners to prevent leaks
|
|
330
|
+
* - State Reset: Return to initial state for consistent disposal
|
|
331
|
+
* - Handler Clearing: Remove all custom handlers
|
|
332
|
+
* - DOM Cleanup: Remove visual state classes (.hovered, .selected)
|
|
333
|
+
*
|
|
334
|
+
* **Cleanup Pattern Benefits:**
|
|
335
|
+
* - Memory Leak Prevention: Proper event listener disposal
|
|
336
|
+
* - State Consistency: Clean slate for reinitialization
|
|
337
|
+
* - Resource Optimization: Free unused memory and references
|
|
338
|
+
* - Visual Cleanup: Remove transient UI states
|
|
339
|
+
*
|
|
340
|
+
* **Architecture Integration:**
|
|
341
|
+
* - Service Lifecycle: Proper service disposal pattern
|
|
342
|
+
* - Event-Driven Cleanup: Coordinated with other services
|
|
343
|
+
* - DOM State Management: Visual consistency maintenance
|
|
344
|
+
* - Performance Optimization: Resource deallocation
|
|
345
|
+
*/
|
|
346
|
+
cleanup(): void;
|
|
347
|
+
/**
|
|
348
|
+
* Get current interaction state
|
|
349
|
+
*/
|
|
350
|
+
getInteractionState(): Readonly<InteractionState>;
|
|
351
|
+
/**
|
|
352
|
+
* Check if interactions are enabled
|
|
353
|
+
*/
|
|
354
|
+
isInteractionEnabled(): boolean;
|
|
355
|
+
/**
|
|
356
|
+
* Get interaction statistics
|
|
357
|
+
*/
|
|
358
|
+
getInteractionStats(): {
|
|
359
|
+
eventListeners: number;
|
|
360
|
+
keyboardEnabled: boolean;
|
|
361
|
+
touchSupported: boolean;
|
|
362
|
+
lastInteraction: {
|
|
363
|
+
x: number;
|
|
364
|
+
y: number;
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* Programmatically trigger element hover
|
|
369
|
+
*/
|
|
370
|
+
triggerElementHover(element: Element): void;
|
|
371
|
+
/**
|
|
372
|
+
* Programmatically trigger element click
|
|
373
|
+
*/
|
|
374
|
+
triggerElementClick(element: Element): void;
|
|
375
|
+
}
|
|
376
|
+
export {};
|
|
377
|
+
//# sourceMappingURL=InteractionService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InteractionService.d.ts","sourceRoot":"","sources":["../../src/services/InteractionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAItC,KAAK,cAAc,GAAG,E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E,CAAC;KAC7C;IASD;;OAEG;IACI,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAWlD;;OAEG;IACI,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;CAUrD"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import * as d3 from 'd3';
|
|
2
|
+
import { GraphStroke, YearTotals } from '@/types';
|
|
3
|
+
import { EventBus } from '@/core/events/EventBus';
|
|
4
|
+
import { ConfigurationService } from '@/services/ConfigurationService';
|
|
5
|
+
import { SummaryService } from '@/services/calculation/SummaryService';
|
|
6
|
+
import { GraphService } from '@/services/calculation/GraphService';
|
|
7
|
+
import { DataService } from "@/services/data/DataService";
|
|
8
|
+
type D3SVGSelection = d3.Selection<SVGSVGElement, unknown, HTMLElement, any>;
|
|
9
|
+
type D3DivSelection = d3.Selection<HTMLDivElement, unknown, HTMLElement, any>;
|
|
10
|
+
/**
|
|
11
|
+
* Chart Rendering Service - D3.js SVG Generation & Visual Rendering Engine
|
|
12
|
+
*
|
|
13
|
+
* ARCHITECTURAL RESPONSIBILITY: Mathematical Data → Visual SVG Transformation
|
|
14
|
+
*
|
|
15
|
+
* This service implements sophisticated D3.js patterns to transform mathematical energy flow
|
|
16
|
+
* calculations into interactive SVG visualizations. It manages the complete visual rendering
|
|
17
|
+
* pipeline from raw data to user-ready interactive charts.
|
|
18
|
+
*
|
|
19
|
+
* D3.JS DESIGN PATTERNS IMPLEMENTED:
|
|
20
|
+
* 1. **Selection Patterns**: Efficient DOM element selection and manipulation
|
|
21
|
+
* 2. **Data Binding**: Binding energy data to SVG elements with enter/update/exit patterns
|
|
22
|
+
* 3. **Method Chaining**: Fluent D3 API usage for concise and readable code
|
|
23
|
+
* 4. **Event Handling**: Mouse interactions with tooltip integration
|
|
24
|
+
* 5. **Transition Management**: Smooth animations for year-to-year transitions
|
|
25
|
+
* 6. **Scale Management**: Coordinate transformations and responsive scaling
|
|
26
|
+
*
|
|
27
|
+
* SVG GENERATION ARCHITECTURE:
|
|
28
|
+
* - **Fuel Boxes**: Left column showing energy sources (solar, coal, etc.)
|
|
29
|
+
* - **Sector Boxes**: Right column showing consumption sectors (residential, industrial, etc.)
|
|
30
|
+
* - **Flow Paths**: connecting fuel sources to consumption sectors
|
|
31
|
+
* - **Labels & Text**: Dynamic text elements with data-driven content
|
|
32
|
+
* - **Tooltips**: Interactive information overlays with precise positioning
|
|
33
|
+
*
|
|
34
|
+
* VISUAL RENDERING PIPELINE:
|
|
35
|
+
* Mathematical Data → D3 Selections → SVG Elements → Interactive Features → User Interface
|
|
36
|
+
*
|
|
37
|
+
* PERFORMANCE OPTIMIZATIONS:
|
|
38
|
+
* - Efficient DOM manipulation using D3 selections
|
|
39
|
+
* - Minimal DOM re-creation during year transitions
|
|
40
|
+
* - Event delegation for tooltip management
|
|
41
|
+
* - CSS class-based styling for performance
|
|
42
|
+
* - Cached line generator for path creation
|
|
43
|
+
*/
|
|
44
|
+
export declare class RenderingService {
|
|
45
|
+
private configService;
|
|
46
|
+
private summaryCalculationService;
|
|
47
|
+
private graphCalculationService;
|
|
48
|
+
private dataService;
|
|
49
|
+
private eventBus;
|
|
50
|
+
private lineGenerator;
|
|
51
|
+
constructor(configService: ConfigurationService, summaryCalculationService: SummaryService, graphCalculationService: GraphService, dataService: DataService, eventBus: EventBus);
|
|
52
|
+
/**
|
|
53
|
+
* Draws the main title, subtitle, and affiliations in separate title container
|
|
54
|
+
*/
|
|
55
|
+
drawHeader(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Draw Fuel Source Labels - Left Column Energy Source Visualization
|
|
58
|
+
*
|
|
59
|
+
* RENDERING RESPONSIBILITY: Create dynamic fuel source labels with proportional positioning
|
|
60
|
+
*
|
|
61
|
+
* This method implements D3.js text element creation for fuel source identification.
|
|
62
|
+
* Label positions are calculated dynamically based on energy totals to maintain
|
|
63
|
+
* accurate visual alignment with proportional fuel box heights.
|
|
64
|
+
*
|
|
65
|
+
* D3.JS TEXT RENDERING PATTERNS:
|
|
66
|
+
* - Dynamic content from configuration and energy data
|
|
67
|
+
* - Conditional visibility based on energy values (hidden if zero)
|
|
68
|
+
* - Data attributes for animation and programmatic access
|
|
69
|
+
* - CSS classes for styling and state management
|
|
70
|
+
*
|
|
71
|
+
* PROPORTIONAL POSITIONING ALGORITHM:
|
|
72
|
+
* Y-position calculated dynamically: TOP_Y + cumulative_energy_heights + gaps
|
|
73
|
+
* Ensures perfect alignment between fuel labels and their corresponding flow origins
|
|
74
|
+
*/
|
|
75
|
+
drawLeftLabels(svg: D3SVGSelection, totals: YearTotals): void;
|
|
76
|
+
/**
|
|
77
|
+
* Draw Energy Sector Boxes & Labels - Right Column Consumption Visualization
|
|
78
|
+
*
|
|
79
|
+
* RENDERING RESPONSIBILITY: Create interactive sector boxes with labels and totals
|
|
80
|
+
*
|
|
81
|
+
* This method implements the most complex D3.js element creation patterns, generating
|
|
82
|
+
* rectangular sector boxes with multi-line labels and dynamic energy totals.
|
|
83
|
+
* Demonstrates advanced SVG composition with nested text elements.
|
|
84
|
+
*
|
|
85
|
+
* ADVANCED D3.JS PATTERNS DEMONSTRATED:
|
|
86
|
+
* 1. **Conditional Positioning**: Different algorithms for electricity vs. sector boxes
|
|
87
|
+
* 2. **Complex Text Composition**: Multi-line labels using tspan elements
|
|
88
|
+
* 3. **Dynamic Sizing**: Proportional box heights based on energy consumption
|
|
89
|
+
* 4. **Data-Driven Visibility**: Conditional hiding based on energy values
|
|
90
|
+
* 5. **Nested Element Creation**: Text elements with multiple tspan children
|
|
91
|
+
* 6. **Special Case Handling**: Residential/Commercial label splitting
|
|
92
|
+
*
|
|
93
|
+
* SVG ELEMENT ARCHITECTURE:
|
|
94
|
+
* Each sector generates: Rectangle (visual box) + Text (label + total + waste)
|
|
95
|
+
* - Rectangle: Proportionally sized based on energy consumption
|
|
96
|
+
* - Text Label: Human-readable sector name with special formatting
|
|
97
|
+
* - Energy Total: Numeric display of energy consumption value
|
|
98
|
+
* - Waste Total: Thermodynamic losses for electricity-consuming sectors
|
|
99
|
+
*/
|
|
100
|
+
drawBoxes(svg: D3SVGSelection, totals: YearTotals): void;
|
|
101
|
+
/**
|
|
102
|
+
* Draw Interactive Energy Flow Paths - Advanced D3.js SVG Path Rendering
|
|
103
|
+
*
|
|
104
|
+
* RENDERING RESPONSIBILITY: Transform Mathematical Flow Data → Interactive SVG Paths
|
|
105
|
+
*
|
|
106
|
+
* This method implements the most sophisticated D3.js rendering patterns in the entire
|
|
107
|
+
* visualization system, creating interactive paths that represent energy
|
|
108
|
+
* flows between fuel sources and consumption sectors.
|
|
109
|
+
*
|
|
110
|
+
* ADVANCED D3.JS PATTERNS IMPLEMENTED:
|
|
111
|
+
* 1. **Complex Path Generation**: Mathematical GraphStroke data → SVG path strings
|
|
112
|
+
* 2. **Interactive Event Binding**: Mouse event handlers for tooltip interactions
|
|
113
|
+
* 3. **Dynamic Content Creation**: Data-driven SVG element creation with unique attributes
|
|
114
|
+
* 4. **Transition Management**: Smooth fade-in/fade-out tooltip animations
|
|
115
|
+
* 5. **Context-Aware Selection**: Targeting existing fuel group containers
|
|
116
|
+
* 6. **Performance Optimization**: Efficient DOM manipulation and event delegation
|
|
117
|
+
*
|
|
118
|
+
* ENERGY FLOW VISUALIZATION ARCHITECTURE:
|
|
119
|
+
* Each energy flow (Fuel → Sector) becomes an SVG <path> element with:
|
|
120
|
+
* - Geometry calculated by GraphService
|
|
121
|
+
* - Stroke width proportional to energy quantity (visual data encoding)
|
|
122
|
+
* - Interactive tooltip showing detailed energy values on hover
|
|
123
|
+
* - CSS classes enabling styling and animation hooks
|
|
124
|
+
* - Data attributes for programmatic access and filtering
|
|
125
|
+
*
|
|
126
|
+
* TOOLTIP INTERACTION DESIGN:
|
|
127
|
+
* - Mouseover: 200ms fade-in with energy flow details
|
|
128
|
+
* - Mouseout: 500ms fade-out for smooth visual transitions
|
|
129
|
+
* - Dynamic positioning: Follows cursor with offset for readability
|
|
130
|
+
* - Content formatting: "Fuel → Sector" with numerical energy value
|
|
131
|
+
*
|
|
132
|
+
* SVG PATH GENERATION PIPELINE:
|
|
133
|
+
* Mathematical Coordinates → parseLineData() → SVG Path String → Interactive Path Element
|
|
134
|
+
*/
|
|
135
|
+
drawFlows(svg: D3SVGSelection, yearIndex: number, tooltip: D3DivSelection): void;
|
|
136
|
+
/**
|
|
137
|
+
* Clear chart content
|
|
138
|
+
*/
|
|
139
|
+
clearChart(svg: D3SVGSelection): void;
|
|
140
|
+
drawInitialChart(svg: D3SVGSelection, tooltip: D3DivSelection): boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Highlight specific fuel flows
|
|
143
|
+
*/
|
|
144
|
+
highlightFuel(svg: D3SVGSelection, fuelName: string): void;
|
|
145
|
+
/**
|
|
146
|
+
* Reset highlighting
|
|
147
|
+
*/
|
|
148
|
+
resetHighlight(svg: D3SVGSelection): void;
|
|
149
|
+
parseLineData(stroke: GraphStroke): string;
|
|
150
|
+
}
|
|
151
|
+
export {};
|
|
152
|
+
//# sourceMappingURL=RenderingService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderingService.d.ts","sourceRoot":"","sources":["../../src/services/RenderingService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAa,WAAW,EAAE,UAAU,EAAC,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAC,oBAAoB,EAAC,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAC,cAAc,EAAC,MAAM,uCAAuC,CAAC;AACrE,OAAO,EAAC,YAAY,EAAC,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AAIxD,KAAK,cAAc,GAAG,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC;AAC7E,KAAK,cAAc,GAA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1
|
+
import * as d3 from 'd3';
|
|
2
|
+
import { GraphData, GraphPoint } from '@/types';
|
|
3
|
+
import { DataService } from "@/services/data/DataService";
|
|
4
|
+
import { ConfigurationService } from "@/services/ConfigurationService";
|
|
5
|
+
import { SummaryService } from "@/services/calculation/SummaryService";
|
|
6
|
+
/**
|
|
7
|
+
* Graph Service
|
|
8
|
+
*
|
|
9
|
+
* Performs complex mathematical calculations for energy flow positioning and routing.
|
|
10
|
+
* Handles the sophisticated algorithms needed to calculate Sankey diagram paths,
|
|
11
|
+
* including triple nested loops for flow positioning and waste heat calculations.
|
|
12
|
+
*
|
|
13
|
+
* Key Algorithms:
|
|
14
|
+
* - Complex flow positioning with mathematical precision
|
|
15
|
+
* - Waste heat cloning and distribution calculations
|
|
16
|
+
* - Multi-layer caching system for performance optimization
|
|
17
|
+
* - D3 line generation for smooth rendering
|
|
18
|
+
* - Graph data structure management and optimization
|
|
19
|
+
*/
|
|
20
|
+
export declare class GraphService {
|
|
21
|
+
private configService;
|
|
22
|
+
private dataService;
|
|
23
|
+
private summaryCalculationService;
|
|
24
|
+
graphs: GraphData[];
|
|
25
|
+
constructor(configService: ConfigurationService, // Will inject when available
|
|
26
|
+
dataService: DataService, summaryCalculationService: SummaryService);
|
|
27
|
+
/**
|
|
28
|
+
* Extract expensive calculation to separate method (same logic as original)
|
|
29
|
+
*/
|
|
30
|
+
private buildGraphs;
|
|
31
|
+
/**
|
|
32
|
+
* Calculate Flow Y-Coordinates - Complex Triple Nested Loop Algorithm
|
|
33
|
+
*
|
|
34
|
+
* COMPUTATIONAL COMPLEXITY: O(n³) - Years × Fuels × Sectors
|
|
35
|
+
* This is the most mathematically sophisticated method in the entire energy visualization system,
|
|
36
|
+
* handling precise flow positioning, coordinate calculations, and waste heat thermodynamics.
|
|
37
|
+
*
|
|
38
|
+
* ALGORITHM STRUCTURE - THREE NESTED LEVELS:
|
|
39
|
+
*
|
|
40
|
+
* Level 1 (i): Years Loop - Process each chronological data point
|
|
41
|
+
* └─ Creates GraphStroke arrays for energy flow paths
|
|
42
|
+
* └─ Manages vertical offset tracking for precise positioning
|
|
43
|
+
*
|
|
44
|
+
* Level 2 (j): Fuels Loop - Process each energy source type
|
|
45
|
+
* └─ Special handling for electricity (j=0) vs. primary fuels (j>0)
|
|
46
|
+
* └─ Calculates fuel-specific positioning and offsets
|
|
47
|
+
*
|
|
48
|
+
* Level 3 (k): Sectors Loop - Process each consumption category
|
|
49
|
+
* └─ Creates GraphStroke objects for each Fuel → Sector flow
|
|
50
|
+
* └─ Applies complex coordinate mathematics for positioning
|
|
51
|
+
*
|
|
52
|
+
* CRITICAL COORDINATE MATHEMATICS:
|
|
53
|
+
* 1. Y-Coordinate Positioning: Uses cumulative offset tracking
|
|
54
|
+
* 2. Stroke Width Calculation: Energy value × SCALE factor
|
|
55
|
+
* 3. Control Points: mathematics for smooth flow
|
|
56
|
+
* 4. Waste Heat Cloning: Deep object cloning with thermodynamic calculations
|
|
57
|
+
*
|
|
58
|
+
* WASTE HEAT PHYSICS IMPLEMENTATION:
|
|
59
|
+
* Implements the fundamental thermodynamic principle that electricity generation
|
|
60
|
+
* produces waste heat according to Carnot efficiency limits. Each electricity
|
|
61
|
+
* flow gets a corresponding waste heat flow with identical path geometry.
|
|
62
|
+
*
|
|
63
|
+
* COORDINATE SYSTEM DETAILS:
|
|
64
|
+
* - SCALE (0.02): Converts energy units (Quads) to pixel heights
|
|
65
|
+
* - ELEC_BOX coordinates: Special positioning for electricity flows
|
|
66
|
+
* - SR3: Slope ratio for smooth transitions (slope = height/3)
|
|
67
|
+
* - PATH_GAP: Visual spacing between parallel flow paths
|
|
68
|
+
* - LEFT_GAP: Spacing between fuel source boxes
|
|
69
|
+
*
|
|
70
|
+
* PERFORMANCE OPTIMIZATIONS:
|
|
71
|
+
* - Method inlining: Configuration constants cached locally
|
|
72
|
+
* - Direct array indexing: Eliminates object property lookups
|
|
73
|
+
* - In-place calculations: Minimizes temporary object creation
|
|
74
|
+
*
|
|
75
|
+
* MATHEMATICAL PRECISION REQUIREMENTS:
|
|
76
|
+
* All calculations must maintain sub-pixel precision to ensure:
|
|
77
|
+
* - Smooth flow animations during year transitions
|
|
78
|
+
* - Perfect alignment between interconnected flows
|
|
79
|
+
* - Accurate proportional representation of energy values
|
|
80
|
+
* - Thermodynamically correct waste heat positioning
|
|
81
|
+
*/
|
|
82
|
+
calculateGraphY(): void;
|
|
83
|
+
calculateGraphX(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Method Inlined calculateGraphXUps() - eliminates repeated property access
|
|
86
|
+
*/
|
|
87
|
+
private calculateGraphXUps;
|
|
88
|
+
/**
|
|
89
|
+
* Method Inlined calculateGraphXDowns() - eliminates repeated property access
|
|
90
|
+
*/
|
|
91
|
+
private calculateGraphXDowns;
|
|
92
|
+
/**
|
|
93
|
+
* Method Inlined spaceUpsAndDowns() - eliminates repeated property access
|
|
94
|
+
*/
|
|
95
|
+
spaceUpsAndDowns(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Waste heat processing
|
|
98
|
+
*/
|
|
99
|
+
processWasteHeatFlows(): void;
|
|
100
|
+
/**
|
|
101
|
+
* Method Inlined sortGraphUp() - eliminates repeated array access
|
|
102
|
+
*/
|
|
103
|
+
private sortGraphUp;
|
|
104
|
+
/**
|
|
105
|
+
* Method Inlined sortGraphDown() - eliminates repeated array access
|
|
106
|
+
*/
|
|
107
|
+
private sortGraphDown;
|
|
108
|
+
sigfig2(n: number | string | undefined | null): number;
|
|
109
|
+
createLine(): d3.Line<GraphPoint>;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=GraphService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphService.d.ts","sourceRoot":"","sources":["../../../src/services/calculation/GraphService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAwB,SAAS,EAAE,UAAU,EAAsB,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,oBAAoB,EAAC,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAC,cAAc,EAAC,MAAM,uCAAuC,CAAC;AAGrE;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAY;IAIjB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,yBAAyB;IAL9B,MAAM,EAAE,SAAS,EAAE,CAAM;gBAGpB,aAAa,EAAE,oBAAoB,EAAE,6BAA6B;IAClE,WAAW,EAAE,WAAW,EACxB,yBAAyB,EAAE,cAAc;IAKrD;;OAEG;IACH,OAAO,CAAC,WAAW;IAcnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkDG;IACI,eAAe;IAmRf,eAAe;IAMtB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA8B1B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IA8B5B;;OAEG;IACI,gBAAgB;IA8CvB;;OAEG;IACI,qBAAqB;IA8B5B;;OAEG;IACH,OAAO,CAAC,WAAW;IAoBnB;;OAEG;IACH,OAAO,CAAC,aAAa;IAoBd,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM;IA+BtD,UAAU,IAAI,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC;CAS3C"}
|