x6自定义节点样式
![](https://img-blog.csdnimg.cn/img_convert/5737e8493b7c3cb67169f3199ce04b49.png)
自定义节点
- 官方的示例如下自定义节点示例(由于自动布局示例的要素过多,暂以倒数第二个示例来看)
- 要素:
- markup:markup官方文档
markup
指定了渲染节点/边时使用的 SVG/HTML
片段,使用 JSON
格式描述。例如 Shape.Rect
节点的markup
定义如下。
- tagname:
通过tagname
指定需要创建的SVG/HTML
元素 - selector:
SVG/HTML
元素的唯一标识,可以在attrs
中通过selector:'name'
的name
属性修改样式 - className:
该SVG/HTML
元素的css
样式名 - style:
该SVG/HTML
元素的内联样式
- attrs:
定制节点样式的选项,是一个复杂的对象key:{value...}
,key
是节点中的selector
值,value
是该元素的SVG
属性值
注册自定义节点样式
Graph.registerNode('diy-shape',{
width:200,
height:60,
markup:[
{
tagName:'rect',
selector:'body',
},
{
tagName:'image',
selector:'avatar'
},
{
tagName: 'text',
selector: 'rank',
},
{
tagName: 'text',
selector: 'name',
},
],
attrs:{
body: {
refWidth: '100%',
refHeight: '100%',
fill: '#ffffff',
stroke: '#000000',
rx: 10,
ry: 10,
PointerEvent: 'visiblePainted',
},
avatar: {
width: 48,
height: 48,
refX: 8,
refY: 6,
},
rank: {
refX: 0.9,
refY: 0.2,
fontFamily: 'Courier New',
fontSize: 14,
textAnchor: 'end',
},
name: {
refX: 0.9,
refY: 0.6,
fontFamily: 'Courier New',
fontSize: 14,
fontWeight: '800',
textAnchor: 'end',
},
}
},true)
添加自定义节点
id:'diy-shape1',
shape:'diy-shape',
attrs: {
body: {
fill: '#7c68fd',
stroke: 'none',
},
avatar: {
opacity: 0.7,
'xlink:href':'自定义图片链接或base64',
width: '50px',
height: '50px',
},
rank: {
text: 'Step 0',
fill: '#f1f1f1',
wordSpacing: '-5px',
letterSpacing: 0,
},
name: {
text: '完成',
fill: '#f1f1f1',
fontSize: 13,
fontFamily: 'Arial',
letterSpacing: 0,
},
ports: { ...ports },
},
自定义连线
注册连线样式
Graph.registerEdge(
'diy-edge',
{
zIndex: -1,
attrs: {
line: {
fill: 'none',
strokeLinejoin: 'round',
strokeWidth: '2',
stroke: '#4b4a67',
sourceMarker: null,
targetMarker: null,
},
},
},
true
);
使用自定义连线
在data的edges中声明shape
{
source: 'Step1-Vasp晶格常数-GeoOpt',
target: 'Step2-结果收敛判断脚本',
fileDependencies: [
{
targetAppFile: '08d88153-6397-4136-8c09-7052f740dc87',
dependencyAppFile: '08d85499-af1c-428c-867c-b78a8fde4597',
dependencyType: 'appFile',
},
{
targetAppFile: '08d88153-76de-435d-8c4d-477393c28d95',
dependencyAppFile: '08d85499-d4aa-4580-880e-d1dfab86e2cd',
dependencyType: 'appFile',
},
],
shape: 'diy-edge',
zIndex: 1,
},