Compare commits

..

14 Commits

Author SHA1 Message Date
newbyvector
556121d68d chore(release): 🚀 publish
- @antv/x6-react-shape@1.6.5
2023-11-14 10:19:20 +08:00
newbyvector
2a132a2c19 fix: 🐛 support multiple graph 2023-11-14 10:16:18 +08:00
newbyvector
6d37943855 chore(release): 🚀 publish
- @antv/x6@1.35.0
2023-09-25 18:00:00 +08:00
newbyvector
1ca2114005 fix: 🐛 add judge when call renderHTMLComponent 2023-09-25 17:52:31 +08:00
newbyvector
032cce51df fix: 🐛 stop listen event when transform removed 2023-09-25 17:30:43 +08:00
newbyvector
add5600a26 chore(release): 🚀 publish
- @antv/x6@1.34.14
2023-07-06 09:41:49 +08:00
newbyvector
0fb2dcc96a fix: 🐛 check label node existed before change position 2023-07-05 22:46:52 +08:00
大卫
d440dfc6b1 docs: fixed the link to the homepage of the official website (#3651) (#3652)
Co-authored-by: qiufeihong <qiufeihong.qfh@alibaba-inc.com>
2023-06-06 19:26:20 +08:00
newbyvector
87fac22cd0 docs: 📚️ add animation example 2023-05-12 15:17:17 +08:00
newbyvector
de35af5d84 chore(release): 🚀 publish
- @antv/x6@1.34.13
2023-03-31 21:56:30 +08:00
newbyvector
d59e62605a fix: 🐛 fix parseInt error 2023-03-31 21:50:29 +08:00
newbyvector
b242a00bd0 chore(release): 🚀 publish
- @antv/x6@1.34.12
2023-03-22 16:51:32 +08:00
newbyvector
0b27331a4d fix: 🐛 parseint zindex to get correct max zindex node 2023-03-22 16:44:18 +08:00
JasonSun
05c3821ee9 docs(v1-react): fix memo equal condition (#3368)
docs(react): fix memo equal condition
2023-03-10 21:55:43 +08:00
12 changed files with 203 additions and 14 deletions

View File

@@ -0,0 +1,81 @@
import React from 'react'
import { Graph, EdgeView, NodeView } from '@antv/x6'
import { animateAlongEdge, animateAlongNode, clearAnimation } from './animation'
import '../index.less'
export default class Example extends React.Component {
private container: HTMLDivElement
private animate = false
componentDidMount() {
const graph = new Graph({
container: this.container,
width: 800,
height: 600,
grid: true,
})
const source = graph.addNode({
id: 'source',
shape: 'rect',
x: 80,
y: 250,
width: 160,
height: 60,
})
const target = graph.addNode({
id: 'target',
shape: 'rect',
x: 520,
y: 250,
width: 160,
height: 60,
})
graph.addEdge({
id: 'edge',
source,
target,
})
document.addEventListener('click', () => {
if (this.animate) {
this.animate = false
clearAnimation()
} else {
this.animate = true
this.play(graph)
}
})
}
play(graph: Graph) {
const sourceNodeView = graph.findViewByCell(
graph.getCellById('source'),
) as NodeView
const targetNodeView = graph.findViewByCell(
graph.getCellById('target'),
) as NodeView
const edgeView = graph.findViewByCell(graph.getCellById('edge')) as EdgeView
animateAlongNode(sourceNodeView, 'M 0 30 L 0 0 L 160 0 L 160 30')
animateAlongNode(sourceNodeView, 'M 0 30 L 0 60 L 160 60 L 160 30', () => {
animateAlongEdge(edgeView, () => {
animateAlongNode(targetNodeView, 'M 0 0 L 160 0 L 160 60 L 0 60')
})
})
}
refContainer = (container: HTMLDivElement) => {
this.container = container
}
render() {
return (
<div className="x6-graph-wrap">
<div ref={this.refContainer} className="x6-graph" />
</div>
)
}
}

View File

@@ -0,0 +1,94 @@
import { Vector, EdgeView, NodeView, Dom } from '@antv/x6'
const animateToken: SVGElement[] = []
export const removeAnimationElem = (elem: SVGElement) => {
const index = animateToken.findIndex((token) => token === elem)
if (index) {
animateToken.splice(index, 1)
}
Dom.remove(elem)
}
export const animateAlongEdge = (
edgeView: EdgeView,
compelete?: () => void,
) => {
const token = Vector.create('circle', { r: 4, fill: 'red' })
const path = edgeView.container.querySelector('path')
const animate = Dom.createSvgElement<SVGAnimateMotionElement>('animateMotion')
const mpath = Dom.createSvgElement('mpath')
const attrs = {
dur: '1000ms',
repeatCount: '1',
calcMode: 'linear',
fill: 'freeze',
}
const id = Dom.ensureId(path!)
animate.appendChild(mpath)
token.node.appendChild(animate)
token.appendTo(edgeView.container)
Dom.attr(mpath, { 'xlink:href': `#${id}` })
Dom.attr(animate, attrs)
animateToken.push(token.node)
animate.addEventListener('endEvent', () => {
removeAnimationElem(token.node)
if (compelete) {
compelete()
}
})
const ani = animate as any
setTimeout(() => {
ani.beginElement()
})
}
export const animateAlongNode = (
nodeView: NodeView,
path: string,
compelete?: () => void,
) => {
const token = Vector.create('circle', { r: 4, fill: 'red' })
const animate = Dom.createSvgElement<SVGAnimateMotionElement>('animateMotion')
const attrs = {
dur: '2000ms',
repeatCount: '1',
calcMode: 'linear',
fill: 'freeze',
}
Dom.attr(animate, {
...attrs,
path,
})
token.append(animate)
nodeView.container.appendChild(token.node)
animateToken.push(token.node)
animate.addEventListener('endEvent', () => {
removeAnimationElem(token.node)
if (compelete) {
compelete()
}
})
const ani = animate as any
setTimeout(() => {
ani.beginElement()
})
}
export const clearAnimation = () => {
const animations = [...animateToken]
animations.forEach((item) => {
removeAnimationElem(item)
})
}

View File

@@ -1,6 +1,6 @@
{
"name": "@antv/x6-react-shape",
"version": "1.6.4",
"version": "1.6.5",
"description": "X6 shape for rendering react components.",
"main": "lib/index.js",
"module": "es/index.js",

View File

@@ -6,10 +6,14 @@ import { Portal } from './portal'
import { Wrap } from './wrap'
export class ReactShapeView extends NodeView<ReactShape> {
protected targetId() {
return `${this.graph.view.cid}:${this.cell.id}`
}
protected init() {
super.init()
this.cell.on('removed', () => {
Portal.disconnect(this.cell.id)
Portal.disconnect(this.targetId())
})
}
@@ -42,7 +46,7 @@ export class ReactShapeView extends NodeView<ReactShape> {
const component = this.graph.hook.getReactComponent(node)
const elem = React.createElement(Wrap, { graph, node, component })
if (Portal.isActive()) {
Portal.connect(this.cell.id, ReactDOM.createPortal(elem, root))
Portal.connect(this.targetId(), ReactDOM.createPortal(elem, root))
} else {
ReactDOM.render(elem, root)
}
@@ -58,7 +62,7 @@ export class ReactShapeView extends NodeView<ReactShape> {
}
unmount() {
Portal.disconnect(this.cell.id)
Portal.disconnect(this.targetId())
this.unmountReactComponent()
super.unmount()
return this

View File

@@ -1,6 +1,6 @@
{
"name": "@antv/x6",
"version": "1.34.11",
"version": "1.35.0",
"description": "JavaScript diagramming library that uses SVG and HTML for rendering.",
"main": "lib/index.js",
"module": "es/index.js",

View File

@@ -521,6 +521,11 @@ export class Transform extends Widget<Transform.Options> {
}
}
}
protected onRemove() {
this.stopListening()
super.onRemove()
}
}
export namespace Transform {

View File

@@ -77,7 +77,7 @@ export namespace HTML {
}
protected renderHTMLComponent() {
const container = this.selectors.foContent
const container = this.selectors && this.selectors.foContent
if (container) {
const $wrap = this.$(container).empty()
const component = this.graph.hook.getHTMLComponent(this.cell)

View File

@@ -1153,15 +1153,18 @@ export class EdgeView<
for (let i = 0, ii = labels.length; i < ii; i += 1) {
const label = labels[i]
const labelNode = this.labelCache[i]
if (!labelNode) {
continue
}
const labelPosition = this.normalizeLabelPosition(
label.position as Edge.LabelPosition,
)
const pos = ObjectExt.merge({}, defaultPosition, labelPosition)
const matrix = this.getLabelTransformationMatrix(pos)
this.labelCache[i].setAttribute(
'transform',
Dom.matrixToTransformString(matrix),
)
labelNode.setAttribute('transform', Dom.matrixToTransformString(matrix))
}
return this

View File

@@ -861,7 +861,9 @@ export class NodeView<
if (options.frontOnly) {
if (candidates.length > 0) {
const zIndexMap = ArrayExt.groupBy(candidates, 'zIndex')
const maxZIndex = ArrayExt.max(Object.keys(zIndexMap))
const maxZIndex = ArrayExt.max(
Object.keys(zIndexMap).map((z) => parseInt(z, 10)),
)
if (maxZIndex) {
candidates = zIndexMap[maxZIndex]
}

View File

@@ -185,7 +185,7 @@ export const MyComponent = memo(
return // ...
},
(prev, next) => {
return Boolean(next.node?.hasChanged('data'))
return !next.node?.hasChanged('data')
},
)
```

View File

@@ -183,7 +183,7 @@ export const MyComponent = memo(
return // ...
},
(prev, next) => {
return Boolean(next.node?.hasChanged('data'))
return !next.node?.hasChanged('data')
},
)
```

View File

@@ -79,7 +79,7 @@ const IndexPage = () => {
type: 'News',
title: 'X6 2.0 来了!',
date: '2022.11.22',
link: 'https://www.yuque.com/antv/operation/bgo171',
link: 'https://www.yuque.com/antv/blog/kt8nugz3kdg32h7v',
},
]