Skip to content

Commit 45337e4

Browse files
authored
fix: optimize rendering logic to prevent loops (#3108)
1 parent 91fc977 commit 45337e4

File tree

5 files changed

+100
-74
lines changed

5 files changed

+100
-74
lines changed

packages/x6/src/renderer/scheduler.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ export class Scheduler extends Disposable {
223223
cell.isEdge() &&
224224
(result & view.getFlag(['source', 'target'])) === 0
225225
) {
226-
this.requestViewUpdate(
227-
view,
228-
result,
229-
options,
230-
JOB_PRIORITY.RenderEdge,
231-
false,
232-
)
226+
this.queue.queueJob({
227+
id,
228+
priority: JOB_PRIORITY.RenderEdge,
229+
cb: () => {
230+
this.updateView(view, flag, options)
231+
},
232+
})
233233
}
234234
}
235235
}

sites/x6-sites/.dumi/global.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
if (window) {
2-
(window as any).react = require('react');
3-
(window as any).reactDom = require('react-dom');
4-
(window as any).antd = require('antd');
5-
(window as any).dagre = require('dagre');
6-
(window as any).x6 = require('@antv/x6');
7-
(window as any).x6PluginSnapline = require('@antv/x6-plugin-snapline');
8-
(window as any).x6PluginClipboard = require('@antv/x6-plugin-clipboard');
9-
(window as any).x6PluginKeyboard = require('@antv/x6-plugin-keyboard');
10-
(window as any).x6PluginSelection = require('@antv/x6-plugin-selection');
11-
(window as any).x6PluginTransform = require('@antv/x6-plugin-transform');
12-
(window as any).x6PluginStencil = require('@antv/x6-plugin-stencil');
13-
(window as any).x6PluginHistory = require('@antv/x6-plugin-history');
14-
(window as any).x6ReactShape = require('@antv/x6-react-shape');
15-
(window as any).x6Common = require('@antv/x6-common');
16-
(window as any).layout = require('@antv/layout');
17-
(window as any).classnames = require('classnames');
18-
(window as any).hierarchy = require('@antv/hierarchy');
19-
(window as any).elkjs = require('elkjs/lib/elk.bundled.js');
2+
;(window as any).react = require('react')
3+
;(window as any).reactDom = require('react-dom')
4+
;(window as any).antd = require('antd')
5+
;(window as any).dagre = require('dagre')
6+
;(window as any).x6 = require('@antv/x6')
7+
;(window as any).x6PluginSnapline = require('@antv/x6-plugin-snapline')
8+
;(window as any).x6PluginClipboard = require('@antv/x6-plugin-clipboard')
9+
;(window as any).x6PluginKeyboard = require('@antv/x6-plugin-keyboard')
10+
;(window as any).x6PluginSelection = require('@antv/x6-plugin-selection')
11+
;(window as any).x6PluginTransform = require('@antv/x6-plugin-transform')
12+
;(window as any).x6PluginStencil = require('@antv/x6-plugin-stencil')
13+
;(window as any).x6PluginHistory = require('@antv/x6-plugin-history')
14+
;(window as any).x6ReactShape = require('@antv/x6-react-shape')
15+
;(window as any).layout = require('@antv/layout')
16+
;(window as any).classnames = require('classnames')
17+
;(window as any).hierarchy = require('@antv/hierarchy')
18+
;(window as any).elkjs = require('elkjs/lib/elk.bundled.js')
2019
}

sites/x6-sites/docs/tutorial/about.zh.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ X6 是基于 HTML 和 SVG 的图编辑引擎,提供低成本的定制能力和
1111
如果你还没有使用过 X6, 建议通过 [快速上手](/zh/docs/tutorial/getting-started) 抢先体验 X6 的魅力。
1212

