Skip to content

Displaying Node IDs for Better Usability #28

@RTQS1792

Description

@RTQS1792

Issue: Displaying Node IDs for Better Usability

Reason:

Without knowing the node ID, it will be difficult for users to initialize nodes to their desired positions.

Optional Solution:

Changes in pygame_engine.py:

  1. Line 43: Add a variable to control drawing of node IDs:

    self.draw_node_id = False
  2. Line 161: Pass the self.draw_node_id as an additional parameter to the draw_graph function:

    self._graph_visual.draw_graph(self._screen, self.draw_node_id)

Changes in graph_visual.py:

  1. Line 77: Update the draw_graph function to accept a draw_id parameter:

    def draw_graph(self, screen, draw_id=False):
        """Draw the entire graph (edges and nodes)."""
        self.screen = screen
        for edge in self.graph.edges.values():
            self.draw_edge(screen, edge)
        for node in self.graph.nodes.values():
            self.draw_node(screen, node, draw_id=draw_id)
  2. Line 48: Modify the draw_node function to optionally render the node ID:

    def draw_node(self, screen, node, color=(90, 90, 90), draw_id=False):
        """Draw a node as a circle with a light greenish color."""
        position = (node.x, node.y)
        (x, y) = self.ScalePositionToScreen(position)
        pygame.draw.circle(screen, color, (int(x), int(y)), 4)
        
        # Draw node ID if draw_id is True
        if draw_id:
            font = pygame.font.Font(None, 15)
            text = font.render(str(node.id), True, (0, 0, 0))
            text_rect = text.get_rect(center=(int(x), int(y) + 10))
            screen.blit(text, text_rect)

Usage in game.py:

Directly enable node ID display:

ctx.visual.draw_node_id = True

Note:

This modification may significantly slow down the rendering speed for the simulation. However, it is necessary to allow users to retrieve node IDs for config.py setup.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions