Skip to content

Commit

Permalink
fix: interp definition
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Jul 16, 2020
1 parent 89962d7 commit f43254c
Show file tree
Hide file tree
Showing 150 changed files with 108 additions and 99 deletions.
21 changes: 11 additions & 10 deletions packages/x6/src/common/animation/interp.ts
@@ -1,17 +1,18 @@
export namespace Interp {
export function number(a: number, b: number) {
export type Definition<T> = (from: T, to: T) => (time: number) => T
}

export namespace Interp {
export const number: Definition<number> = (a, b) => {
const d = b - a
return (t: number) => {
return a + d * t
}
}

export function object(
a: { [key: string]: number },
b: { [key: string]: number },
) {
export const object: Definition<{ [key: string]: number }> = (a, b) => {
const keys = Object.keys(a)
return (t: number) => {
return (t) => {
const ret: { [key: string]: number } = {}
for (let i = keys.length - 1; i !== -1; i -= 1) {
const key = keys[i]
Expand All @@ -21,7 +22,7 @@ export namespace Interp {
}
}

export function unit(a: string, b: string) {
export const unit: Definition<string> = (a, b) => {
const reg = /(-?[0-9]*.[0-9]*)(px|em|cm|mm|in|pt|pc|%)/
const ma = reg.exec(a)
const mb = reg.exec(b)
Expand All @@ -36,12 +37,12 @@ export namespace Interp {
const d = bb - aa
const u = ma ? ma[2] : ''

return (t: number) => {
return (t) => {
return (aa + d * t).toFixed(precision) + u
}
}

export function color(a: string, b: string) {
export const color: Definition<string> = (a, b) => {
const ca = parseInt(a.slice(1), 16)
const cb = parseInt(b.slice(1), 16)
const ra = ca & 0x0000ff
Expand All @@ -51,7 +52,7 @@ export namespace Interp {
const ba = ca & 0xff0000
const bd = (cb & 0xff0000) - ba

return (t: number) => {
return (t) => {
const r = (ra + rd * t) & 0x000000ff
const g = (ga + gd * t) & 0x0000ff00
const b = (ba + bd * t) & 0x00ff0000
Expand Down
1 change: 0 additions & 1 deletion packages/x6/src/common/index.ts
Expand Up @@ -6,5 +6,4 @@ export * from './dictionary'

export * from './algorithm'
export * from './animation'
export * from './registry'
export * from './localstorage'
7 changes: 0 additions & 7 deletions packages/x6/src/connection/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/x6/src/definition/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/x6/src/global/util.ts
@@ -1,6 +1,6 @@
import { KeyValue } from '../types'
import { snapToGrid as snap } from '../geometry/util'
import { normalize } from '../connection/marker/util'
import { normalize } from '../registry/marker/util'
import { Cell } from '../model/cell'
import { Node } from '../model/node'
import { Edge } from '../model/edge'
Expand Down
6 changes: 3 additions & 3 deletions packages/x6/src/global/version.ts
@@ -1,7 +1,7 @@
/* tslint:disable */

/**
* Auto generated version file, do not modify it!
*/
const version = '0.10.25'
* Auto generated version file, do not modify it!
*/
const version = '0.10.27'
export { version }
2 changes: 1 addition & 1 deletion packages/x6/src/graph/background.ts
@@ -1,6 +1,6 @@
import { ObjectExt } from '../util'
import { Rectangle } from '../geometry'
import { Background } from '../definition'
import { Background } from '../registry'
import { Base } from './base'

export class BackgroundManager extends Base {
Expand Down
3 changes: 1 addition & 2 deletions packages/x6/src/graph/defs.ts
@@ -1,7 +1,6 @@
import { StringExt, Dom } from '../util'
import { Attr, Filter } from '../definition'
import { Attr, Filter, Marker } from '../registry'
import { Markup } from '../view'
import { Marker } from '../connection'
import { Base } from './base'

export class DefsManager extends Base {
Expand Down
4 changes: 1 addition & 3 deletions packages/x6/src/graph/graph.ts
Expand Up @@ -44,16 +44,14 @@ import {
Filter as FilterDefinition,
Background as BackgroundDefinition,
Highlighter as HighlightDefinition,
} from '../definition'
import {
Marker,
Router,
Connector,
ConnectionPoint,
ConnectionStrategy,
NodeConnectionAnchor,
EdgeConnectionAnchor,
} from '../connection'
} from '../registry'

export class Graph extends Basecoat<EventArgs> {
public readonly options: GraphOptions.Definition
Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/graph/grid.ts
@@ -1,4 +1,4 @@
import { Grid as GridDefinition } from '../definition'
import { Grid as GridDefinition } from '../registry'
import { Dom } from '../util'
import { Base } from './base'

Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/graph/highlight.ts
@@ -1,7 +1,7 @@
import { Dom } from '../util'
import { KeyValue } from '../types'
import { CellView } from '../view'
import { Highlighter } from '../definition'
import { Highlighter } from '../registry'
import { Base } from './base'

export class HighlightManager extends Base {
Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/graph/options.ts
Expand Up @@ -12,7 +12,7 @@ import {
ConnectionStrategy,
NodeConnectionAnchor,
EdgeConnectionAnchor,
} from '../connection'
} from '../registry'
import { Widget } from '../addon/common'
import { Hook } from './hook'
import { Graph } from './graph'
Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/model/animation.ts
Expand Up @@ -123,6 +123,6 @@ export namespace Animation {
delay?: number
duration?: number
timing?: Timing.Names | Timing.Definition
interp?: <T>(from: T, to: T) => (time: number) => T
interp?: Interp.Definition<any>
}
}
15 changes: 11 additions & 4 deletions packages/x6/src/model/cell.ts
Expand Up @@ -3,7 +3,7 @@ import { ArrayExt, StringExt, ObjectExt } from '../util'
import { Rectangle, Point } from '../geometry'
import { KeyValue, Size } from '../types'
import { Basecoat } from '../common'
import { Attr } from '../definition'
import { Attr } from '../registry'
import { Markup, CellView } from '../view'
import { Graph } from '../graph'
import { Model } from './model'
Expand Down Expand Up @@ -240,7 +240,7 @@ export class Cell<
options?: Cell.SetOptions,
): this
setProp(key: string, value: any, options?: Cell.SetOptions): this
setProp(data: Partial<Properties>, options?: Cell.SetOptions): this
setProp(props: Partial<Properties>, options?: Cell.SetOptions): this
setProp(
key: string | Partial<Properties>,
value?: any,
Expand Down Expand Up @@ -311,7 +311,7 @@ export class Cell<
): this
prop(key: string, value: any, options?: Cell.SetOptions): this
prop(path: string[], value: any, options?: Cell.SetOptions): this
prop(data: Partial<Properties>, options?: Cell.SetOptions): this
prop(props: Partial<Properties>, options?: Cell.SetOptions): this
prop(
key?: string | string[] | Partial<Properties>,
value?: any,
Expand Down Expand Up @@ -837,6 +837,7 @@ export class Cell<
} else {
this.store.remove('parent', options)
}
return this
}

setChildren(children: Cell[] | null, options: Cell.SetOptions = {}) {
Expand All @@ -850,6 +851,7 @@ export class Cell<
} else {
this.store.remove('children', options)
}
return this
}

unembed(child: Cell, options: Cell.SetOptions = {}) {
Expand All @@ -869,7 +871,7 @@ export class Cell<
}

addTo(model: Model, options?: Cell.SetOptions): this
addTo(graph: Graph, options: Cell.SetOptions): this
addTo(graph: Graph, options?: Cell.SetOptions): this
addTo(parent: Cell, options?: Cell.SetOptions): this
addTo(target: Model | Graph | Cell, options: Cell.SetOptions = {}) {
if (target instanceof Cell) {
Expand All @@ -882,6 +884,7 @@ export class Cell<

insertTo(parent: Cell, index?: number, options: Cell.SetOptions = {}) {
parent.insertChild(this, index, options)
return this
}

addChild(child: Cell | null, options: Cell.SetOptions = {}) {
Expand Down Expand Up @@ -952,6 +955,7 @@ export class Cell<
const index = parent.getChildIndex(this)
parent.removeChildAt(index, options)
}
return this
}

removeChild(child: Cell, options: Cell.RemoveOptions = {}) {
Expand Down Expand Up @@ -985,6 +989,7 @@ export class Cell<
}
})
}
return this
}

// #endregion
Expand Down Expand Up @@ -1199,12 +1204,14 @@ export class Cell<
if (this.model) {
this.model.startBatch(name, { ...data, cell: this })
}
return this
}

stopBatch(name: Model.BatchName, data: KeyValue = {}) {
if (this.model) {
this.model.stopBatch(name, { ...data, cell: this })
}
return this
}

batchUpdate<T>(name: Model.BatchName, execute: () => T, data?: KeyValue): T {
Expand Down
6 changes: 3 additions & 3 deletions packages/x6/src/model/edge.ts
@@ -1,17 +1,17 @@
import { Registry } from '../common'
import { Size, KeyValue } from '../types'
import { ObjectExt, StringExt } from '../util'
import { Point, Polyline } from '../geometry'
import {
Registry,
Attr,
Router,
Connector,
EdgeConnectionAnchor,
NodeConnectionAnchor,
ConnectionPoint,
ConnectionStrategy,
} from '../connection'
} from '../registry'
import { Markup } from '../view/markup'
import { Attr } from '../definition'
import { Share } from './registry'
import { Store } from './store'
import { Cell } from './cell'
Expand Down
25 changes: 13 additions & 12 deletions packages/x6/src/model/node.ts
@@ -1,5 +1,5 @@
import { DeepPartial } from 'utility-types'
import { Registry } from '../common'
import { Registry } from '../registry'
import { Size, KeyValue } from '../types'
import { Point, Rectangle, Angle } from '../geometry'
import { StringExt, ObjectExt, NumberExt } from '../util'
Expand All @@ -9,6 +9,8 @@ import { Edge } from './edge'
import { Store } from './store'
import { Share } from './registry'
import { PortManager } from './port'
import { Animation } from './animation'
import { Interp } from '../common'

export class Node<
Properties extends Node.Properties = Node.Properties
Expand Down Expand Up @@ -383,16 +385,15 @@ export class Node<
options.ty = ty

if (options.transition) {
// if (!isObject(options.transition)) options.transition = {}
// this.transition(
// 'position',
// translatedPosition,
// assign({}, options.transition, {
// valueFunction: interpolate.object,
// }),
// )
// // Recursively call `translate()` on all the embeds cells.
// this.eachChild(child => child.translate(tx, ty, options))
if (typeof options.transition !== 'object') {
options.transition = {}
}

this.transition('position', translatedPosition, {
...options.transition,
interp: Interp.object,
})
this.eachChild((child) => child.translate(tx, ty, options))
} else {
this.startBatch('translate', options)
this.store.set('position', translatedPosition, options)
Expand Down Expand Up @@ -1011,7 +1012,7 @@ export namespace Node {
}

export interface TranslateOptions extends Cell.TranslateOptions {
transition?: boolean
transition?: boolean | Animation.Options
restrictedArea?: Rectangle.RectangleLike | null
}

Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/model/port.ts
@@ -1,4 +1,4 @@
import { Attr, PortLayout, PortLabelLayout } from '../definition'
import { Attr, PortLayout, PortLabelLayout } from '../registry'
import { JSONObject, ObjectExt } from '../util'
import { Point, Rectangle } from '../geometry'
import { Size, KeyValue } from '../types'
Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/model/registry.ts
@@ -1,4 +1,4 @@
import { Registry } from '../common'
import { Registry } from '../registry'

export namespace Share {
let edgeRegistry: Registry<any>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,8 +1,8 @@
import { Rectangle, Point } from '../../geometry'
import { JSONObject } from '../../util'
import { Registry } from '../../common'
import { Cell } from '../../model'
import { CellView } from '../../view'
import { Registry } from '../registry'
import { raw } from './raw'
import * as attrs from './main'

Expand Down
File renamed without changes.
@@ -1,7 +1,7 @@
import { KeyValue } from '../../types'
import { CellView } from '../../view'
import { Marker } from '../../connection'
import { ObjectExt, JSONObject } from '../../util'
import { Marker } from '../marker'
import { Attr } from './index'

function qualify(value: any) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,8 +1,9 @@

import { ValuesType } from 'utility-types'
import * as CSS from 'csstype'
import * as patterns from './main'
import { KeyValue } from '../../types'
import { Registry } from '../../common'
import { Registry } from '../registry'

export namespace Background {
export interface Options {
Expand Down
File renamed without changes.
@@ -1,7 +1,7 @@
import { KeyValue } from '../../types'
import { Registry } from '../../common'
import { Point, Line } from '../../geometry'
import { NodeView } from '../../view'
import { Registry } from '../registry'
import * as connectionPoints from './main'

export namespace ConnectionPoint {
Expand Down
@@ -1,7 +1,7 @@
import { KeyValue } from '../../types'
import { Registry } from '../../common'
import { Point, Path } from '../../geometry'
import { EdgeView } from '../../view'
import { Registry } from '../registry'
import * as connectors from './main'

export namespace Connector {
Expand Down
File renamed without changes.
@@ -1,7 +1,7 @@
import { Registry } from '../../common'
import { KeyValue } from '../../types'
import { Point } from '../../geometry'
import { EdgeView } from '../../view'
import { Registry } from '../registry'
import * as anchors from './main'

export namespace EdgeConnectionAnchor {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit f43254c

Please sign in to comment.