cams-pollution-dashboard / templates /interactive_plot.html
aditya-me13's picture
Enhance plot titles and improve UI consistency
b395e0e
raw
history blame
12.9 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Air Pollution Map - India CAMS Dashboard</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}
.container {
max-width: 1400px;
margin: 0 auto;
padding: 20px;
}
.header {
background: rgba(255, 255, 255, 0.95);
border-radius: 15px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
backdrop-filter: blur(4px);
border: 1px solid rgba(255, 255, 255, 0.18);
}
.header h1 {
color: #2c3e50;
margin-bottom: 10px;
text-align: center;
}
.plot-container {
background: rgba(255, 255, 255, 0.95);
border-radius: 15px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
backdrop-filter: blur(4px);
border: 1px solid rgba(255, 255, 255, 0.18);
}
.plot-info {
background: rgba(255, 255, 255, 0.95);
border-radius: 15px;
padding: 20px;
box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
backdrop-filter: blur(4px);
border: 1px solid rgba(255, 255, 255, 0.18);
}
.info-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.info-item {
background: rgba(52, 73, 94, 0.1);
padding: 15px;
border-radius: 10px;
border-left: 4px solid #3498db;
}
.info-item h3 {
color: #2c3e50;
margin-bottom: 5px;
font-size: 14px;
font-weight: 600;
}
.info-item p {
color: #34495e;
font-size: 16px;
font-weight: 500;
}
.controls {
display: flex;
gap: 15px;
flex-wrap: wrap;
margin-bottom: 20px;
}
.btn {
background: linear-gradient(45deg, #3498db, #2980b9);
color: white;
padding: 12px 24px;
border: none;
border-radius: 25px;
text-decoration: none;
font-weight: 600;
transition: all 0.3s ease;
cursor: pointer;
font-size: 14px;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(52, 152, 219, 0.4);
}
.btn-download {
background: linear-gradient(45deg, #27ae60, #219a52);
}
.btn-back {
background: linear-gradient(45deg, #95a5a6, #7f8c8d);
}
.instructions {
background: rgba(255, 255, 255, 0.95);
border-radius: 15px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
backdrop-filter: blur(4px);
border: 1px solid rgba(255, 255, 255, 0.18);
}
.instructions h3 {
color: #2c3e50;
margin-bottom: 15px;
}
.instructions ul {
color: #34495e;
}
.btn-download:hover {
box-shadow: 0 8px 25px rgba(39, 174, 96, 0.4);
}
.btn-back {
background: linear-gradient(45deg, #95a5a6, #7f8c8d);
}
.btn-back:hover {
box-shadow: 0 8px 25px rgba(149, 165, 166, 0.4);
}
.instructions {
background: rgba(241, 196, 15, 0.1);
border: 2px solid rgba(241, 196, 15, 0.3);
border-radius: 10px;
padding: 15px;
margin-bottom: 20px;
}
.instructions h3 {
color: #f39c12;
margin-bottom: 10px;
}
.instructions ul {
color: #34495e;
padding-left: 20px;
}
.instructions li {
margin-bottom: 5px;
}
.interactive-plot {
border-radius: 10px;
overflow: hidden;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
@media (max-width: 768px) {
.container {
padding: 10px;
}
.controls {
justify-content: center;
}
.btn {
padding: 10px 20px;
font-size: 12px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🌍 Interactive Air Pollution Map</h1>
<p style="text-align: center; color: #7f8c8d; margin-top: 10px;">
Hover over the map to see exact coordinates and pollution values. Use the toolbar to zoom, pan, and download.
</p>
</div>
<div class="instructions">
<h3>🎯 How to Use This Interactive Map:</h3>
<ul>
<li><strong>πŸ–±οΈ Hover:</strong> Move your mouse over any point to see exact coordinates, pollution values, and location data</li>
<li><strong>πŸ” Zoom:</strong> Use mouse wheel, zoom buttons in toolbar, or draw a rectangle to zoom to specific area</li>
<li><strong>πŸ“ Pan:</strong> Click and drag to move around the map</li>
<li><strong>πŸ“₯ Download:</strong> Click the camera icon in the toolbar to download as PNG image</li>
<li><strong>πŸ”„ Reset:</strong> Double-click anywhere to reset zoom to original view</li>
<li><strong>✏️ Annotate:</strong> Use drawing tools in the toolbar to add lines, shapes, and annotations</li>
</ul>
</div>
<div class="controls">
<a href="{{ url_for('index') }}" class="btn btn-back">← Back to Dashboard</a>
{% if plot_info.png_path %}
<a href="{{ url_for('serve_plot', filename=plot_info.png_path.split('/')[-1]) }}"
class="btn btn-download" download>πŸ“₯ Download PNG</a>
{% endif %}
{% if plot_info.html_path %}
<a href="{{ url_for('serve_plot', filename=plot_info.html_path.split('/')[-1]) }}"
class="btn btn-download" download>πŸ“„ Download HTML</a>
{% endif %}
</div>
<div class="plot-container">
<div class="interactive-plot" id="plotly-container">
{{ plot_html|safe }}
</div>
</div>
<div class="plot-info">
<h2 style="color: #2c3e50; margin-bottom: 20px;">πŸ“Š Plot Information</h2>
<div class="info-grid">
<div class="info-item">
<h3>πŸ§ͺ Variable</h3>
<p>{{ plot_info.variable }}</p>
</div>
{% if plot_info.units %}
<div class="info-item">
<h3>πŸ“ Units</h3>
<p>{{ plot_info.units }}</p>
</div>
{% endif %}
{% if plot_info.pressure_level %}
<div class="info-item">
<h3>🌑️ Pressure Level</h3>
<p>{{ plot_info.pressure_level }} hPa</p>
</div>
{% endif %}
<div class="info-item">
<h3>🎨 Color Theme</h3>
<p>{{ plot_info.color_theme }}</p>
</div>
<div class="info-item">
<h3>πŸ“ Data Shape</h3>
<p>{{ plot_info.shape }}</p>
</div>
<div class="info-item">
<h3>⏰ Generated</h3>
<p>{{ plot_info.generated_time }}</p>
</div>
<!-- </div>
<div class="info-grid"> -->
<div class="info-item">
<h3>πŸ“Š Minimum Value</h3>
<p>{{ "%.3f"|format(plot_info.data_range.min) }}{% if plot_info.units %} {{ plot_info.units }}{% endif %}</p>
</div>
<div class="info-item">
<h3>πŸ“Š Maximum Value</h3>
<p>{{ "%.3f"|format(plot_info.data_range.max) }}{% if plot_info.units %} {{ plot_info.units }}{% endif %}</p>
</div>
<div class="info-item">
<h3>πŸ“Š Average Value</h3>
<p>{{ "%.3f"|format(plot_info.data_range.mean) }}{% if plot_info.units %} {{ plot_info.units }}{% endif %}</p>
</div>
</div>
</div>
</div>
<script>
// Additional interactivity enhancements and debugging
document.addEventListener('DOMContentLoaded', function() {
console.log('Interactive plot page loaded');
// Check if Plotly is loaded
if (typeof Plotly === 'undefined') {
console.error('Plotly is not loaded!');
document.getElementById('plotly-container').innerHTML =
'<div style="padding: 40px; text-align: center; color: red; border: 2px dashed red; margin: 20px;">' +
'<h3>⚠️ Plot Loading Error</h3>' +
'<p>Plotly library failed to load. Please refresh the page or check your internet connection.</p>' +
'</div>';
return;
}
// Look for the plotly div
const plotDiv = document.querySelector('[id^="interactive-plot"]') || document.querySelector('.plotly-graph-div');
if (!plotDiv) {
console.error('No Plotly div found!');
document.getElementById('plotly-container').innerHTML =
'<div style="padding: 40px; text-align: center; color: orange; border: 2px dashed orange; margin: 20px;">' +
'<h3>⚠️ Plot Not Found</h3>' +
'<p>The interactive plot could not be initialized. The data may be processing.</p>' +
'<button onclick="location.reload()" style="padding: 10px 20px; background: #3498db; color: white; border: none; border-radius: 5px; cursor: pointer;">πŸ”„ Refresh Page</button>' +
'</div>';
return;
}
console.log('Plotly div found:', plotDiv);
// Add responsive behavior
window.addEventListener('resize', function() {
if (plotDiv && typeof Plotly !== 'undefined') {
Plotly.Plots.resize(plotDiv);
}
});
// Add loading indicator for downloads
const downloadButtons = document.querySelectorAll('.btn-download');
downloadButtons.forEach(button => {
button.addEventListener('click', function() {
const originalText = this.textContent;
this.textContent = '⏳ Preparing download...';
this.style.pointerEvents = 'none';
setTimeout(() => {
this.textContent = originalText;
this.style.pointerEvents = 'auto';
}, 2000);
});
});
// Add a small delay then check if plot rendered correctly
setTimeout(function() {
const plotlyGraphDiv = document.querySelector('.plotly-graph-div');
if (plotlyGraphDiv) {
const svg = plotlyGraphDiv.querySelector('svg');
if (!svg || svg.children.length === 0) {
console.warn('Plot may not have rendered correctly');
// Try to redraw
if (typeof Plotly !== 'undefined' && plotDiv._fullData) {
Plotly.redraw(plotDiv);
}
} else {
console.log('Plot rendered successfully');
}
}
}, 1000);
});
</script>
</body>
</html>