-
Notifications
You must be signed in to change notification settings - Fork 1.8k
WIP: feat: 迁移并优化v1动画能力 #4798
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
Open
q32757468
wants to merge
1
commit into
master
Choose a base branch
from
feat_animation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
WIP: feat: 迁移并优化v1动画能力 #4798
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
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', () => { | ||
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> | ||
) | ||
} | ||
} |
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,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> | ||
) | ||
} | ||
} |
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,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> | ||
) | ||
} | ||
} |
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,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, { | ||
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. 这个示例感觉也不合适。 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. 可考虑下配置式实现,默认是节点加载完成开始动画,节点上添加对应的 API,例如 |
||
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> | ||
) | ||
} | ||
} |
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
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.
用法上感觉怪怪的
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.
我感觉也和现有的其他使用形式不太搭,但是考虑和参考了很多其他的方式,只有这种改动成本最低最使用最简单了,开会可以再讨论讨论~