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,229 @@
|
|
|
1
|
+
import * as d3 from 'd3';
|
|
2
|
+
import { GraphData, SankeyOptions } from '@/types';
|
|
3
|
+
import { EventBus } from '@/core/events/EventBus';
|
|
4
|
+
import { SummaryService } from '@/services/calculation/SummaryService';
|
|
5
|
+
import { GraphService } from '@/services/calculation/GraphService';
|
|
6
|
+
import { Logger } from "@/utils/Logger";
|
|
7
|
+
import { DataService } from "@/services/data/DataService";
|
|
8
|
+
import { ConfigurationService } from "@/services/ConfigurationService";
|
|
9
|
+
type D3SVGSelection = d3.Selection<SVGSVGElement, unknown, HTMLElement, any>;
|
|
10
|
+
type D3DivSelection = d3.Selection<HTMLDivElement, unknown, HTMLElement, any>;
|
|
11
|
+
export interface GraphNest {
|
|
12
|
+
strokes: {
|
|
13
|
+
[year: number]: {
|
|
14
|
+
[fuel: string]: {
|
|
15
|
+
[sector: string]: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
tops: {
|
|
20
|
+
[year: number]: {
|
|
21
|
+
[fuel: string]: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
heights: {
|
|
25
|
+
[year: number]: {
|
|
26
|
+
[sector: string]: number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
waste: {
|
|
30
|
+
[year: number]: {
|
|
31
|
+
[sector: string]: number;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Animation Control Service - Advanced Timeline Management & Smooth Transitions
|
|
37
|
+
*
|
|
38
|
+
* ARCHITECTURAL RESPONSIBILITY: Temporal Visualization Control & User Interaction
|
|
39
|
+
*
|
|
40
|
+
* This service implements sophisticated animation control patterns for temporal energy
|
|
41
|
+
* visualizations, managing smooth year-to-year transitions, timeline navigation,
|
|
42
|
+
* milestone events, and user interaction with historical energy data.
|
|
43
|
+
*
|
|
44
|
+
* TEMPORAL VISUALIZATION PATTERNS:
|
|
45
|
+
* 1. **Timeline Navigation**: Seamless movement through 200+ years of energy history
|
|
46
|
+
* 2. **State Management**: Centralized animation state with event-driven updates
|
|
47
|
+
* 3. **Smooth Transitions**: D3.js-powered animations with configurable timing
|
|
48
|
+
* 4. **Milestone Integration**: Interactive historical event markers and dialogs
|
|
49
|
+
* 5. **User Controls**: Play/pause/seek controls with keyboard accessibility
|
|
50
|
+
* 6. **Loop Management**: Configurable animation looping for presentations
|
|
51
|
+
*
|
|
52
|
+
* ANIMATION ARCHITECTURE:
|
|
53
|
+
* - **Timeline State**: Current year, animation status, timing controls
|
|
54
|
+
* - **Transition Management**: Smooth interpolation between energy data years
|
|
55
|
+
* - **Interactive Controls**: Slider, buttons, and keyboard input handling
|
|
56
|
+
* - **Milestone System**: Historical event markers with contextual information
|
|
57
|
+
* - **Performance Optimization**: Efficient DOM updates and animation scheduling
|
|
58
|
+
*
|
|
59
|
+
* USER INTERACTION DESIGN:
|
|
60
|
+
* - Intuitive timeline slider with year selection
|
|
61
|
+
* - Responsive play/pause controls
|
|
62
|
+
* - Keyboard navigation (arrow keys, space bar)
|
|
63
|
+
* - Milestone hover/click interactions
|
|
64
|
+
* - Configurable playback speed controls
|
|
65
|
+
*
|
|
66
|
+
* EVENT-DRIVEN INTEGRATION:
|
|
67
|
+
* Communicates with other services via event bus for coordinated visual updates,
|
|
68
|
+
* ensuring synchronized animation across all visualization components.
|
|
69
|
+
*/
|
|
70
|
+
export declare class AnimationService {
|
|
71
|
+
private configService;
|
|
72
|
+
private summaryCalculationService;
|
|
73
|
+
private graphCalculationService;
|
|
74
|
+
private dataService;
|
|
75
|
+
private options;
|
|
76
|
+
private eventBus;
|
|
77
|
+
private logger;
|
|
78
|
+
private state;
|
|
79
|
+
private svg;
|
|
80
|
+
private tooltip;
|
|
81
|
+
private graphs;
|
|
82
|
+
private graphNest;
|
|
83
|
+
private sliderWidth;
|
|
84
|
+
constructor(configService: ConfigurationService, summaryCalculationService: SummaryService, graphCalculationService: GraphService, dataService: DataService, options: SankeyOptions, eventBus: EventBus, logger: Logger);
|
|
85
|
+
/**
|
|
86
|
+
* Receives pre-built data structures and sets up animation system
|
|
87
|
+
*/
|
|
88
|
+
setupAnimation(graphs: GraphData[], graphNest: GraphNest, svg: D3SVGSelection, tooltip: D3DivSelection): void;
|
|
89
|
+
/**
|
|
90
|
+
* Sets up slider, year labels, tick marks, and milestone interactions
|
|
91
|
+
*/
|
|
92
|
+
private setupTimelineControls;
|
|
93
|
+
/**
|
|
94
|
+
* Creates milestone markers and dialog interactions
|
|
95
|
+
*/
|
|
96
|
+
private setupMilestones;
|
|
97
|
+
/**
|
|
98
|
+
* Handles milestone dot clicks and dialog positioning
|
|
99
|
+
*/
|
|
100
|
+
private setupMilestoneDialogs;
|
|
101
|
+
/**
|
|
102
|
+
* Creates dialog element with same styling and behavior
|
|
103
|
+
*/
|
|
104
|
+
private createMilestoneDialog;
|
|
105
|
+
/**
|
|
106
|
+
* Set up play/pause button controls
|
|
107
|
+
*/
|
|
108
|
+
private setupPlayControls;
|
|
109
|
+
/**
|
|
110
|
+
* Set up year display element
|
|
111
|
+
*/
|
|
112
|
+
private setupYearDisplay;
|
|
113
|
+
/**
|
|
114
|
+
* Set Year - Programmatic Timeline Navigation with Coordinated Updates
|
|
115
|
+
*
|
|
116
|
+
* NAVIGATION RESPONSIBILITY: Move visualization to specific year with system-wide coordination
|
|
117
|
+
*
|
|
118
|
+
* This method implements the core temporal navigation functionality, orchestrating
|
|
119
|
+
* synchronized updates across all visualization components when changing years.
|
|
120
|
+
* Essential for both user interaction (slider) and programmatic control (API).
|
|
121
|
+
*
|
|
122
|
+
* COORDINATED UPDATE SEQUENCE:
|
|
123
|
+
* 1. **State Validation**: Verify target year exists in available data
|
|
124
|
+
* 2. **State Update**: Update internal animation state to new year
|
|
125
|
+
* 3. **UI Synchronization**: Update slider position to reflect state
|
|
126
|
+
* 4. **Visualization Update**: Trigger complex chart transition animations
|
|
127
|
+
* 5. **Visual Indicators**: Update timeline position indicators
|
|
128
|
+
* 6. **Display Update**: Update year text display elements
|
|
129
|
+
* 7. **Event Broadcasting**: Notify other services of year change
|
|
130
|
+
*
|
|
131
|
+
* ANIMATION INTEGRATION:
|
|
132
|
+
* Seamlessly integrates with animation playback - can be called during
|
|
133
|
+
* active animation for smooth seeking or by user interaction for direct navigation.
|
|
134
|
+
*
|
|
135
|
+
* PERFORMANCE CONSIDERATIONS:
|
|
136
|
+
* Efficiently updates only necessary DOM elements and triggers minimal
|
|
137
|
+
* re-calculations by leveraging pre-computed mathematical data structures.
|
|
138
|
+
*/
|
|
139
|
+
setYear(year: number): void;
|
|
140
|
+
/**
|
|
141
|
+
* Handles the complex animation transitions between years
|
|
142
|
+
*/
|
|
143
|
+
private animatePeriod;
|
|
144
|
+
/**
|
|
145
|
+
* Updates the position and content of the year indicator above the slider
|
|
146
|
+
*/
|
|
147
|
+
private updateSliderIndicator;
|
|
148
|
+
private calculateIndicatorPosition;
|
|
149
|
+
private applyIndicatorPosition;
|
|
150
|
+
private updateYearDisplay;
|
|
151
|
+
/**
|
|
152
|
+
* Start Animation Playback - Temporal Visualization Timeline Control
|
|
153
|
+
*
|
|
154
|
+
* PLAYBACK RESPONSIBILITY: Initiate automated year-by-year progression through energy data
|
|
155
|
+
*
|
|
156
|
+
* This method starts the animation loop that automatically advances through years
|
|
157
|
+
* of energy data, creating a cinematic progression through US energy history.
|
|
158
|
+
* Essential for presentation mode and automated demonstration of energy trends.
|
|
159
|
+
*
|
|
160
|
+
* ANIMATION LIFECYCLE MANAGEMENT:
|
|
161
|
+
* 1. **Guard Clause**: Prevent multiple simultaneous animations
|
|
162
|
+
* 2. **State Update**: Set animation flag for system-wide coordination
|
|
163
|
+
* 3. **UI Update**: Change play button to pause state for user feedback
|
|
164
|
+
* 4. **Timer Initialization**: Start interval-based animation loop
|
|
165
|
+
* 5. **Event Broadcasting**: Notify other services animation has started
|
|
166
|
+
*
|
|
167
|
+
* TIMING MECHANISM:
|
|
168
|
+
* Uses JavaScript setInterval() for consistent frame timing at configured speed.
|
|
169
|
+
* Timer interval determined by this.state.speed (milliseconds between years).
|
|
170
|
+
* Each timer tick calls nextFrame() for year progression logic.
|
|
171
|
+
*
|
|
172
|
+
* USER INTERACTION INTEGRATION:
|
|
173
|
+
* Updates visual play button state to indicate animation status,
|
|
174
|
+
* providing immediate visual feedback for user understanding.
|
|
175
|
+
*/
|
|
176
|
+
play(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Pause Animation Playback - Temporal Visualization Control
|
|
179
|
+
*
|
|
180
|
+
* PAUSE RESPONSIBILITY: Stop automated timeline progression while preserving current position
|
|
181
|
+
*
|
|
182
|
+
* This method halts the animation loop while maintaining the current year position,
|
|
183
|
+
* enabling users to pause for detailed examination of specific time periods.
|
|
184
|
+
* Critical for interactive exploration and presentation control.
|
|
185
|
+
*
|
|
186
|
+
* PAUSE LIFECYCLE MANAGEMENT:
|
|
187
|
+
* 1. **Guard Clause**: Ensure animation is actually running before stopping
|
|
188
|
+
* 2. **State Update**: Clear animation flag for system coordination
|
|
189
|
+
* 3. **UI Update**: Restore play button state for user interface consistency
|
|
190
|
+
* 4. **Timer Cleanup**: Properly clear interval timer to prevent memory leaks
|
|
191
|
+
* 5. **Event Broadcasting**: Notify other services animation has stopped
|
|
192
|
+
*
|
|
193
|
+
* RESOURCE MANAGEMENT:
|
|
194
|
+
* Properly clears JavaScript interval timer to prevent continued execution
|
|
195
|
+
* and potential memory leaks during long-running visualization sessions.
|
|
196
|
+
*/
|
|
197
|
+
pause(): void;
|
|
198
|
+
/**
|
|
199
|
+
* Move to next frame in animation
|
|
200
|
+
* Stop at end instead of looping
|
|
201
|
+
*/
|
|
202
|
+
private nextFrame;
|
|
203
|
+
/**
|
|
204
|
+
* Set animation speed AnimationService.setSpeed()
|
|
205
|
+
*/
|
|
206
|
+
setSpeed(speed: number): void;
|
|
207
|
+
/**
|
|
208
|
+
* Check if animation is currently playing
|
|
209
|
+
*/
|
|
210
|
+
isPlaying(): boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Get current year
|
|
213
|
+
*/
|
|
214
|
+
getCurrentYear(): number;
|
|
215
|
+
/**
|
|
216
|
+
* Move to next year
|
|
217
|
+
*/
|
|
218
|
+
nextYear(): void;
|
|
219
|
+
/**
|
|
220
|
+
* Move to previous year
|
|
221
|
+
*/
|
|
222
|
+
previousYear(): void;
|
|
223
|
+
/**
|
|
224
|
+
* Clean up animation resources
|
|
225
|
+
*/
|
|
226
|
+
cleanup(): void;
|
|
227
|
+
}
|
|
228
|
+
export {};
|
|
229
|
+
//# sourceMappingURL=AnimationService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimationService.d.ts","sourceRoot":"","sources":["../../src/services/AnimationService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAC,SAAS,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AACjD,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAC,cAAc,EAAC,MAAM,uCAAuC,CAAC;AACrE,OAAO,EAAC,YAAY,EAAC,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,oBAAoB,EAAC,MAAM,iCAAiC,CAAC;AAIrE,KAAK,cAAc,GAAG,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC;AAC7E,KAAK,cAAc,GAAG,EAAE,CAAC,SAAS,CAAC,cAAc,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC;AAW9E,MAAM,WAAW,SAAS;IACtB,OAAO,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG;YAAE,CAAC,IAAI,EAAE,MAAM,GAAG;gBAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAC;IAC9E,IAAI,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG;YAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IACrD,OAAO,EAAE;QAAE,CAAC,IAAI,E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B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IA2ClC;;OAEG;IACH,OAAO,CAAC,aAAa;IAyLrB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAkB7B,OAAO,CAAC,0BAA0B;IAkBlC,OAAO,CAAC,sBAAsB;IAW9B,OAAO,CAAC,iBAAiB;IASzB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACI,IAAI,IAAI,IAAI;IAkCnB;;;;;;;;;;;;;;;;;;;OAmBG;IACI,KAAK,IAAI,IAAI;IAkCpB;;;OAGG;IACH,OAAO,CAAC,SAAS;IAejB;;OAEG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IA4BpC;;OAEG;IACI,SAAS,IAAI,OAAO;IAI3B;;OAEG;IACI,cAAc,IAAI,MAAM;IAI/B;;OAEG;IACI,QAAQ,IAAI,IAAI;IAOvB;;OAEG;IACI,YAAY,IAAI,IAAI;IAO3B;;OAEG;IACI,OAAO,IAAI,IAAI;CAazB"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { SankeyOptions } from '@/types';
|
|
2
|
+
import { EventBus } from "@/core/events/EventBus";
|
|
3
|
+
import { Logger } from "@/utils/Logger";
|
|
4
|
+
/**
|
|
5
|
+
* Fuel configuration interface
|
|
6
|
+
*/
|
|
7
|
+
export interface FuelConfig {
|
|
8
|
+
readonly fuel: string;
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly color: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Sector/Box configuration interface
|
|
14
|
+
*/
|
|
15
|
+
export interface BoxConfig {
|
|
16
|
+
readonly box: string;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly color: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Configuration Service - Mathematical Constants & Visual Parameters
|
|
22
|
+
*
|
|
23
|
+
* ARCHITECTURAL RESPONSIBILITY: Central Mathematical Constants Repository
|
|
24
|
+
*
|
|
25
|
+
* This service provides all the mathematical constants, visual parameters, and scaling factors
|
|
26
|
+
* that determine the precise positioning, sizing, and styling of the energy visualization.
|
|
27
|
+
* Every coordinate calculation, energy-to-pixel conversion, and visual spacing depends on
|
|
28
|
+
* these carefully calibrated values.
|
|
29
|
+
*
|
|
30
|
+
* MATHEMATICAL SIGNIFICANCE OF CONSTANTS:
|
|
31
|
+
* Each constant has been precisely calculated to ensure:
|
|
32
|
+
* - Accurate proportional representation of energy values
|
|
33
|
+
* - Optimal visual clarity and readability
|
|
34
|
+
* - Smooth animation transitions between years
|
|
35
|
+
* - Responsive behavior across different screen sizes
|
|
36
|
+
* - Perfect alignment between flows and boxes
|
|
37
|
+
*
|
|
38
|
+
* COORDINATE SYSTEM ARCHITECTURE:
|
|
39
|
+
* The visualization uses a custom coordinate system where:
|
|
40
|
+
* - Origin (0,0) is at top-left of container
|
|
41
|
+
* - X increases rightward (fuel boxes → sector boxes)
|
|
42
|
+
* - Y increases downward (stacked vertically)
|
|
43
|
+
* - All measurements in pixels for precise SVG positioning
|
|
44
|
+
*/
|
|
45
|
+
export declare class ConfigurationService {
|
|
46
|
+
private container;
|
|
47
|
+
options: SankeyOptions;
|
|
48
|
+
private eventBus;
|
|
49
|
+
private logger;
|
|
50
|
+
hasHeatData: boolean;
|
|
51
|
+
readonly HEIGHT = 620;
|
|
52
|
+
readonly BOX_WIDTH: number;
|
|
53
|
+
readonly BOX_HEIGHT = 30;
|
|
54
|
+
readonly LEFT_X = 10;
|
|
55
|
+
readonly TOP_Y = 100;
|
|
56
|
+
readonly SCALE = 0.02;
|
|
57
|
+
readonly ELEC_BOX_X: 300;
|
|
58
|
+
readonly ELEC_BOX_Y: 120;
|
|
59
|
+
readonly HEAT_BOX_X: 750;
|
|
60
|
+
readonly HEAT_BOX_Y: 200;
|
|
61
|
+
readonly LEFT_GAP: number;
|
|
62
|
+
readonly RIGHT_GAP: number;
|
|
63
|
+
readonly SPEED: number;
|
|
64
|
+
readonly BLEED = 0.5;
|
|
65
|
+
readonly SR3: number;
|
|
66
|
+
readonly HSR3: number;
|
|
67
|
+
readonly PATH_GAP: number;
|
|
68
|
+
readonly ELEC_GAP = 19;
|
|
69
|
+
readonly FUELS: readonly FuelConfig[];
|
|
70
|
+
readonly BOXES: readonly BoxConfig[];
|
|
71
|
+
readonly BOXES_DEFAULT_FLOW_PATHS_ORDER: {
|
|
72
|
+
elec: number;
|
|
73
|
+
res: number;
|
|
74
|
+
ag: number;
|
|
75
|
+
indus: number;
|
|
76
|
+
trans: number;
|
|
77
|
+
heat: number;
|
|
78
|
+
};
|
|
79
|
+
readonly HEAT_BOX_FIRST_FLOW_PATHS_ORDER: {
|
|
80
|
+
elec: number;
|
|
81
|
+
heat: number;
|
|
82
|
+
res: number;
|
|
83
|
+
ag: number;
|
|
84
|
+
indus: number;
|
|
85
|
+
trans: number;
|
|
86
|
+
};
|
|
87
|
+
FLOW_PATHS_ORDER: Record<string, Record<string, number>>;
|
|
88
|
+
readonly BOX_NAMES: readonly string[];
|
|
89
|
+
readonly FUEL_NAMES: readonly string[];
|
|
90
|
+
constructor(container: HTMLElement, options: SankeyOptions, eventBus: EventBus, logger: Logger);
|
|
91
|
+
/**
|
|
92
|
+
* Get human-readable display name for fuel
|
|
93
|
+
*/
|
|
94
|
+
getFuelDisplayName(fuel: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* Get human-readable display name for sector/box
|
|
97
|
+
*/
|
|
98
|
+
getBoxDisplayName(sector: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* Get color for fuel type
|
|
101
|
+
*/
|
|
102
|
+
getFuelColor(fuel: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Get color for sector type
|
|
105
|
+
*/
|
|
106
|
+
getSectorColor(sector: string): string;
|
|
107
|
+
/**
|
|
108
|
+
* Get dynamic width from container ConfigurationService.WIDTH getter
|
|
109
|
+
* This dynamically calculates width based on actual container size
|
|
110
|
+
*/
|
|
111
|
+
get WIDTH(): number;
|
|
112
|
+
/**
|
|
113
|
+
* Get default width when container width cannot be determined
|
|
114
|
+
*/
|
|
115
|
+
private getDefaultWidth;
|
|
116
|
+
/**
|
|
117
|
+
* Apply responsive adjustments based on screen size
|
|
118
|
+
*/
|
|
119
|
+
private applyResponsiveAdjustments;
|
|
120
|
+
/**
|
|
121
|
+
* Calculate right box X position
|
|
122
|
+
*/
|
|
123
|
+
calculateRightBoxX(): number;
|
|
124
|
+
/**
|
|
125
|
+
* Validate configuration consistency
|
|
126
|
+
* Ensures all required constants are properly defined
|
|
127
|
+
*/
|
|
128
|
+
private validateConfiguration;
|
|
129
|
+
/**
|
|
130
|
+
* Check if fuel is defined in configuration
|
|
131
|
+
*/
|
|
132
|
+
isValidFuel(fuel: string): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Check if sector is defined in configuration
|
|
135
|
+
*/
|
|
136
|
+
isValidSector(sector: string): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Get all fuel configurations
|
|
139
|
+
*/
|
|
140
|
+
getAllFuels(): readonly FuelConfig[];
|
|
141
|
+
/**
|
|
142
|
+
* Get all sector configurations
|
|
143
|
+
*/
|
|
144
|
+
getAllSectors(): readonly BoxConfig[];
|
|
145
|
+
/**
|
|
146
|
+
* Get fuel configuration by name
|
|
147
|
+
*/
|
|
148
|
+
getFuelConfig(fuel: string): FuelConfig | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* Get sector configuration by name
|
|
151
|
+
*/
|
|
152
|
+
getSectorConfig(sector: string): BoxConfig | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Calculate responsive scaling factor based on container size
|
|
155
|
+
* Maintains aspect ratio while fitting within container
|
|
156
|
+
*/
|
|
157
|
+
calculateResponsiveScale(containerWidth: number, containerHeight: number): {
|
|
158
|
+
scale: number;
|
|
159
|
+
width: number;
|
|
160
|
+
height: number;
|
|
161
|
+
offsetX: number;
|
|
162
|
+
offsetY: number;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Get configuration optimized for mobile devices
|
|
166
|
+
*/
|
|
167
|
+
getMobileConfiguration(): Partial<ConfigurationService>;
|
|
168
|
+
/**
|
|
169
|
+
* Check if current viewport suggests mobile device
|
|
170
|
+
*/
|
|
171
|
+
isMobileViewport(): boolean;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=ConfigurationService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigurationService.d.ts","sourceRoot":"","sources":["../../src/services/ConfigurationService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,oBAAoB;IAiHzB,OAAO,CAAC,SAAS;IACV,OAAO,EAAE,aAAa;IAC7B,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,MAAM;IAlHX,WAAW,UAAS;IAK3B,SAAgB,MAAM,OAAO;IAG7B,SAAgB,SAAS,EAAE,MAAM,CAAO;IACxC,SAAgB,UAAU,MAAM;IAKhC,SAAgB,MAAM,MAAM;IAC5B,SAAgB,KAAK,OAAO;IAK5B,SAAgB,KAAK,QAAQ;IAK7B,S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