TreeDemo = {
const wrapper = html`<div style="text-align: center;"></div>`;
const container = html`<div></div>`
wrapper.appendChild(container);
yield wrapper;
const data = tree;
G6.registerNode(
'flow-rect',
{
draw(cfg, group) {
const {
name = '',
status,
totalFinishIncomeAmtString,
finishRate,
collapsed,
} = cfg;
const rectConfig = {
width: 200,
height: 74,
lineWidth: 1,
fontSize: 12,
fill: '#fff',
radius: 4,
stroke: status === 'I' ? '#DCDFE5' : '#1890FF',
opacity: 1,
};
if (finishRate < 0.95) rectConfig.stroke = '#EB2F96';
const textConfig = {
textAlign: 'left',
textBaseline: 'top',
};
const rect = group.addShape('rect', {
attrs: {
x: 0,
y: 0,
...rectConfig,
},
});
// label title
group.addShape('text', {
attrs: {
...textConfig,
x: 12,
y: 8,
text: name,
fontSize: 20,
fill: '#000',
cursor: 'pointer',
},
});
// label count
group.addShape('text', {
attrs: {
...textConfig,
x: 12,
y: 34,
text: totalFinishIncomeAmtString,
fontSize: 20,
fill: '#000',
},
});
// label percentage
group.addShape('text', {
attrs: {
...textConfig,
x: 188,
y: 37,
text: `${((finishRate || 0) * 100).toFixed(2)}%`,
fontSize: 14,
textAlign: 'right',
fill: rectConfig.stroke,
},
});
// bottom line
group.addShape('rect', {
attrs: {
x: 0,
y: 70,
width: rectConfig.width,
height: 4,
radius: [0, 0, rectConfig.radius, rectConfig.radius],
fill: '#DCDFE5',
},
});
// bottom percent
group.addShape('rect', {
attrs: {
x: 0,
y: 70,
width: rectConfig.width * cfg.finishRate,
height: 4,
radius: [0, 0, 0, rectConfig.radius],
fill: rectConfig.stroke,
},
});
if (cfg.children && cfg.children.length) {
// collapse circle
group.addShape('circle', {
attrs: {
x: rectConfig.width,
y: rectConfig.height / 2,
r: 8,
stroke: rectConfig.stroke,
fill: '#fff',
},
name: 'collapse-marker'
});
// collpase text
group.addShape('text', {
attrs: {
x: rectConfig.width,
y: rectConfig.height / 2,
width: 16,
height: 16,
textAlign: 'center',
textBaseline: 'middle',
text: collapsed ? '+' : '-',
fontSize: 16,
fill: rectConfig.stroke,
cursor: 'pointer',
},
name: 'collapse-marker-text'
});
}
return rect;
}
},
'rect',
);
// Instantiate the Graph
const graph = new G6.TreeGraph({
container, // the html container for the graph
// the size of the graph
width: 1000,
height: 1000,
fitView: true, // fit the graph to the view
modes: { // intraction modes
default: [ 'drag-canvas', {
type: 'collapse-expand',
shouldBegin: e => {
if (e.target.get('name') === 'collapse-marker' || e.target.get('name') === 'collapse-marker-text') {
graph.setItemState(e.item, 'collapse', e.item.getModel().collapsed ? 'yes' : 'no');
return true;
}
return false;
}
}]
},
defaultNode: { // global node configuration
type: 'flow-rect'
},
defaultEdge: { // global edge configuration
type: 'cubic-horizontal'
},
nodeStateStyles: { // node styles in different states
'collapse:yes': {
'collapse-marker-text': {
text: '-',
},
},
'collapse:no': {
'collapse-marker-text': {
text: '+',
},
}
},
layout: { // layout algorithm for the tree graph
type: 'compactBox',
direction: 'LR',
getVGap: function getVGap() {
return 50;
},
getHGap: function getHGap() {
return 100;
},
}
});
// Load the data
graph.data(data);
// Render the graph
graph.render();
}