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-rough-canvas-renderer

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

Hand-drawn style rendering using the Canvas version of rough.js, example.

Usage

First you need to use the g-canvas renderer, register the plugin and it will replace the rendering of 2D graphics in g-plugin-canvas-renderer.

import { Canvas } from '@antv/g';
import { Renderer } from '@antv/g-canvas';
import { Plugin as PluginRoughCanvasRenderer } from '@antv/g-plugin-rough-canvas-renderer';
// create a renderer
const renderer = new Renderer();
renderer.registerPlugin(new PluginRoughCanvasRenderer());
// create a canvas & use `g-canvas`
const canvas = new Canvas({
container: 'container',
width: 600,
height: 500,
renderer,
});

Note that once the plugin is used, "Dirty Rectangle Rendering" is not available, which means that any change in the style properties of any graphic will result in a full redraw of the canvas.

In addition, we support all 2D graphics, among which Text, Image and HTML have no hand-drawn style.

Style properties

In addition to the style properties of 2D graphics, the configuration items provided byrough.js can also be used.

opacity

rough.js doesn't support opacity, but we can achieve it with globalAlpha, same as g-plugin-canvas-renderer.

Note, however, that fillOpacity and strokeOpacity do not work because rough.js does not open the relevant configuration items.

circle.style.opacity = 0.5;

shadow

rough.js does not support shadow related effects, but we do provide them.

Configuration items can be found in shadow.

circle.style.shadowColor = '#000';
circle.style.shadowBlur = 0;
circle.style.shadowOffsetX = 0;
circle.style.shadowOffsetY = 0;

roughness

rough.js provides many configuration items that affect the hand-drawn effect, all of which work properly. example

The default value is 1, indicating the degree of hand-drawn style. 0 means no hand-drawn effect, the larger the number the more obvious the stylization effect, but more than 10 will completely lose the original shape and it is meaningless.

roughness
circle.style.roughness = 2;

bowing

The degree of curvature of the line, the default value is 1. 0 represents a straight line. example

bowing
circle.style.bowing = 2;

fillStyle

Fill style, supporting the following enumerated values, example:

  • 'hachure'
  • 'solid'
  • 'zigzag'
  • 'cross-hatch'
  • 'dots'
  • 'dashed'
  • 'zigzag-line'
hachuresolidzigzagcross-hatchdotsdashedzigzag-line
circle.style.fillStyle = 'zigzag';

fillWeight

Numeric value representing the width of the hachure lines. Default value of the fillWeight is set to half the strokeWidth of that shape.

When using dots styles to fill the shape, this value represents the diameter of the dot.

fillWeight
circle.style.fillWeight = 2;

hachureAngle

Numerical value (in degrees) that defines the angle of the hachure lines. Default value is -41 degrees.

hachureAngle
circle.style.hachureAngle = 30;

hachureGap

Numerical value that defines the average gap, in pixels, between two hachure lines. Default value of the hachureGap is set to four times the strokeWidth of that shape.

hachureGap

curveStepCount

When drawing ellipses, circles, and arcs, RoughJS approximates curveStepCount number of points to estimate the shape. Default value is 9.

curveStepCount

curveFitting

When drawing ellipses, circles, and arcs, Let RoughJS know how close should the rendered dimensions be when compared to the specified one. Default value is 0.95 - which means the rendered dimensions will be at least 95% close to the specified dimensions. A value of 1 will ensure that the dimensions are almost 100% accurate.

curveFitting

lineDash

If you want the stroke to be dashed (This does not affect the hachure and other fills of the shape), set this property. The value is an array of numbers as described in setLineDash method of canvas

lineDash
circle.style.lineDash = [10, 10];

lineDashOffset

When using dashed strokes, this property sets the line dash offset or phase. This is akin to the lineDashOffset of canvas

lineDashOffset
circle.style.lineDashOffset = 10;

fillLineDash

This property is similar to the strokeLineDash property but it affects the fills, not the stroke. eg. when you want hachure lines to be dashed.

fillLineDash
circle.style.fillLineDash = [10, 10];

fillLineDashOffset

This property is similar to the strokeLineDashOffset property but it affects the fills, not the stroke.

fillLineDashOffset
circle.style.fillLineDashOffset = 10;

disableMultiStroke

If this property is set to true, roughjs does not apply multiple strokes to sketch the shape.

disableMultiStroke
circle.style.disableMultiStroke = true;

disableMultiStrokeFill

If this property is set to true, roughjs does not apply multiple strokes to sketch the hachure lines to fill the shape.

disableMultiStrokeFill
circle.style.disableMultiStrokeFill = true;

simplification

Simplification can be set to simplify the shape by the specified factor. The value can be between 0 and 1.

dashOffset

When filling a shape using the dashed style, this property indicates the nominal length of dash (in pixels). If not set, it defaults to the hachureGap value.

dashOffset

dashGap

When filling a shape using the dashed style, this property indicates the nominal gap between dashes (in pixels). If not set, it defaults to the hachureGap value.

dashGap

zigzagOffset

When filling a shape using the zigzag-line style, this property indicates the nominal width of the zig-zag triangle in each line. If not set, it defaults to the hachureGap value.

zigzagOffset

preserveVertices

Picking

In g-plugin-canvas-picker we use the spatial index for quick filtering and the mathematical calculation of the geometric definition of the figure for exact picking.

However, in the hand-drawn style, it seems impossible and unnecessary to do exact picking, so we still use this plugin.