docs: update layout pipe demmo

This commit is contained in:
Yanyan-Wang 2021-05-26 15:17:47 +08:00 committed by Yanyan Wang
parent e1111b1787
commit 2694bce521
8 changed files with 697 additions and 522 deletions

View File

@ -16,7 +16,7 @@
- fix: depth problem for addItem with comboId, closes: #2888;
- feat: focus edge item;
- feat: legend plugin;
- feat: allow to new a tree layout indenpently;
- feat: allow to new a tree layout independently;
#### 4.2.7

View File

@ -61,7 +61,7 @@
},
"dependencies": {
"@antv/g-base": "^0.5.1",
"@antv/g6-core": "*",
"@antv/g6-core": "0.3.2",
"@antv/util": "~2.0.5"
},
"devDependencies": {

View File

@ -66,7 +66,7 @@
]
},
"dependencies": {
"@antv/g6-pc": "*"
"@antv/g6-pc": "0.3.2"
},
"devDependencies": {
"@babel/core": "^7.7.7",

View File

@ -74,9 +74,9 @@
"@antv/g-canvas": "^0.5.2",
"@antv/g-math": "^0.1.1",
"@antv/g-svg": "^0.5.1",
"@antv/g6-core": "*",
"@antv/g6-plugin": "*",
"@antv/g6-element": "*",
"@antv/g6-core": "0.3.2",
"@antv/g6-plugin": "0.3.2",
"@antv/g6-element": "0.3.2",
"@antv/algorithm": "^0.1.8",
"@antv/hierarchy": "^0.6.7",
"@antv/layout": "^0.1.14",

View File

@ -22,7 +22,7 @@
"@antv/g-base": "^0.5.1",
"@antv/g-canvas": "^0.5.2",
"@antv/g-svg": "^0.5.2",
"@antv/g6-core": "*",
"@antv/g6-core": "0.3.2",
"@antv/matrix-util": "^3.0.4",
"@antv/scale": "^0.3.4",
"@antv/util": "^2.0.9",

View File

@ -1,500 +1,57 @@
import G6 from '@antv/g6';
const data = {
nodes: [
{
id: '0',
label: '0',
cluster: 'a',
},
{
id: '1',
label: '1',
cluster: 'a',
},
{
id: '2',
label: '2',
cluster: 'a',
},
{
id: '3',
label: '3',
cluster: 'a',
},
{
id: '4',
label: '4',
cluster: 'a',
},
{
id: '5',
label: '5',
cluster: 'a',
},
{
id: '6',
label: '6',
cluster: 'a',
},
{
id: '7',
label: '7',
cluster: 'a',
},
{
id: '8',
label: '8',
cluster: 'a',
},
{
id: '9',
label: '9',
cluster: 'a',
},
{
id: '10',
label: '10',
cluster: 'a',
},
{
id: '11',
label: '11',
cluster: 'a',
},
{
id: '12',
label: '12',
cluster: 'a',
},
{
id: '13',
label: '13',
cluster: 'b',
},
{
id: '14',
label: '14',
cluster: 'b',
},
{
id: '15',
label: '15',
cluster: 'b',
},
{
id: '16',
label: '16',
cluster: 'b',
},
{
id: '17',
label: '17',
cluster: 'b',
},
{
id: '18',
label: '18',
cluster: 'c',
},
{
id: '19',
label: '19',
cluster: 'c',
},
{
id: '20',
label: '20',
cluster: 'c',
},
{
id: '21',
label: '21',
cluster: 'c',
},
{
id: '22',
label: '22',
cluster: 'c',
},
{
id: '23',
label: '23',
cluster: 'c',
},
{
id: '24',
label: '24',
cluster: 'c',
},
{
id: '25',
label: '25',
cluster: 'c',
},
{
id: '26',
label: '26',
cluster: 'c',
},
{
id: '27',
label: '27',
cluster: 'c',
},
{
id: '28',
label: '28',
cluster: 'c',
},
{
id: '29',
label: '29',
cluster: 'c',
},
{
id: '30',
label: '30',
cluster: 'c',
},
{
id: '31',
label: '31',
cluster: 'd',
},
{
id: '32',
label: '32',
cluster: 'd',
},
{
id: '33',
label: '33',
cluster: 'd',
},
],
edges: [
{
source: '0',
target: '1',
},
{
source: '0',
target: '2',
},
{
source: '0',
target: '3',
},
{
source: '0',
target: '4',
},
{
source: '0',
target: '5',
},
{
source: '0',
target: '7',
},
{
source: '0',
target: '8',
},
{
source: '0',
target: '9',
},
{
source: '0',
target: '10',
},
{
source: '0',
target: '11',
},
{
source: '0',
target: '13',
},
{
source: '0',
target: '14',
},
{
source: '0',
target: '15',
},
{
source: '0',
target: '16',
},
{
source: '2',
target: '3',
},
{
source: '4',
target: '5',
},
{
source: '4',
target: '6',
},
{
source: '5',
target: '6',
},
{
source: '7',
target: '13',
},
{
source: '8',
target: '14',
},
{
source: '9',
target: '10',
},
{
source: '10',
target: '22',
},
{
source: '10',
target: '14',
},
{
source: '10',
target: '12',
},
{
source: '10',
target: '24',
},
{
source: '10',
target: '21',
},
{
source: '10',
target: '20',
},
{
source: '11',
target: '24',
},
{
source: '11',
target: '22',
},
{
source: '11',
target: '14',
},
{
source: '12',
target: '13',
},
{
source: '16',
target: '17',
},
{
source: '16',
target: '18',
},
{
source: '16',
target: '21',
},
{
source: '16',
target: '22',
},
{
source: '17',
target: '18',
},
{
source: '17',
target: '20',
},
{
source: '18',
target: '19',
},
{
source: '19',
target: '20',
},
{
source: '19',
target: '33',
},
{
source: '19',
target: '22',
},
{
source: '19',
target: '23',
},
{
source: '20',
target: '21',
},
{
source: '21',
target: '22',
},
{
source: '22',
target: '24',
},
{
source: '22',
target: '25',
},
{
source: '22',
target: '26',
},
{
source: '22',
target: '23',
},
{
source: '22',
target: '28',
},
{
source: '22',
target: '30',
},
{
source: '22',
target: '31',
},
{
source: '22',
target: '32',
},
{
source: '22',
target: '33',
},
{
source: '23',
target: '28',
},
{
source: '23',
target: '27',
},
{
source: '23',
target: '29',
},
{
source: '23',
target: '30',
},
{
source: '23',
target: '31',
},
{
source: '23',
target: '33',
},
{
source: '32',
target: '33',
},
],
};
const data = { nodes: [], edges: [] };
for (let i = 0; i < 32; i++) {
data.nodes.push({
id: `${i}`,
label: i < 17 ? `employee-${i}` : `company-${i - 17}`,
dataType: i < 17 ? 'employee' : 'company',
style: i < 17 ?
{ stroke: '#5D7092', fill: '#5D7092', fillOpacity: 0.5 } :
{ stroke: '#5B8FF9', fill: '#5B8FF9', fillOpacity: 0.5 }
});
}
data.edges = [
{ source: '0', target: '1' },
{ source: '0', target: '2' },
{ source: '0', target: '3' },
{ source: '0', target: '4' },
{ source: '0', target: '5' },
{ source: '0', target: '6' },
{ source: '1', target: '2' },
{ source: '1', target: '3' },
{ source: '1', target: '4' },
{ source: '1', target: '5' },
{ source: '1', target: '6' },
{ source: '2', target: '3' },
{ source: '2', target: '4' },
{ source: '2', target: '5' },
{ source: '2', target: '6' },
const colors = [
'#BDD2FD',
'#BDEFDB',
'#C2C8D5',
'#FBE5A2',
'#F6C3B7',
'#B6E3F5',
'#D3C6EA',
'#FFD8B8',
'#AAD8D8',
'#FFD6E7',
{ source: '7', target: '8' },
{ source: '8', target: '9' },
{ source: '9', target: '10' },
{ source: '11', target: '12' },
{ source: '12', target: '13' },
{ source: '13', target: '14' },
{ source: '14', target: '15' },
{ source: '15', target: '16' },
{ source: '11', target: '14' },
{ source: '31', target: '11' },
{ source: '24', target: '4' },
{ source: '23', target: '7' },
];
const strokes = [
'#5B8FF9',
'#5AD8A6',
'#5D7092',
'#F6BD16',
'#E8684A',
'#6DC8EC',
'#9270CA',
'#FF9D4D',
'#269A99',
'#FF99C3',
];
const clusterMap = new Map();
let clusterId = 0;
data.nodes.forEach(function (node) {
// cluster
if (node.cluster && clusterMap.get(node.cluster) === undefined) {
clusterMap.set(node.cluster, clusterId);
clusterId++;
}
const cid = clusterMap.get(node.cluster);
if (!node.style) {
node.style = {};
}
node.style.fill = colors[cid % colors.length];
node.style.stroke = strokes[cid % strokes.length];
});
data.edges.forEach(edge => {
edge.cluster = data.nodes[+edge.source].cluster;
const cid = clusterMap.get(edge.cluster);
console.log(edge.cluster, cid)
edge.style = {
stroke: colors[cid % colors.length]
}
})
const legendData = {
nodes: [
{ id: 'a', label: 'a', },
{ id: 'b', label: 'b', },
{ id: 'c', label: 'c', },
{ id: 'd', label: 'd', }
], edges: [
{ id: 'a', label: 'a', },
{ id: 'b', label: 'b', },
{ id: 'c', label: 'c', },
{ id: 'd', label: 'd', }
]
{ id: 'employee', label: 'employee', style: { stroke: '#5D7092', fill: '#5D7092' } },
{ id: 'company', label: 'company', style: { stroke: '#5B8FF9', fill: '#5B8FF9' } },
],
edges: []
}
legendData.nodes.forEach(node => {
const cid = clusterMap.get(node.id);
node.style = {
fill: colors[cid % colors.length],
stroke: strokes[cid % strokes.length]
};
})
legendData.edges.forEach(node => {
const cid = clusterMap.get(node.id);
node.style = {
fill: colors[cid % colors.length],
stroke: strokes[cid % strokes.length]
};
})
const legend = new G6.Legend({
data: legendData,
align: 'center',
@ -553,22 +110,6 @@ const graph = new G6.Graph({
},
plugins: [legend],
animate: true,
defaultNode: {
size: 20,
style: {
lineWidth: 2,
},
},
defaultEdge: {
size: 1,
color: '#e2e2e2',
style: {
endArrow: {
path: 'M 0,0 L 8,4 L 8,-4 Z',
fill: '#e2e2e2',
},
},
},
nodeStateStyles: {
activeByLegend: {
lineWidth: 5,
@ -579,17 +120,34 @@ const graph = new G6.Graph({
opacity: 0.5
}
},
edgeStateStyles: {
activeByLegend: {
lineWidth: 10,
strokeOpacity: 0.5
},
inactiveByLegend: {
opacity: 0.5
}
},
layout: {
type: 'gForce',
pipes: [
{
type: 'circular',
nodesFilter: (node) => (+node.id) <= 6,
center: [width / 5 * 4 - 30, height / 2],
radius: width / 10
},
{
type: 'circular',
nodesFilter: (node) => ((+node.id) >= 7 && (+node.id) <= 10),
center: [width / 20 + 30, height / 3 * 2],
radius: width / 20
},
{
type: 'circular',
nodesFilter: (node) => ((+node.id) >= 11 && (+node.id) <= 16),
center: [width / 20 + 30, height / 3],
radius: width / 20
},
{
type: 'grid',
nodesFilter: (node) => (+node.id) > 16,
begin: [width / 10 + 50, 20],
width: width / 5 * 3 - 100,
height: height - 40,
}
],
},
});
graph.data(data);

View File

@ -0,0 +1,609 @@
import G6 from '@antv/g6';
const container = document.getElementById('container');
const width = container.scrollWidth;
const height = (container.scrollHeight || 500) - 50;
const el = document.createElement('pre');
el.innerHTML =
'Click the legend item to filter\n点击图例上的元素进行筛选';
container.appendChild(el);
const data = {
nodes: [
{
id: '0',
label: '0',
cluster: 'a',
},
{
id: '1',
label: '1',
cluster: 'a',
},
{
id: '2',
label: '2',
cluster: 'a',
},
{
id: '3',
label: '3',
cluster: 'a',
},
{
id: '4',
label: '4',
cluster: 'a',
},
{
id: '5',
label: '5',
cluster: 'a',
},
{
id: '6',
label: '6',
cluster: 'a',
},
{
id: '7',
label: '7',
cluster: 'a',
},
{
id: '8',
label: '8',
cluster: 'a',
},
{
id: '9',
label: '9',
cluster: 'a',
},
{
id: '10',
label: '10',
cluster: 'a',
},
{
id: '11',
label: '11',
cluster: 'a',
},
{
id: '12',
label: '12',
cluster: 'a',
},
{
id: '13',
label: '13',
cluster: 'b',
},
{
id: '14',
label: '14',
cluster: 'b',
},
{
id: '15',
label: '15',
cluster: 'b',
},
{
id: '16',
label: '16',
cluster: 'b',
},
{
id: '17',
label: '17',
cluster: 'b',
},
{
id: '18',
label: '18',
cluster: 'c',
},
{
id: '19',
label: '19',
cluster: 'c',
},
{
id: '20',
label: '20',
cluster: 'c',
},
{
id: '21',
label: '21',
cluster: 'c',
},
{
id: '22',
label: '22',
cluster: 'c',
},
{
id: '23',
label: '23',
cluster: 'c',
},
{
id: '24',
label: '24',
cluster: 'c',
},
{
id: '25',
label: '25',
cluster: 'c',
},
{
id: '26',
label: '26',
cluster: 'c',
},
{
id: '27',
label: '27',
cluster: 'c',
},
{
id: '28',
label: '28',
cluster: 'c',
},
{
id: '29',
label: '29',
cluster: 'c',
},
{
id: '30',
label: '30',
cluster: 'c',
},
{
id: '31',
label: '31',
cluster: 'd',
},
{
id: '32',
label: '32',
cluster: 'd',
},
{
id: '33',
label: '33',
cluster: 'd',
},
],
edges: [
{
source: '0',
target: '1',
},
{
source: '0',
target: '2',
},
{
source: '0',
target: '3',
},
{
source: '0',
target: '4',
},
{
source: '0',
target: '5',
},
{
source: '0',
target: '7',
},
{
source: '0',
target: '8',
},
{
source: '0',
target: '9',
},
{
source: '0',
target: '10',
},
{
source: '0',
target: '11',
},
{
source: '0',
target: '13',
},
{
source: '0',
target: '14',
},
{
source: '0',
target: '15',
},
{
source: '0',
target: '16',
},
{
source: '2',
target: '3',
},
{
source: '4',
target: '5',
},
{
source: '4',
target: '6',
},
{
source: '5',
target: '6',
},
{
source: '7',
target: '13',
},
{
source: '8',
target: '14',
},
{
source: '9',
target: '10',
},
{
source: '10',
target: '22',
},
{
source: '10',
target: '14',
},
{
source: '10',
target: '12',
},
{
source: '10',
target: '24',
},
{
source: '10',
target: '21',
},
{
source: '10',
target: '20',
},
{
source: '11',
target: '24',
},
{
source: '11',
target: '22',
},
{
source: '11',
target: '14',
},
{
source: '12',
target: '13',
},
{
source: '16',
target: '17',
},
{
source: '16',
target: '18',
},
{
source: '16',
target: '21',
},
{
source: '16',
target: '22',
},
{
source: '17',
target: '18',
},
{
source: '17',
target: '20',
},
{
source: '18',
target: '19',
},
{
source: '19',
target: '20',
},
{
source: '19',
target: '33',
},
{
source: '19',
target: '22',
},
{
source: '19',
target: '23',
},
{
source: '20',
target: '21',
},
{
source: '21',
target: '22',
},
{
source: '22',
target: '24',
},
{
source: '22',
target: '25',
},
{
source: '22',
target: '26',
},
{
source: '22',
target: '23',
},
{
source: '22',
target: '28',
},
{
source: '22',
target: '30',
},
{
source: '22',
target: '31',
},
{
source: '22',
target: '32',
},
{
source: '22',
target: '33',
},
{
source: '23',
target: '28',
},
{
source: '23',
target: '27',
},
{
source: '23',
target: '29',
},
{
source: '23',
target: '30',
},
{
source: '23',
target: '31',
},
{
source: '23',
target: '33',
},
{
source: '32',
target: '33',
},
],
};
const colors = [
'#BDD2FD',
'#BDEFDB',
'#C2C8D5',
'#FBE5A2',
'#F6C3B7',
'#B6E3F5',
'#D3C6EA',
'#FFD8B8',
'#AAD8D8',
'#FFD6E7',
];
const strokes = [
'#5B8FF9',
'#5AD8A6',
'#5D7092',
'#F6BD16',
'#E8684A',
'#6DC8EC',
'#9270CA',
'#FF9D4D',
'#269A99',
'#FF99C3',
];
const clusterMap = new Map();
let clusterId = 0;
data.nodes.forEach(function (node) {
// cluster
if (node.cluster && clusterMap.get(node.cluster) === undefined) {
clusterMap.set(node.cluster, clusterId);
clusterId++;
}
const cid = clusterMap.get(node.cluster);
if (!node.style) {
node.style = {};
}
node.style.fill = colors[cid % colors.length];
node.style.stroke = strokes[cid % strokes.length];
});
data.edges.forEach(edge => {
edge.cluster = data.nodes[+edge.source].cluster;
const cid = clusterMap.get(edge.cluster);
console.log(edge.cluster, cid)
edge.style = {
stroke: colors[cid % colors.length]
}
})
const legendData = {
nodes: [
{ id: 'a', label: 'a', },
{ id: 'b', label: 'b', },
{ id: 'c', label: 'c', },
{ id: 'd', label: 'd', }
], edges: [
{ id: 'a', label: 'a', },
{ id: 'b', label: 'b', },
{ id: 'c', label: 'c', },
{ id: 'd', label: 'd', }
]
}
legendData.nodes.forEach(node => {
const cid = clusterMap.get(node.id);
node.style = {
fill: colors[cid % colors.length],
stroke: strokes[cid % strokes.length]
};
})
legendData.edges.forEach(node => {
const cid = clusterMap.get(node.id);
node.style = {
fill: colors[cid % colors.length],
stroke: strokes[cid % strokes.length]
};
})
const legend = new G6.Legend({
data: legendData,
align: 'center',
layout: 'horizontal', // vertical
position: 'bottom-left',
vertiSep: 12,
horiSep: 24,
offsetY: -24,
padding: [4, 16, 8, 16],
containerStyle: {
fill: '#ccc',
lineWidth: 1
},
title: 'Legend',
titleConfig: {
position: 'left',
offsetX: 0,
offsetY: 12,
},
filter: {
enable: true,
multiple: true,
trigger: 'click',
graphActiveState: 'activeByLegend',
graphInactiveState: 'inactiveByLegend',
filterFunctions: {
'a': (d) => {
if (d.cluster === 'a') return true;
return false
},
'b': (d) => {
if (d.cluster === 'b') return true;
return false
},
'c': (d) => {
if (d.cluster === 'c') return true;
return false
},
'd': (d) => {
if (d.cluster === 'd') return true;
return false
},
}
}
});
const graph = new G6.Graph({
container: 'container',
width,
height,
modes: {
default: ['drag-canvas', 'drag-node'],
},
plugins: [legend],
animate: true,
defaultNode: {
size: 20,
style: {
lineWidth: 2,
},
},
defaultEdge: {
size: 1,
color: '#e2e2e2',
style: {
endArrow: {
path: 'M 0,0 L 8,4 L 8,-4 Z',
fill: '#e2e2e2',
},
},
},
nodeStateStyles: {
activeByLegend: {
lineWidth: 5,
strokeOpacity: 0.5,
stroke: '#f00'
},
inactiveByLegend: {
opacity: 0.5
}
},
edgeStateStyles: {
activeByLegend: {
lineWidth: 10,
strokeOpacity: 0.5
},
inactiveByLegend: {
opacity: 0.5
}
},
layout: {
type: 'gForce',
},
});
graph.data(data);
graph.render();
if (typeof window !== 'undefined')
window.onresize = () => {
if (!graph || graph.get('destroyed')) return;
if (!container || !container.scrollWidth || !container.scrollHeight) return;
graph.changeSize(container.scrollWidth, container.scrollHeight);
};

View File

@ -19,6 +19,14 @@
"en": "Legend with Hovering Filtering"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*ftAtR6k9RWIAAAAAAAAAAAAAARQnAQ"
},
{
"filename": "legendClick.js",
"title": {
"zh": "图例-点击筛选2",
"en": "Legend with Clicking Filtering 2"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*nCTfRq6522kAAAAAAAAAAAAAARQnAQ"
}
]
}