Skip to content

Commit

Permalink
feat: add rect radius
Browse files Browse the repository at this point in the history
  • Loading branch information
PerkinJ committed Mar 1, 2020
1 parent 1a5a3f8 commit f9a2647
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 35 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
plugins: ['@typescript-eslint/tslint', 'react-hooks'],
rules: {
'@typescript-eslint/tslint/config': ['warn'],
'no-restricted-globals': 0,
'no-undef': 0,
'no-template-curly-in-string': 0,
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn'
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@types/jest": "^24.9.1",
"@types/node": "^12.12.29",
"@types/react": "^16.9.23",
"@types/react-dom": "^16.9.5",
"@types/react-dom": "^16.9.5"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
21 changes: 13 additions & 8 deletions src/editor/EditorNode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
border-color: #6ca0f5;
}

.polygon-border {
.rectRadius-border {
border-color: #65ca92;
}

.ellipse-border {
.diamond-border {
border-color: #c6aaa7;
}

Expand All @@ -28,11 +28,11 @@
background: #6ca0f5;
}

.polygon-bgColor {
.rectRadius-bgColor {
background: #65ca92;
}

.ellipse-bgColor {
.diamond-bgColor {
background: #c6aaa7;
}

Expand All @@ -44,11 +44,11 @@
border-color: #5084d8;
}

.polygon-clicked {
.rectRadius-clicked {
border-color: #3b9262;
}

.ellipse-clicked {
.diamond-clicked {
border-color: #906e6a;
}

Expand All @@ -64,11 +64,11 @@
background: #5084d8;
}

.polygon-parallel-clicked {
.rectRadius-parallel-clicked {
background: #3b9262;
}

.ellipse-parallel-clicked {
.diamond-parallel-clicked {
background: #906e6a;
}

Expand Down Expand Up @@ -111,3 +111,8 @@
.editorNode-circle {
border-radius: 50%;
}

.editorNode-rectRadius {
border-radius: 15px;
}

13 changes: 10 additions & 3 deletions src/editor/EditorNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,23 @@ export function EditorNode(props: EditorNodeProps) {
borderColor = `${currentNode.key}-border`;
}

// 是否是圆形,TODO: 后续放开多边形
// 是否是圆形
const isCircle = currentNode.key === "circle";

// 是否为圆角
const isRadius = currentNode.key === 'rectRadius';

// 是否为菱形
const isDiamond = currentNode.key === 'diamond';

const borderClass = classNames(
"editorNode-box",
borderColor,
{
dragging: isDragged
},
{ "editorNode-circle": isCircle }
{ "editorNode-circle": isCircle },
{ "editorNode-rectRadius": isRadius},
);

const menuList = [
Expand Down Expand Up @@ -189,7 +196,7 @@ export function EditorNode(props: EditorNodeProps) {
onContextMenu={interactive ? onContextMenu : null}
>
<div className="editorNode" ref={editorNodeRef}>
<div className={borderClass}>
<div className={borderClass} style={ { transform: isDiamond?`rotateZ(45deg) skew(30deg,30deg)`: 'none'}}>
<div className="editorNode-box-property">
<div className="editorNode-name">{currentNode.name}</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/editor/components/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ const Node = React.forwardRef((props: NodeProps, ref: any) => {
data-type="edge"
data-position={item.position}
key={item.position}
href="javascript:void(0)"
className={`node-selector`}
style={item.style}
/>
Expand Down
11 changes: 10 additions & 1 deletion src/editor/components/NodePanel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
width: 100%;
height: 100%;

// 顶部控制条高度
$barHeight: 33px;
$textColor: #4c4c4c;
$activeColor: #d9dbe8;
Expand Down Expand Up @@ -154,4 +153,14 @@
}
}
}

.diamond {
width: 36px;
height: 36px;
margin-top:5px;
transform:rotate(-45deg);
background: transparent;
border:2px solid rgb(82, 97, 155);
}

}
30 changes: 29 additions & 1 deletion src/editor/defines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ export const LINKICON_HEIGHT = 18;

export enum ComponentKey {
rect = "rect",
rectRadius = 'rectRadius',
circle = "circle",
diamond = "diamond",
polygon = "polygon",
ellipse = "ellipse",
star = "star"
Expand All @@ -175,6 +177,18 @@ const COMMON_COMPONENT: Node[] = [
),
disabled: false
},
/** 矩形带圆角 */
{
type: ComponentType.common,
key: ComponentKey.rectRadius,
name: "RECT-RADIU",
width: 100,
height: 100,
icon: (
<div style={{ width: 36, height: 36, border: "2px solid #52619b", borderRadius: 10 }} />
),
disabled: false
},
/** 圆形 */
{
type: ComponentType.common,
Expand All @@ -200,7 +214,21 @@ const COMMON_COMPONENT: Node[] = [
</svg>
),
disabled: false
}
},
/** TODO 菱形 */
// {
// type: ComponentType.common,
// key: ComponentKey.diamond,
// name: "DIAMOND",
// width: 100,
// height: 100,
// icon: (
// <div className="diamond">

// </div>
// ),
// disabled: false
// }
/** 多边形 */
// {
// type: ComponentType.common,
Expand Down
40 changes: 20 additions & 20 deletions src/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,43 @@ export default function EditorDemo(props) {
setCopiedNodes
} = useEditorStore();

// 画布容器
// 画布容器
const screenRef = useRef(null);

// 画布 ref
// 画布 ref
const canvasRef = useRef({
getWrappedInstance: () => Object
} as any);

const canvasInstance = canvasRef.current;

/** 删除组件 */
/** 删除组件 */
const handleDeleteNodes = (ids: string[]) => {
if (!ids) {
return;
}
// 删除与组件相连的连线,不论上游或下游
// 删除与组件相连的连线,不论上游或下游

const newLinks = _.cloneDeep(links);
ids.forEach(id => {
// 删除与节点连接的任意边
// 删除与节点连接的任意边
_.remove(newLinks, link => link.source === id || link.target === id);
});
// 更新连线
// 更新连线
setLinks(newLinks);

// 剔除components
// 剔除components
const cloneNodes = _.cloneDeep(nodes);
const newNodes = _.remove(cloneNodes, item => !ids.includes(item.id));

setNodes(newNodes);

// 清空高亮状态
// 清空高亮状态
setSelectedLinks([]);
setSelectedNodes([]);
};

/** 删除连线 */
/** 删除连线 */
const handleDeleteLinks = (activeLinks: string[]) => {
if (!activeLinks) {
return;
Expand All @@ -75,7 +75,7 @@ export default function EditorDemo(props) {
setLinks(newLinks);
};

/** 复制节点 */
/** 复制节点 */
const handleNodesCopy = (ids: string[]) => {
const newCopiedNodes = ids.map(id => {
return _.find(nodes, item => item.id === id);
Expand All @@ -84,14 +84,14 @@ export default function EditorDemo(props) {
setCopiedNodes(newCopiedNodes);
};

/** 粘贴节点 */
/** 粘贴节点 */
const handleNodesPaste = () => {
if (copiedNodes) {
const currentCopied = copiedNodes.map(node => {
return {
...node,
id: uuid.v4(),
/** @todo 后续可优化布局算法 */
/** @todo 后续可优化布局算法 */
x: node.x + node.width + 20,
ref: React.createRef()
};
Expand All @@ -101,29 +101,29 @@ export default function EditorDemo(props) {
}
};

// 剪切
// 剪切
const handleShear = () => {
if (selectedNodes) {
handleNodesCopy(selectedNodes);
handleDeleteNodes(selectedNodes);
}
};

// 复制
// 复制
const handleCopy = () => {
if (selectedNodes) {
handleNodesCopy(selectedNodes);
}
};

// 粘贴
// 粘贴
const handlePaste = () => {
if (copiedNodes) {
handleNodesPaste();
}
};

// 删除
// 删除
const handleDelete = () => {
if (selectedNodes) {
handleDeleteNodes(selectedNodes);
Expand Down Expand Up @@ -159,7 +159,7 @@ export default function EditorDemo(props) {



/** 操作区 */
/** 操作区 */
const renderOperation = (
<div>
<Toolbar
Expand All @@ -176,14 +176,14 @@ export default function EditorDemo(props) {
/>
</div>
);
/** 渲染节点选择区 */
/** 渲染节点选择区 */
const renderNodePanel = (
<div className="editor-nodePanel">
<NodePanel onDrag={setDragNode} />
</div>
);

/** 渲染中间画布区 */
/** 渲染中间画布区 */
const renderCanvas = (
<div className="editor-canvas">
<CanvasContent
Expand All @@ -207,7 +207,7 @@ export default function EditorDemo(props) {
</div>
);

/** 渲染配置区 */
/** 渲染配置区 */
const renderProperty = <div className="editor-property"></div>;

return (
Expand Down

0 comments on commit f9a2647

Please sign in to comment.