refactor(connectionLine): create connection line type enum
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
import React, { useEffect, useState, CSSProperties } from 'react';
|
import React, { useEffect, useState, CSSProperties } from 'react';
|
||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
|
|
||||||
import { ElementId, Node, Transform, HandleElement, Position } from '../../types';
|
import { ElementId, Node, Transform, HandleElement, Position, ConnectionLineType } from '../../types';
|
||||||
|
|
||||||
interface ConnectionLineProps {
|
interface ConnectionLineProps {
|
||||||
connectionSourceId: ElementId;
|
connectionSourceId: ElementId;
|
||||||
connectionPositionX: number;
|
connectionPositionX: number;
|
||||||
connectionPositionY: number;
|
connectionPositionY: number;
|
||||||
connectionLineType?: string | null;
|
connectionLineType: ConnectionLineType;
|
||||||
nodes: Node[];
|
nodes: Node[];
|
||||||
transform: Transform;
|
transform: Transform;
|
||||||
isInteractive: boolean;
|
isInteractive: boolean;
|
||||||
@@ -17,10 +17,10 @@ interface ConnectionLineProps {
|
|||||||
|
|
||||||
export default ({
|
export default ({
|
||||||
connectionSourceId,
|
connectionSourceId,
|
||||||
connectionLineStyle = {},
|
connectionLineStyle,
|
||||||
connectionPositionX,
|
connectionPositionX,
|
||||||
connectionPositionY,
|
connectionPositionY,
|
||||||
connectionLineType,
|
connectionLineType = ConnectionLineType.Bezier,
|
||||||
nodes = [],
|
nodes = [],
|
||||||
className,
|
className,
|
||||||
transform,
|
transform,
|
||||||
@@ -60,7 +60,7 @@ export default ({
|
|||||||
|
|
||||||
let dAttr: string = '';
|
let dAttr: string = '';
|
||||||
|
|
||||||
if (connectionLineType === 'bezier') {
|
if (connectionLineType === ConnectionLineType.Bezier) {
|
||||||
if (sourceHandle?.position === Position.Left || sourceHandle?.position === Position.Right) {
|
if (sourceHandle?.position === Position.Left || sourceHandle?.position === Position.Right) {
|
||||||
const xOffset = Math.abs(targetX - sourceX) / 2;
|
const xOffset = Math.abs(targetX - sourceX) / 2;
|
||||||
const centerX = targetX < sourceX ? targetX + xOffset : targetX - xOffset;
|
const centerX = targetX < sourceX ? targetX + xOffset : targetX - xOffset;
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ import React, { memo, CSSProperties } from 'react';
|
|||||||
import { useStoreState } from '../../store/hooks';
|
import { useStoreState } from '../../store/hooks';
|
||||||
import ConnectionLine from '../../components/ConnectionLine/index';
|
import ConnectionLine from '../../components/ConnectionLine/index';
|
||||||
import { isEdge } from '../../utils/graph';
|
import { isEdge } from '../../utils/graph';
|
||||||
import { XYPosition, Position, Edge, Node, ElementId, HandleElement, Elements } from '../../types';
|
import { XYPosition, Position, Edge, Node, ElementId, HandleElement, Elements, ConnectionLineType } from '../../types';
|
||||||
|
|
||||||
interface EdgeRendererProps {
|
interface EdgeRendererProps {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
edgeTypes: any;
|
edgeTypes: any;
|
||||||
|
connectionLineType: ConnectionLineType;
|
||||||
connectionLineStyle?: CSSProperties;
|
connectionLineStyle?: CSSProperties;
|
||||||
connectionLineType?: string;
|
|
||||||
onElementClick?: (element: Node | Edge) => void;
|
onElementClick?: (element: Node | Edge) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,16 @@ import useGlobalKeyHandler from '../../hooks/useGlobalKeyHandler';
|
|||||||
import useElementUpdater from '../../hooks/useElementUpdater';
|
import useElementUpdater from '../../hooks/useElementUpdater';
|
||||||
import { getDimensions } from '../../utils';
|
import { getDimensions } from '../../utils';
|
||||||
import { fitView, zoomIn, zoomOut, project } from '../../utils/graph';
|
import { fitView, zoomIn, zoomOut, project } from '../../utils/graph';
|
||||||
import { Elements, NodeTypesType, EdgeTypesType, OnLoadFunc, Node, Edge, Connection } from '../../types';
|
import {
|
||||||
|
Elements,
|
||||||
|
NodeTypesType,
|
||||||
|
EdgeTypesType,
|
||||||
|
OnLoadFunc,
|
||||||
|
Node,
|
||||||
|
Edge,
|
||||||
|
Connection,
|
||||||
|
ConnectionLineType,
|
||||||
|
} from '../../types';
|
||||||
|
|
||||||
export interface GraphViewProps {
|
export interface GraphViewProps {
|
||||||
elements: Elements;
|
elements: Elements;
|
||||||
@@ -26,8 +35,8 @@ export interface GraphViewProps {
|
|||||||
selectionKeyCode: number;
|
selectionKeyCode: number;
|
||||||
nodeTypes: NodeTypesType;
|
nodeTypes: NodeTypesType;
|
||||||
edgeTypes: EdgeTypesType;
|
edgeTypes: EdgeTypesType;
|
||||||
connectionLineType: string;
|
connectionLineType: ConnectionLineType;
|
||||||
connectionLineStyle: CSSProperties;
|
connectionLineStyle?: CSSProperties;
|
||||||
deleteKeyCode: number;
|
deleteKeyCode: number;
|
||||||
snapToGrid: boolean;
|
snapToGrid: boolean;
|
||||||
snapGrid: [number, number];
|
snapGrid: [number, number];
|
||||||
|
|||||||
@@ -20,7 +20,16 @@ import StraightEdge from '../../components/Edges/StraightEdge';
|
|||||||
import StepEdge from '../../components/Edges/StepEdge';
|
import StepEdge from '../../components/Edges/StepEdge';
|
||||||
import { createEdgeTypes } from '../EdgeRenderer/utils';
|
import { createEdgeTypes } from '../EdgeRenderer/utils';
|
||||||
import store from '../../store';
|
import store from '../../store';
|
||||||
import { Elements, NodeTypesType, EdgeTypesType, OnLoadFunc, Node, Edge, Connection } from '../../types';
|
import {
|
||||||
|
Elements,
|
||||||
|
NodeTypesType,
|
||||||
|
EdgeTypesType,
|
||||||
|
OnLoadFunc,
|
||||||
|
Node,
|
||||||
|
Edge,
|
||||||
|
Connection,
|
||||||
|
ConnectionLineType,
|
||||||
|
} from '../../types';
|
||||||
|
|
||||||
import '../../style.css';
|
import '../../style.css';
|
||||||
|
|
||||||
@@ -36,8 +45,8 @@ export interface ReactFlowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'on
|
|||||||
onSelectionChange?: (elements: Elements | null) => void;
|
onSelectionChange?: (elements: Elements | null) => void;
|
||||||
nodeTypes: NodeTypesType;
|
nodeTypes: NodeTypesType;
|
||||||
edgeTypes: EdgeTypesType;
|
edgeTypes: EdgeTypesType;
|
||||||
connectionLineType: string;
|
connectionLineType: ConnectionLineType;
|
||||||
connectionLineStyle: CSSProperties;
|
connectionLineStyle?: CSSProperties;
|
||||||
deleteKeyCode: number;
|
deleteKeyCode: number;
|
||||||
selectionKeyCode: number;
|
selectionKeyCode: number;
|
||||||
snapToGrid: boolean;
|
snapToGrid: boolean;
|
||||||
@@ -119,8 +128,7 @@ ReactFlow.defaultProps = {
|
|||||||
straight: StraightEdge,
|
straight: StraightEdge,
|
||||||
step: StepEdge,
|
step: StepEdge,
|
||||||
},
|
},
|
||||||
connectionLineType: 'bezier',
|
connectionLineType: ConnectionLineType.Bezier,
|
||||||
connectionLineStyle: {},
|
|
||||||
deleteKeyCode: 8,
|
deleteKeyCode: 8,
|
||||||
selectionKeyCode: 16,
|
selectionKeyCode: 16,
|
||||||
snapToGrid: false,
|
snapToGrid: false,
|
||||||
|
|||||||
@@ -153,6 +153,11 @@ export interface Connection {
|
|||||||
target: ElementId | null;
|
target: ElementId | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ConnectionLineType {
|
||||||
|
Bezier = 'bezier',
|
||||||
|
Straight = 'straight',
|
||||||
|
}
|
||||||
|
|
||||||
export type OnConnectFunc = (connection: Connection) => void;
|
export type OnConnectFunc = (connection: Connection) => void;
|
||||||
|
|
||||||
export interface HandleElement extends XYPosition, Dimensions {
|
export interface HandleElement extends XYPosition, Dimensions {
|
||||||
|
|||||||
Reference in New Issue
Block a user