Skip to content

Commit df80599

Browse files
committed
fix: resolve price statistics toggle button not working
- Create PriceAnalytics instance in app.js initialization - Fix toggleOverlay method to create overlay when it doesn't exist - Add createEmptyOverlay method for initial state - Ensure overlay shows appropriate message when no data available - Fix button event handlers to properly toggle visibility - Add proper initialization check for PriceAnalytics class
1 parent 0bd19a0 commit df80599

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

public/js/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1676,9 +1676,12 @@ map.on('load', function () {
16761676

16771677
// Initialize Price Analytics
16781678
try {
1679-
if (window.priceAnalytics) {
1679+
if (typeof PriceAnalytics !== 'undefined') {
1680+
window.priceAnalytics = new PriceAnalytics();
16801681
window.priceAnalytics.init(map);
16811682
console.log('📊 Price analytics initialized successfully');
1683+
} else {
1684+
console.warn('PriceAnalytics class not found');
16821685
}
16831686
} catch (error) {
16841687
console.warn('Failed to initialize price analytics:', error);

public/js/price-analytics.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,52 @@ class PriceAnalytics {
618618
*/
619619
toggleOverlay() {
620620
this.overlayVisible = !this.overlayVisible;
621-
const overlay = document.getElementById('price-stats-overlay');
622-
if (overlay) {
623-
overlay.style.display = this.overlayVisible ? 'block' : 'none';
621+
let overlay = document.getElementById('price-stats-overlay');
622+
623+
if (this.overlayVisible) {
624+
// Show overlay - create it if it doesn't exist
625+
if (!overlay) {
626+
// Try to get current station data to show stats
627+
if (window.lastStationData) {
628+
this.updateStatistics(window.lastStationData);
629+
} else {
630+
// Create empty overlay with message
631+
this.createEmptyOverlay();
632+
}
633+
overlay = document.getElementById('price-stats-overlay');
634+
}
635+
if (overlay) {
636+
overlay.style.display = 'block';
637+
}
638+
} else {
639+
// Hide overlay
640+
if (overlay) {
641+
overlay.style.display = 'none';
642+
}
624643
}
644+
625645
return this.overlayVisible;
626646
}
627647

648+
/**
649+
* Create empty overlay when no data is available
650+
*/
651+
createEmptyOverlay() {
652+
const overlay = document.createElement('div');
653+
overlay.id = 'price-stats-overlay';
654+
overlay.className = 'price-stats-overlay';
655+
overlay.innerHTML = `
656+
<div class="stats-header">
657+
<h3>${this.getIcon('chart')} Price Statistics</h3>
658+
</div>
659+
<div style="text-align: center; padding: 20px; color: #666;">
660+
<p>Move the map to view stations and generate price statistics.</p>
661+
<p style="font-size: 12px; margin-top: 10px;">Statistics will appear automatically when fuel stations are loaded.</p>
662+
</div>
663+
`;
664+
document.body.appendChild(overlay);
665+
}
666+
628667
/**
629668
* Update statistics when map data changes
630669
*/

0 commit comments

Comments
 (0)