!!!###!!!title=Tag——VisActor/VGraph tutorial documents!!!###!!!

Tag Tool

Custom nodes are one of the biggest pain points in developing graph visualization applications. vGraph has summarized common custom node components from business scenarios and abstracted them into configurable tool methods to help everyone solve some visual effects that are not easy to implement.

Tags are often used in custom nodes and can be configured with icons that have business meaning, as well as add/close functions. You can generate a single tag or a row of tags, with built-in overflow handling. You can experience this in the custom node with tags demo.

import { TagUtils, Layer } from '@visactor/vgraph';

// container is the tag container, which is generally the Layer parameter passed in by the node's custom method
const container = new Layer({...});

// Generate a single tag
const tagLayer = TagUtils.initTag(container, tagOption);

// Remove a single tag
TagUtils.removeTag(tagLayer);

The configuration for a single tag is as follows:

FieldTypeDescription
textstring[Required] The text displayed on the tag.
leftnumber[Required] The horizontal coordinate of the top-left corner of the tag.
topnumber[Required] The vertical coordinate of the top-left corner of the tag.
maxWidthnumberThe maximum width of the tag.
theme'rect' | 'capsule'The style of the tag. The default is rectangle.
labelThe custom style of the tag text.
label.fillStylestringThe color of the tag text.
label.fontSizenumberThe font size of the tag text.
label.lineHeightnumberThe line height of the tag text.
label.triggerIdstringUsed to bind with a tooltip.
label.fontFamilystringThe font family of the badge text.
backgroundThe background configuration of the tag.
background.fillStylestringThe background fill color of the tag.
background.strokeStylestringThe background border color of the tag.
background.paddingnumber | number[]The padding around the tag.
background.radiusnumberThe border radius of the tag.
iconnumberThe configuration for the icon on the left of the tag.
icon.iconstringThe iconfont reference for the icon on the left of the tag.
icon.fillStylenumberThe color of the icon on the left of the tag.
icon.sizenumberThe size of the icon on the left of the tag.
icon.onClick(e: GraphEvent, layer: Layer) => voidThe click event for the icon on the left of the tag.
closenumberThe configuration for the close icon on the right of the tag.
close.iconstringThe iconfont reference for the close icon on the right of the tag.
close.fillStylenumberThe color of the close icon on the right of the tag.
close.sizenumberThe size of the close icon on the right of the tag.
close.onClick(e: GraphEvent, layer: Layer) => voidThe click event for the close icon on the right of the tag.

TagUtils also has good support for single-line multiple texts. You can refer to the node with deletable tags demo.

import { TagUtils, Layer } from '@visactor/vgraph';

// container is the tag container, which is generally the Layer parameter passed in by the node's custom method
const container = new Layer({...});

// Generate multiple tags
const tagsLayer = TagUtils.initTag(container, tagsOption);

// Remove a single tag
TagUtils.removeTag(tagLayer);

// Add a single tag
TagUtils.addTag(tagsLayer, tagOption);
FieldTypeDescription
leftnumber[Required] The horizontal coordinate of the top-left corner of the tag.
topnumber[Required] The vertical coordinate of the top-left corner of the tag.
maxWidthnumberThe maximum width of the row where the tag is located.
theme'rect' | 'capsule'The style of the tag. The default is rectangle.
tagstagOptionThe style of the tag text. Refer to the configuration for a single tag. left and top will be calculated automatically and do not need to be passed.
overflowTagtagOptionThe style of the tag for the overflow count. Refer to the configuration for a single tag. left and top will be calculated automatically and do not need to be passed.