# mhkeller/layercake architecture

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

- Interactive diagram: https://gitdiagram.com/mhkeller/layercake
- Repository: https://github.com/mhkeller/layercake

## Overview

##### Main Components Overview

a) Core Components:
- LayerCake Component (Central Wrapper)
- Layout Components (Svg, Html, Canvas, Webgl, ScaledSvg)
- Helper Functions
- Visualization Components

b) Data Flow System:
- Props/Configuration
- Scale Calculations
- Rendering Pipeline

**[User Application]**
- ↓
**[LayerCake Wrapper Component]**
- ↓
**┌──────────────────────────────────┐**
- Layout Components         │
- ┬──────────┬────────────┤
- Svg   │  Canvas  │    Html    │
- ┴──────────┴────────────┘
- ↓           ↓           ↓
**[Visualization Components Library]**
- ↓
**[Helper Functions & Utilities]**

##### Detailed Component Relationships

**[Data Input] → [LayerCake Props]**
- ↓
**┌─────────────────────────────────┐**
- Scale & Domain Handlers     │
- ┤
- calcDomain                    │
- createScale                   │
- calcScaleExtents             │
- ┘
- ↓
**┌─────────────────────────────────┐**
- Rendering Containers       │
- ┬──────────┬──────────┤
- SVG    │  Canvas  │   HTML   │
- Context  │ Context  │ Context  │
- ┴──────────┴──────────┘
- ↓
**┌─────────────────────────────────┐**
- Visualization Components     │
- ┤
- Charts (Line, Bar, etc.)     │
- Axes                         │
- Annotations                  │
- ┘

##### Implementation Details

How the following key features are connected:
- Scale Management
- Component Communication
- Layout System
- Helper Functions
- Visualization Components

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "User Application"
        UA[User Application]:::user
    end

    subgraph "LayerCake Core"
        LC["LayerCake Component"]:::core
        click LC "https://github.com/mhkeller/layercake/blob/main/src/lib/LayerCake.svelte"
    end

    subgraph "Layout Components"
        SL["SVG Layout"]:::layout
        HL["HTML Layout"]:::layout
        CL["Canvas Layout"]:::layout
        WL["WebGL Layout"]:::layout
        SSL["Scaled SVG Layout"]:::layout
        click SL "https://github.com/mhkeller/layercake/blob/main/src/lib/layouts/Svg.svelte"
        click HL "https://github.com/mhkeller/layercake/blob/main/src/lib/layouts/Html.svelte"
        click CL "https://github.com/mhkeller/layercake/blob/main/src/lib/layouts/Canvas.svelte"
        click WL "https://github.com/mhkeller/layercake/blob/main/src/lib/layouts/Webgl.svelte"
        click SSL "https://github.com/mhkeller/layercake/blob/main/src/lib/layouts/ScaledSvg.svelte"
    end

    subgraph "Scale & Domain Processing"
        CD["Calc Domain"]:::scale
        CS["Create Scale"]:::scale
        CSE["Calc Scale Extents"]:::scale
        FST["Find Scale Type"]:::scale
        click CD "https://github.com/mhkeller/layercake/blob/main/src/lib/helpers/calcDomain.js"
        click CS "https://github.com/mhkeller/layercake/blob/main/src/lib/helpers/createScale.js"
        click CSE "https://github.com/mhkeller/layercake/blob/main/src/lib/helpers/calcScaleExtents.js"
        click FST "https://github.com/mhkeller/layercake/blob/main/src/lib/helpers/findScaleType.js"
    end

    subgraph "Helper Functions"
        CG["Create Getter"]:::helper
        PF["Pad Functions"]:::helper
        GR["Get Range"]:::helper
        IOD["Is Ordinal Domain"]:::helper
        click CG "https://github.com/mhkeller/layercake/blob/main/src/lib/helpers/createGetter.js"
        click PF "https://github.com/mhkeller/layercake/blob/main/src/lib/helpers/getPadFunctions.js"
        click GR "https://github.com/mhkeller/layercake/blob/main/src/lib/helpers/getRange.js"
        click IOD "https://github.com/mhkeller/layercake/blob/main/src/lib/helpers/isOrdinalDomain.js"
    end

    subgraph "Data Processing"
        CE["Calc Extents"]:::data
        FL["Flatten"]:::data
        ST["Stack"]:::data
        UN["Uniques"]:::data
        click CE "https://github.com/mhkeller/layercake/blob/main/src/lib/lib/calcExtents.js"
        click FL "https://github.com/mhkeller/layercake/blob/main/src/lib/lib/flatten.js"
        click ST "https://github.com/mhkeller/layercake/blob/main/src/lib/lib/stack.js"
        click UN "https://github.com/mhkeller/layercake/blob/main/src/lib/lib/uniques.js"
    end

    subgraph "Visualization Components"
        LC1["Line Charts"]:::viz
        BC["Bar Charts"]:::viz
        SP["Scatter Plots"]:::viz
        AC["Area Charts"]:::viz
        click LC1 "https://github.com/mhkeller/layercake/blob/main/src/_components/Line.svelte"
        click BC "https://github.com/mhkeller/layercake/blob/main/src/_components/Bar.svelte"
        click SP "https://github.com/mhkeller/layercake/blob/main/src/_components/Scatter.svelte"
        click AC "https://github.com/mhkeller/layercake/blob/main/src/_components/Area.svelte"
    end

    subgraph "Default Settings"
        DS["Default Scales"]:::settings
        DR["Default Range"]:::settings
        click DS "https://github.com/mhkeller/layercake/blob/main/src/lib/settings/defaultScales.js"
        click DR "https://github.com/mhkeller/layercake/blob/main/src/lib/settings/getDefaultRange.js"
    end

    %% Relationships
    UA --> LC
    LC --> SL & HL & CL & WL & SSL
    LC --> CD & CS & CSE & FST
    LC --> CG & PF & GR & IOD
    LC --> CE & FL & ST & UN
    SL & HL & CL & WL & SSL --> LC1 & BC & SP & AC
    CD & CS --> DS
    GR --> DR

    %% Styles
    classDef user fill:#9370DB
    classDef core fill:#4169E1
    classDef layout fill:#3CB371
    classDef scale fill:#FF8C00
    classDef helper fill:#CD853F
    classDef data fill:#20B2AA
    classDef viz fill:#4682B4
    classDef settings fill:#778899

    %% Legend
    subgraph Legend
        L1[User Application]:::user
        L2[Core Component]:::core
        L3[Layout Components]:::layout
        L4[Scale Processing]:::scale
        L5[Helper Functions]:::helper
        L6[Data Processing]:::data
        L7[Visualization]:::viz
        L8[Settings]:::settings
    end
```
