feat: added mass and scale

This commit is contained in:
əlemi 2023-10-03 04:45:13 +02:00
parent e1e80a717d
commit 48195cdeb3
2 changed files with 8 additions and 6 deletions

7
dist/index.html vendored
View file

@ -47,8 +47,8 @@
'#05979A', '#05979A',
] ]
for (const i in graph.nodes) { for (const i in graph.nodes) {
if (graph.nodes[i].label === domain) graph.nodes[i].color = '#BF616A'; if (graph.nodes[i].label === domain) { graph.nodes[i].color = '#BF616A' }
else graph.nodes[i].color = palette[Math.floor(Math.random() * palette.length)];; else { graph.nodes[i].color = palette[Math.floor(Math.random() * palette.length)] }
} }
const nodes = new vis.DataSet(graph.nodes); const nodes = new vis.DataSet(graph.nodes);
@ -60,9 +60,8 @@
nodes: nodes, nodes: nodes,
edges: edges, edges: edges,
}; };
const options = { edges: { dashes: true, arrows: 'to' }, nodes: { mass: 2, color: "#bf616a", shape: "box" }}; const options = { edges: { dashes: true, arrows: 'to' }, nodes: { color: "#bf616a", shape: "box", scaling: { min: 1, max: 500, label: { enabled: true, min: 14, max: 56 }}}};
const network = new vis.Network(container, data, options); const network = new vis.Network(container, data, options);
document.getElementById("loader").remove();
})) }))
</script> </script>
</body> </body>

View file

@ -1,4 +1,4 @@
use std::{collections::{HashSet, HashMap}, sync::Arc}; use std::{collections::HashMap, sync::Arc};
use serde::Serialize; use serde::Serialize;
use tokio::sync::{mpsc, RwLock}; use tokio::sync::{mpsc, RwLock};
@ -38,7 +38,7 @@ impl MapCollector {
for (i, node) in nodes_domains.iter().enumerate() { for (i, node) in nodes_domains.iter().enumerate() {
nodes_map.insert( nodes_map.insert(
node.domain.clone(), node.domain.clone(),
Node { id: i, label: node.domain.clone(), title: node.name.clone(), value: 1 } Node { id: i, label: node.domain.clone(), title: node.name.clone(), value: 1, mass: 1. }
); );
} }
@ -46,6 +46,7 @@ impl MapCollector {
let from = { let from = {
if let Some(node) = nodes_map.get_mut(&vertex.from) { if let Some(node) = nodes_map.get_mut(&vertex.from) {
node.value += 1; node.value += 1;
node.mass += 0.1;
node.id node.id
} else { } else {
tracing::warn!("vertex from nonexisting node {}", vertex.from); tracing::warn!("vertex from nonexisting node {}", vertex.from);
@ -56,6 +57,7 @@ impl MapCollector {
let to = { let to = {
if let Some(node) = nodes_map.get_mut(&vertex.to) { if let Some(node) = nodes_map.get_mut(&vertex.to) {
node.value += 10; node.value += 10;
node.mass += 1.;
node.id node.id
} else { } else {
tracing::warn!("vertex to nonexisting node {}", vertex.to); tracing::warn!("vertex to nonexisting node {}", vertex.to);
@ -120,6 +122,7 @@ pub struct Node {
pub id: usize, pub id: usize,
pub label: String, pub label: String,
pub value: usize, pub value: usize,
pub mass: f32,
pub title: String, pub title: String,
} }