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-path-generator

Previous
g-plugin-rough-svg-renderer
Next
g-plugin-canvas-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...

Use CanvasRenderingContext2D to draw the path of individual shapes, for example using arcTo() Draws Circle.

In addition to being used for final rendering, you also need to draw in the off-screen canvas before using isPointInPath() .

Token

The plugin provides two Tokens, which are injected via Token when used.

export const PathGeneratorFactory = Syringe.defineToken('PathGeneratorFactory');
export const PathGenerator = Syringe.defineToken('PathGenerator');

PathGeneratorFactory

For example, you can currently see the factory method injected into g-plugin-canvas-renderer and g-plugin-canvas-picker in both plugins. You can see that the factory method is injected via the token PathGeneratorFactory, and passing nodeName will give you the drawing method for the corresponding graphic path: PathGeneratorFactory.

@inject(PathGeneratorFactory)
private pathGeneratorFactory: (tagName: Shape | string) => PathGenerator<any>;
const circlePathGenerator = this.pathGeneratorFactory(Shape.CIRCLE);

PathGenerator

The path drawing method specific to each base drawing accepts as parameters the CanvasRenderingContext2D context and the parsed drawing style property.

export type PathGenerator<T extends ParsedBaseStyleProps> = (
context: CanvasRenderingContext2D,
attributes: T,
) => void;

Take Circle as an example.

function generatePath(
context: CanvasRenderingContext2D,
parsedStyle: ParsedCircleStyleProps,
) {
const { r } = parsedStyle;
context.arc(r.value, r.value, r.value, 0, Math.PI * 2, false);
}