Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'canMoveNode(INode)'. #331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ All props are detailed below.
| `canDeleteSelected` | `func` | `false` | takes the place of `canDeleteNode` and `canDeleteEdge`. It accepts a `SelectionT` type as a parameter. It is called before a node or edge is deleted. The function should return a boolean.
| `canCreateEdge` | `func` | `false` | Called before an edge is created.|
| `canSwapEdge` | `func` | `false` | Called before an edge 'target' is swapped.
| `canMoveNode` | `func` | `false` | Called before a node is moved (e.g. by being dragged). |
| `afterRenderEdge` | `func` | `false` | Called after an edge is rendered. |
| `renderNode` | `func` | `false` | Called to render node geometry. |
| `renderNodeText` | `func` | `false` | Called to render the node text |
Expand Down
1 change: 1 addition & 0 deletions src/components/graph-view-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export type IGraphViewProps = {
hoveredNode: INode | null,
swapEdge: IEdge
) => boolean,
canMoveNode?: (node: INode) => boolean,
onBackgroundClick?: (x: number, y: number, event: any) => void,
onCopySelected?: () => void,
onCreateEdge?: (sourceNode: INode, targetNode: INode) => void,
Expand Down
14 changes: 13 additions & 1 deletion src/components/graph-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> {
canCreateEdge: (startNode?: INode, endNode?: INode) => true,
canSwapEdge: () => true,
canDeleteSelected: () => true,
canMoveNode: () => true,
allowMultiselect: true,
edgeArrowSize: 8,
gridSpacing: 36,
Expand Down Expand Up @@ -862,7 +863,14 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> {
}

handleNodeMove = (position: IPoint, nodeId: string, shiftKey: boolean) => {
const { canCreateEdge, readOnly, selected, nodeKey, onSelect } = this.props;
const {
canCreateEdge,
canMoveNode,
readOnly,
selected,
nodeKey,
onSelect,
} = this.props;
const { draggingEdge, nodesMap } = this.state;
const nodeMapNode: INodeMapNode | null = this.getNodeById(nodeId);

Expand All @@ -872,6 +880,10 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> {

const node = nodeMapNode.node;

if (canMoveNode && !canMoveNode(node)) {
return;
}

if (!shiftKey && !draggingEdge) {
const originalX = node.x || 0;
const originalY = node.y || 0;
Expand Down