Skip to content

Commit 4a89251

Browse files
committed
Better map
1 parent e9ba8ff commit 4a89251

File tree

2 files changed

+58
-32
lines changed

2 files changed

+58
-32
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"react-leaflet": "^4.2.1",
1313
"react-leaflet-markercluster": "^4.1.1",
1414
"react-router-dom": "^6.0.2",
15-
"react-scripts": "^5.0.1"
15+
"react-scripts": "^5.0.1",
16+
"react-timeago": "^7.2.0"
1617
},
1718
"scripts": {
1819
"start": "react-scripts start",

src/components/WorldMap.js

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { useState } from "react";
2-
import { MapContainer, TileLayer, Marker, Popup } from "react-leaflet";
2+
import { MapContainer, TileLayer, Marker, Tooltip } from "react-leaflet";
33
import MarkerClusterGroup from "react-leaflet-markercluster";
44
import "leaflet/dist/leaflet.css";
55
import "react-leaflet-markercluster/dist/styles.min.css";
66
import L from "leaflet";
77
import "./WorldMap.css";
8+
import TimeAgo from 'react-timeago';
89

910
// Hardcoded probe region pins
1011
const probeRegions = [
@@ -29,26 +30,30 @@ const AccordionItem = ({ instanceScore, orchObj, instanceObj, startExpanded }) =
2930
</div>
3031
{isExpanded && (
3132
<div className="accordion-item-details">
32-
<p>Instance KPI: {instanceScore?.toFixed(2) || "N/A"}</p>
33-
<p>Orchestrator Name: {orchObj.name}</p>
34-
<p>Orchestrator ID: {orchObj.id}</p>
35-
<p>Average Discovery Time: {orchObj.avgDiscoveryTime}</p>
36-
<p>Average Price: {orchObj.avgPrice}</p>
37-
<p>Average RTR: {orchObj.avgRTR}</p>
38-
<p>Average SR: {orchObj.avgSR}</p>
39-
<p>Normalized Discovery Time: {orchObj.normalizedDiscoveryTime}</p>
40-
<p>Normalized Price: {orchObj.normalizedPrice}</p>
41-
<p>Normalized RTR: {orchObj.normalizedRTR}</p>
42-
<p>Instance Average RTR: {instanceObj.avgRTR}</p>
43-
<p>Instance Average SR: {instanceObj.avgSR}</p>
44-
<p>Instance ID: {instanceObj.id}</p>
45-
<p>Instance Last Ping: {instanceObj.lastPing}</p>
46-
<p>Instance Normalized Discovery Time: {instanceObj.normalizedDiscoveryTime}</p>
47-
<p>Instance Normalized Price: {instanceObj.normalizedPrice}</p>
48-
<p>Instance Normalized RTR: {instanceObj.normalizedRTR}</p>
49-
<p>Instance Price: {instanceObj.price}</p>
50-
<p>Instance Probed From: {instanceObj.probedFrom}</p>
51-
<p>Instance Regions: {instanceObj.regions}</p>
33+
<p>Address: {orchObj.id}</p>
34+
{orchObj.name != orchObj.id && <p>ENS: {orchObj.name}</p>}
35+
<div><strong>KPI score:</strong> {instanceScore.toFixed(4) * 100}%</div>
36+
<hr />
37+
<strong>Global Stats:</strong>
38+
<p>Discovery Time: {orchObj.avgDiscoveryTime.toPrecision(3)} ms</p>
39+
<p>Price: {orchObj.avgPrice.toPrecision(3)}</p>
40+
<p>RTR: {orchObj.avgRTR.toFixed(1)}</p>
41+
<p>SR: {orchObj.avgSR.toFixed(1)}</p>
42+
<hr />
43+
<strong>Instance Stats:</strong>
44+
<p>IP: {instanceObj.id}</p>
45+
<div>Last Ping: <TimeAgo
46+
date={instanceObj.lastPing}
47+
component={"p"}
48+
minPeriod={60}
49+
style={{}}
50+
/></div>
51+
<p>Discovery Time: {instanceObj.bestDiscoveryTime.toPrecision(3)} ms</p>
52+
<p>Price: {instanceObj.price.toPrecision(3)}</p>
53+
<p>RTR: {instanceObj.avgRTR.toFixed(1)}</p>
54+
<p>SR: {instanceObj.avgSR.toFixed(1)}</p>
55+
<hr />
56+
<div><strong>Probed From:</strong> {instanceObj.probedFrom.map((location) => <p>{location}</p>)}</div>
5257
</div>
5358
)}
5459
</div>
@@ -187,7 +192,17 @@ const WorldMap = ({ orchestrators, selectedKPI }) => {
187192
clusterclick: (e) => {
188193
const cluster = e.layer;
189194
const markers = cluster.getAllChildMarkers();
190-
setSelectedData(markers);
195+
if (!selectedData || !Array.isArray(selectedData)) {
196+
setSelectedData(markers);
197+
return;
198+
}
199+
const notChanged = Array.isArray(selectedData) && selectedData.length == markers.length &&
200+
selectedData.every((marker, index) => marker._leaflet_id === markers[index]._leaflet_id) || false;
201+
if (!notChanged) {
202+
setSelectedData(markers);
203+
} else {
204+
setSelectedData(null);
205+
}
191206
},
192207
}}
193208
>
@@ -204,7 +219,7 @@ const WorldMap = ({ orchestrators, selectedKPI }) => {
204219
icon={L.divIcon({
205220
className: "dummy",
206221
html: `<div class="custom-pin" style="background-color: ${selectedData?.instanceObj?.id === instance.id ? "var(--magenta)" :
207-
getPinColor(instance[selectedKPI])
222+
getPinColor(instance[selectedKPI])
208223
}; width: ${selectedData?.instanceObj?.id === instance.id ? "36px" :
209224
"24px"
210225
}; height: ${selectedData?.instanceObj?.id === instance.id ? "36px" :
@@ -213,14 +228,24 @@ const WorldMap = ({ orchestrators, selectedKPI }) => {
213228
})}
214229
eventHandlers={{
215230
click: () => {
216-
setSelectedData({
217-
instanceScore: instance[selectedKPI],
218-
orchObj: orch,
219-
instanceObj: instance,
220-
});
231+
if (!selectedData || Array.isArray(selectedData) || selectedData.instanceObj.id != instance.id) {
232+
setSelectedData({
233+
instanceScore: instance[selectedKPI],
234+
orchObj: orch,
235+
instanceObj: instance,
236+
});
237+
} else {
238+
setSelectedData(null);
239+
}
221240
},
222241
}}
223-
/>
242+
>
243+
<Tooltip>
244+
<strong>{instance.id}</strong>
245+
<br />
246+
Orchestrator node
247+
</Tooltip>
248+
</Marker>
224249
))
225250
)}
226251
</MarkerClusterGroup>
@@ -235,11 +260,11 @@ const WorldMap = ({ orchestrators, selectedKPI }) => {
235260
html: `<div class="probe-pin""></div>`,
236261
})}
237262
>
238-
<Popup>
263+
<Tooltip>
239264
<strong>{region.name}</strong>
240265
<br />
241266
Stronk Origin
242-
</Popup>
267+
</Tooltip>
243268
</Marker>
244269
))}
245270
</MapContainer>

0 commit comments

Comments
 (0)