Skip to content

Commit 79fd9b3

Browse files
pgallinoManuel-Pol
andauthored
Split graphs (#27)
Split Graphs This update divides the graph functionality into two distinct components: DataGraph and ViewGraph. DataGraph is solely responsible for maintaining the entire network’s information, while ViewGraph handles the creation, updating, and removal of device and edge drawings in the view. Additionally, this update introduces new features: - Functionality to delete nodes and edges. - Ability to click edges. Closes #16 Closes #20 --------- Co-authored-by: Manuel <[email protected]>
1 parent b82497e commit 79fd9b3

File tree

10 files changed

+1141
-779
lines changed

10 files changed

+1141
-779
lines changed

package-lock.json

Lines changed: 254 additions & 325 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{
22
"dependencies": {
33
"pixi-viewport": "^5.0.3",
4-
"pixi.js": "8.4.1"
4+
"pixi.js": "^8.4.1"
55
},
66
"name": "netsim",
77
"version": "1.0.0",
88
"private": true,
99
"devDependencies": {
10-
"@eslint/js": "^9.12.0",
10+
"@eslint/js": "^9.14.0",
1111
"@types/eslint__js": "^8.42.3",
12-
"@types/jest": "^29.5.13",
12+
"@types/jest": "^29.5.14",
13+
"@types/pixi.js": "^5.0.0",
1314
"css-loader": "7.1.2",
14-
"eslint": "^9.12.0",
15+
"eslint": "^9.14.0",
1516
"html-webpack-plugin": "5.6.0",
1617
"inline-source-map": "0.6.3",
17-
"prettier": "3.3.3",
1818
"jest": "^29.7.0",
19+
"prettier": "3.3.3",
1920
"style-loader": "4.0.0",
2021
"ts-jest": "^29.2.5",
2122
"ts-loader": "9.5.1",
22-
"typescript": "5.6.2",
23-
"typescript-eslint": "^8.8.1",
23+
"typescript": "^5.6.2",
24+
"typescript-eslint": "^8.13.0",
2425
"webpack": "5.94.0",
2526
"webpack-cli": "5.1.4",
2627
"webpack-dev-server": "^5.1.0"

src/index.ejs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
<div class="canvas-container">
1919
<canvas id="canvas"></canvas>
2020
<select id="layer-select" class="dropdown-menu">
21-
<option value="application">Capa de Aplicación</option>
22-
<option value="transport">Capa de Transporte</option>
23-
<option value="network">Capa de Red</option>
24-
<option value="link">Capa de Enlace</option>
21+
<option value="application">App Layer</option>
22+
<option value="transport">Transport Layer</option>
23+
<option value="network">Network Layer</option>
24+
<option value="link">Link Layer</option>
2525
</select>
2626
</div>
2727
<div id="right-bar" class="right-bar">
28-
<h2>Información</h2>
28+
<h2>Information</h2>
2929
<div id="info-content">
3030
<!-- Información dinámica sobre el conejo y los routers se mostrará aquí -->
3131
</div>

src/index.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import ComputerSvg from "./assets/pc.svg";
99
import { Application, Graphics, EventSystem, Assets } from "pixi.js";
1010

1111
import * as pixi_viewport from "pixi-viewport";
12-
import { NetworkGraph } from "./types/networkgraph";
12+
import { ViewGraph } from "./types/graphs/viewgraph";
1313
import {
1414
AddPc,
1515
AddRouter,
1616
AddServer,
1717
loadGraph,
1818
saveGraph,
1919
} from "./types/viewportManager";
20+
import { DataGraph } from "./types/graphs/datagraph";
2021

2122
const WORLD_WIDTH = 10000;
2223
const WORLD_HEIGHT = 10000;
@@ -25,18 +26,25 @@ const WORLD_HEIGHT = 10000;
2526

2627
export class GlobalContext {
2728
private viewport: Viewport = null;
28-
private network: NetworkGraph = new NetworkGraph();
29+
private datagraph: DataGraph;
30+
private viewgraph: ViewGraph;
2931

3032
initialize(viewport: Viewport) {
3133
this.viewport = viewport;
34+
this.datagraph = new DataGraph();
35+
this.viewgraph = new ViewGraph(this.datagraph, this.viewport);
3236
}
3337

3438
getViewport() {
3539
return this.viewport;
3640
}
3741

38-
getNetwork() {
39-
return this.network;
42+
getViewGraph() {
43+
return this.viewgraph;
44+
}
45+
46+
getDataGraph() {
47+
return this.datagraph;
4048
}
4149
}
4250

@@ -141,7 +149,6 @@ class RightBar {
141149

142150
// IIFE to avoid errors
143151
(async () => {
144-
// Obtener el ancho y alto de las barras laterales y superior
145152
const lBar = document.getElementById("left-bar");
146153
const rBar = document.getElementById("right-bar");
147154
const tBar = document.getElementById("top-bar");
@@ -152,7 +159,7 @@ class RightBar {
152159
width: window.innerWidth,
153160
height: window.innerHeight,
154161
resolution: window.devicePixelRatio || 1,
155-
autoDensity: true, // Ajusta la densidad para pantallas de alta resolución
162+
autoDensity: true,
156163
});
157164

158165
const canvasPlaceholder = document.getElementById("canvas");
@@ -173,17 +180,17 @@ class RightBar {
173180

174181
// Add router button
175182
leftBar.addButton(RouterSvg, () => {
176-
AddRouter(ctx); // Esta es una función anónima que ejecuta AddRouter cuando se hace clic
183+
AddRouter(ctx);
177184
});
178185

179186
// Add server button
180187
leftBar.addButton(ServerSvg, () => {
181-
AddServer(ctx); // Función anónima que ejecuta AddServer cuando se hace clic
188+
AddServer(ctx);
182189
});
183190

184191
// // Add PC button
185192
leftBar.addButton(ComputerSvg, () => {
186-
AddPc(ctx); // Función anónima que ejecuta AddPc cuando se hace clic
193+
AddPc(ctx);
187194
});
188195

189196
// Get right bar
@@ -197,16 +204,13 @@ class RightBar {
197204

198205
// Resize logic
199206
function resize() {
200-
// Obtener los tamaños actuales de las barras desde el DOM
201-
const leftBarWidth = lBar ? lBar.offsetWidth : 100; // Ancho actual de la barra izquierda
202-
const rightBarWidth = rBar ? rBar.offsetWidth : 250; // Ancho actual de la barra derecha
203-
const topBarHeight = tBar ? tBar.offsetHeight : 40; // Altura actual de la barra superior
207+
const leftBarWidth = lBar ? lBar.offsetWidth : 100;
208+
const rightBarWidth = rBar ? rBar.offsetWidth : 250;
209+
const topBarHeight = tBar ? tBar.offsetHeight : 40;
204210

205-
// Calcular el nuevo tamaño del canvas
206211
const newWidth = window.innerWidth - leftBarWidth - rightBarWidth;
207212
const newHeight = window.innerHeight - topBarHeight;
208213

209-
// Redimensionar el renderer y el viewport de Pixi.js
210214
app.renderer.resize(newWidth, newHeight);
211215
viewport.resize(newWidth, newHeight);
212216
}
@@ -215,16 +219,13 @@ class RightBar {
215219

216220
window.addEventListener("resize", resize);
217221

218-
// Gestión de los botones de carga y guardado
219222
const loadButton = document.getElementById("load-button");
220223
const saveButton = document.getElementById("save-button");
221224

222-
// Función para manejar el botón de guardar
223225
saveButton.onclick = () => {
224-
saveGraph(ctx); // Llama a la función saveGraph pasando el contexto actual
226+
saveGraph(ctx);
225227
};
226228

227-
// Función para manejar el botón de cargar
228229
loadButton.onclick = () => {
229230
const input = document.createElement("input");
230231
input.type = "file";
@@ -237,11 +238,11 @@ class RightBar {
237238

238239
reader.onload = (readerEvent) => {
239240
const jsonData = readerEvent.target.result as string;
240-
loadGraph(jsonData, ctx); // Llama a la función loadGraph pasando el JSON y el contexto
241+
loadGraph(jsonData, ctx);
241242
};
242243
};
243244

244-
input.click(); // Simula el click para abrir el cuadro de diálogo de selección de archivo
245+
input.click();
245246
};
246247

247248
console.log("initialized!");

0 commit comments

Comments
 (0)