util.ts


Overview

The util.ts file provides utility classes and functions primarily focused on processing and organizing graph nodes and edges into groups called "combos." It includes:

This file is intended for use in applications dealing with graph data structures, where nodes are grouped into clusters (combos) based on connectivity or community membership. It helps prepare data for visualization or further graph processing.


Classes and Functions

Class: KeyGenerator

A utility class that generates sequential single-character keys ('a' to 'z').

Properties

Name

Type

Description

idx

number

Current index of the key generator (starts at 0).

chars

string[]

Array of characters from 'a' to 'z'.

Constructor

constructor()

Initializes the chars array with all lowercase English letters ('a' to 'z').

Methods


Class: Converter

Processes graph nodes and edges to assign nodes into combos based on edge connectivity.

Properties

Name

Type

Description

keyGenerator

KeyGenerator

Instance of KeyGenerator to assign combo keys.

dict

Record<string, string>

Maps node IDs to their combo key.

Constructor

constructor()

Initializes a new KeyGenerator and an empty dict.

Methods


Function: isDataExist

Checks if valid graph data exists within an input object.

export const isDataExist = (data: any) => boolean

Usage example:

if (isDataExist(response)) {
  // proceed with processing graph data
}

Function: buildNodesAndCombos

Creates combos based on a node's communities property and assigns nodes to these combos.

export const buildNodesAndCombos = (nodes: any[]) => { nodes: any[]; combos: any[] }

Implementation detail:

Usage example:

const nodes = [
  { id: '1', communities: ['group1', 'group2'] },
  { id: '2', communities: ['group1'] },
];
const { nodes: newNodes, combos } = buildNodesAndCombos(nodes);

Helper Function: findCombo

Extracts the first community label from an array.

const findCombo = (communities: string[]) => string | undefined

Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

flowchart TD
    A[KeyGenerator] -->|generateKey| B[Converter]
    B -->|buildDict(edges)| C[dict: nodeId -> comboKey]
    B -->|buildNodesAndCombos(nodes, edges)| D[Output: nodes with combos + combos array]
    E[buildNodesAndCombos(nodes)] --> F[Build combos by community]
    F --> G[Output: nodes with combo UUID + combos with UUID]
    H[isDataExist(data)] -->|validates| I[Graph data presence check]

    style A fill:#f9f,stroke:#333,stroke-width:1px
    style B fill:#ccf,stroke:#333,stroke-width:1px
    style E fill:#cfc,stroke:#333,stroke-width:1px
    style H fill:#ffc,stroke:#333,stroke-width:1px

Summary

The util.ts file encapsulates utilities that convert graph nodes and edges into grouped combos, facilitating cluster identification based on either graph connectivity or community membership. It provides both class-based and functional interfaces for flexible usage depending on input data format. The file's design supports modular graph data preparation for visualization or analysis components in larger applications.