From 48195cdeb375607841896c1c3e3708cb16f6ed5d Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 3 Oct 2023 04:45:13 +0200 Subject: [PATCH] feat: added mass and scale --- dist/index.html | 7 +++---- src/model.rs | 7 +++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dist/index.html b/dist/index.html index 55d24b4..2766e18 100644 --- a/dist/index.html +++ b/dist/index.html @@ -47,8 +47,8 @@ '#05979A', ] for (const i in graph.nodes) { - if (graph.nodes[i].label === domain) graph.nodes[i].color = '#BF616A'; - else graph.nodes[i].color = palette[Math.floor(Math.random() * palette.length)];; + if (graph.nodes[i].label === domain) { graph.nodes[i].color = '#BF616A' } + else { graph.nodes[i].color = palette[Math.floor(Math.random() * palette.length)] } } const nodes = new vis.DataSet(graph.nodes); @@ -60,9 +60,8 @@ nodes: nodes, 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); - document.getElementById("loader").remove(); })) diff --git a/src/model.rs b/src/model.rs index d402e33..1a6b9f9 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1,4 +1,4 @@ -use std::{collections::{HashSet, HashMap}, sync::Arc}; +use std::{collections::HashMap, sync::Arc}; use serde::Serialize; use tokio::sync::{mpsc, RwLock}; @@ -38,7 +38,7 @@ impl MapCollector { for (i, node) in nodes_domains.iter().enumerate() { nodes_map.insert( 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 = { if let Some(node) = nodes_map.get_mut(&vertex.from) { node.value += 1; + node.mass += 0.1; node.id } else { tracing::warn!("vertex from nonexisting node {}", vertex.from); @@ -56,6 +57,7 @@ impl MapCollector { let to = { if let Some(node) = nodes_map.get_mut(&vertex.to) { node.value += 10; + node.mass += 1.; node.id } else { tracing::warn!("vertex to nonexisting node {}", vertex.to); @@ -120,6 +122,7 @@ pub struct Node { pub id: usize, pub label: String, pub value: usize, + pub mass: f32, pub title: String, }