Skip to content
Open
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
14 changes: 14 additions & 0 deletions examples/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ import { StencilExample } from './pages/stencil'
import { TransformExample } from './pages/transform'
import { UndoExample } from './pages/undo'
import { TransitionExample } from './pages/animation/transition'
import { AnimateExample } from './pages/animation/animate'
import { SendTokenExample } from './pages/animation/sendToken'
import { HistoryExample } from './pages/history'
import { AnimateTransformExample } from './pages/animation/animateTransform'
import { AnimateAlongPathExample } from './pages/animation/animateAlongPath'

function App() {
return (
Expand Down Expand Up @@ -96,6 +100,16 @@ function App() {
<Route path="/transform" element={<TransformExample />} />
<Route path="/undo" element={<UndoExample />} />
<Route path="/animation/transition" element={<TransitionExample />} />
<Route path="/animation/animate" element={<AnimateExample />} />
<Route
path="/animation/animateTransform"
element={<AnimateTransformExample />}
/>
<Route
path="/animation/animateAlongPath"
element={<AnimateAlongPathExample />}
/>
<Route path="/animation/sendToken" Component={SendTokenExample} />
<Route path="/history" element={<HistoryExample />} />
</Routes>
)
Expand Down
79 changes: 79 additions & 0 deletions examples/src/pages/animation/animate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react'
import { Graph } from '../../../../src'
import '../index.less'

export class AnimateExample extends React.Component {
private container!: HTMLDivElement

componentDidMount() {
const graph = new Graph({
container: this.container,
grid: true,
})

const rect1 = graph.addNode({
x: 80,
y: 40,
width: 100,
height: 40,
})

const rect2 = graph.addNode({
x: 460,
y: 40,
width: 100,
height: 40,
attrs: {
rect: {
fill: null,
class: 'rect-bg',
},
},
})
const view2 = graph.findView(rect2)

view2?.on('view:render', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用法上感觉怪怪的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我感觉也和现有的其他使用形式不太搭,但是考虑和参考了很多其他的方式,只有这种改动成本最低最使用最简单了,开会可以再讨论讨论~

view2.animate('rect', {
attributeType: 'CSS',
attributeName: 'fill',
from: 'red',
to: 'green',
dur: '1s',
repeatCount: 'indefinite',
})
})

const edge = graph.addEdge({
source: rect1,
target: rect2,
attrs: {
line: {
strokeDasharray: 5,
},
},
})
const edgeView = graph.findViewByCell(edge)

edgeView?.on('view:render', () => {
edgeView.animate('path:nth-child(2)', {
attributeName: 'stroke-dashoffset',
from: 20,
to: 0,
dur: '1s',
repeatCount: 'indefinite',
})
})
}

refContainer = (container: HTMLDivElement) => {
this.container = container
}

render() {
return (
<div className="x6-graph-wrap" style={{ height: 500 }}>
<div ref={this.refContainer} className="x6-graph" />
</div>
)
}
}
57 changes: 57 additions & 0 deletions examples/src/pages/animation/animateAlongPath.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react'
import { Graph } from '../../../../src'
import '../index.less'

export class AnimateAlongPathExample extends React.Component {
private container!: HTMLDivElement

componentDidMount() {
const graph = new Graph({
container: this.container,
grid: true,
})

const node = graph.addNode({
shape: 'path',
x: 420,
y: 40,
width: 100,
height: 100,
// https://www.svgrepo.com/svg/13653/like
path: 'M24.85,10.126c2.018-4.783,6.628-8.125,11.99-8.125c7.223,0,12.425,6.179,13.079,13.543c0,0,0.353,1.828-0.424,5.119c-1.058,4.482-3.545,8.464-6.898,11.503L24.85,48L7.402,32.165c-3.353-3.038-5.84-7.021-6.898-11.503c-0.777-3.291-0.424-5.119-0.424-5.119C0.734,8.179,5.936,2,13.159,2C18.522,2,22.832,5.343,24.85,10.126z',
attrs: {
body: {
fill: '#fff',
stroke: '#8f8f8f',
strokeWidth: 2,
},
text: {
refX: 0,
refY: 0,
},
},
label: 'path',
})

const view = graph.findViewByCell(node)

view?.on('view:render', () => {
view.animateAlongPath('text', {
dur: '3s',
repeatCount: 'indefinite',
})
})
}

refContainer = (container: HTMLDivElement) => {
this.container = container
}

render() {
return (
<div className="x6-graph-wrap" style={{ height: 500 }}>
<div ref={this.refContainer} className="x6-graph" />
</div>
)
}
}
106 changes: 106 additions & 0 deletions examples/src/pages/animation/animateTransform.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import React from 'react'
import { Graph } from '../../../../src'
import '../index.less'

Graph.registerNode(
'custom-node',
{
width: 200,
height: 60,
attrs: {
body: {
stroke: '#5F95FF',
strokeWidth: 1,
fill: 'rgba(95,149,255,0.05)',
refWidth: 1,
refHeight: 1,
},
image: {
'xlink:href':
'https://gw.alipayobjects.com/zos/antfincdn/FLrTNDvlna/antv.png',
width: 16,
height: 16,
x: 12,
y: 12,
},
title: {
text: 'Node',
refX: 40,
refY: 14,
fill: 'rgba(0,0,0,0.85)',
fontSize: 12,
'text-anchor': 'start',
},
text: {
text: 'this is content text',
refX: 40,
refY: 38,
fontSize: 12,
fill: 'rgba(0,0,0,0.6)',
'text-anchor': 'start',
},
},
markup: [
{
tagName: 'rect',
selector: 'body',
},
{
tagName: 'image',
selector: 'image',
},
{
tagName: 'text',
selector: 'title',
},
{
tagName: 'text',
selector: 'text',
},
],
},
true,
)

export class AnimateTransformExample extends React.Component {
private container!: HTMLDivElement

componentDidMount() {
const graph = new Graph({
container: this.container,
grid: true,
})

const rect1 = graph.addNode({
shape: 'custom-node',
x: 40,
y: 40,
})

const view1 = graph.findView(rect1)

view1?.on('view:render', () => {
view1.animateTransform('image', {
attributeType: 'XML',
attributeName: 'transform',
type: 'rotate',
from: '0 20 20',
to: '360 20 20',
dur: '3s',
repeatCount: 'indefinite',
})
})
}

refContainer = (container: HTMLDivElement) => {
this.container = container
}

render() {
return (
<div className="x6-graph-wrap" style={{ height: 500 }}>
<div ref={this.refContainer} className="x6-graph" />
</div>
)
}
}
56 changes: 56 additions & 0 deletions examples/src/pages/animation/sendToken.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react'
import { Graph, EdgeView, Vector } from '../../../../src'
import '../index.less'

export class SendTokenExample extends React.Component {
private container!: HTMLDivElement

componentDidMount() {
const graph = new Graph({
container: this.container,
grid: true,
})

const rect1 = graph.addNode({
x: 40,
y: 40,
width: 100,
height: 40,
})

const rect2 = graph.addNode({
x: 280,
y: 40,
width: 100,
height: 40,
})

const edge = graph.addEdge({
source: rect1,
target: rect2,
})

const view = graph.findViewByCell(edge) as EdgeView
const token = Vector.create('circle', { r: 6, fill: 'green' })

view.on('view:render', () => {
view.sendToken(token.node, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个示例感觉也不合适。

Copy link
Member

@lxfu1 lxfu1 Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可考虑下配置式实现,默认是节点加载完成开始动画,节点上添加对应的 API,例如 startAnimate
stopAnimate

duration: 2000,
reversed: false,
repeatCount: 'indefinite',
})
})
}

refContainer = (container: HTMLDivElement) => {
this.container = container
}

render() {
return (
<div className="x6-graph-wrap" style={{ height: 500 }}>
<div ref={this.refContainer} className="x6-graph" />
</div>
)
}
}
16 changes: 16 additions & 0 deletions examples/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ const dataSource = [
example: 'animation/transition',
description: '动画',
},
{
example: 'animation/animate',
description: '动画',
},
{
example: 'animation/animateTransform',
description: '动画',
},
{
example: 'animation/animateAlongPath',
description: '动画',
},
{
example: 'animation/sendToken',
description: '动画',
},
{
example: 'history',
description: '时光回溯',
Expand Down
Loading