Skip to content

Real-time dashboard for monitoring global news, markets, and geopolitical events

TypeScript

Add enhanced tooltips with live data

Reggie9a207481d01c
diff --git a/index.html b/index.html
index 98df1c5..beaa0b8 100644
--- a/index.html
+++ b/index.html
@@ -96,7 +96,7 @@
</div>
<div class="panel-content" id="mapPanel" style="max-height: none; height: 550px; overflow: hidden; background: #0a1a14; position: relative;">
<svg id="mapSvg" style="width:100%;height:100%;"></svg>
- <div id="mapTooltip" style="position:absolute;display:none;background:rgba(0,20,15,0.95);border:1px solid #00ff88;padding:8px 12px;border-radius:4px;font-size:11px;color:#00ff88;pointer-events:none;z-index:1000;max-width:200px;font-family:monospace;"></div>
+ <div id="mapTooltip" style="position:absolute;display:none;background:rgba(0,20,15,0.95);border:1px solid #00ff88;padding:10px 14px;border-radius:4px;font-size:11px;color:#00ff88;pointer-events:none;z-index:1000;max-width:280px;font-family:monospace;line-height:1.4;"></div>
</div>
<script>
// Inline map render with hotspots
@@ -114,6 +114,101 @@
const path = d3.geoPath().projection(projection);
+ // Data cache for tooltips
+ const dataCache = {};
+
+ // Get local time at longitude
+ function getLocalTime(lon) {
+ const now = new Date();
+ const utcHours = now.getUTCHours();
+ const utcMinutes = now.getUTCMinutes();
+ const offsetHours = Math.round(lon / 15);
+ let localHours = (utcHours + offsetHours + 24) % 24;
+ const ampm = localHours >= 12 ? 'PM' : 'AM';
+ localHours = localHours % 12 || 12;
+ return `${localHours}:${utcMinutes.toString().padStart(2, '0')} ${ampm}`;
+ }
+
+ // Fetch weather from Open-Meteo
+ async function getWeather(lat, lon) {
+ const key = `weather_${lat}_${lon}`;
+ if (dataCache[key]) return dataCache[key];
+ try {
+ const res = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&current=temperature_2m,weather_code,wind_speed_10m`);
+ const data = await res.json();
+ const temp = data.current?.temperature_2m;
+ const tempF = temp ? Math.round(temp * 9/5 + 32) : null;
+ const wind = data.current?.wind_speed_10m;
+ const code = data.current?.weather_code;
+ const conditions = {
+ 0: '☀️ Clear', 1: '🌤️ Mostly clear', 2: '⛅ Partly cloudy', 3: '☁️ Overcast',
+ 45: '🌫️ Fog', 48: '🌫️ Fog', 51: '🌧️ Drizzle', 53: '🌧️ Drizzle', 55: '🌧️ Drizzle',
+ 61: '🌧️ Rain', 63: '🌧️ Rain', 65: '🌧️ Heavy rain', 71: '🌨️ Snow', 73: '🌨️ Snow',
+ 75: '🌨️ Heavy snow', 77: '🌨️ Snow', 80: '🌧️ Showers', 81: '🌧️ Showers', 82: '⛈️ Heavy showers',
+ 85: '🌨️ Snow', 86: '🌨️ Snow', 95: '⛈️ Thunderstorm', 96: '⛈️ Thunderstorm', 99: '⛈️ Thunderstorm'
+ };
+ const result = { temp: tempF, wind: wind ? Math.round(wind) : null, condition: conditions[code] || '—' };
+ dataCache[key] = result;
+ return result;
+ } catch (e) { return null; }
+ }
+
+ // Fetch news from GDELT
+ async function getNews(query, lat, lon) {
+ const key = `news_${query}`;
+ if (dataCache[key]) return dataCache[key];
+ try {
+ const searchTerm = encodeURIComponent(query);
+ const res = await fetch(`https://api.gdeltproject.org/api/v2/doc/doc?query=${searchTerm}&mode=artlist&maxrecords=3&format=json`);
+ const data = await res.json();
+ const articles = data.articles?.slice(0, 2).map(a => a.title?.substring(0, 60) + '...') || [];
+ dataCache[key] = articles;
+ return articles;
+ } catch (e) { return []; }
+ }
+
+ // Fetch flight count from OpenSky
+ async function getFlightCount(lat, lon) {
+ const key = `flights_${Math.round(lat)}_${Math.round(lon)}`;
+ if (dataCache[key] !== undefined) return dataCache[key];
+ try {
+ const bbox = `${lon-3},${lat-3},${lon+3},${lat+3}`;
+ const res = await fetch(`https://opensky-network.org/api/states/all?lamin=${lat-2}&lomin=${lon-2}&lamax=${lat+2}&lomax=${lon+2}`);
+ const data = await res.json();
+ const count = data.states?.length || 0;
+ dataCache[key] = count;
+ return count;
+ } catch (e) { dataCache[key] = null; return null; }
+ }
+
+ // Build enhanced tooltip content
+ async function buildTooltip(name, lat, lon, baseContent, color) {
+ const localTime = getLocalTime(lon);
+ let html = `<strong style="color:${color}">${baseContent}</strong>`;
+ html += `<br><span style="opacity:0.7">🕐 Local: ${localTime}</span>`;
+
+ // Show loading, then fetch data
+ tooltip.innerHTML = html + '<br><span style="opacity:0.5">Loading data...</span>';
+
+ const [weather, flights, news] = await Promise.all([
+ getWeather(lat, lon),
+ getFlightCount(lat, lon),
+ getNews(name, lat, lon)
+ ]);
+
+ if (weather) {
+ html += `<br><span style="opacity:0.7">${weather.condition} ${weather.temp}°F, ${weather.wind}mph</span>`;
+ }
+ if (flights !== null) {
+ html += `<br><span style="opacity:0.7">✈️ ${flights} aircraft nearby</span>`;
+ }
+ if (news && news.length > 0) {
+ html += `<br><span style="color:#888;font-size:9px">📰 ${news[0]}</span>`;
+ }
+
+ return html;
+ }
+
// Threat level colors
const threatColors = {
high: '#ff4444',
@@ -457,13 +552,14 @@
.attr('cx', x).attr('cy', y).attr('r', 12)
.attr('fill', 'transparent')
.attr('class', 'hotspot-hit')
- .on('mouseenter', function(event) {
+ .on('mouseenter', async function(event) {
const rect = mapPanel.getBoundingClientRect();
const levelLabel = h.level.charAt(0).toUpperCase() + h.level.slice(1);
- tooltip.innerHTML = `<strong style="color:${color}">[${levelLabel}]</strong> ${h.desc}`;
tooltip.style.display = 'block';
tooltip.style.left = (event.clientX - rect.left + 15) + 'px';
tooltip.style.top = (event.clientY - rect.top - 10) + 'px';
+ const html = await buildTooltip(h.name, h.lat, h.lon, `[${levelLabel}] ${h.desc}`, color);
+ tooltip.innerHTML = html;
})
.on('mousemove', function(event) {
const rect = mapPanel.getBoundingClientRect();