Skip to content

πŸ”΅ Node

Bart edited this page Jun 19, 2024 · 2 revisions

File: Meesterproef-SNSimulation/js/Node.js

Description

The Node class represents a node in the network. It serves as a base class for other types of nodes, such as Person and Post. The Node class includes methods for drawing the node, handling links, and managing interactions.

Methods

  • constructor(id, label, x, y, radius): Initializes a new instance of the Node class.

    • Parameters:
      • id (number): The unique identifier for the node.
      • label (string): The label for the node (e.g., "Person", "Social Media Post").
      • x (number): The x-coordinate of the node.
      • y (number): The y-coordinate of the node.
      • radius (number): The radius of the node.
    • View Code
  • draw(): Draws the node on the canvas, creating a DOM element and positioning it based on the node's coordinates.

    • Returns: HTMLElement - The created node element.
    • View Code
  • linkHandler(node, links, filteredEdges): Handles link actions based on the type of node. Calls either friendsHandler or itemHandler.

    • Parameters:
      • node (Node): The node to link with.
      • links (Map): The map of links in the network.
      • filteredEdges (Array): The list of filtered edges.
    • View Code
  • friendsHandler(node, links): Handles friend actions, adding or removing friends.

    • Parameters:
      • node (Node): The node to handle as a friend.
      • links (Map): The map of links in the network.
    • View Code
  • itemHandler(node, links, filteredEdges): Handles item actions, adding or removing item links.

    • Parameters:
      • node (Node): The node to handle as an item.
      • links (Map): The map of links in the network.
      • filteredEdges (Array): The list of filtered edges.
    • View Code

Design rational

Clone this wiki locally