mirror of
https://github.com/wisplite/BLE-mesh-sim.git
synced 2026-10-30 13:32:21 -05:00
getting rid of a lot of stuff that i'm gonna rewrite
This commit is contained in:
@@ -64,6 +64,8 @@ var edges = new vis.DataSet([
|
||||
|
||||
var nodeTable = {};
|
||||
|
||||
var grid = new GridIndex(CONNECTION_DISTANCE);
|
||||
|
||||
var container = document.getElementById('simContainer');
|
||||
|
||||
var data = {
|
||||
@@ -382,124 +384,12 @@ const markNeighborsAsFailed = (nodeId, from, packetId, visited = new Set()) => {
|
||||
}
|
||||
}
|
||||
|
||||
function nodeSelectUpdateHandler(properties) {
|
||||
// get containers
|
||||
const connectionsTable = document.getElementById('connections');
|
||||
|
||||
// clear containers
|
||||
let connectionElements = connectionsTable.querySelectorAll('.connectionElement');
|
||||
for (let connection of connectionElements) {
|
||||
connection.remove();
|
||||
}
|
||||
|
||||
try {
|
||||
for (let connection of nodeTable[properties.nodes[0]].connections) {
|
||||
const connectionElement = document.createElement('div');
|
||||
connectionElement.classList.add('connectionElement');
|
||||
connectionElement.innerHTML = connection;
|
||||
connectionsTable.appendChild(connectionElement);
|
||||
}
|
||||
} catch (error) {
|
||||
return;
|
||||
}
|
||||
function recomputeNodeConnections(nodeId) {
|
||||
const p = network.getPosition(nodeId);
|
||||
grid.update(nodeId, p.x, p.y);
|
||||
}
|
||||
|
||||
network.on('selectNode', function(properties) {
|
||||
selectedNode = properties.nodes[0];
|
||||
if (document.getElementById('showRanges').checked) {
|
||||
const centerPoint = network.getPosition(properties.nodes[0]);
|
||||
const centerPointDOM = network.canvasToDOM({x: centerPoint.x, y: centerPoint.y});
|
||||
const edgePointDOM = network.canvasToDOM({x: centerPoint.x + CONNECTION_DISTANCE, y: centerPoint.y});
|
||||
const radius = Math.abs(edgePointDOM.x - centerPointDOM.x);
|
||||
const rangeVis = document.createElement('div');
|
||||
rangeVis.style.position = 'absolute';
|
||||
rangeVis.style.top = (centerPointDOM.y - radius) + 'px';
|
||||
rangeVis.style.left = (centerPointDOM.x - radius) + 'px';
|
||||
rangeVis.style.width = radius * 2 + 'px';
|
||||
rangeVis.style.height = radius * 2 + 'px';
|
||||
rangeVis.classList.add('rangeVis');
|
||||
document.getElementById('simContainer').appendChild(rangeVis);
|
||||
} else {
|
||||
const rangeVis = document.querySelector('.rangeVis');
|
||||
if (rangeVis) {
|
||||
rangeVis.remove();
|
||||
}
|
||||
}
|
||||
nodeSelectUpdateHandler(properties);
|
||||
});
|
||||
|
||||
network.on('dragging', function(properties) {
|
||||
if (properties.nodes.length > 0) {
|
||||
selectedNode = properties.nodes[0];
|
||||
}
|
||||
if (document.getElementById('showRanges').checked) {
|
||||
if (selectedNode != null) {
|
||||
const centerPoint = network.getPosition(selectedNode);
|
||||
const centerPointDOM = network.canvasToDOM({x: centerPoint.x, y: centerPoint.y});
|
||||
const edgePointDOM = network.canvasToDOM({x: centerPoint.x + CONNECTION_DISTANCE, y: centerPoint.y});
|
||||
const radius = Math.abs(edgePointDOM.x - centerPointDOM.x);
|
||||
const rangeVis = document.querySelector('.rangeVis');
|
||||
if (rangeVis) {
|
||||
rangeVis.style.top = (centerPointDOM.y - radius) + 'px';
|
||||
rangeVis.style.left = (centerPointDOM.x - radius) + 'px';
|
||||
rangeVis.style.width = radius * 2 + 'px';
|
||||
rangeVis.style.height = radius * 2 + 'px';
|
||||
} else {
|
||||
const rangeVis = document.createElement('div');
|
||||
rangeVis.style.position = 'absolute';
|
||||
rangeVis.style.top = (centerPointDOM.y - radius) + 'px';
|
||||
rangeVis.style.left = (centerPointDOM.x - radius) + 'px';
|
||||
rangeVis.style.width = radius * 2 + 'px';
|
||||
rangeVis.style.height = radius * 2 + 'px';
|
||||
rangeVis.classList.add('rangeVis');
|
||||
document.getElementById('simContainer').appendChild(rangeVis);
|
||||
}
|
||||
} else if (properties.nodes.length > 0) {
|
||||
selectedNode = properties.nodes[0];
|
||||
const centerPoint = network.getPosition(selectedNode);
|
||||
const centerPointDOM = network.canvasToDOM({x: centerPoint.x, y: centerPoint.y});
|
||||
const edgePointDOM = network.canvasToDOM({x: centerPoint.x + CONNECTION_DISTANCE, y: centerPoint.y});
|
||||
const radius = Math.abs(edgePointDOM.x - centerPointDOM.x);
|
||||
const rangeVis = document.querySelector('.rangeVis');
|
||||
if (rangeVis) {
|
||||
rangeVis.style.top = (centerPointDOM.y - radius) + 'px';
|
||||
rangeVis.style.left = (centerPointDOM.x - radius) + 'px';
|
||||
rangeVis.style.width = radius * 2 + 'px';
|
||||
rangeVis.style.height = radius * 2 + 'px';
|
||||
}
|
||||
}
|
||||
}
|
||||
nodeSelectUpdateHandler(properties);
|
||||
});
|
||||
|
||||
network.on('zoom', function(properties) {
|
||||
if (document.getElementById('showRanges').checked) {
|
||||
if (selectedNode) {
|
||||
const centerPoint = network.getPosition(selectedNode);
|
||||
const centerPointDOM = network.canvasToDOM({x: centerPoint.x, y: centerPoint.y});
|
||||
const edgePointDOM = network.canvasToDOM({x: centerPoint.x + CONNECTION_DISTANCE, y: centerPoint.y});
|
||||
const radius = Math.abs(edgePointDOM.x - centerPointDOM.x);
|
||||
const rangeVis = document.querySelector('.rangeVis');
|
||||
if (rangeVis) {
|
||||
rangeVis.style.top = (centerPointDOM.y - radius) + 'px';
|
||||
rangeVis.style.left = (centerPointDOM.x - radius) + 'px';
|
||||
rangeVis.style.width = radius * 2 + 'px';
|
||||
rangeVis.style.height = radius * 2 + 'px';
|
||||
}
|
||||
}
|
||||
}
|
||||
nodeSelectUpdateHandler(properties);
|
||||
});
|
||||
|
||||
network.on('deselectNode', function(properties) {
|
||||
selectedNode = null;
|
||||
const rangeVis = document.querySelector('.rangeVis');
|
||||
if (rangeVis) {
|
||||
rangeVis.remove();
|
||||
}
|
||||
nodeSelectUpdateHandler(properties);
|
||||
});
|
||||
|
||||
// main event loop
|
||||
function main() {
|
||||
const currentNodes = network.getPositions();
|
||||
|
||||
Reference in New Issue
Block a user