logo

G6

  • Docs
  • API
  • Playground
  • Community
  • Productsantv logo arrow
  • 5.0.47
  • Introduction
  • Data
  • Getting Started
    • Quick Start
    • Installation
    • Integration
      • react
      • vue
      • angular
    • Step-by-step guide
  • Graph
    • Extensions En
    • Graph
    • Options
    • extension
  • Element
    • Element Overview
    • Element State
    • Node
      • Node Overview
      • Build-in Node
        • Common Node Configurations
        • Diamond
        • Donut
        • Ellipse
        • Hexagon
        • Html
        • Image
        • Rect
        • Star
        • Triangle
        • Circle
      • Custom Node
      • Define Nodes with React
    • Edge
      • Edge Overview
      • Build-in Edge
        • Common Edge Configurations
        • Cubic Bezier Curve
        • CubicHorizontal Bezier Curve
        • CubicVertical Bezier Curve
        • Line
        • Polyline
        • Quadratic Bezier Curve
      • Custom Edge
    • Combo
      • Combo Overview
      • Build-in Combo
        • Circle
        • Combo Configuration Options
        • Rect
      • Custom Combo
    • Shape
      • Shape and KeyShape
      • Atomic Shapes and Their Properties
      • Design and Implementation of Composite Shape
  • Layout
    • Layout Overview
    • Build-in Layout
      • 3D Force-Directed Layout
      • AntvDagre Layout
      • Circular Layout
      • ComboCombined Layout
      • Common Layout Configuration Options
      • CompactBox
      • Concentric Layout
      • D3 Force-Directed Layout
      • Dagre Layout
      • Dendrogram Layout
      • Fishbone Layout
      • Force Force-directed Layout
      • ForceAtlas2 Force-directed Layout
      • Fruchterman Force-directed Layout
      • Grid Layout
      • Indented Tree
      • MDS High-dimensional Data Dimensionality Reduction Layout
      • Mindmap Tree
      • Radial Layout
      • Random Layout
      • Snake Layout
    • Custom Layout
  • Behavior
    • Behavior Overview
    • Build-in Behavior
      • AutoAdaptLabel
      • BrushSelect
      • ClickSelect
      • CollapseExpand
      • CreateEdge
      • DragCanvas
      • DragElement
      • DragElementForce
      • FixElementSize
      • FocusElement
      • HoverActivate
      • LassoSelect
      • OptimizeViewportTransform
      • ScrollCanvas
      • ZoomCanvas
    • Custom Behavior
  • Plugin
    • Plugin Overview
    • Build-in Plugin
      • Background
      • BubbleSets
      • Contextmenu
      • EdgeBundling
      • EdgeFilterLens
      • Fisheye
      • Fullscreen
      • GridLine
      • History
      • Hull
      • Legend
      • Minimap
      • Snapline
      • Timebar
      • Toolbar
      • Tooltip
      • Watermark
    • Custom Plugin
  • Transform
    • Data Transformation Overview
    • Build-in Transform
      • MapNodeSize
      • PlaceRadialLabels
      • ProcessParallelEdges
    • Custom Transform
  • Theme
    • Theme Overview
    • Custom Theme
    • Palette
    • Custom Palette
  • Animation
    • Animation Overview
    • Custom Animation
  • Further Reading
    • Event
    • renderer
    • coordinate
    • download-image
    • Using Iconfont
    • Use 3D
    • Bundle Project
  • What's new
    • Feature
    • Upgrade To 5.0
  • FAQ
  • contribute

Watermark

Previous
Tooltip
Next
Custom Plugin

Resources

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-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

The watermark plugin supports using text and images as watermarks. The principle is to add a background-image attribute to the div of the Graph container, and then control the position and style of the watermark through CSS. For text watermarks, a hidden canvas is used to convert the text into an image.

Use Cases

  • Add copyright or ownership marks to charts
  • Mark the status of charts during presentations or previews
  • Add anti-leakage marks to sensitive data

Basic Usage

Below is a simple example of initializing the Watermark plugin:

const graph = new Graph({
plugins: [
{
type: 'watermark',
text: 'G6 Graph', // Watermark text
opacity: 0.2, // Opacity
rotate: Math.PI / 12, // Rotation angle
},
],
});

Online Experience

createGraph(
{
data: { nodes: [{ id: 'node-1' }] },
node: { style: { fill: '#7e3feb' } },
edge: { style: { stroke: '#8b9baf' } },
layout: { type: 'force' },
behaviors: ['drag-canvas'],
plugins: [{ type: 'watermark', key: 'watermark', text: 'G6: Graph Visualization' }],
},
{ width: 600, height: 300 },
(gui, graph) => {
const options = {
type: 'watermark',
width: 200,
height: 100,
opacity: 0.2,
rotate: Math.PI / 12,
text: 'G6: Graph Visualization',
};
const optionFolder = gui.addFolder('Watermark Options');
optionFolder.add(options, 'type').disable(true);
optionFolder.add(options, 'width', 1, 1280, 1);
optionFolder.add(options, 'height', 1, 800, 1);
optionFolder.add(options, 'opacity', 0, 1, 0.1);
optionFolder.add(options, 'rotate', 0, 2 * Math.PI, Math.PI / 12);
optionFolder.add(options, 'text');
optionFolder.onChange(({ property, value }) => {
graph.updatePlugin({
key: 'watermark',
[property]: value,
});
graph.render();
});
},
);

Configuration Options

PropertyDescriptionTypeDefault ValueRequired
typePlugin typestringwatermark✓
widthWidth of a single watermarknumber200
heightHeight of a single watermarknumber100
opacityOpacity of the watermarknumber0.2
rotateRotation angle of the watermarknumberMath.PI / 12
imageURLImage watermark URL, higher priority than text watermarkstring-
textWatermark text contentstring-
textFillColor of the text watermarkstring#000
textFontSizeFont size of the text watermarknumber16
textFontFamilyFont of the text watermarkstring-
textFontWeightFont weight of the text watermarkstring-
textFontVariantFont variant of the text watermarkstring-
textAlignText alignment of the watermarkcenter | end | left | right | startcenter
textBaselineBaseline alignment of the text watermarkalphabetic | bottom | hanging | ideographic | middle | topmiddle
backgroundRepeatRepeat mode of the watermarkstringrepeat
backgroundAttachmentBackground attachment behavior of the watermarkstring-
backgroundBlendModeBackground blend mode of the watermarkstring-
backgroundClipBackground clip of the watermarkstring-
backgroundColorBackground color of the watermarkstring-
backgroundImageBackground image of the watermarkstring-
backgroundOriginBackground origin of the watermarkstring-
backgroundPositionBackground position of the watermarkstring-
backgroundPositionXHorizontal position of the watermark backgroundstring-
backgroundPositionYVertical position of the watermark backgroundstring-
backgroundSizeBackground size of the watermarkstring-

Code Examples

Text Watermark

The simplest text watermark configuration:

const graph = new Graph({
plugins: [
{
type: 'watermark',
text: 'G6 Graph',
},
],
});

Image Watermark

Use an image as a watermark:

const graph = new Graph({
plugins: [
{
type: 'watermark',
imageURL: 'https://example.com/logo.png',
width: 100,
height: 50,
opacity: 0.1,
},
],
});

Custom Styles

You can customize the style and position of the watermark:

const graph = new Graph({
plugins: [
{
type: 'watermark',
text: 'G6 Graph',
textFontSize: 20, // Set font size
textFontFamily: 'Arial', // Set font
textFontWeight: 'bold', // Set font weight
textFill: '#1890ff', // Set text color
rotate: Math.PI / 6, // Set rotation angle
opacity: 0.15, // Set opacity
width: 180, // Set watermark width
height: 100, // Set watermark height
backgroundRepeat: 'space', // Set repeat mode
backgroundPosition: 'center', // Set position
textAlign: 'center', // Set text alignment
textBaseline: 'middle', // Set baseline alignment
},
],
});

Real Cases

  • Text Watermark
  • Image Watermark