How the Node Type to Treatment Matrix Is Defined in Diagram-Design

The Node Type to Treatment Matrix in cathrynlavery/diagram-design is defined as a centralized read-only constant NODE_TYPE_TREATMENT_MATRIX located in src/constants/nodeTypeTreatmentMatrix.ts that maps diagram node type strings to Treatment enum values, enabling consistent rendering logic across the application.

The cathrynlavery/diagram-design repository uses a declarative mapping system to control how different diagram nodes are rendered and processed. This system centers on the Node Type to Treatment Matrix, a single source of truth that associates each node type with a specific visual or behavioral treatment. By externalizing this mapping from the rendering logic, the codebase achieves a clean separation between node classification and presentation concerns.

How the Node Type to Treatment Matrix Is Structured

The matrix implementation relies on two core files: an enum that defines valid treatments and a constant that stores the actual mappings.

The Treatment Enum Definition

The values used in the matrix are defined in src/enums/treatment.ts as members of the Treatment enum. This enum declares how a node should be handled by the rendering engine, such as highlighting, dimming, or grouping.

The NODE_TYPE_TREATMENT_MATRIX Constant

In src/constants/nodeTypeTreatmentMatrix.ts, the matrix is declared as a Record<string, Treatment> that maps node type strings to their corresponding treatments. The definition follows this pattern:

import { Treatment } from '../enums/treatment';

export const NODE_TYPE_TREATMENT_MATRIX: Record<string, Treatment> = {
  process: Treatment.Highlight,
  decision: Treatment.Dim,
  dataStore: Treatment.Group,
  externalSystem: Treatment.Highlight,
  // …more node‑type entries
};

Each key represents a node type identifier (e.g., "process", "decision"), while the value is a treatment identifier drawn from the Treatment enum.

Implementing Lookup Logic with the Matrix

Utility functions in src/utils/nodeTreatment.ts consume the matrix to resolve treatments at runtime. The lookup implements a fallback strategy using the nullish coalescing operator to ensure every node receives a valid treatment even if its type is not explicitly registered.

import { NODE_TYPE_TREATMENT_MATRIX } from './constants/nodeTypeTreatmentMatrix';
import { Treatment } from './enums/treatment';

function getTreatmentForNode(nodeType: string): Treatment {
  return NODE_TYPE_TREATMENT_MATRIX[nodeType] ?? Treatment.Default;
}

// Usage
const treatment = getTreatmentForNode('decision'); // → Treatment.Dim

If a node type is missing from the Node Type to Treatment Matrix, the engine falls back to Treatment.Default, preventing rendering failures.

Rendering Nodes Using the Treatment Matrix

The rendering pipeline in src/render/renderer.ts relies on the matrix to determine drawing strategies. By querying the matrix during the render loop, the engine applies the correct visual treatment without hardcoding node-specific logic.

function renderNode(node) {
  const treatment = getTreatmentForNode(node.type);
  switch (treatment) {
    case Treatment.Highlight:
      drawHighlighted(node);
      break;
    case Treatment.Dim:
      drawDimmed(node);
      break;
    case Treatment.Group:
      drawGrouped(node);
      break;
    default:
      drawStandard(node);
  }
}

This design centralizes treatment logic, allowing the rendering code to remain generic while the Node Type to Treatment Matrix controls node-specific behavior.

Extending the Node Type to Treatment Matrix

You can extend the matrix with custom node types by importing the constant and adding new key-value pairs. This pattern is useful for project-specific extensions that introduce new node classifications without modifying core library files.

// In a project‑specific extension file
import { NODE_TYPE_TREATMENT_MATRIX } from '../constants/nodeTypeTreatmentMatrix';
import { Treatment } from '../enums/treatment';

NODE_TYPE_TREATMENT_MATRIX['customAnalytics'] = Treatment.Highlight;

Summary

Frequently Asked Questions

Where is the Node Type to Treatment Matrix stored?

The matrix is stored in src/constants/nodeTypeTreatmentMatrix.ts as a TypeScript constant that exports a Record<string, Treatment> mapping node type strings to treatment enum values.

What happens if a node type is not found in the matrix?

The lookup utility returns Treatment.Default as a fallback, ensuring the node still renders using standard styling rather than throwing a runtime error.

Can I add custom node types to the matrix?

Yes, you can import NODE_TYPE_TREATMENT_MATRIX from its constants file and assign new key-value pairs where the key is your custom node type string and the value is a valid Treatment enum member, such as Treatment.Highlight or Treatment.Group.

How does the renderer use the Treatment enum values?

The renderer calls helper functions like getTreatmentForNode to retrieve the treatment for a given node, then uses a switch statement to execute drawing logic specific to that treatment, such as calling drawHighlighted() for Treatment.Highlight or drawDimmed() for Treatment.Dim.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →