# saehm/hagrid architecture

> Architecture diagram of the GitHub repository saehm/hagrid, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saehm/hagrid
- Repository: https://github.com/saehm/hagrid

## Overview

Hagrid is a TypeScript library for reducing scatterplot overlap: a caller supplies 2D points and selects a layout, then receives distinct grid-cell positions (or, for CMDS, intermediate layouts and a final snapped result). Its principal path is the public API through the method dispatcher into one of seven techniques. The README documents all seven methods and their differing coordinate spaces. The dispatcher’s imports and calls are visible; utility use is supported by the source index. Other implementation details were not sampled, so no further internal links are inferred.

Main entry points: [`src/gridify.ts`](https://github.com/saehm/hagrid/blob/master/src/gridify.ts) (Layout dispatcher), [`src/utils.ts`](https://github.com/saehm/hagrid/blob/master/src/utils.ts) (Geometry utilities), [`src/main.ts`](https://github.com/saehm/hagrid/blob/master/src/main.ts) (Public exports), [`src/hilbert.ts`](https://github.com/saehm/hagrid/blob/master/src/hilbert.ts) (Hilbert curve)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_entry["Public exports<br/>[main.ts]"]
  node_dispatcher["Layout dispatcher<br/>[gridify.ts]"]
  node_utils["Geometry utilities<br/>[utils.ts]"]
end

subgraph group_curves["Curve layouts"]
  node_hilbert["Hilbert curve<br/>[hilbert.ts]"]
  node_gilbert["Gilbert curve<br/>[gilbert.ts]"]
  node_gosper["Gosper curve<br/>[gosper.ts]"]
end

subgraph group_methods["Grid methods"]
  node_dgrid["DGrid layout<br/>[dgrid.ts]"]
  node_cmds["CMDS layout<br/>[cmds.ts]"]
  node_nmap["NMap layout<br/>[nmap.ts]"]
  node_gridfit["GridFit layout<br/>[gridfit.ts]"]
end

node_caller(("Library caller"))
node_positions["Grid positions"]
node_delaunay["d3-delaunay"]

node_caller -->|"calls API"| node_entry
node_entry -->|"exports"| node_dispatcher
node_caller -->|"selects layout"| node_dispatcher
node_dispatcher -->|"returns positions"| node_positions
node_dispatcher -->|"dispatches"| node_hilbert
node_dispatcher -->|"dispatches"| node_gilbert
node_dispatcher -->|"dispatches"| node_gosper
node_dispatcher -->|"dispatches"| node_dgrid
node_dispatcher -->|"dispatches"| node_cmds
node_dispatcher -->|"dispatches"| node_nmap
node_dispatcher -->|"dispatches"| node_gridfit
node_hilbert -->|"uses scales"| node_utils
node_gilbert -->|"gets bounds"| node_utils
node_nmap -->|"gets bounds"| node_utils
node_cmds -->|"builds proximity graph"| node_delaunay

click node_entry "https://github.com/saehm/hagrid/blob/master/src/main.ts"
click node_dispatcher "https://github.com/saehm/hagrid/blob/master/src/gridify.ts"
click node_hilbert "https://github.com/saehm/hagrid/blob/master/src/hilbert.ts"
click node_gilbert "https://github.com/saehm/hagrid/blob/master/src/gilbert.ts"
click node_gosper "https://github.com/saehm/hagrid/blob/master/src/gosper.ts"
click node_dgrid "https://github.com/saehm/hagrid/blob/master/src/dgrid.ts"
click node_cmds "https://github.com/saehm/hagrid/blob/master/src/cmds.ts"
click node_nmap "https://github.com/saehm/hagrid/blob/master/src/nmap.ts"
click node_gridfit "https://github.com/saehm/hagrid/blob/master/src/gridfit.ts"
click node_utils "https://github.com/saehm/hagrid/blob/master/src/utils.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_dispatcher,node_utils toneBlue
class node_hilbert,node_gilbert,node_gosper toneAmber
class node_dgrid,node_cmds,node_nmap,node_gridfit toneMint
class node_caller,node_positions,node_delaunay toneIndigo
```

## Components

### Public API

- [Public exports](https://github.com/saehm/hagrid/blob/master/src/main.ts): `src/main.ts`
- [Layout dispatcher](https://github.com/saehm/hagrid/blob/master/src/gridify.ts): `src/gridify.ts`
- [Geometry utilities](https://github.com/saehm/hagrid/blob/master/src/utils.ts): `src/utils.ts`

### Curve layouts

- [Hilbert curve](https://github.com/saehm/hagrid/blob/master/src/hilbert.ts): `src/hilbert.ts`
- [Gilbert curve](https://github.com/saehm/hagrid/blob/master/src/gilbert.ts): `src/gilbert.ts`
- [Gosper curve](https://github.com/saehm/hagrid/blob/master/src/gosper.ts): `src/gosper.ts`

### Grid methods

- [DGrid layout](https://github.com/saehm/hagrid/blob/master/src/dgrid.ts): `src/dgrid.ts`
- [CMDS layout](https://github.com/saehm/hagrid/blob/master/src/cmds.ts): `src/cmds.ts`
- [NMap layout](https://github.com/saehm/hagrid/blob/master/src/nmap.ts): `src/nmap.ts`
- [GridFit layout](https://github.com/saehm/hagrid/blob/master/src/gridfit.ts): `src/gridfit.ts`

### Other components

- **Library caller**
- **Grid positions**
- **d3-delaunay**

## Connections

- Library caller → Public exports: calls API (evidence: `README.md`)
- Public exports → Layout dispatcher: exports (evidence: `src/main.ts`)
- Library caller → Layout dispatcher: selects layout (evidence: `README.md`)
- Layout dispatcher → Grid positions: returns positions (evidence: `README.md`)
- Layout dispatcher → Hilbert curve: dispatches (evidence: `src/gridify.ts`)
- Layout dispatcher → Gilbert curve: dispatches (evidence: `src/gridify.ts`)
- Layout dispatcher → Gosper curve: dispatches (evidence: `src/gridify.ts`)
- Layout dispatcher → DGrid layout: dispatches (evidence: `src/gridify.ts`)
- Layout dispatcher → CMDS layout: dispatches (evidence: `src/gridify.ts`)
- Layout dispatcher → NMap layout: dispatches (evidence: `src/gridify.ts`)
- Layout dispatcher → GridFit layout: dispatches (evidence: `src/gridify.ts`)
- Hilbert curve → Geometry utilities: uses scales (evidence: `src/hilbert.ts`)
- Gilbert curve → Geometry utilities: gets bounds (evidence: `src/gilbert.ts`)
- NMap layout → Geometry utilities: gets bounds (evidence: `src/nmap.ts`)
- CMDS layout → d3-delaunay: builds proximity graph (evidence: `src/cmds.ts`)
