G

💥 A flexible rendering engine for visualization.

Downloads
3.6M
Stars
1K
Committers
39

English | 简体中文

G

一款高效易用的可视化渲染引擎。

✨ 特性

📦 安装

# 安装核心包
$ npm install @antv/g --save
# Canvas 渲染器
$ npm install @antv/g-canvas --save
# SVG 渲染器
$ npm install @antv/g-svg --save
# WebGL 渲染器
$ npm install @antv/g-webgl --save

🔨 使用

<div id="container"></div>
import { Circle, Canvas, CanvasEvent } from '@antv/g';
import { Renderer as CanvasRenderer } from '@antv/g-canvas';
// or
// import { Renderer as WebGLRenderer } from '@antv/g-webgl';
// import { Renderer as SVGRenderer } from '@antv/g-svg';

// 创建画布
const canvas = new Canvas({
    container: 'container',
    width: 500,
    height: 500,
    renderer: new CanvasRenderer(), // 选择一个渲染器
});

// 创建一个圆
const circle = new Circle({
    style: {
        cx: 100,
        cy: 100,
        r: 50,
        fill: 'red',
        stroke: 'blue',
        lineWidth: 5,
    },
});

canvas.addEventListener(CanvasEvent.READY, function () {
    // 加入画布
    canvas.appendChild(circle);

    // 监听 `click` 事件
    circle.addEventListener('click', function () {
        this.style.fill = 'green';
    });
});

⌨️ 开发

启动并预览示例:

git clone [email protected]:antvis/g.git
cd g
pnpm install
pnpm build
pnpm dev

API Spec

在项目根目录下启动开发服务器,例如 http-server:

http-server -p 9090

访问 localhost:9090/spec/api.html 即可预览 API Spec。

运行测试用例

构建并运行测试用例:

pnpm build
pnpm test

启动开发示例

构建并启动 vite 示例:

pnpm build
pnpm dev

受以下项目启发