logo

X6

  • Tutorials
  • API
  • Examples
  • Q&A
  • Change Log
  • XFlow
  • Productsantv logo arrow
  • 2.x
  • Graph
    • Graph
    • Grid
    • Background
    • Panning
    • Mousewheel
    • Viewport Transformation
    • Coordinate Systems
  • Element
    • Cell
    • Node
    • Edge
    • Labels
    • Arrow
    • Element Attributes
    • Interaction
  • MVC
    • Model
    • View
  • Extension
    • Node Tools
    • Edge Tools
    • Routing
    • Connector
    • Node Anchor
    • Edge Anchor
    • Connection Point
    • Port Layout Algorithm
    • Port Label Layout
    • Attributes
    • Highlighter
    • Filter

Filter

Previous
Highlighter

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...

We can use the special attribute filter to specify SVG filters for elements. For example, we can define a predefined object for the filter attribute of the element, where name and args specify the filter name and filter parameters, respectively.

// Create a node by specifying the filter through the attrs option
const rect = graph.addNode({
x: 40,
y: 40,
width: 80,
height: 30,
attrs: {
body: {
filter: {
name: 'dropShadow',
args: {
dx: 2,
dy: 2,
blur: 3,
},
},
},
},
})
// After creating the node, we can modify or specify the element's filter using the `attr()` method
rect.attr('body/filter', {
name: 'dropShadow',
args: {
dx: 2,
dy: 2,
blur: 3,
},
})

Additionally, we can call the graph.defineFilter(...) method to obtain a filter ID, and then set the filter attribute to this filter ID.

const filterId = graph.defineFilter({
name: 'dropShadow',
args: {
dx: 2,
dy: 2,
blur: 3,
},
})
rect.attr('body/filter', `#${filterId}`)

Through this brief introduction, we have learned how to use filters. Next, let's take a look at the predefined filters available in X6.

Built-in Filters

dropShadow

Shadow filter. Refer to CSS drop-shadow() filter.

Parameter NameTypeDefault ValueDescription
dxnumber0Shadow offset on the X-axis.
dynumber0Shadow offset on the Y-axis.
blurnumber0Shadow blur radius.
opacitynumber1Shadow opacity.

blur

Gaussian blur filter. Refer to CSS blur() filter.

Parameter NameTypeDefault ValueDescription
xnumber2Blur amount in the X direction.
ynumber-Blur amount in the Y direction; defaults to X.

grayScale

Grayscale filter. Refer to CSS grayscale() filter.

Parameter NameTypeDefault ValueDescription
amountnumber1Grayscale amount. Ranges from [0-1], where 0 means no grayscale and 1 means full grayscale.

sepia

Sepia filter. Refer to CSS sepia() filter.

Parameter NameTypeDefault ValueDescription
amountnumber1Sepia amount. Ranges from [0-1], where 0 means no sepia and 1 means full sepia.

saturate

Saturation filter. Refer to CSS saturate() filter.

Parameter NameTypeDefault ValueDescription
amountnumber1Saturation. Ranges from [0-1].

hueRotate

Hue rotation filter. Refer to CSS hue-rotate() filter.

Parameter NameTypeDefault ValueDescription
anglenumber0Hue rotation angle.

invert

Invert filter. Refer to CSS invert() filter.

Parameter NameTypeDefault ValueDescription
amountnumber1Inversion amount. Ranges from [0-1], where 0 means no inversion and 1 means full inversion.

brightness

Brightness filter. Refer to CSS brightness() filter.

Parameter NameTypeDefault ValueDescription
amountnumber1Brightness. Ranges from [0-1], where 0 means completely dark and 1 means completely bright.

contrast

Contrast filter. Refer to CSS contrast() filter.

Parameter NameTypeDefault ValueDescription
amountnumber1Contrast. Ranges from [0-1], where 0 means completely dark and 1 means completely bright.

highlight

Highlight filter.

Parameter NameTypeDefault ValueDescription
colorstringredHighlight color.
widthnumber1Width of the highlight border.
blurnumber0Blur radius.
opacitynumber1Opacity.

outline

Outline filter.

Parameter NameTypeDefault ValueDescription
colorstringblueOutline color.
widthnumber1Outline width.
marginnumber2Margin.
opacitynumber1Opacity.

Custom Filters

A filter definition is a function with the following signature that returns a <filter> tag string.

export type Definition<T> = (args: T) => string

For example, the definition of the Gaussian blur filter is:

export interface BlurArgs {
x?: number
y?: number
}
export function blur(args: BlurArgs = {}) {
const x = getNumber(args.x, 2)
const stdDeviation = args.y != null && isFinite(args.y) ? [x, args.y] : x
return `
<filter>
<feGaussianBlur stdDeviation="${stdDeviation}"/>
</filter>
`.trim()
}

We can register a filter by calling the Graph.registerFilter(...) method.

Graph.registerFilter('blur', blur)
Settings
color
dx
10.00
dy
10.00
blur
10.00
opacity
0.50
Settings
fill
x
10.00
y
10.00
Settings
fill
amount
0.30
Settings
fill
amount
0.30
Settings
color
amount
0.30
Settings
fill
angle
0.00
Settings
fill
amount
0.30
Settings
fill
amount
0.30
Settings
fill
amount
0.30
Settings
color
width
10.00
blur
1.00
opacity
0.50
Settings
color
width
2.00
margin
2.00
opacity
0.50