feat(rg): removeElements helper

This commit is contained in:
moklick
2019-07-25 18:27:41 +02:00
parent d587b1340d
commit bb17c2fcb6
4 changed files with 36 additions and 17 deletions
+13
View File
@@ -1,6 +1,19 @@
export const isEdge = element => element.source && element.target;
export const isNode = element => !element.source && !element.target;
export const removeElements = (elements, elementsToRemove) => {
const nodeIdsToRemove = elementsToRemove.filter(isNode).map(n => n.id);
return elements.filter(e => {
return (
!nodeIdsToRemove.includes(e.id) &&
!nodeIdsToRemove.includes(e.target) &&
!nodeIdsToRemove.includes(e.source)
);
});
}
export const parseElements = e => {
e.type = e.type || 'default';
+8 -3
View File
@@ -1,7 +1,12 @@
import ReactGraph from './ReactGraph';
import { isNode as isNodeRG , isEdge as isEdgeRG } from './graph-utils';
import {
isNode as _isNode ,
isEdge as _isEdge,
removeElements as _removeElements
} from './graph-utils';
export const isNode = isNodeRG;
export const isEdge = isEdgeRG;
export const isNode = _isNode;
export const isEdge = _isEdge;
export const removeElements = _removeElements;
export default ReactGraph;