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

Hull

Previous
History
Next
Legend

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

Hull is used to process and represent the convex or concave polygon bounding box of a set of points. It can wrap a set of nodes in a minimal geometric shape, helping users better understand and analyze datasets.

  • Convex Hull: This is a convex polygon that contains all the points and has no indentations.
  • Concave Hull: This is a concave polygon that also contains all the points but may have indentations. The degree of indentation is controlled by the concavity parameter.

Usage Scenarios

The hull plugin is mainly applicable to the following scenarios:

  • Wrapping node collections in data visualization
  • Providing visual references to enhance spatial awareness
  • Identifying the collection relationship of specific nodes in complex network graphs

Basic Usage

Below is a simple example of initializing the Hull plugin:

const graph = new Graph({
plugins: [
{
type: 'hull',
key: 'my-hull', // Specify a unique identifier for subsequent dynamic updates
members: ['node-1', 'node-2'], // List of node IDs to be wrapped
concavity: Infinity, // Default to convex hull
},
],
});

Online Experience

createGraph(
{
data: {
nodes: [
{
id: 'node-0',
data: { cluster: 'a' },
style: { x: 555, y: 151 },
},
{
id: 'node-1',
data: { cluster: 'a' },
style: { x: 532, y: 323 },
},
{
id: 'node-2',
data: { cluster: 'a' },
style: { x: 473, y: 227 },
},
{
id: 'node-3',
data: { cluster: 'a' },
style: { x: 349, y: 212 },
},
{
id: 'node-4',
data: { cluster: 'b' },
style: { x: 234, y: 201 },
},
{
id: 'node-5',
data: { cluster: 'b' },
style: { x: 338, y: 333 },
},
{
id: 'node-6',
data: { cluster: 'b' },
style: { x: 365, y: 91 },
},
],
edges: [
{
source: 'node-0',
target: 'node-2',
},
{
source: 'node-1',
target: 'node-2',
},
{
source: 'node-2',
target: 'node-3',
},
{
source: 'node-3',
target: 'node-4',
},
{
source: 'node-3',
target: 'node-5',
},
{
source: 'node-3',
target: 'node-6',
},
],
},
node: {
style: { labelText: (d) => d.id },
palette: { field: 'cluster', color: ['#7e3feb', '#ffa940'] },
},
behaviors: ['drag-canvas', 'drag-element'],
plugins: [
'grid-line',
{
type: 'hull',
key: 'hull-a',
members: ['node-0', 'node-1', 'node-2', 'node-3'],
labelText: 'hull-a',
fill: '#7e3feb',
stroke: '#7e3feb',
fillOpacity: 0.1,
strokeOpacity: 1,
labelFill: '#fff',
labelPadding: 2,
labelBackgroundFill: '#7e3feb',
labelBackgroundRadius: 5,
},
],
},
{ width: 600, height: 450 },
(gui, graph) => {
const options = {
type: 'hull',
members: ['node-0', 'node-1', 'node-2', 'node-3'],
concavity: Infinity,
corner: 'rounded',
padding: 10,
// style
fill: '#7e3feb',
stroke: '#7e3feb',
fillOpacity: 0.1,
strokeOpacity: 1,
// label
label: true,
labelCloseToPath: true,
labelAutoRotate: true,
labelOffsetX: 0,
labelOffsetY: 0,
labelPlacement: 'bottom',
};
const optionFolder = gui.addFolder('Hull Options');
optionFolder.add(options, 'type').disable();
optionFolder.add(options, 'concavity', 0, 200, 1);
optionFolder.add(options, 'corner', ['rounded', 'smooth', 'sharp']);
optionFolder.add(options, 'padding', 0, 20, 1);
optionFolder.addColor(options, 'fill');
optionFolder.addColor(options, 'stroke');
optionFolder.add(options, 'fillOpacity', 0, 1, 0.1);
optionFolder.add(options, 'strokeOpacity', 0, 1, 0.1);
optionFolder.add(options, 'label');
optionFolder.add(options, 'labelCloseToPath');
optionFolder.add(options, 'labelAutoRotate');
optionFolder.add(options, 'labelOffsetX', 0, 20, 1);
optionFolder.add(options, 'labelOffsetY', 0, 20, 1);
optionFolder.add(options, 'labelPlacement', ['left', 'right', 'top', 'bottom', 'center']);
optionFolder.onChange(({ property, value }) => {
graph.updatePlugin({
key: 'hull-a',
[property]: value,
});
graph.render();
});
const apiConfig = {
member: 'node-1',
};
const apiFolder = gui.addFolder('Hull API');
const instance = graph.getPluginInstance('hull-a');
apiFolder.add(
apiConfig,
'member',
new Array(7).fill(0).map((_, index) => `node-${index}`),
);
apiFolder.add({ addMember: () => instance.addMember(apiConfig.member) }, 'addMember').name('add member');
apiFolder
.add({ removeMember: () => instance.removeMember(apiConfig.member) }, 'removeMember')
.name('remove member');
apiFolder
.add({ removeMember: () => alert('Members in Hull-a: ' + instance.getMember()) }, 'removeMember')
.name('get member');
},
);

