antvis / g6-editor

532 stars 172 forks source link

Get edges when drawing node #90

Open karaxuna opened 5 years ago

karaxuna commented 5 years ago

I'm trying to draw node with different color depending on whether it has edges or not, my data looks like this:

        nodes: [{
            type: 'node',
            shape: 'task',
            label: 'test1,
            x: 155,
            y: 155,
            id: 'ea1184e8',
            index: 0,
        }, {
            type: 'node',
            shape: 'task',
            label: 'test2',
            x: 155,
            y: 255,
            id: '481fbb1a',
            index: 2,
        }],
        edges: [{
            source: 'ea1184e8',
            target: '481fbb1a',
        }]

I'm calling page.read:

page.read(data);

Then node's draw is called. My draw method looks like this:

G6Editor.registerNode('task', {
    draw(item) {
        const edges = item.getEdges();
        // Edges is empty array
    }
}, 'flow-rect');

I was expecting edge to be:

{
    source: 'ea1184e8',
    target: '481fbb1a',
}