Skip to content

Commit

Permalink
fix: animation examples
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Jun 1, 2020
1 parent 23fb270 commit e439f5b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
8 changes: 4 additions & 4 deletions examples/x6-example-features/src/pages/animation/1.tsx
Expand Up @@ -10,7 +10,7 @@ export default class Example extends React.Component {
container: this.container,
width: 650,
height: 400,
gridSize: 1,
grid: 1,
})

const ball = graph.addNode({
Expand Down Expand Up @@ -50,7 +50,7 @@ export default class Example extends React.Component {
ball.transition('attrs/body/fill', '#FFFF00', {
delay: 3000,
duration: 500,
interpolate: Interpolation.color,
interp: Interp.color,
})

ball.transition(
Expand All @@ -60,7 +60,7 @@ export default class Example extends React.Component {
delay: 5000,
duration: 2000,
easing: 'easeInBounce',
interpolation: (
interp: (
start: { text: String; fontSize: number },
end: { text: String; fontSize: number },
) => {
Expand Down Expand Up @@ -95,7 +95,7 @@ export default class Example extends React.Component {
cell.transition('position', 20, {
delay: 0,
duration: 5000,
interpolation: function (a: Point.PointLike, b: number) {
interp: function (a: Point.PointLike, b: number) {
return function (t: number) {
return {
x: a.x + 10 * b * (Math.cos(t * 2 * Math.PI) - 1),
Expand Down
11 changes: 4 additions & 7 deletions examples/x6-example-features/src/pages/animation/2.tsx
Expand Up @@ -13,7 +13,7 @@ class BallView extends NodeView {
delay: (1 + Math.random()) * 3000,
duration: 3000,
timing: 'inout',
interpolation: function (a: number, b: number) {
interp: function (a: number, b: number) {
return function (t: number) {
return a + b * (1 - Math.abs(1 - 2 * t))
}
Expand Down Expand Up @@ -67,7 +67,7 @@ class BallView extends NodeView {

this.cell.transition('position', options, {
duration: 100 * flightTime,
interpolation(
interp(
position: Point.PointLike,
params: { speed: number; angle: number },
) {
Expand Down Expand Up @@ -131,11 +131,8 @@ class BallView extends NodeView {
this.graph.options.width,
this.graph.options.height,
)
const interpolation = Interp.color('#ffffff', '#ff0000')
edge.attr(
'line/targetMarker/fill',
interpolation(dist / maxDist / Math.sqrt(2)),
)
const interp = Interp.color('#ffffff', '#ff0000')
edge.attr('line/targetMarker/fill', interp(dist / maxDist / Math.sqrt(2)))
})
}

Expand Down
2 changes: 1 addition & 1 deletion examples/x6-example-features/src/pages/embed/nested.tsx
Expand Up @@ -10,7 +10,7 @@ export default class Example extends React.Component {
container: this.container,
width: 800,
height: 600,
gridSize: 10,
grid: 10,
})

const r1 = graph.addNode({
Expand Down
14 changes: 8 additions & 6 deletions examples/x6-example-features/src/pages/expand/index.tsx
Expand Up @@ -157,14 +157,16 @@ export default class Example extends React.Component {
width: 800,
height: 600,
grid: 1,
defaultConnectionPoint: { name: 'boundary' },
connecting: {
connectionPoint: 'boundary',
validateMagnet: function (cellView: CellView, magnet: Element) {
var cell = (cellView.cell as any) as TogglableRect
var portId = magnet.getAttribute('port')
return portId ? !cell.isPortCollapsed(portId) : true
},
},
magnetThreshold: 'onleave',
clickThreshold: 5,
validateMagnet: function (cellView: CellView, magnet: Element) {
var cell = (cellView.cell as any) as TogglableRect
var portId = magnet.getAttribute('port')
return portId ? !cell.isPortCollapsed(portId) : true
},
})

graph.on('node:click', ({ view }) => {
Expand Down
11 changes: 8 additions & 3 deletions examples/x6-example-features/src/pages/fta/index.tsx
Expand Up @@ -18,10 +18,15 @@ export default class Example extends React.Component {
container: this.container,
width: 1000,
height: 800,
connecting: {
connectionPoint: {
name: 'boundary',
args: { extrapolate: true },
},
connector: 'rounded',
router: 'orth',
},
sorting: 'approx',
defaultConnectionPoint: { name: 'boundary', args: { extrapolate: true } },
defaultConnector: { name: 'rounded' },
defaultRouter: { name: 'orth' },
async: true,
interactive: false,
frozen: true,
Expand Down
8 changes: 4 additions & 4 deletions packages/x6/src/model/animation.ts
Expand Up @@ -35,12 +35,12 @@ export class Animation {
}

const current = this.cell.getPropByPath<T>(path)
const interpolation = localOptions.interpolation
const interp = localOptions.interp

let interpolate: any

if (interpolation) {
interpolate = interpolation(current, target)
if (interp) {
interpolate = interp(current, target)
} else if (typeof target === 'object') {
interpolate = Interp.object(
current as KeyValue<number>,
Expand Down Expand Up @@ -123,6 +123,6 @@ export namespace Animation {
delay?: number
duration?: number
timing?: Timing.Names | Timing.Definition
interpolation?: <T>(from: T, to: T) => (time: number) => T
interp?: <T>(from: T, to: T) => (time: number) => T
}
}

0 comments on commit e439f5b

Please sign in to comment.