1313
<p align="left">
14-
<a href="https://github.com/antvis/X6/actions/workflows/ci.yml"><img alt="build" src="https://img.shields.io/github/workflow/status/antvis/x6/%F0%9F%91%B7%E3%80%80CI/master?logo=github&style=flat-square"></a>
15-
<a href="https://app.codecov.io/gh/antvis/X6"><img alt="coverage" src="https://img.shields.io/codecov/c/gh/antvis/x6?logo=codecov&style=flat-square&token=15CO54WYUV"></a>
16-
<a href="https://lgtm.com/projects/g/antvis/x6/context:javascript"><img alt="Language grade: JavaScript" src="https://img.shields.io/lgtm/grade/javascript/g/antvis/x6.svg?logo=lgtm&style=flat-square"></a>
14+
<a href="https://github.com/antvis/X6/actions/workflows/ci.yml"><img alt="build" src="https://img.shields.io/github/actions/workflow/status/antvis/x6/ci.yml?branch=master&logo=github&style=flat-square"></a>
15+
<!-- <a href="https://app.codecov.io/gh/antvis/X6"><img alt="coverage" src="https://img.shields.io/codecov/c/gh/antvis/x6?logo=codecov&style=flat-square&token=15CO54WYUV"></a>
16+
<a href="https://lgtm.com/projects/g/antvis/x6/context:javascript"><img alt="Language grade: JavaScript" src="https://img.shields.io/lgtm/grade/javascript/g/antvis/x6.svg?logo=lgtm&style=flat-square"></a> -->
1717
<a href="https://www.npmjs.com/package/@antv/x6"><img alt="NPM Package" src="https://img.shields.io/npm/v/@antv/x6.svg?style=flat-square"></a>
1818
<a href="https://www.npmjs.com/package/@antv/x6"><img alt="NPM Downloads" src="https://img.shields.io/npm/dm/@antv/x6?logo=npm&style=flat-square"></a>
1919
</p>

sites/x6-sites/examples/showcase/practices/demo/dataProcessingDag.tsx