Configuration Options

PropertyDescriptionTypeDefault ValueRequired
typePlugin typestringhull✓
keyUnique identifier for the plugin, used for subsequent updatesstring-
membersElements within the Hull, including nodes and edgesstring[]-✓
concavityConcavity, the larger the value, the smaller the concavity; default is Infinity representing Convex HullnumberInfinity
cornerCorner type, options are rounded | smooth | sharpstringrounded
paddingPaddingnumber10
labelWhether to display the labelbooleantrue
labelPlacementLabel positionleft | right | top | bottom | centerbottom
labelBackgroundWhether to display the backgroundbooleanfalse
labelPaddingLabel paddingnumber | number[]0
labelCloseToPathWhether the label is close to the hullbooleantrue
labelAutoRotateWhether the label rotates with the hull, effective only when closeToPath is truebooleantrue
labelOffsetXX-axis offsetnumber0
labelOffsetYY-axis offsetnumber0
labelMaxWidthMaximum width of the text, exceeding will automatically ellipsisnumber0

For complete label styles, see this link

concavity

The concavity attribute is used to control the concavity of the Hull. When set to Infinity, a convex hull is generated; otherwise, a concave hull is generated.

// Convex hull example
const graph = new Graph({
plugins: [
{
type: 'hull',
concavity: Infinity, // Convex hull
members: ['node-1', 'node-2'],
},
],
});
// Concave hull example
const graph = new Graph({
plugins: [
{
type: 'hull',
concavity: 50, // Concave hull
members: ['node-1', 'node-2'],
},
],
});

Code Examples

Basic Hull

The simplest way is to use the preset configuration directly:

const graph = new Graph({
plugins: [
{
type: 'hull',
members: ['node-1', 'node-2'], // List of node IDs to be wrapped
},
],
});

The effect is as follows:

createGraph(
{
autoFit: 'view',
data: {
nodes: [
{
id: 'node-0',
data: { cluster: 'a' },
style: { x: 555, y: 151 },
},
{
id: 'node-1',
data: { cluster: 'a' },
style: { x: 532, y: 323 },
},
{
id: 'node-2',
data: { cluster: 'a' },
style: { x: 473, y: 227 },
},
{
id: 'node-3',
data: { cluster: 'a' },
style: { x: 349, y: 212 },
},
{
id: 'node-4',
data: { cluster: 'b' },
style: { x: 234, y: 201 },
},
{
id: 'node-5',
data: { cluster: 'b' },
style: { x: 338, y: 333 },
},
{
id: 'node-6',
data: { cluster: 'b' },
style: { x: 365, y: 91 },
},
],
edges: [
{
source: 'node-0',
target: 'node-2',
},
{
source: 'node-1',
target: 'node-2',
},
{
source: 'node-2',
target: 'node-3',
},
{
source: 'node-3',
target: 'node-4',
},
{
source: 'node-3',
target: 'node-5',
},
{
source: 'node-3',
target: 'node-6',
},
],
},
plugins: [
{
type: 'hull',
members: ['node-1', 'node-2'], // List of node IDs to be wrapped
},
],
behaviors: ['zoom-canvas', 'drag-canvas'],
},
{ width: 300, height: 150 },
);

