# wupeiwen/vue-g2 architecture

> Architecture diagram of the GitHub repository wupeiwen/vue-g2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wupeiwen/vue-g2
- Repository: https://github.com/wupeiwen/vue-g2

## Overview

Step 1: Identify the project type and purpose
- This is a Vue.js–based, open-source visual-component library (“vue-g2”) that wraps AntV/G2 charts into Vue components.
- It’s not a full server-backed app; rather it’s a frontend plugin/package that you install into a Vue or Nuxt project (or drop in via CDN) to get chart components (pie, line, bar, etc.).

Step 2: Analyze the file structure
- Top-level:
- package.json, babel.config.js, vue.config.js, Travis CI config → build & deployment
- README.md → documentation & usage
- public/index.html → demo page for local development
- src/
- main.js → entry point for the demo app
- components/g2Components/*.vue → one Vue component per chart type
- components/registerG2Components.js → plugin installer that globally registers all chart components
- mixins/chart.js → shared chart lifecycle logic & props
- utils/index.js → helper functions (data processing, theme defaults)
- No backend, DB, microservices, etc.

Step 3: Examine the README for additional insights
- Usage modes: Vue CLI plugin, Nuxt.js SSR plugin, CDN script
- Dependencies: @antv/g2, @antv/data-set
- Shows how the plugin registers components globally and how end-users embed `<g2-*>` tags.

a. Main components
1. End-user Application (Vue or Nuxt project)
2. vue-g2 Plugin
3. G2 Components Factory (registerG2Components.js)
4. Individual Chart Components (area.vue, pie.vue, line.vue, …)
5. Chart Mixin (chart.js) & Utils Module (index.js)
6. External Libraries: @antv/g2 & @antv/data-set
7. (Optional) CDN delivery layer

b. Relationships & interactions
- The Application imports/installs vue-g2.
- Plugin invokes registerG2Components.js → loops over chart components → calls `Vue.component('g2-xxx', xxxComponent)`
- Individual chart components mix in chart.js to share lifecycle hooks (beforeMount, mounted) that call G2 APIs.
- Utils module provides data transformations or style defaults before passing to G2 chart instance.
- Chart components invoke G2 to render into their `<canvas>` or `<svg>` container.
- In SSR (Nuxt), the plugin is loaded client-side only; in CDN mode, scripts load in sequence: Vue → G2 → Data-set → vue-g2.

c. Architectural patterns & design principles
- Plugin pattern (Vue.use)
- Component-based architecture
- Mixin for cross-cutting concerns (chart lifecycle)
- Single Responsibility: each `.vue` handles one chart type
- Progressive enhancement: supports direct `<script>` tag inclusion

d. Key technologies
- Vue.js (2.x) plugin system
- AntV/G2 chart engine
- @antv/data-set for data transformations
- Babel & Vue CLI (build pipeline)
- Travis CI (continuous integration)

- As an open-source frontend tool, emphasize:
- Core plugin installer → global component registration
- Component internals (mixin + utils → G2)
- Integration points: Vue CLI, Nuxt.js SSR, CDN
- Extension points: users can override props, supply custom data, slot in custom templates

- Labels: “App”, “vue-g2 Plugin”, “registerG2Components”, each “g2-xxx component”, “chart mixin”, “utils”, “@antv/g2”, “@antv/data-set”
- From App → Plugin install
- Plugin → registerG2Components → each component
- Component → Mixin → Utils → G2/Data-set

Step 7: Be as detailed as possible
- Build pipeline (babel → vue-cli) feeding into the package distributed via NPM or CDN.
- SSR plugin path vs. Vue CLI plugin path.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% End-user Application
    subgraph "End-user Application"
        direction TB
        A1["public/index.html"]:::code
        A2["src/main.js"]:::code
        A3["src/App.vue"]:::code
        A4["src/components/g2Demo.vue"]:::code
    end

    %% vue-g2 Plugin
    subgraph "vue-g2 Plugin"
        direction TB
        P1["registerG2Components.js"]:::code
        P2["chart.js (Mixin)"]:::code
        P3["index.js (Utils)"]:::code

        subgraph "Chart Components"
            direction TB
            C1["area.vue"]:::code
            C2["bubble.vue"]:::code
            C3["column.vue"]:::code
            C4["custom.vue"]:::code
            C5["double-axis-column.vue"]:::code
            C6["histogram.vue"]:::code
            C7["line.vue"]:::code
            C8["liquidfill.vue"]:::code
            C9["map-bubble.vue"]:::code
            C10["map-fill.vue"]:::code
            C11["mirror-interval.vue"]:::code
            C12["pie.vue"]:::code
            C13["progress-bar.vue"]:::code
            C14["radar.vue"]:::code
            C15["scatter-point.vue"]:::code
            C16["sparkline.vue"]:::code
            C17["word-cloud.vue"]:::code
        end
    end

    %% External Libraries
    subgraph "Third-party Libraries"
        direction TB
        L1["@antv/g2"]:::lib
        L2["@antv/data-set"]:::lib
    end

    %% Build & Deployment
    subgraph "Build & Deployment Config"
        direction TB
        B1["package.json"]:::config
        B2["babel.config.js"]:::config
        B3["vue.config.js"]:::config
        B4[".travis.yml"]:::config
        B5[".gitignore"]:::config
    end

    %% CDN Delivery (Optional)
    subgraph "CDN Delivery" 
        direction TB
        D1["Vue.js"]:::lib
        D2["@antv/g2"]:::lib
        D3["@antv/data-set"]:::lib
        D4["vue-g2"]:::code
    end

    %% Connections
    A2 -->|"installs via Vue.use"| P1
    P1 -->|"registers"| C1
    P1 --> C2
    P1 --> C3
    P1 --> C4
    P1 --> C5
    P1 --> C6
    P1 --> C7
    P1 --> C8
    P1 --> C9
    P1 --> C10
    P1 --> C11
    P1 --> C12
    P1 --> C13
    P1 --> C14
    P1 --> C15
    P1 --> C16
    P1 --> C17

    C1 -->|"mixes in"| P2
    C2 --> P2
    C3 --> P2
    C4 --> P2
    C5 --> P2
    C6 --> P2
    C7 --> P2
    C8 --> P2
    C9 --> P2
    C10 --> P2
    C11 --> P2
    C12 --> P2
    C13 --> P2
    C14 --> P2
    C15 --> P2
    C16 --> P2
    C17 --> P2

    P2 -->|"uses utils"| P3
    P3 -->|"transforms data"| L2
    P2 -->|"renders via"| L1

    %% CDN sequence
    D1 --> D2 --> D3 --> D4

    %% Build pipeline
    B1 -->|"configures"| B2
    B2 --> B3

    %% Click Events
    click A1 "https://github.com/wupeiwen/vue-g2/blob/develop/public/index.html"
    click A2 "https://github.com/wupeiwen/vue-g2/blob/develop/src/main.js"
    click A3 "https://github.com/wupeiwen/vue-g2/blob/develop/src/App.vue"
    click A4 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Demo.vue"
    click P1 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/registerG2Components.js"
    click P2 "https://github.com/wupeiwen/vue-g2/blob/develop/src/mixins/chart.js"
    click P3 "https://github.com/wupeiwen/vue-g2/blob/develop/src/utils/index.js"
    click C1 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/area.vue"
    click C2 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/bubble.vue"
    click C3 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/column.vue"
    click C4 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/custom.vue"
    click C5 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/double-axis-column.vue"
    click C6 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/histogram.vue"
    click C7 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/line.vue"
    click C8 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/liquidfill.vue"
    click C9 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/map-bubble.vue"
    click C10 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/map-fill.vue"
    click C11 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/mirror-interval.vue"
    click C12 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/pie.vue"
    click C13 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/progress-bar.vue"
    click C14 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/radar.vue"
    click C15 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/scatter-point.vue"
    click C16 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/sparkline.vue"
    click C17 "https://github.com/wupeiwen/vue-g2/blob/develop/src/components/g2Components/word-cloud.vue"
    click B1 "https://github.com/wupeiwen/vue-g2/blob/develop/package.json"
    click B2 "https://github.com/wupeiwen/vue-g2/blob/develop/babel.config.js"
    click B3 "https://github.com/wupeiwen/vue-g2/blob/develop/vue.config.js"
    click B4 "https://github.com/wupeiwen/vue-g2/blob/develop/.travis.yml"
    click B5 "https://github.com/wupeiwen/vue-g2/blob/develop/.gitignore"

    %% Styles
    classDef code fill:#D0E8FF,stroke:#0366d6,stroke-width:1px
    classDef lib fill:#DFFFE0,stroke:#228B22,stroke-width:1px
    classDef config fill:#FFF5BA,stroke:#DAA520,stroke-width:1px
    class A1,A2,A3,A4,B1,B2,B3,B4,B5,P1,P2,P3,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C13,C14,C15,C16,C17 code
    class L1,L2,D1,D2,D3 lib
    class D4 code
```
