From d587b1340dc432b90cd6368fddd526a1b4a56ff8 Mon Sep 17 00:00:00 2001 From: moklick Date: Thu, 25 Jul 2019 18:22:32 +0200 Subject: [PATCH] feat(example): remove handler --- example/SimpleGraph.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/example/SimpleGraph.js b/example/SimpleGraph.js index 00063a1f..ec00d214 100644 --- a/example/SimpleGraph.js +++ b/example/SimpleGraph.js @@ -1,6 +1,6 @@ import React, { PureComponent } from 'react'; -import Graph, { isEdge } from '../src'; +import Graph, { isEdge, isNode } from '../src'; // import Graph from '../dist/ReactGraph'; const SpecialNode = ({ data, onChange, styles }) => ( @@ -98,12 +98,26 @@ class App extends PureComponent { this.graphInstance.zoomOut(); } + onElementsRemove(elements) { + const nodeIds = elements.filter(isNode).map(n => n.id); + + this.setState(prevState => ({ + elements: prevState.elements.filter(e => { + return ( + !nodeIds.includes(e.id) && + !nodeIds.includes(e.target) && + !nodeIds.includes(e.source) + ); + }) + })); + } + render() { return ( console.log('clicked', node)} - onElementsRemove={elements => console.log('remove', elements)} + onElementsRemove={elements => this.onElementsRemove(elements)} style={{ width: '100%', height: '100%' }} onLoad={graphInstance => this.onLoad(graphInstance)} onChange={(elements) => this.onChange(elements)}