Custom Styles

You can customize the style of the Hull as needed, such as adjusting color, transparency, and other properties.

const graph = new Graph({
plugins: [
{
type: 'hull',
members: ['node-1', 'node-2', 'node-3'],
stroke: '#ff000033', // Red semi-transparent border
fill: '#7e3feb', // Light purple fill
fillOpacity: 0.2,
lineWidth: 2,
padding: 15, // Larger padding
},
],
});

The effect is as follows:

createGraph(
{
autoFit: 'view',
data: {
nodes: [
{
id: 'node-0',
data: { cluster: 'a' },
style: { x: 555, y: 151 },
},
{
id: 'node-1',
data: { cluster: 'a' },
style: { x: 532, y: 323 },
},
{
id: 'node-2',
data: { cluster: 'a' },
style: { x: 473, y: 227 },
},
{
id: 'node-3',
data: { cluster: 'a' },
style: { x: 349, y: 212 },
},
{
id: 'node-4',
data: { cluster: 'b' },
style: { x: 234, y: 201 },
},
{
id: 'node-5',
data: { cluster: 'b' },
style: { x: 338, y: 333 },
},
{
id: 'node-6',
data: { cluster: 'b' },
style: { x: 365, y: 91 },
},
],
edges: [
{
source: 'node-0',
target: 'node-2',
},
{
source: 'node-1',
target: 'node-2',
},
{
source: 'node-2',
target: 'node-3',
},
{
source: 'node-3',
target: 'node-4',
},
{
source: 'node-3',
target: 'node-5',
},
{
source: 'node-3',
target: 'node-6',
},
],
},
plugins: [
{
type: 'hull',
members: ['node-1', 'node-2', 'node-3'],
stroke: '#ff000033', // Red semi-transparent border
fill: '#7e3feb', // Light purple fill
fillOpacity: 0.2,
lineWidth: 2,
padding: 15, // Larger padding
},
],
behaviors: ['zoom-canvas', 'drag-canvas'],
},
{ width: 300, height: 150 },
);

Label Configuration

You can configure the position, background, offset, and other properties of the label to enhance the visual effect.

const graph = new Graph({
plugins: [
{
type: 'hull',
members: ['node-1', 'node-2'],
label: true, // Display label
labelText: 'hull-a',
labelPlacement: 'top', // Label position
labelBackground: true, // Display label background
labelPadding: 5, // Label padding
},
],
});

The effect is as follows:

createGraph(
{
autoFit: 'center',
data: {
nodes: [
{
id: 'node-0',
data: { cluster: 'a' },
style: { x: 555, y: 151 },
},
{
id: 'node-1',
data: { cluster: 'a' },
style: { x: 532, y: 323 },
},
{
id: 'node-2',
data: { cluster: 'a' },
style: { x: 473, y: 227 },
},
{
id: 'node-3',
data: { cluster: 'a' },
style: { x: 349, y: 212 },
},
{
id: 'node-4',
data: { cluster: 'b' },
style: { x: 234, y: 201 },
},
{
id: 'node-5',
data: { cluster: 'b' },
style: { x: 338, y: 333 },
},
{
id: 'node-6',
data: { cluster: 'b' },
style: { x: 365, y: 91 },
},
],
edges: [
{
source: 'node-0',
target: 'node-2',
},
{
source: 'node-1',
target: 'node-2',
},
{
source: 'node-2',
target: 'node-3',
},
{
source: 'node-3',
target: 'node-4',
},
{
source: 'node-3',
target: 'node-5',
},
{
source: 'node-3',
target: 'node-6',
},
],
},
plugins: [
{
type: 'hull',
members: ['node-1', 'node-2'],
label: true, // Display label
labelText: 'hull-a',
labelPlacement: 'top', // Label position
labelBackground: true, // Display label background
labelPadding: 5, // Label padding
},
],
behaviors: ['zoom-canvas', 'drag-canvas'],
},
{ width: 300, height: 150 },
);

Practical Cases