# valor-software/ng2-charts architecture

> Architecture diagram of the GitHub repository valor-software/ng2-charts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/valor-software/ng2-charts
- Repository: https://github.com/valor-software/ng2-charts

## Overview

##### Project Type & Purpose
- This is a front-end library intended for Angular developers to integrate Chart.js charts easily.
- It contains three main parts: (a) the core library (in libs/ng2-charts), (b) Angular schematics support (in libs/ng2-charts-schematics) for smooth project integration, and (c) a demo application (in apps/ng2-charts-demo) that exhibits all available chart types and usage samples.

##### Main Components
- External Dependency: Chart.js – highlight that this is a peer dependency required by ng2-charts.
- Core Library:
- Base Chart Directive: The directive (BaseChartDirective) that abstracts all chart types.
- Theme & Provider Services: Components like ThemeService and the configuration provided by provideCharts or similar configuration methods.
- Chart Types Implementations: Components and services for different chart types (line, bar, radar, pie, doughnut, bubble, scatter, polar-area) located in the library’s source code.
- Schematics:
- Angular CLI schematic support found under libs/ng2-charts-schematics. This module helps automatically install and configure the library within a consuming Angular application.
- Demo Application:
- The Angular demo app (apps/ng2-charts-demo) which includes multiple components for each chart type (bar-chart, line-chart, bubble-chart, etc.) to demonstrate usage, testing files, and configuration (with its own e2e and unit test setups).

##### Relationships & Interactions
- The Demo Application imports and uses the Core Library’s directives/components.
- The Demo Application configures the Charts provider (via main.ts or app configurations) to register Chart.js with default or minimal configurations.
- That the various Angular components (each chart type) in the demo are consuming the Base Chart Directive.

##### Architectural Patterns & Design Principles
- Component-Based Architecture: Since it is in Angular, emphasize the separation between UI components (chart components) and services (theme configuration, chart providers).
- Modularization: The code is split between a demo application, a core library, and schematics – a good example of separation of concerns.
- Dependency Injection: Especially regarding how the provider for charts (via provideCharts and related configurations) is added across the app.
- Testing & Continuous Integration: Note the presence of Jest, ESLint, Prettier, and GitHub workflows which show best practices in maintaining code quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Library (ng2-charts)"
        C1["BaseChartDirective"]:::core
        C2["ThemeService"]:::core
        C3["NgChartsProvider"]:::core
    end

    subgraph "Schematics (ng2-charts-schematics)"
        S1["Schematic Setup (ng-add)"]:::schematic
        S2["Add Ng2-Charts Provider"]:::schematic
    end

    subgraph "Demo Application (ng2-charts-demo)"
        D1["Bar Chart Component"]:::demo
        D2["Line Chart Component"]:::demo
        D3["Other Chart Components"]:::demo
    end

    E["Peer Dependency: Chart.js"]:::external

    %% Relationships
    D1 -->|"consumes"| C1
    D2 -->|"consumes"| C1
    D3 -->|"consumes"| C1

    C2 -->|"configures"| C1
    C3 -->|"injects"| C1

    S1 -->|"integrates"| C1
    S2 -->|"updates"| C3

    C1 -->|"requires"| E

    %% Click Events for Core Library
    click C1 "https://github.com/valor-software/ng2-charts/blob/master/libs/ng2-charts/src/lib/base-chart.directive.ts"
    click C2 "https://github.com/valor-software/ng2-charts/blob/master/libs/ng2-charts/src/lib/theme.service.ts"
    click C3 "https://github.com/valor-software/ng2-charts/blob/master/libs/ng2-charts/src/lib/ng-charts.provider.ts"

    %% Click Events for Schematics
    click S1 "https://github.com/valor-software/ng2-charts/blob/master/libs/ng2-charts-schematics/src/ng-add/index.ts"
    click S2 "https://github.com/valor-software/ng2-charts/blob/master/libs/ng2-charts-schematics/src/ng-add/steps/add-ng2-charts-provider.ts"

    %% Click Events for Demo Application
    click D1 "https://github.com/valor-software/ng2-charts/tree/master/apps/ng2-charts-demo/src/app/bar-chart"
    click D2 "https://github.com/valor-software/ng2-charts/tree/master/apps/ng2-charts-demo/src/app/line-chart"
    click D3 "https://github.com/valor-software/ng2-charts/tree/master/apps/ng2-charts-demo"

    %% Styles
    classDef core fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef schematic fill:#aed6f1,stroke:#1b4f72,stroke-width:2px;
    classDef demo fill:#d5f5e3,stroke:#196f3d,stroke-width:2px;
    classDef external fill:#fadbd8,stroke:#922b21,stroke-width:2px;
```
