Skip to content

Commit

Permalink
Merge pull request #119 from KaplanTestPrep/prevent-edge-handle-rotation
Browse files Browse the repository at this point in the history
Possibility to not rotate edge handle
  • Loading branch information
ajbogh authored Jun 5, 2019
2 parents 176fc00 + b6ad9bf commit a2562a9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ All props are detailed below.
| zoomDur | number | false | Duration of zoom transition. |
| showGraphControls | boolean | false | Whether to show zoom controls. |
| layoutEngineType | typeof LayoutEngineType | false | Uses a pre-programmed layout engine, such as 'SnapToGrid' |
| rotateEdgeHandle | boolean | false | Whether to rotate edge handle with edge when a node is moved |
| centerNodeOnMove | boolean | false | Weather the node should be centered on cursor when moving a node |
| initialBBox | typeof IBBox | false | If specified, initial render graph using the given bounding box|

Expand Down Expand Up @@ -298,6 +299,7 @@ Prop Types:
) => any;
renderNodeText?: (data: any, id: string | number, isSelected: boolean) => any;
layoutEngineType?: LayoutEngineType;
rotateEdgeHandle?: boolean;
centerNodeOnMove?: boolean;
initialBBox?: IBBox;
```
Expand Down
10 changes: 6 additions & 4 deletions src/components/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ type IEdgeProps = {
isSelected: boolean;
nodeKey: string;
viewWrapperElem: HTMLDivElement;
rotateEdgeHandle: true;
};

class Edge extends React.Component<IEdgeProps> {
static defaultProps = {
edgeHandleSize: 50,
isSelected: false
isSelected: false,
rotateEdgeHandle: true,
};

static getTheta(pt1: any, pt2: any) {
Expand Down Expand Up @@ -466,7 +468,7 @@ class Edge extends React.Component<IEdgeProps> {
}

getEdgeHandleRotation = (negate: any = false) => {
let rotated = false
let rotated = false;
const src = this.props.sourceNode;
const trg = this.props.targetNode;
let theta = Edge.getTheta(src, trg) * 180 / Math.PI;
Expand All @@ -482,7 +484,7 @@ class Edge extends React.Component<IEdgeProps> {

getEdgeHandleTransformation = () => {
const translation = this.getEdgeHandleTranslation();
const [ rotation, ]= this.getEdgeHandleRotation();
const rotation = this.props.rotateEdgeHandle ? this.getEdgeHandleRotation()[0] : '';
const offset = this.getEdgeHandleOffsetTranslation();
return `${translation} ${rotation} ${offset}`;
}
Expand Down Expand Up @@ -546,7 +548,7 @@ class Edge extends React.Component<IEdgeProps> {
}

render() {
const { data, edgeTypes, edgeHandleSize, viewWrapperElem } = this.props;
const { data, edgeTypes, edgeHandleSize, viewWrapperElem, rotateEdgeHandle } = this.props;
if (!viewWrapperElem) {
return null;
}
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 @@ -78,6 +78,7 @@ export type IGraphViewProps = {
) => any;
afterRenderEdge?: (id: string, element: any, edge: IEdge, edgeContainer: any, isEdgeSelected: boolean) => void;
renderNodeText?: (data: any, id: string | number, isSelected: boolean) => any;
rotateEdgeHandle?: boolean;
centerNodeOnMove?: boolean;
initialBBox: IBBox;
};
4 changes: 3 additions & 1 deletion src/components/graph-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> {
showGraphControls: true,
zoomDelay: 1000,
zoomDur: 750,
centerNodeOnMove: true
rotateEdgeHandle: true,
centerNodeOnMove: true,
};

static getDerivedStateFromProps(nextProps: IGraphViewProps, prevState: IGraphViewState) {
Expand Down Expand Up @@ -1146,6 +1147,7 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> {
nodeKey={nodeKey}
viewWrapperElem={this.viewWrapper.current}
isSelected={this.isEdgeSelected(edge)}
rotateEdgeHandle={this.props.rotateEdgeHandle}
/>
);
}
Expand Down

0 comments on commit a2562a9

Please sign in to comment.