From 926480971e2ea28148b77757b40fc8746fc67873 Mon Sep 17 00:00:00 2001 From: man-person <68955078+man-person@users.noreply.github.com> Date: Sun, 11 Oct 2020 11:16:46 +0300 Subject: [PATCH 1/3] center svg icon in re-center control button --- src/styles/main.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/styles/main.scss b/src/styles/main.scss index 6afc3d59..adcea7f4 100644 --- a/src/styles/main.scss +++ b/src/styles/main.scss @@ -158,6 +158,10 @@ $background-color: #f9f9f9; border-radius: 2px; cursor: pointer; margin: 0; + + > svg { + vertical-align: sub; + } } } From c5b15e45bdee30c0dea26e22cc038b472dcde2c6 Mon Sep 17 00:00:00 2001 From: Ivan Yulin Date: Thu, 22 Oct 2020 22:12:32 +0300 Subject: [PATCH 2/3] expose "onMoveNode" method (optional), added "canDragNode" method (optional) --- src/components/graph-view-props.js | 2 ++ src/components/graph-view.js | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/graph-view-props.js b/src/components/graph-view-props.js index aa9cccce..c7d5dd0d 100644 --- a/src/components/graph-view-props.js +++ b/src/components/graph-view-props.js @@ -61,6 +61,7 @@ export type IGraphViewProps = { hoveredNode: INode | null, swapEdge: IEdge ) => boolean, + canDragNode?: (nodeId: string) => boolean, onBackgroundClick?: (x: number, y: number, event: any) => void, onCopySelected?: () => void, onCreateEdge?: (sourceNode: INode, targetNode: INode) => void, @@ -77,6 +78,7 @@ export type IGraphViewProps = { onSwapEdge?: (sourceNode: INode, targetNode: INode, edge: IEdge) => void, onUndo?: () => void, onUpdateNode?: (node: INode) => void, + onMoveNode?: (node: INode) => void, onArrowClicked?: (selectedEdge: IEdge) => void, renderBackground?: (gridSize?: number) => any, renderDefs?: () => any, diff --git a/src/components/graph-view.js b/src/components/graph-view.js index 4326e2a9..5d8409ff 100644 --- a/src/components/graph-view.js +++ b/src/components/graph-view.js @@ -67,6 +67,7 @@ class GraphView extends React.Component { canSwapEdge: () => true, canDeleteEdge: () => true, canDeleteNode: () => true, + canDragNode: () => true, edgeArrowSize: 8, gridSpacing: 36, layoutEngineType: 'None', @@ -774,7 +775,7 @@ class GraphView extends React.Component { } handleNodeMove = (position: IPoint, nodeId: string, shiftKey: boolean) => { - const { canCreateEdge, readOnly } = this.props; + const { canCreateEdge, readOnly, onMoveNode, canDragNode } = this.props; const nodeMapNode: INodeMapNode | null = this.getNodeById(nodeId); if (!nodeMapNode) { @@ -783,10 +784,14 @@ class GraphView extends React.Component { const node = nodeMapNode.node; - if (readOnly) { + if (readOnly || !canDragNode(nodeId)) { return; } + if (onMoveNode) { + onMoveNode(node); + } + if (!shiftKey && !this.state.draggingEdge) { // node moved node.x = position.x; From f5313c9dc7eeb52ed286d65c4dca7594ba5a672e Mon Sep 17 00:00:00 2001 From: man-person <68955078+man-person@users.noreply.github.com> Date: Sun, 25 Oct 2020 12:24:01 +0200 Subject: [PATCH 3/3] update typings for changes --- typings/index.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index b7ff27b0..1f12ded1 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -129,7 +129,8 @@ declare module 'react-digraph' { sourceNode: INode, hoveredNode: INode | null, swapEdge: IEdge - ) => boolean, + ) => boolean; + canDragNode?: (nodeId: string) => boolean; onBackgroundClick?: (x: number, y: number, event: any) => void, onCopySelected?: () => void; onCreateEdge?: (sourceNode: INode, targetNode: INode) => void; @@ -139,10 +140,11 @@ declare module 'react-digraph' { onPasteSelected?: ( selectedNode: INode, xyCoords?: { x: number, y: number } - ) => void, + ) => void; onSelectEdge?: (selectedEdge: IEdge) => void; onSelectNode?: (node: INode | null, event: any) => void; onSwapEdge?: (sourceNode: INode, targetNode: INode, edge: IEdge) => void; + onMoveNode?: (node: INode) => void; onUndo?: () => void; onUpdateNode?: (node: INode) => void; renderBackground?: (gridSize?: number) => any;