energy-visualization-sankey 1.0.1 → 1.0.3

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/LICENSE CHANGED
@@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
+
package/README.md CHANGED
@@ -14,7 +14,6 @@ across historical energy data.
14
14
  - [Data Format](#data-format)
15
15
  - [Architecture](#architecture)
16
16
  - [Development](#development)
17
- - [Examples](#examples)
18
17
  - [Browser Support](#browser-support)
19
18
  - [Contributing](#contributing)
20
19
  - [License](#license)
@@ -73,14 +72,8 @@ npm install energy-visualization-sankey
73
72
  For quick prototyping or simple integration, use the standalone build that includes D3:
74
73
 
75
74
  ```html
76
- <!-- Standalone ES Module (recommended for modern browsers) -->
77
- <script type="module">
78
- import Sankey from './dist/sankey.standalone.esm.js';
79
- // Your code here
80
- </script>
81
-
82
75
  <!-- Standalone UMD (compatible with older browsers) -->
83
- <script src="./dist/sankey.standalone.umd.js"></script>
76
+ <script src="https://cdn.jsdelivr.net/npm/energy-visualization-sankey@1.0.1/dist/sankey.standalone.esm.js"></script>
84
77
  <script>
85
78
  const sankey = new Sankey('container', options);
86
79
  </script>
@@ -93,7 +86,7 @@ If you already have D3 v7 in your project:
93
86
  ```html
94
87
 
95
88
  <script src="https://d3js.org/d3.v7.min.js"></script>
96
- <script src="./dist/sankey.umd.js"></script>
89
+ <script src="https://cdn.jsdelivr.net/npm/energy-visualization-sankey@1.0.1/dist/sankey.umd.js"></script>
97
90
  ```
98
91
 
99
92
  ## Quick Start
@@ -150,7 +143,7 @@ const sankey = new Sankey('sankey-container', {
150
143
  <div id="sankey-container"></div>
151
144
 
152
145
  <script type="module">
153
- import Sankey from './dist/sankey.standalone.esm.js';
146
+ import Sankey from 'https://cdn.jsdelivr.net/npm/energy-visualization-sankey@1.0.1/dist/sankey.standalone.esm.js';
154
147
  // Initialize as shown above
155
148
  </script>
156
149
  </body>
@@ -406,40 +399,6 @@ src/
406
399
  └── index.ts # Public API exports
407
400
  ```
408
401
 
409
- ## Examples
410
-
411
- ### Working Examples
412
-
413
- See the `examples/` directory for complete working examples:
414
-
415
- - **examples/data-us.html** - US energy data visualization (1800-2021)
416
- - **examples/data-china.html** - China energy data visualization
417
- - **examples/visual-test.html** - Visual testing interface
418
-
419
- ### Running Examples
420
-
421
- ```bash
422
- npm run serve
423
- # Open http://localhost:8080/examples/data-us.html
424
- ```
425
-
426
- ### Custom Data Example
427
-
428
- ```typescript
429
- // Load your own energy dataset
430
- fetch('./my-energy-data.json')
431
- .then(response => response.json())
432
- .then(energyData => {
433
- const sankey = new Sankey('my-container', {
434
- data: energyData,
435
- country: "My Country",
436
- includeControls: true,
437
- animationSpeed: 150,
438
- autoPlay: true
439
- });
440
- });
441
- ```
442
-
443
402
  ## Browser Support
444
403
 
445
404
  | Browser | Minimum Version | Notes |
@@ -463,7 +422,7 @@ fetch('./my-energy-data.json')
463
422
  ### Development Setup
464
423
 
465
424
  1. Fork the repository
466
- 2. Clone your fork: `git clone https://github.com/appdev-rcc/energy-visualization-sankey.git`
425
+ 2. Clone your fork
467
426
  3. Install dependencies: `npm install`
468
427
  4. Create a feature branch: `git checkout -b feature/your-feature`
469
428
  5. Make your changes with tests
@@ -1 +1 @@
1
- {"version":3,"file":"Sankey.d.ts","sourceRoot":"","sources":["../../src/core/Sankey.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAA6D,aAAa,EAAC,MAAM,SAAS,CAAC;AAavG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IAIvB,OAAO,CAAC,QAAQ,C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AwB;CAgBnC"}
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * @author Research Computing Center (RCC), University of Chicago
15
15
  */
16
- export { default } from '@/core/Sankey';
17
16
  export type { SankeyOptions, EnergyDataPoint, SummaryData, GraphData, YearTotals, BoxMaxes, BoxTops } from '@/types/index';
18
17
  export { SankeyError, DataValidationError } from '@/types/index';
18
+ export { default as default } from '@/core/Sankey';
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAGtC,YAAY,EACR,aAAa,EACb,eAAe,EACf,WAAW,EACX,SAAS,EACT,UAAU,EACV,QAAQ,EACR,OAAO,EACV,MAAM,eAAe,CAAC;AAGvB,OAAO,EACH,WAAW,EACX,mBAAmB,EACtB,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,YAAY,EACR,aAAa,EACb,eAAe,EACf,WAAW,EACX,SAAS,EACT,UAAU,EACV,QAAQ,EACR,OAAO,EACV,MAAM,eAAe,CAAC;AAGvB,OAAO,EACH,WAAW,EACX,mBAAmB,EACtB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,eAAe,CAAC"}
@@ -728,6 +728,21 @@ class ConfigurationService {
728
728
  };
729
729
  return fallbackNames[fuel] || fuel.charAt(0).toUpperCase() + fuel.slice(1);
730
730
  }
731
+ /**
732
+ * Get responsive header dimensions for current container width
733
+ */
734
+ getResponsiveHeaderInfo() {
735
+ const containerWidth = this.WIDTH;
736
+ const isNarrow = containerWidth < 1024;
737
+ const isMobile = containerWidth < 768;
738
+ const animationScale = isMobile ? 0.85 : 1;
739
+ return {
740
+ containerWidth,
741
+ isNarrow,
742
+ isMobile,
743
+ animationScale
744
+ };
745
+ }
731
746
  /**
732
747
  * Get human-readable display name for sector/box
733
748
  */
@@ -2357,69 +2372,72 @@ class RenderingService {
2357
2372
  .y((d) => d.y);
2358
2373
  }
2359
2374
  /**
2360
- * Draws the main title, subtitle, and affiliations in separate title container
2375
+ * Draws the animated header elements (year and energy units) as separate SVG overlays
2361
2376
  */
2362
2377
  drawHeader() {
2363
- // Use separate title container
2364
- const titleContainer = d3.select('.title_container')
2365
- .style('height', '58px');
2366
- const titleSvg = titleContainer
2378
+ // Create Energy Usage Overlay in the title section
2379
+ this.createEnergyUsageOverlay();
2380
+ // Create Year Overlay in separate year section
2381
+ this.createYearOverlay();
2382
+ }
2383
+ /**
2384
+ * Creates the energy usage SVG overlay in the title section
2385
+ */
2386
+ createEnergyUsageOverlay() {
2387
+ const energyContainer = d3.select('.energy-usage-overlay');
2388
+ const energySvg = energyContainer
2367
2389
  .append('svg')
2368
- .attr('id', 'title')
2369
- .attr('width', this.configService.WIDTH)
2370
- .attr('height', 58);
2371
- const country = this.configService.options.country;
2372
- // Draw title of graph
2373
- const svg_title = titleSvg.append('text')
2374
- .text(`${country} energy usage`)
2375
- .attr('text-anchor', 'end')
2376
- .attr('x', this.configService.ELEC_BOX_X - 10)
2377
- .attr('y', '1.5em')
2378
- .attr('class', 'title');
2379
- // Draw units of graph (will be populated by animation)
2380
- svg_title.append('tspan')
2390
+ .attr('id', 'energy-usage-overlay')
2391
+ .attr('class', 'energy-svg-overlay')
2392
+ .style('position', 'absolute')
2393
+ .style('top', '0')
2394
+ .style('left', '25%')
2395
+ .style('width', '100%')
2396
+ .style('height', '25px')
2397
+ .style('pointer-events', 'none')
2398
+ .style('overflow', 'visible');
2399
+ // Draw energy usage units (will be populated by animation)
2400
+ energySvg.append('text')
2381
2401
  .text('0 W/capita') // Will be updated by animation to show actual energy usage
2382
- .attr('text-anchor', 'end')
2383
- .attr('x', this.configService.ELEC_BOX_X - 13)
2384
- .attr('dy', '1.4em')
2402
+ .attr('text-anchor', 'right')
2403
+ .attr('x', 0)
2404
+ .attr('y', 18)
2385
2405
  .attr('class', 'unit year-total animate title-bottom')
2386
2406
  .attr('data-incr', '0')
2387
- .attr('data-value', '0');
2388
- // Draw year (will be populated by animation)
2407
+ .attr('data-value', '0')
2408
+ .style('font-size', '0.9em')
2409
+ .style('font-weight', 'bold');
2410
+ }
2411
+ /**
2412
+ * Creates the year SVG overlay in the year section
2413
+ */
2414
+ createYearOverlay() {
2389
2415
  const firstYear = this.dataService.firstYear;
2390
- const lastYear = this.dataService.lastYear;
2391
- svg_title.append('tspan')
2416
+ const yearContainer = d3.select('.year-overlay');
2417
+ const yearSvg = yearContainer
2418
+ .append('svg')
2419
+ .attr('id', 'year-overlay')
2420
+ .attr('class', 'year-svg-overlay')
2421
+ .style('position', 'absolute')
2422
+ .style('top', '0')
2423
+ .style('left', '0')
2424
+ .style('width', '100%')
2425
+ .style('height', '100%')
2426
+ .style('pointer-events', 'none')
2427
+ .style('overflow', 'visible');
2428
+ // Draw year (will be populated by animation)
2429
+ yearSvg.append('text')
2392
2430
  .text(firstYear.toString())
2393
- .attr('text-anchor', 'start')
2394
- .attr('x', this.configService.ELEC_BOX_X)
2395
- .attr('dy', '0em')
2431
+ .attr('text-anchor', 'middle')
2432
+ .attr('x', '50%')
2433
+ .attr('y', '90%')
2396
2434
  .attr('class', 'year animate')
2397
2435
  .attr('data-incr', '0')
2398
- .attr('data-value', firstYear);
2399
- // Add subtitle
2400
- titleSvg.append('text')
2401
- .text(`Energy Transitions in ${country} History, ${firstYear}-${lastYear}`)
2402
- .attr('x', this.configService.ELEC_BOX_X + this.configService.BOX_WIDTH + 25)
2403
- .attr('y', '1.5em')
2404
- .attr('class', 'affiliation')
2405
- .append('tspan')
2406
- .text('Suits, Matteson, and Moyer (2020)')
2407
- .attr('class', 'affiliation-bottom')
2408
- .attr('x', this.configService.ELEC_BOX_X + this.configService.BOX_WIDTH + 25)
2409
- .attr('dy', '1.4em');
2410
- // Draw affiliations
2411
- const affiliationX = this.configService.ELEC_BOX_X + this.configService.BOX_WIDTH +
2412
- (this.configService.WIDTH - (this.configService.ELEC_BOX_X + this.configService.BOX_WIDTH)) / 2 + 50;
2413
- titleSvg.append('text')
2414
- .text('Center for Robust Decision-making on')
2415
- .attr('x', affiliationX)
2416
- .attr('y', '1.5em')
2417
- .attr('class', 'affiliation')
2418
- .append('tspan')
2419
- .text('Climate and Energy Policy, UChicago')
2420
- .attr('class', 'affiliation-bottom')
2421
- .attr('x', affiliationX)
2422
- .attr('dy', '1.4em');
2436
+ .attr('data-value', firstYear)
2437
+ .style('font-size', '3.1em')
2438
+ .style('font-weight', 'bold')
2439
+ .style('letter-spacing', '0.05em')
2440
+ .style('font-variant-numeric', 'tabular-nums');
2423
2441
  }
2424
2442
  /**
2425
2443
  * Draw Fuel Source Labels - Left Column Energy Source Visualization
@@ -3114,9 +3132,48 @@ class Sankey {
3114
3132
  * Creates the DOM structure needed for controls, timeline, and chart display
3115
3133
  */
3116
3134
  injectHTML() {
3135
+ const country = this.options.country;
3136
+ const firstYear = this.services.dataService.firstYear;
3137
+ const lastYear = this.services.dataService.lastYear;
3117
3138
  let html = `
3118
- <div class="us-energy-sankey-wrapper">
3119
- <div class="sankey" style="line-height: 0;"></div>
3139
+ <div class="title_container">
3140
+ <div class="header-content">
3141
+ <div class="header-logo">
3142
+ <a href="https://www.rdcep.org/" target="_blank">
3143
+ <img src="https://images.squarespace-cdn.com/content/v1/54dcfad0e4b0eaff5e0068bf/1446137765478-FX9WM00VV1LWAFUJRZBI/rdcep+sig2.png"
3144
+ alt="The Center for Robust Decision-making on Climate and Energy Policy (RDCEP)"
3145
+ title="The Center for Robust Decision-making on Climate and Energy Policy (RDCEP)">
3146
+ </a>
3147
+ </div>
3148
+
3149
+ <div class="header-main">
3150
+ <div class="header-title-section">
3151
+ <h1 class="main-title">${country} energy usage</h1>
3152
+ <div class="energy-usage-overlay">
3153
+ <!-- SVG overlay for energy usage will be positioned here -->
3154
+ </div>
3155
+ </div>
3156
+ </div>
3157
+
3158
+ <div class="header-year">
3159
+ <div class="year-overlay">
3160
+ <!-- SVG overlay for animated year will be positioned here -->
3161
+ </div>
3162
+ </div>
3163
+
3164
+ <div class="header-info">
3165
+ <div class="subtitle">Energy Transitions in ${country} History, ${firstYear}-${lastYear}</div>
3166
+ <div class="attribution">Suits, Matteson, and Moyer (2020)</div>
3167
+ </div>
3168
+
3169
+ <div class="header-affiliation">
3170
+ <div class="affiliation-text">Center for Robust Decision-making on</div>
3171
+ <div class="affiliation-text">Climate and Energy Policy, UChicago</div>
3172
+ </div>
3173
+ </div>
3174
+ </div>
3175
+ <div class="us-energy-sankey-wrapper">
3176
+ <div class="sankey" style="line-height: 0;"></div>
3120
3177
  `;
3121
3178
  if (this.options.includeTimeline) {
3122
3179
  html += `
@@ -3161,12 +3218,6 @@ class Sankey {
3161
3218
  html += `<div id="dialog" title="" style="display: none;"></div>`;
3162
3219
  }
3163
3220
  this.container.innerHTML = html;
3164
- // Add title container
3165
- if (!document.querySelector('.title_container')) {
3166
- const titleContainer = document.createElement('div');
3167
- titleContainer.className = 'title_container';
3168
- this.container.insertBefore(titleContainer, this.container.firstChild);
3169
- }
3170
3221
  // Set initial waste heat visibility state
3171
3222
  const sankeyContainer = this.container.querySelector('.sankey');
3172
3223
  if (sankeyContainer) {