logo

G

  • Tutorials
  • API
  • Examples
  • Plugins
  • Productsantv logo arrow
  • 6.1.26
  • Introduction to the plug-in system
  • 插件结构
  • g-plugin-a11y
  • g-plugin-annotation
  • g-plugin-box2d
  • g-plugin-gpgpu
  • g-plugin-matterjs
  • g-plugin-yoga
  • g-plugin-css-select
  • g-plugin-3d
  • g-plugin-device-renderer
  • g-plugin-canvas-renderer
  • g-plugin-canvaskit-renderer
  • g-plugin-rough-canvas-renderer
  • g-plugin-rough-svg-renderer
  • g-plugin-canvas-path-generator
  • g-plugin-canvas-picker
  • g-plugin-svg-renderer
  • g-plugin-svg-picker
  • g-plugin-dom-interaction
  • g-plugin-dragndrop
  • g-plugin-control

g-plugin-canvas-renderer

Previous
g-plugin-device-renderer
Next
g-plugin-canvaskit-renderer

Resource

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Provides Canvas2D-based rendering capabilities.

Usage

The g-canvas renderer is built in by default, so there is no need to introduce it manually.

import { Renderer as CanvasRenderer } from '@antv/g-canvas';
// Create a renderer with the plugin built in
const canvasRenderer = new CanvasRenderer();

Contributions

StyleRenderer

When rendering the base graphics using CanvasRenderingContext2D, you can implement this interface after using g-plugin- canvas-path-generator to generate the graphical path, implement this interface to finish drawing the style.

export interface StyleRenderer {
render: (
context: CanvasRenderingContext2D,
parsedStyle: ParsedBaseStyleProps,
object: DisplayObject,
renderingService: RenderingService,
) => void;
}

We provide different extension points for different types of graphics. For example, in g-plugin-rough-canvas-renderer, we use the API provided by rough.js for Circle to add a hand-drawn style.

@singleton({
token: CanvasRenderer.CircleRendererContribution,
})
export class CircleRenderer implements CanvasRenderer.StyleRenderer {
render(
context: CanvasRenderingContext2D,
parsedStyle: ParsedCircleStyleProps,
object: DisplayObject<any, any>,
) {
const { r } = parsedStyle as ParsedCircleStyleProps;
// rough.js use diameter instead of radius
// @see https://github.com/rough-stuff/rough/wiki#circle-x-y-diameter--options
context.roughCanvas.circle(r.value, r.value, r.value * 2, generateRoughOptions(object));
}
}