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

Fix highlight node related lines #391

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { CommandConfig } from './config'
import type { ICmdHooks } from './interface'
import type { IEvent } from '../hooks/interface'
import type { NsGraph } from '../interface'
import { NsAddGroup } from './group/group-add'

/** Commands 配置项目*/
const hookhubList = [...nodeHooks, ...edgeHooks, ...groupHooks, ...graphHooks, ...observablesHooks]
Expand Down Expand Up @@ -86,7 +87,6 @@ export class XFlowCommandContribution

const isCollapsed = group.getProp('isCollapsed')
let originSize = group.getProp('originSize')
let hasChange = false

if (originSize == null) {
originSize = group.size()
Expand All @@ -98,52 +98,27 @@ export class XFlowCommandContribution
group.prop('originPosition', originPosition)
}

let x = originPosition.x
let y = originPosition.y
let cornerX = originPosition.x + originSize.width
let cornerY = originPosition.y + originSize.height
const childs = group.getChildren()
if (childs) {
childs.forEach(child => {
const bbox = child.getBBox().inflate(12)
const corner = bbox.getCorner()

if (bbox.x < x) {
x = bbox.x
hasChange = true
}

if (bbox.y < y) {
y = bbox.y
hasChange = true
}

if (corner.x > cornerX) {
cornerX = corner.x
hasChange = true
}

if (corner.y > cornerY) {
cornerY = corner.y
hasChange = true
}
})
}
const bbox = graph.getCellsBBox(childs).inflate(NsAddGroup.GROUP_PADDING)
const x = bbox.x
const y = bbox.y - NsAddGroup.GROUP_HEADER_HEIGHT
const width = bbox!.width
const height = bbox!.height + NsAddGroup.GROUP_HEADER_HEIGHT

if (hasChange) {
group.prop({
position: { x, y },
size: { width: cornerX - x, height: cornerY - y },
size: { width, height },
})
const groupData: NsGraph.INodeConfig = {
...group.getData(),
x,
y,
width: cornerX - x,
height: cornerY - y,
width,
height,
}
if (isCollapsed !== true) {
groupData.groupChildrenSize = { width: cornerX - x, height: cornerY - y }
groupData.groupChildrenSize = { width, height }
}
group.setData(groupData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ export class HighlightNodeCommand implements ICommand {
/** 节点关联的连线, 联动高亮 */
if (handlerArgs?.isHighlightRelatedLines) {
const { edgeStroke, edgeStrokeWidth } = handlerArgs
const allEdges = x6Graph?.getEdges()
allEdges.forEach((x6Edge: X6Edge) => {
const x6EdgeData = x6Edge?.getData<any>()
handlerArgs?.commandService.executeCommand(XFlowEdgeCommands.HIGHLIGHT_EDGE.id, {
edgeId: x6EdgeData?.id,
strokeColor: edgeStroke,
strokeWidth: edgeStrokeWidth,
} as NsEdgeCmd.HighlightEdge.IArgs)
const connectedEdges = x6Graph?.getConnectedEdges(x6Node)
connectedEdges.forEach((x6Edge: X6Edge) => {
x6Edge.setAttrs({
line: {
stroke: edgeStroke,
strokeWidth: edgeStrokeWidth,
}
})
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ XFlow 提供节点添加的命令 `XFlowNodeCommands.HIGHLIGHT_NODE`, 通过该
| strokeWidth | number | | - | 节点高亮边框宽度 |
| isHighlightRelatedLines | boolean | | - | 是否联动高亮节点的关联边 |
| edgeStroke | string | | - | 边高亮颜色 |
| edgeStrokeWidth | number | | - | 边高亮宽度 |

| edgeStrokeWidth?: number
| number | | - | 边高亮宽度 |
Expand Down
Loading