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-svg-renderer

Previous
g-plugin-canvas-picker
Next
g-plugin-svg-picker

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 SVG-based rendering capabilities.

Usage

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

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

Contributions

The plugin exposes the following contributions.

ElementLifeCycleContribution

This contribution provides the lifecycle of SVG elements from creation, update to destruction.

export interface ElementLifeCycleContribution {
createElement: (object: DisplayObject) => SVGElement;
shouldUpdateElementAttribute: (
object: DisplayObject,
attributeName: string,
) => boolean;
updateElementAttribute: (object: DisplayObject, $el: SVGElement) => void;
destroyElement: (object: DisplayObject, $el: SVGElement) => void;
}

Different renderer plugins can implement the above interface to manage the lifecycle of each graphic using a custom approach. For example, the following code shows two SVG-based renderer plugins, the former built for g-svg, which provides rendering capabilities for default SVG elements, and the latter which implements hand-drawn style rendering with rough.js on top of that.

// g-plugin-svg-renderer
@singleton({ token: ElementLifeCycleContribution })
export class DefaultElementLifeCycleContribution
implements ElementLifeCycleContribution {}
// g-plugin-svg-rough-renderer
@singleton({ token: ElementLifeCycleContribution })
export class RoughElementLifeCycleContribution
implements ElementLifeCycleContribution {}

createElement

This method uses the DOM API to create the corresponding SVGElement based on the incoming base drawing, and is called when the ElementEvent.MOUNTED event is triggered.

shouldUpdateElementAttribute

Redrawing is expressed as attribute update in SVG, but some attributes (e.g. [visibility](/en/api/basic/display-object#hidden display), z-index, etc.) of updates we have a unified internal implementation and do not intend to open up custom capabilities. So there needs to be a judgment method to decide whether to trigger an attribute update or not.

This method gets called when MOUNTED triggered for the first time and ElementEvent.ATTR_MODIFIED for subsequent property updates.

updateElementAttribute

After passing the attribute update judgment method, the update attribute logic is executed.

destroyElement

This method is called when ElementEvent.UNMOUNTED is triggered when the drawing is removed from the canvas.