-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: 添加画布一件美化 #1618
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
Merged
Merged
feat: 添加画布一件美化 #1618
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,26 @@ class AppNode extends HtmlResize.view { | |
} | ||
|
||
class AppNodeModel extends HtmlResize.model { | ||
refreshDeges() { | ||
// 更新节点连接边的path | ||
this.incoming.edges.forEach((edge: any) => { | ||
// 调用自定义的更新方案 | ||
edge.updatePathByAnchor() | ||
}) | ||
this.outgoing.edges.forEach((edge: any) => { | ||
edge.updatePathByAnchor() | ||
}) | ||
} | ||
set_position(position: { x?: number; y?: number }) { | ||
const { x, y } = position | ||
if (x) { | ||
this.x = x | ||
} | ||
if (y) { | ||
this.y = y | ||
} | ||
this.refreshDeges() | ||
} | ||
getResizeOutlineStyle() { | ||
const style = super.getResizeOutlineStyle() | ||
style.stroke = 'none' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我发现了两个问题:
对于第一个问题和第二个问题,可以采取两种解决方案: 对第一个人而言:你可以将它转换为子类别或实现自己的功能,并将其放在HTMLResizer组件内; 其次,对第二个人而言:你可以创建一个新的父类别或改变结构来管理整个系统的布局。 |
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { DagreLayout, type DagreLayoutOptions } from '@antv/layout' | ||
|
||
export default class Dagre { | ||
static pluginName = 'dagre' | ||
lf: any | ||
option: DagreLayoutOptions | any | ||
render(lf: any) { | ||
this.lf = lf | ||
} | ||
|
||
/** | ||
* option: { | ||
* rankdir: "TB", // layout 方向, 可选 TB, BT, LR, RL | ||
* align: undefined, // 节点对齐方式,可选 UL, UR, DL, DR | ||
* nodeSize: undefined, // 节点大小 | ||
* nodesepFunc: undefined, // 节点水平间距(px) | ||
* ranksepFunc: undefined, // 每一层节点之间间距 | ||
* nodesep: 40, // 节点水平间距(px) 注意:如果有grid,需要保证nodesep为grid的偶数倍 | ||
* ranksep: 40, // 每一层节点之间间距 注意:如果有grid,需要保证ranksep为grid的偶数倍 | ||
* controlPoints: false, // 是否保留布局连线的控制点 | ||
* radial: false, // 是否基于 dagre 进行辐射布局 | ||
* focusNode: null, // radial 为 true 时生效,关注的节点 | ||
* }; | ||
*/ | ||
layout(option = {}) { | ||
const { nodes, edges, gridSize } = this.lf.graphModel | ||
// 为了保证生成的节点在girdSize上,需要处理一下。 | ||
let nodesep = 40 | ||
let ranksep = 40 | ||
if (gridSize > 20) { | ||
nodesep = gridSize * 2 | ||
ranksep = gridSize * 2 | ||
} | ||
this.option = { | ||
type: 'dagre', | ||
rankdir: 'LR', | ||
// align: 'UL', | ||
// align: 'UR', | ||
align: 'DR', | ||
nodesep, | ||
ranksep, | ||
begin: [120, 120], | ||
...option | ||
} | ||
const layoutInstance = new DagreLayout(this.option) | ||
const layoutData = layoutInstance.layout({ | ||
nodes: nodes.map((node: any) => ({ | ||
id: node.id, | ||
size: { | ||
width: node.width, | ||
height: node.height | ||
}, | ||
model: node | ||
})), | ||
edges: edges.map((edge: any) => ({ | ||
source: edge.sourceNodeId, | ||
target: edge.targetNodeId, | ||
model: edge | ||
})) | ||
}) | ||
|
||
layoutData.nodes?.forEach((node: any) => { | ||
// @ts-ignore: pass node data | ||
const { model } = node | ||
model.set_position({ x: node.x, y: node.y }) | ||
}) | ||
this.lf.fitView() | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 该代码存在一些问题和不规则的部分:
根据这些发现进行调整:
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个代码中的一个主要问题是样式重复使用(style和class重叠)。例如,两个div都有相同的style部分:height: 100%; width: 100%,所以应该只在第一个出现一次。另一个问题是没有明确地将这些内容分块或归类为不同的组件文件。
对于优化,可以创建一个单独的CSS文件来集中处理这些图标和其他元素的样式,并且尽量减少标签的选择器长度以提高性能。此外,考虑重构并按逻辑模块进行组织结构,以清晰展示每个任务的功能和状态。