@@ -9,14 +9,15 @@ import ComputerSvg from "./assets/pc.svg";
99import { Application , Graphics , EventSystem , Assets } from "pixi.js" ;
1010
1111import * as pixi_viewport from "pixi-viewport" ;
12- import { NetworkGraph } from "./types/networkgraph " ;
12+ import { ViewGraph } from "./types/graphs/viewgraph " ;
1313import {
1414 AddPc ,
1515 AddRouter ,
1616 AddServer ,
1717 loadGraph ,
1818 saveGraph ,
1919} from "./types/viewportManager" ;
20+ import { DataGraph } from "./types/graphs/datagraph" ;
2021
2122const WORLD_WIDTH = 10000 ;
2223const WORLD_HEIGHT = 10000 ;
@@ -25,18 +26,25 @@ const WORLD_HEIGHT = 10000;
2526
2627export 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