Lines changed: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
2-
import { Graph, Node, Path, Edge, Platform } from '@antv/x6'
2+
import { Graph, Node, Path, Edge, Platform, StringExt } from '@antv/x6'
33
import { Selection } from '@antv/x6-plugin-selection'
4-
import { StringExt } from '@antv/x6-common'
54
import classnames from 'classnames'
65
import insertCss from 'insert-css'
76
import { register } from '@antv/x6-react-shape'
@@ -57,12 +56,16 @@ const PROCESSING_TYPE_LIST = [
5756

5857
// 不同节点类型的icon
5958
const NODE_TYPE_LOGO = {
60-
INPUT: 'https://mdn.alipayobjects.com/huamei_f4t1bn/afts/img/A*RXnuTpQ22xkAAAAAAAAAAAAADtOHAQ/original', // 数据输入
61-
FILTER: 'https://mdn.alipayobjects.com/huamei_f4t1bn/afts/img/A*ZJ6qToit8P4AAAAAAAAAAAAADtOHAQ/original', // 数据筛选
59+
INPUT:
60+
'https://mdn.alipayobjects.com/huamei_f4t1bn/afts/img/A*RXnuTpQ22xkAAAAAAAAAAAAADtOHAQ/original', // 数据输入
61+
FILTER:
62+
'https://mdn.alipayobjects.com/huamei_f4t1bn/afts/img/A*ZJ6qToit8P4AAAAAAAAAAAAADtOHAQ/original', // 数据筛选
6263
JOIN: 'https://mdn.alipayobjects.com/huamei_f4t1bn/afts/img/A*EHqyQoDeBvIAAAAAAAAAAAAADtOHAQ/original', // 数据连接
63-
UNION: 'https://mdn.alipayobjects.com/huamei_f4t1bn/afts/img/A*k4eyRaXv8gsAAAAAAAAAAAAADtOHAQ/original', // 数据合并
64+
UNION:
65+
'https://mdn.alipayobjects.com/huamei_f4t1bn/afts/img/A*k4eyRaXv8gsAAAAAAAAAAAAADtOHAQ/original', // 数据合并
6466
AGG: 'https://mdn.alipayobjects.com/huamei_f4t1bn/afts/img/A*TKG8R6nfYiAAAAAAAAAAAAAADtOHAQ/original', // 数据聚合
65-
OUTPUT: 'https://mdn.alipayobjects.com/huamei_f4t1bn/afts/img/A*zUgORbGg1HIAAAAAAAAAAAAADtOHAQ/original', // 数据输出
67+
OUTPUT:
68+
'https://mdn.alipayobjects.com/huamei_f4t1bn/afts/img/A*zUgORbGg1HIAAAAAAAAAAAAADtOHAQ/original', // 数据输出
6669
}
6770

6871
/**
@@ -105,7 +108,7 @@ const getDownstreamNodePosition = (
105108

106109
return {
107110
x: minX !== Infinity ? minX : position.x + dx,
108-
y: maxY !== -Infinity ? maxY + dy : position.y,
111+
y: maxY !== -Infinity ? maxY + dy : position.y,
109112
}
110113
}
111114

@@ -161,8 +164,12 @@ export const createNode = (
161164
return {}
162165
}
163166
let newNode = {}
164-
const sameTypeNodes = graph.getNodes().filter(item => item.getData()?.type === type);
165-
const typeName = PROCESSING_TYPE_LIST?.find((item) => item.type === type)?.name;
167+
const sameTypeNodes = graph
168+
.getNodes()
169+
.filter((item) => item.getData()?.type === type)
170+
const typeName = PROCESSING_TYPE_LIST?.find(
171+
(item) => item.type === type,
172+
)?.name
166173
const id = StringExt.uuid()
167174
const node = {
168175
id,
@@ -243,21 +250,24 @@ class DataProcessingDagNode extends React.Component<{
243250
getPlusDagMenu = () => {
244251
return (
245252
<ul>
246-
{
247-
PROCESSING_TYPE_LIST.map((item) => {
248-
const content = (
249-
<a onClick={() => this.clickPlusDragMenu(item.type)}>
250-
<i
251-
className="node-mini-logo"
252-
style={{ backgroundImage: `url(${NODE_TYPE_LOGO[item.type]})` }}
253-
/>
254-
255-
<span>{item.name}</span>
256-
</a>
257-
)
258-
return <li className="each-sub-menu">{content}</li>
259-
})
260-
}
253+
{PROCESSING_TYPE_LIST.map((item) => {
254+
const content = (
255+
// eslint-disable-next-line
256+
<a onClick={() => this.clickPlusDragMenu(item.type)}>
257+
<i
258+
className="node-mini-logo"
259+
style={{ backgroundImage: `url(${NODE_TYPE_LOGO[item.type]})` }}
260+
/>
261+
262+
<span>{item.name}</span>
263+
</a>
264+
)
265+
return (
266+
<li className="each-sub-menu" key={item.type}>
267+
{content}
268+
</li>
269+
)
270+
})}
261271
</ul>
262272
)
263273
}
@@ -273,9 +283,12 @@ class DataProcessingDagNode extends React.Component<{
273283
onMainMouseEnter = () => {
274284
const { node } = this.props
275285
// 获取该节点下的所有连接桩
276-
const ports = node.getPorts() || [];
286+
const ports = node.getPorts() || []
277287
ports.forEach((port) => {
278-
node.setPortProp(port.id, 'attrs/circle', { fill: '#fff', stroke: '#85A5FF' })
288+
node.setPortProp(port.id, 'attrs/circle', {
289+
fill: '#fff',
290+
stroke: '#85A5FF',
291+
})
279292
})
280293
}
281294

@@ -285,7 +298,10 @@ class DataProcessingDagNode extends React.Component<{
285298
// 获取该节点下的所有连接桩
286299
const ports = node.getPorts() || []
287300
ports.forEach((port) => {
288-
node.setPortProp(port.id, 'attrs/circle', { fill: 'transparent', stroke: 'transparent' })
301+
node.setPortProp(port.id, 'attrs/circle', {
302+
fill: 'transparent',
303+
stroke: 'transparent',
304+
})
289305
})
290306
}
291307

@@ -404,21 +420,31 @@ Graph.registerConnector(
404420
(sourcePoint, targetPoint) => {
405421
const hgap = Math.abs(targetPoint.x - sourcePoint.x)
406422
const path = new Path()
407-
path.appendSegment(Path.createSegment('M', sourcePoint.x - 4, sourcePoint.y))
408-
path.appendSegment(Path.createSegment('L', sourcePoint.x + 12, sourcePoint.y))
423+
path.appendSegment(
424+
Path.createSegment('M', sourcePoint.x - 4, sourcePoint.y),
425+
)
426+
path.appendSegment(
427+
Path.createSegment('L', sourcePoint.x + 12, sourcePoint.y),
428+
)
409429
// 水平三阶贝塞尔曲线
410430
path.appendSegment(
411431
Path.createSegment(
412432
'C',
413-
sourcePoint.x < targetPoint.x ? sourcePoint.x + hgap / 2 : sourcePoint.x - hgap / 2,
433+
sourcePoint.x < targetPoint.x
434+
? sourcePoint.x + hgap / 2
435+
: sourcePoint.x - hgap / 2,
414436
sourcePoint.y,
415-
sourcePoint.x < targetPoint.x ? targetPoint.x - hgap / 2 : targetPoint.x + hgap / 2,
437+
sourcePoint.x < targetPoint.x
438+
? targetPoint.x - hgap / 2
439+
: targetPoint.x + hgap / 2,
416440
targetPoint.y,
417441
targetPoint.x - 6,
418442
targetPoint.y,
419443
),
420444
)
421-
path.appendSegment(Path.createSegment('L', targetPoint.x + 2, targetPoint.y))
445+
path.appendSegment(
446+
Path.createSegment('L', targetPoint.x + 2, targetPoint.y),
447+
)
422448

423449
return path.serialize()
424450
},
@@ -521,7 +547,7 @@ const graph: Graph = new Graph({
521547
})
522548
},
523549
// 连接桩校验
524-
validateConnection({ sourceView, targetView, sourceMagnet, targetMagnet }) {
550+
validateConnection({ sourceMagnet, targetMagnet }) {
525551
// 只能从输出链接桩创建连接
526552
if (!sourceMagnet || sourceMagnet.getAttribute('port-group') === 'in') {
527553
return false
@@ -535,14 +561,16 @@ const graph: Graph = new Graph({
535561
},
536562
})
537563

538-
graph.use(new Selection({
539-
enabled: true,
540-
multiple: true,
541-
rubberEdge: true,
542-
rubberNode: true,
543-
modifiers: 'shift',
544-
rubberband: true,
545-
}))
564+
graph.use(
565+
new Selection({
566+
enabled: true,
567+
multiple: true,
568+
rubberEdge: true,
569+
rubberNode: true,
570+
modifiers: 'shift',
571+
rubberband: true,
572+
}),
573+
)
546574

547575
// 节点状态列表
548576
const nodeStatusList = [
@@ -565,7 +593,7 @@ const nodeStatusList = [
565593
{
566594
id: 'node-4',
567595
status: 'error',
568-
statusMsg: '错误信息示例'
596+
statusMsg: '错误信息示例',
569597
},
570598
]
571599

@@ -656,7 +684,6 @@ fetch('/data/data-processing-dag.json')
656684
}, 3000)
657685
})
658686

659-
660687
insertCss(`
661688
.data-processing-dag-node {
662689
display: flex;

sites/x6-sites/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"react": "^18.0.0",
4040
"react-dom": "^18.0.0",
4141
"react-i18next": "^11.5.0",
42-
"classnames": "^2.2.6",
43-
"@antv/x6-common": "^2.0.x"
44-
}
42+
"classnames": "^2.2.6"
43+
},
44+
"repository": "https://github.com/antvis/x6"
4545
}

0 commit comments

Comments
 (0)