22
33import warnings
44from typing import Any , Callable
5- from net_vis .models import Node , Edge , GraphLayer
5+
6+ import networkx as nx
7+
8+ from ..models import Node , Edge , GraphLayer
69
710
811class NetworkXAdapter :
@@ -276,7 +279,6 @@ def _apply_spring_layout(graph: Any) -> dict[Any, tuple[float, float]]:
276279 Returns:
277280 Dictionary mapping node IDs to (x, y) positions
278281 """
279- import networkx as nx
280282 return nx .spring_layout (graph )
281283
282284 @staticmethod
@@ -293,14 +295,13 @@ def _apply_kamada_kawai_layout(graph: Any) -> dict[Any, tuple[float, float]]:
293295 ImportError: If scipy is not installed
294296 """
295297 try :
296- import scipy
298+ import scipy # noqa: F401
297299 except ImportError :
298300 raise ImportError (
299301 "Layout 'kamada_kawai' requires scipy. "
300302 "Install with: pip install net_vis[full]"
301303 )
302304
303- import networkx as nx
304305 return nx .kamada_kawai_layout (graph )
305306
306307 @staticmethod
@@ -317,14 +318,13 @@ def _apply_spectral_layout(graph: Any) -> dict[Any, tuple[float, float]]:
317318 ImportError: If scipy is not installed
318319 """
319320 try :
320- import scipy
321+ import scipy # noqa: F401
321322 except ImportError :
322323 raise ImportError (
323324 "Layout 'spectral' requires scipy. "
324325 "Install with: pip install net_vis[full]"
325326 )
326327
327- import networkx as nx
328328 return nx .spectral_layout (graph )
329329
330330 @staticmethod
@@ -337,7 +337,6 @@ def _apply_circular_layout(graph: Any) -> dict[Any, tuple[float, float]]:
337337 Returns:
338338 Dictionary mapping node IDs to (x, y) positions
339339 """
340- import networkx as nx
341340 return nx .circular_layout (graph )
342341
343342 @staticmethod
@@ -350,7 +349,6 @@ def _apply_random_layout(graph: Any) -> dict[Any, tuple[float, float]]:
350349 Returns:
351350 Dictionary mapping node IDs to (x, y) positions
352351 """
353- import networkx as nx
354352 return nx .random_layout (graph )
355353
356354 @staticmethod
@@ -397,15 +395,6 @@ def _compute_layout(
397395 Returns:
398396 Dictionary mapping node IDs to (x, y) positions
399397 """
400- # Import networkx here to avoid import errors if not installed
401- try :
402- import networkx as nx
403- except ImportError :
404- raise ImportError (
405- "NetworkX is required for graph layout computation. "
406- "Install it with: pip install networkx"
407- )
408-
409398 # Handle empty graphs
410399 if len (graph .nodes ()) == 0 :
411400 return {}
0 commit comments