Loading...
This document introduces combo attribute configuration, with configuration locations as follows:
import { Graph } from '@antv/g6';const graph = new Graph({// Other configurations...combo: {type: 'circle', // Combo typestyle: {}, // Combo stylestate: {}, // State stylepalette: {}, // Palette configurationanimation: {}, // Animation configuration},});
Attribute | Description | Type | Default | Required |
---|---|---|---|---|
type | Combo type, name of built-in combo type or custom combo name | Type | circle | |
style | Combo style, including color, size, etc. | Style | - | |
state | Defines the style of the combo in different states | State | - | |
palette | Defines the palette of the combo, used to map colors based on different data | Palette | - | |
animation | Defines the animation effects of the combo | Animation | - |
Specifies the combo type, name of built-in combo type or custom combo name. The default is circle
(circular combo).
const graph = new Graph({// Other configurations...combo: {type: 'circle',},});
Optional values are:
circle
: Circular Comborect
: Rectangular ComboDefine the style of the combo here, including color, size, etc.
const graph = new Graph({// Other configurations...combo: {style: {},},});
key
: The main graphic of the combo, representing the main shape of the combo, such as a circle, rectangle, etc.halo
: A graphic that displays a halo effect around the main graphic.label
: Text label, usually used to display the name or description of the combo.The following style configurations will be explained in sequence according to atomic graphics:
Main graphic style when the combo is expanded
Attribute | Description | Type | Default | Required |
---|---|---|---|---|
collapsed | Whether the combo is currently collapsed | boolean | false | |
cursor | Combo mouse hover style, configuration item | string | default | |
fill | Combo fill color | string | #99ADD1 | |
fillOpacity | Combo fill color opacity | number string | 0.04 | |
increasedLineWidthForHitTesting | When lineWidth is small, the interactive area also becomes smaller. Sometimes we want to enlarge this area to make "thin lines" easier to pick up | number | 0 | |
lineCap | Combo stroke end style | round square butt | butt | |
lineDash | Combo stroke dash style | number[] | - | |
lineDashOffset | Combo stroke dash offset | number | - | |
lineJoin | Combo stroke join style | round bevel miter | miter | |
lineWidth | Combo stroke width | number | 1 | |
opacity | Combo opacity | number string | 1 | |
shadowBlur | Combo shadow blur | number | - | |
shadowColor | Combo shadow color | string | - | |
shadowOffsetX | Combo shadow offset in the x-axis direction | number string | - | |
shadowOffsetY | Combo shadow offset in the y-axis direction | number string | - | |
shadowType | Combo shadow type | inner outer | outer | |
stroke | Combo stroke color | string | #99add1 | |
strokeOpacity | Combo stroke color opacity | number string | 1 | |
visibility | Whether the combo is visible | visible hidden | visible | |
x | Combo x coordinate | number | 0 | |
y | Combo y coordinate | number | 0 | |
z | Combo z coordinate | number | 0 | |
zIndex | Combo rendering level | number | 0 | |
{styleProps} | More graphic configurations, refer to BaseStyleProps configuration items | BaseStyleProps | - |
Optional values are: auto
| default
| none
| context-menu
| help
| pointer
| progress
| wait
| cell
| crosshair
| text
| vertical-text
| alias
| copy
| move
| no-drop
| not-allowed
| grab
| grabbing
| all-scroll
| col-resize
| row-resize
| n-resize
| e-resize
| s-resize
| w-resize
| ne-resize
| nw-resize
| se-resize
| sw-resize
| ew-resize
| ns-resize
| nesw-resize
| nwse-resize
| zoom-in
| zoom-out
Example:
const graph = new Graph({// Other configurations...combo: {style: {fill: '#1783FF', // Fill colorstroke: '#000', // Stroke colorlineWidth: 2, // Stroke width},},});
The effect is as follows:
createGraph({autoFit: 'center',data: {nodes: [{ id: 'node1', combo: 'combo1' }],combos: [{ id: 'combo1' }],},combo: {style: { fill: '#1783FF', stroke: '#000', lineWidth: 2 },},},{ width: 240, height: 100 },);
Effective when collapsed
is true
Attribute | Description | Type | Default | Required |
---|---|---|---|---|
collapsedCursor | Mouse hover style when the combo is collapsed, configuration item | string | Same as the cursor when expanded | |
collapsedFill | Fill color when the combo is collapsed | string | Same as the fill when expanded | |
collapsedFillOpacity | Fill color opacity when the combo is collapsed | number string | 1 | |
collapsedIncreasedLineWidthForHitTesting | When the combo is collapsed, if lineWidth is small, the interactive area also becomes smaller. Sometimes we want to enlarge this area to make "thin lines" easier to pick up | number | 0 | |
collapsedLineCap | Stroke end style when the combo is collapsed | round square butt | Same as the lineCap when expanded | |
collapsedLineDash | Stroke dash style when the combo is collapsed | number[] | Same as the lineDash when expanded | |
collapsedLineDashOffset | Stroke dash offset when the combo is collapsed | number | Same as the lineDashOffset when expanded | |
collapsedLineJoin | Stroke join style when the combo is collapsed | round bevel miter | Same as the lineJoin when expanded | |
collapsedLineWidth | Stroke width when the combo is collapsed | number | Same as the lineWidth when expanded | |
collapsedMarker | Whether to display the marker when the combo is collapsed, configuration item | boolean | true | |
collapsedOpacity | Opacity when the combo is collapsed | number string | Same as the opacity when expanded | |
collapsedShadowBlur | Shadow blur when the combo is collapsed | number | Same as the shadowBlur when expanded | |
collapsedShadowColor | Shadow color when the combo is collapsed | string | Same as the shadowColor when expanded | |
collapsedShadowOffsetX | Shadow offset in the x-axis direction when the combo is collapsed | number string | Same as the shadowOffsetX when expanded | |
collapsedShadowOffsetY | Shadow offset in the y-axis direction when the combo is collapsed | number string | Same as the shadowOffsetY when expanded | |
collapsedShadowType | Shadow type when the combo is collapsed | inner outer | Same as the shadowType when expanded | |
collapsedSize | Size when the combo is collapsed | number | [number, number] | [number, number, number] | 32 | |
collapsedStroke | Stroke color when the combo is collapsed | string | Same as the stroke when expanded | |
collapsedStrokeOpacity | Stroke color opacity when the combo is collapsed | number string | Same as the strokeOpacity when expanded | |
collapsedVisibility | Whether the combo is visible when collapsed | visible hidden | Same as the visibility when expanded | |
collapsed{styleProps} | More graphic configurations, refer to BaseStyleProps configuration items | BaseStyleProps | - |
Example:
const graph = new Graph({// Other configurations...combo: {style: {collapsedFill: '#1783FF', // Fill colorcollapsedStroke: '#000', // Stroke colorcollapsedLineWidth: 2, // Stroke width},},});
The effect is as follows:
createGraph({autoFit: 'center',data: {nodes: [{ id: 'node1', combo: 'combo1' }],combos: [{ id: 'combo1', style: { collapsed: true } }],},combo: {style: { collapsedFill: '#1783FF', collapsedStroke: '#000', collapsedLineWidth: 2 },},},{ width: 240, height: 100 },);
Effective when collapsedMarker
is true
Attribute | Description | Type | Default | Required |
---|---|---|---|---|
collapsedMarkerType | Marker type displayed when the combo is collapsed - 'child-count' : Number of child elements (including Node and Combo) - 'descendant-count' : Number of descendant elements (including Node and Combo) - 'node-count' : Number of descendant elements (only including Node) - (children: NodeLikeData[]) => string : Custom processing logic | child-count | descendant-count | node-count | ((children: NodeData | ComboData[]) => string) | child-count | |
collapsedMarkerFill | Icon text color | string | #fff | |
collapsedMarkerFillOpacity | Icon text color opacity | number | 1 | |
collapsedMarkerFontSize | Icon font size | number | 12 | |
collapsedMarkerFontWeight | Icon font weight | number | string | normal | |
collapsedMarkerRadius | Icon corner radius | number | 0 | |
collapsedMarkerSrc | Image source. Its priority is higher than collapsedMarkerText | string | - | |
collapsedMarkerText | Icon text | string | - | |
collapsedMarkerTextAlign | Icon text horizontal alignment | center end left right start | center | |
collapsedMarkerTextBaseline | Icon text alignment baseline | alphabetic bottom hanging ideographic middle top | middle | |
collapsedMarkerWidth | Icon width | number | - | |
collapsedMarkerHeight | Icon height | number | - | |
collapsedMarkerZIndex | Icon rendering level | number | 1 | |
collapsedMarker{StyleProps} | More icon style configurations, refer to TextStyleProps, ImageStyleProps configuration items. For example, collapsedMarkerFontSize represents the font size of the text icon | TextStyleProps | ImageStyleProps | - |
Example:
const graph = new Graph({// Other configurations...combo: {style: {collapsedMarkerFill: '#1783FF', // Fill colorcollapsedMarkerFontSize: 30, // Icon font size},},});
The effect is as follows:
createGraph({autoFit: 'center',data: {nodes: [{ id: 'node1', combo: 'combo1' },{ id: 'node2', combo: 'combo1' },],combos: [{ id: 'combo1', style: { collapsed: true } }],},combo: {style: {collapsedMarkerFill: '#1783FF',collapsedMarkerFontSize: 30,},},},{ width: 240, height: 100 },);
Labels are used to display the text information of the combo:
Attribute | Description | Type | Default | Required |
---|---|---|---|---|
label | Whether to display the combo label | boolean | true | |
labelCursor | Mouse hover style when hovering over the combo label, configuration item | string | default | |
labelFill | Combo label text color | string | #000 | |
labelFillOpacity | Combo label text color opacity | number | 1 | |
labelFontFamily | Combo label font family | string | - | |
labelFontSize | Combo label font size | number | 12 | |
labelFontStyle | Combo label font style | normal italic oblique | - | |
labelFontVariant | Combo label font variant | normal small-caps string | - | |
labelFontWeight | Combo label font weight | normal bold bolder lighter number | 400 | |
labelLeading | Line spacing | number | 0 | |
labelLetterSpacing | Combo label letter spacing | number string | - | |
labelLineHeight | Combo label line height | number string | - | |
labelMaxLines | Maximum number of lines for the combo label | number | 1 | |
labelMaxWidth | Maximum width of the combo label, configuration item | number string | 200% | |
labelOffsetX | Offset of the combo label in the x-axis direction | number | 0 | |
labelOffsetY | Offset of the combo label in the y-axis direction | number | 0 | |
labelPadding | Combo label padding | number number[] | 0 | |
labelPlacement | Position of the combo label relative to the main graphic of the combo, configuration item | string | bottom | |
labelText | Combo label text content | string | - | |
labelTextAlign | Combo label text horizontal alignment | start center middle end left right' left` | ||
labelTextBaseline | Combo label text baseline | top hanging middle alphabetic ideographic bottom | - | |
labelTextDecorationColor | Combo label text decoration line color | string | - | |
labelTextDecorationLine | Combo label text decoration line | string | - | |
labelTextDecorationStyle | Combo label text decoration line style | solid double dotted dashed wavy | - | |
labelTextOverflow | Combo label text overflow handling | clip ellipsis string | - | |
labelTextPath | Combo label text path | Path | - | |
labelWordWrap | Whether the combo label enables automatic line wrapping. After enabling labelWordWrap, the part that exceeds labelMaxWidth will automatically wrap | boolean | false | |
labelZIndex | Combo label rendering level | number | 0 | |
label{StyleProps} | More label style configurations, refer to TextStyleProps attribute values. For example, labelOpacity represents label opacity | TextStyleProps | - |
Optional values are: left
| right
| top
| bottom
| left-top
| left-bottom
| right-top
| right-bottom
| top-left
| top-right
| bottom-left
| bottom-right
| center
| bottom
After enabling automatic line wrapping labelWordWrap
, it will wrap if it exceeds this width:
50%
means the label width does not exceed half of the combo widthFor example, set multi-line label text:
{"labelWordWrap": true,"labelMaxWidth": 200,"labelMaxLines": 3}
Example:
const graph = new Graph({// Other configurationscombo: {style: {label: true, // Whether to display the combo labellabelText: 'Combo Name', // Label text contentlabelFill: '#000', // Label text colorlabelFontSize: 12, // Label font sizelabelFontWeight: 'normal', // Label font weightlabelPlacement: 'bottom', // Position of the label relative to the main graphic of the combo},},});
The effect is as follows:
createGraph({autoFit: 'center',data: {nodes: [{ id: 'node1', combo: 'combo1' }],combos: [{id: 'combo1',style: {label: true,labelText: 'Combo Name',labelFill: '#000',labelFontSize: 12,labelFontWeight: 'normal',labelPlacement: 'bottom',},},],},},{ width: 240, height: 100 },);
Label background is used to display the background of the combo label:
Attribute | Description | Type | Default |
---|---|---|---|
labelBackground | Whether to display the combo label background | boolean | false |
labelBackgroundCursor | Mouse hover style for the combo label background, configuration item | string | default |
labelBackgroundFill | Combo label background fill color | string | #000 |
labelBackgroundFillOpacity | Combo label background opacity | number | 0.75 |
labelBackgroundHeight | Combo label background height | string number | - |
labelBackgroundLineDash | Combo label background dash configuration | number string (number string )[] | - |
labelBackgroundLineDashOffset | Combo label background dash offset | number | - |
labelBackgroundLineWidth | Combo label background stroke width | number | - |
labelBackgroundPadding | Combo label background padding | number number[] | [2, 4, 2, 4] |
labelBackgroundRadius | Combo label background corner radius - number: Uniformly set the four corner radii - number[]: Set the four corner radii separately, automatically fill in if insufficient | number number[] | 0 |
labelBackgroundShadowBlur | Combo label background shadow blur | number | - |
labelBackgroundShadowColor | Combo label background shadow color | string | - |
labelBackgroundShadowOffsetX | Combo label background shadow X direction offset | number | - |
labelBackgroundShadowOffsetY | Combo label background shadow Y direction offset | number | - |
labelBackgroundStroke | Combo label background stroke color | string | - |
labelBackgroundStrokeOpacity | Combo label background stroke opacity | number string | 1 |
labelBackgroundVisibility | Whether the combo label background is visible | visible hidden | - |
labelBackgroundZIndex | Combo label background rendering level | number | 1 |
labelBackground{StyleProps} | More label background style configurations, refer to RectStyleProps attribute values. For example, labelBackgroundOpacity represents label background opacity | RectStyleProps | - |
Example:
const graph = new Graph({// Other configurations...combo: {style: {labelBackground: true, // Whether to display the combo label backgroundlabelBackgroundFill: '#000', // Label background filllabelBackgroundRadius: 10, // Label background corner radiuslabelBackgroundFillOpacity: 0.5, // Label background fill color opacity},},});
The effect is as follows:
createGraph({autoFit: 'center',data: {nodes: [{ id: 'node1', combo: 'combo1' }],combos: [{id: 'combo1',style: {label: true,labelText: 'Combo Name',labelFill: '#000',labelFontSize: 12,labelFontWeight: 'normal',labelPlacement: 'bottom',labelBackground: true,labelBackgroundFill: '#000',labelBackgroundRadius: 10,labelBackgroundFillOpacity: 0.5,},},],},},{ width: 240, height: 100 },);
Attribute | Description | Type | Default | Required |
---|---|---|---|---|
halo | Whether to display the combo halo | boolean | false | |
haloCursor | Mouse hover style for the combo halo, configuration item | string | default | |
haloDraggable | Whether the combo halo is draggable | boolean | true | |
haloDroppable | Whether the combo halo can receive dragged elements | boolean | false | |
haloFill | Halo fill color | string | Same as the fill color of the main graphic fill | |
haloFillRule | Combo halo fill rule | nonzero evenodd | - | |
haloFilter | Combo halo filter | string | - | |
haloLineWidth | Combo halo stroke width | number | 12 | |
haloPointerEvents | Whether the combo halo effect responds to pointer events, configuration item | string | none | |
haloStroke | Combo halo stroke color, this attribute is used to set the color of the halo around the combo to help highlight the combo | string | #99add1 | |
haloStrokeOpacity | Combo halo stroke color opacity | number | 0.25 | |
haloVisibility | Combo halo visibility | visible hidden | visible | |
haloZIndex | Combo halo rendering level | number | -1 | |
halo{StyleProps} | More halo style configurations, refer to DisplayObject configuration items. For example, haloFillOpacity represents halo fill color opacity | DisplayObject | - |
Optional values are:
visible
| visiblepainted
| visiblestroke
| non-transparent-pixel
| visiblefill
| visible
| painted
| fill
| stroke
| all
| none
| auto
| inherit
| initial
| unset
Example:
const graph = new Graph({// Other configurations...combo: {style: {halo: true, // Whether to display the combo halohaloStroke: '#FF0000', // Combo halo stroke colorhaloLineWidth: 10, // Combo halo stroke width},},});
The effect is as follows:
createGraph({autoFit: 'center',data: {nodes: [{ id: 'node1', combo: 'combo1' }],combos: [{ id: 'combo1' }],},combo: {style: {halo: true,haloStroke: '#FF0000',haloLineWidth: 10,},},},{ width: 240, height: 100 },);
Attribute | Description | Type | Default |
---|---|---|---|
icon | Whether to display the combo icon | boolean | true |
iconFill | Combo icon text color | string | - |
iconFontFamily | Combo icon font family | string | - |
iconFontSize | Combo icon font size | number | 16 |
iconFontStyle | Combo icon font style | normal italic oblique | normal |
iconFontVariant | Combo icon font variant | normal small-caps string | normal |
iconFontWeight | Combo icon font weight | number string | normal |
iconHeight | Combo icon height | number | Half the height of the main graphic |
iconLetterSpacing | Combo icon text letter spacing | number string | - |
iconLineHeight | Combo icon text line height | number string | - |
iconMaxLines | Maximum number of lines for the combo icon text | number | 1 |
iconRadius | Combo icon corner radius | number | 0 |
iconSrc | Combo image source. Its priority is higher than iconText | string | - |
iconText | Combo icon text | string | - |
iconTextAlign | Combo icon text horizontal alignment | start center middle end left right | left |
iconTextBaseline | Combo icon text baseline | top hanging middle alphabetic ideographic bottom | alphabetic |
iconTextDecorationColor | Combo icon text decoration line color | string | - |
iconTextDecorationLine | Combo icon text decoration line | string | - |
iconTextDecorationStyle | Combo icon text decoration line style | solid double dotted dashed wavy | solid |
iconTextOverflow | Combo icon text overflow handling | clip ellipsis string | clip |
iconWidth | Combo icon width | number | Half the width of the main graphic |
iconWordWrap | Whether the combo icon text automatically wraps | boolean | - |
Example:
const graph = new Graph({// Other configurations...combo: {style: {iconText: 'Text', // Icon texticonFill: '#FF0000', // Icon text coloriconFontSize: 14, // Icon text sizeiconFontWeight: 'bold', // Icon text weighticonFontStyle: 'italic', // Icon text style},},});
The effect is as follows:
createGraph({autoFit: 'center',data: {combos: [{ id: 'combo1' }],},combo: {style: {iconText: 'Text',iconFill: '#FF0000',iconFontSize: 14,iconFontWeight: 'bold',iconFontStyle: 'italic',},},},{ width: 240, height: 100 },);
In some interactive behaviors, such as clicking to select a combo or hovering to activate an edge, it is merely marking certain states on the element. To reflect these states in the visual space seen by the end user, we need to set different graphic element styles for different states to respond to changes in the element's state.
G6 provides several built-in states, including selected, highlight, active, inactive, and disabled. In addition, it also supports custom states to meet more specific needs. For each state, developers can define a set of style rules that will override the default styles of the element.
The data structure is as follows:
type ComboState = {[state: string]: ComboStyle;};
For example, when the combo is in the focus
state, you can add a stroke with a width of 3 and a color of orange.
const graph = new Graph({combo: {state: {focus: {lineWidth: 3, // Stroke widthstroke: 'orange', // Stroke color},},},});
The effect is as follows:
createGraph({autoFit: 'center',data: {nodes: [{ id: 'node1', combo: 'combo1' }],combos: [{ id: 'combo1', states: ['focus'] }],},combo: {state: {focus: {lineWidth: 3,stroke: 'orange',fill: 'orange',fillOpacity: 0.2,},},},},{ width: 200, height: 100 },);
Defines the animation effects of the combo, supporting the following two configuration methods:
{"combo": {"animation": false}}
Stage animations refer to the animation effects of the combo when entering the canvas, updating, and leaving the canvas. The currently supported stages include:
enter
: Animation when the combo enters the canvasupdate
: Animation when the combo is updatedexit
: Animation when the combo leaves the canvasshow
: Animation when the combo is displayed from a hidden statehide
: Animation when the combo is hiddencollapse
: Animation when the combo is collapsedexpand
: Animation when the combo is expandedYou can refer to Animation Paradigm to use animation syntax to configure the combo, such as:
{"combo": {"animation": {"update": [{"fields": ["x", "y"], // Only animate the x and y attributes during update"duration": 1000, // Animation duration"easing": "linear" // Easing function}],}}
You can also use built-in animation effects:
{"combo": {"animation": {"enter": "fade", // Use fade animation"update": "translate", // Use translate animation"exit": "fade" // Use fade animation}}}
You can pass in false to turn off animations for specific stages:
{"combo": {"animation": {"enter": false // Turn off combo entrance animation}}}
Defines the palette of the combo, which is a predefined pool of combo colors, and assigns colors based on rules, mapping colors to the fill
attribute.
For the definition of the palette, please refer to Palette.
Attribute | Description | Type | Default |
---|---|---|---|
type | Specifies the current palette type. - group : Discrete palette - value : Continuous palette | group | value | group |
field | Specifies the grouping field in the element data. If not specified, the id is used as the grouping field by default | string | ((datum) => string) | id |
color | Palette color. If the palette is registered, you can directly specify its registered name, and it also accepts a color array | string | string[] | - |
invert | Whether to invert the palette | boolean | false |
For example, assign combo colors to a set of data based on the category
field, so that combos of the same category have the same color:
{"combo": {"palette": {"type": "group","field": "category","color": ["#1783FF", "#F08F56", "#D580FF", "#00C9C9", "#7863FF"]}}}
The effect is as follows:
createGraph({data: {combos: new Array(8).fill(0).map((_, i) => ({ id: `combo-${i}`, data: { category: ['A', 'B', 'C', 'D', 'E'][i % 5] } })),},layout: { type: 'grid', cols: 8 },combo: {style: { fillOpacity: 0.4 },palette: {type: 'group',field: 'category',color: ['#1783FF', '#F08F56', '#D580FF', '#00C9C9', '#7863FF'],},},},{ width: 600, height: 100 },);
You can also use the default configuration:
{"combo": {"palette": "tableau" // tableau is the palette name, and colors are assigned based on ID by default}}
The effect is as follows:
createGraph({data: {combos: new Array(8).fill(0).map((_, i) => ({ id: `combo-${i}`, data: { category: ['A', 'B', 'C', 'D', 'E'][i % 5] } })),},layout: { type: 'grid', cols: 8 },combo: {style: { fillOpacity: 0.4 },palette: 'tableau',},},{ width: 600, height: 100 },);