This commit is contained in:
Roslund
2025-04-09 09:16:39 +00:00
parent e2202a23e6
commit f57e150ecc
5 changed files with 86 additions and 7 deletions
+75
View File
@@ -0,0 +1,75 @@
async function deviceRolesChart() {
const canvas = document.getElementById('deviceRoles');
const ctx = canvas.getContext('2d');
// Loading message
ctx.font = '16px Arial';
ctx.fillStyle = 'gray';
ctx.textAlign = 'center';
ctx.fillText('Loading data...', canvas.width / 2, canvas.height / 2);
try {
const response = await fetch('https://map.sthlm-mesh.se/api/v1/nodes/');
const data = await response.json();
const predefinedLabels = ['CLIENT', 'CLIENT_MUTE', 'CLIENT_HIDDEN', 'ROUTER_LATE', 'ROUTER', 'ROUTER_CLIENT'];
// Count role occurrences
const roleCounts = {};
data.nodes.forEach(node => {
const role = node.role_name || "UNKNOWN";
roleCounts[role] = (roleCounts[role] || 0) + 1;
});
// Add extra roles not in predefined list
const extraLabels = Object.keys(roleCounts).filter(role => !predefinedLabels.includes(role)).sort();
const labels = [...predefinedLabels, ...extraLabels];
const counts = labels.map(label => roleCounts[label] || 0);
// Dynamically size the container based on the number of elements
const chartContainer = document.getElementById('deviceRolesContainer');
chartContainer.style.height = `${labels.length *35}px`;
const backgroundColors = labels.map(label => {
if (label == "ROUTER_CLIENT") return 'rgb(196, 36, 18)';
if (label == "ROUTER") return 'rgb(242, 161, 67)';
if (label == "ROUTER_LATE") return 'rgb(229, 189, 82)';
return 'rgb(41, 156, 70)';
});
new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Count',
data: counts,
backgroundColor: backgroundColors,
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
indexAxis: 'y',
scales: {
y: {
ticks: { autoSkip: false, font: { size: 12 } }
},
x: { beginAtZero: true },
},
plugins: {
legend: { display: false },
}
}
});
} catch (error) {
console.error('Error loading portnum data:', error);
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = 'red';
ctx.fillText('Error loading data', canvas.width / 2, canvas.height / 2);
}
}
deviceRolesChart();
+1 -1
View File
@@ -17,7 +17,7 @@ async function portnumDistributionChart() {
// Optional: dynamically size the container
const chartContainer = document.getElementById('portnumDistributionContainer');
chartContainer.style.height = `${labels.length * 25}px`;
chartContainer.style.height = `${labels.length * 35}px`;
const backgroundColors = counts.map(count => {
if (count < 500) return '#7EB26D'; // Green
+3
View File
@@ -67,6 +67,9 @@ async function positionPrecisionGraph() {
const labels = sorted.map(entry => formatPositionPrecision(entry.position_precision));
const counts = sorted.map(entry => entry.count);
const chartContainer = document.getElementById('positionPrecisionContainer');
chartContainer.style.height = `${labels.length *35}px`;
new Chart(ctx, {
type: 'bar',
data: {
+1 -1
View File
@@ -1 +1 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"><url><loc>https://sthlm-mesh.se/docs/settings/</loc><lastmod>2025-02-26T18:39:36+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/device_role/</loc><lastmod>2025-02-26T18:42:15+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/position/</loc><lastmod>2025-02-22T09:11:26+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/mqtt/</loc><lastmod>2025-03-31T19:16:34+02:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/neighbor_info/</loc><lastmod>2025-02-23T20:48:06+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/kartor/</loc><lastmod>2025-03-08T20:11:28+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/solar_nodes/</loc><lastmod>2025-02-25T20:03:55+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/communities/</loc><lastmod>2025-02-23T20:48:06+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/categories/</loc></url><url><loc>https://sthlm-mesh.se/docs/</loc><lastmod>2025-03-03T22:48:04+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/messages/</loc><lastmod>2025-03-28T17:26:53+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/meetups/</loc><lastmod>2025-03-03T22:48:04+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/about/</loc><lastmod>2025-02-23T18:02:23+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/status/</loc><lastmod>2025-04-07T22:17:40+02:00</lastmod></url><url><loc>https://sthlm-mesh.se/</loc><lastmod>2025-03-29T13:59:58+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/tags/</loc></url></urlset>
<?xml version="1.0" encoding="utf-8" standalone="yes"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"><url><loc>https://sthlm-mesh.se/docs/settings/</loc><lastmod>2025-02-26T18:39:36+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/device_role/</loc><lastmod>2025-02-26T18:42:15+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/position/</loc><lastmod>2025-02-22T09:11:26+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/mqtt/</loc><lastmod>2025-03-31T19:16:34+02:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/neighbor_info/</loc><lastmod>2025-02-23T20:48:06+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/kartor/</loc><lastmod>2025-03-08T20:11:28+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/solar_nodes/</loc><lastmod>2025-02-25T20:03:55+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/docs/communities/</loc><lastmod>2025-02-23T20:48:06+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/categories/</loc></url><url><loc>https://sthlm-mesh.se/docs/</loc><lastmod>2025-03-03T22:48:04+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/messages/</loc><lastmod>2025-03-28T17:26:53+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/meetups/</loc><lastmod>2025-03-03T22:48:04+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/about/</loc><lastmod>2025-02-23T18:02:23+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/status/</loc><lastmod>2025-04-09T11:15:58+02:00</lastmod></url><url><loc>https://sthlm-mesh.se/</loc><lastmod>2025-03-29T13:59:58+01:00</lastmod></url><url><loc>https://sthlm-mesh.se/tags/</loc></url></urlset>
+6 -5
View File
File diff suppressed because one or more lines are too long