Browse Source

performance

master
Milan Pässler 2 months ago
parent
commit
f6dc827604
3 changed files with 31 additions and 12 deletions
  1. +1
    -3
      client/src/canvas.js
  2. +28
    -8
      client/src/index.js
  3. +2
    -1
      server/package.json

+ 1
- 3
client/src/canvas.js View File

@@ -30,15 +30,13 @@ const y = (p) => {
const drawGraph = () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let link of graph.links) {
ctx.lineWidth = 2 + link.weight * view.scale;
if (link.source === selectedNode) {
ctx.strokeStyle = "rgba(255, 50, 0, .8)";
ctx.lineWidth = 5;
} else if (link.target === selectedNode) {
ctx.strokeStyle = "rgba(0, 50, 255, .8)";
ctx.lineWidth = 5;
} else {
ctx.strokeStyle = "rgba(255, 255, 255, .2)";
ctx.lineWidth = 2;
}
ctx.beginPath();
ctx.moveTo(x(link.source.x), y(link.source.y));

+ 28
- 8
client/src/index.js View File

@@ -30,19 +30,30 @@ const go = async (name, selected) => {
for (let node of data.data.nodes) {
newGraph.nodes[node.as_number] = node;
}
const links = {};
for (let link of data.data.initial_state) {
let last_n = null;
for (let n of link.path) {
if (last_n) {
newGraph.links.push({
source: last_n,
target: n,
});
const linkid = `${last_n}-${n}`;
if (linkid in links) {
links[linkid].weight++;
} else {
links[linkid] = {
source: last_n,
target: n,
weight: 1,
};
}
}
last_n = n;
}
}
console.log(newGraph);
newGraph.links = Object.entries(links).map(([k, v]) => v);
const maxLinkWeight = newGraph.links.sort((a, b) => b.weight - a.weight)[0].weight;
for (let link of newGraph.links) {
link.weight /= maxLinkWeight / 50;
}
} catch(err) {
console.log(err)
newGraph = {
@@ -52,14 +63,24 @@ const go = async (name, selected) => {
}
if (currentRequestNumber !== thisRequest) return;

let maxWeight = 0;
for (let id of Object.keys(newGraph.nodes)) {
newGraph.nodes[id].weight = 5 + newGraph.links.filter(l => l.source == id || l.target == id).length / 50; //Math.min(50, 5 + (newGraph.nodes[id].size / 5000000) || 0);
const weight = newGraph.links.filter(l => l.source == id || l.target == id).map(l => l.weight).reduce((a, b) => a + b, 0) / 50;
console.log();
if (weight > maxWeight) maxWeight = weight;
newGraph.nodes[id].weight = weight;
}
for (let id of Object.keys(newGraph.nodes)) {
newGraph.nodes[id].weight /= maxWeight / 10;
newGraph.nodes[id].weight += 5;
}

console.log(newGraph);
setGraph(newGraph);
document.getElementById("loading").classList.add("hidden");

if (!selected) {
setSelectedNode(nodesAsArray()[0]);
setSelectedNode(nodesAsArray().sort((a, b) => b.weight - a.weight)[0]);
} else {
setSelectedNode(nodesAsArray().filter(node => node.id === selected)[0]);
}
@@ -87,7 +108,6 @@ const handleSubmit = (evt) => {
const handleHashChange = () => {
const hash = window.location.hash.substr(1).split(":");
if (hash.length < 1) return;
console.log(hash);
const name = hash[0];
const selected = hash[1];
const graphId = `${name}`;

+ 2
- 1
server/package.json View File

@@ -7,5 +7,6 @@
"version": "1.0.0",
"repository": "https://git.pbb.lc/petabyteboy/bgpvis/",
"author": "Milan Pässler",
"license": "AGPL-3.0"
"license": "AGPL-3.0",
"bin": "index.js"
}

Loading…
Cancel
Save