Skip to content
Go back

Rough.js Hand-Drawn Style Graphics

Create charming hand-drawn style graphics using the RoughDrawing component powered by Rough.js, with theme-aware colors.

Rough.js renders graphics with a hand-drawn, sketchy appearance. The :::rough directive lets you define shapes via JSON configuration, and all colors automatically adapt to the current theme.

Basic Shapes

Rectangles, circles, ellipses, and lines — the fundamental building blocks of any drawing.

Each shape supports different fillStyle values: hachure (default), cross-hatch, zigzag, solid, and dots. The roughness parameter controls how sketchy the shape looks — higher values produce more hand-drawn effects.

Simple Flowchart

Rough.js shapes can be combined to create informal, hand-drawn diagrams that feel more approachable than rigid box-and-arrow charts.

Bar Chart Visualization

A hand-drawn bar chart comparing frontend framework popularity — demonstrating that Rough.js can convey data in a friendly, informal style.

The bars above use different fill styles to distinguish categories. In a real scenario you would add text labels — but even without them, the visual hierarchy is clear.

Configuration Reference

The :::rough directive accepts a config attribute — a JSON string with the following structure:

:::rough{config='{"width":400,"height":200,"shapes":[...]}'}
markdown
FieldTypeDefaultDescription
widthnumber400SVG canvas width
heightnumber200SVG canvas height
shapesarray[]Array of shape definitions

Shape Types

TypeRequired FieldsDescription
rectanglex, y, width, heightRectangular shape
circlex, y, rCircle (x,y = center, r = radius)
ellipsex, y, width, heightElliptical shape
linex1, y1, x2, y2Straight line segment

Shape Options

Each shape supports an options object:



Previous Post
Mermaid Diagram Examples
Next Post
Rust Concurrency in Practice

评论区

文明评论,共建和谐社区