Skip to content

Commit

Permalink
feat: init routers
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Mar 18, 2020
1 parent 66d463d commit 762633e
Show file tree
Hide file tree
Showing 7 changed files with 433 additions and 17 deletions.
Empty file.
3 changes: 0 additions & 3 deletions packages/x6/src/research/route/normal.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/x6/src/research/router/index-rollup.ts
@@ -0,0 +1,3 @@
export * from './normal'
export * from './oneside'
export * from './orth'
39 changes: 39 additions & 0 deletions packages/x6/src/research/router/index.ts
@@ -0,0 +1,39 @@
import { FunctionKeys } from 'utility-types'
import { KeyValue } from '../../types'
import { Point } from '../../geometry'
import { EdgeView } from '../core/edge-view'
import * as routers from './index-rollup'

export namespace Router {
export type Definition<T> = (
this: EdgeView,
vertices: Point.PointLike[],
options: T,
edgeView: EdgeView,
) => Point.PointLike[]
}

export namespace Router {
export const normal = routers.normal
export const oneSide = routers.oneSide
}

export namespace Router {
type RouterType = typeof Router

export type OptionsMap = {
[K in FunctionKeys<RouterType>]: Parameters<RouterType[K]>[1]
}

export type NativeNames = keyof OptionsMap

export interface NativeDefine<T extends NativeNames = NativeNames> {
name: T
args?: OptionsMap[T]
}

export interface ManaualDefine {
name: string
args?: KeyValue
}
}
7 changes: 7 additions & 0 deletions packages/x6/src/research/router/normal.ts
@@ -0,0 +1,7 @@
import { Router } from './index'

export interface NormalOptions {}

export const normal: Router.Definition<NormalOptions> = vertices => [
...vertices,
]
@@ -1,19 +1,28 @@
import { Point } from '../../geometry'
import { Router } from './index'

export interface OneSideOptions {
side?: 'left' | 'top' | 'right' | 'bottom'
padding?: number
}

/**
* Routes the link always to/from a certain side
*/
export function oneSide(vertices: Point[], options: Options, linkView) {
export const oneSide: Router.Definition<OneSideOptions> = (
vertices,
options,
edgeView,
) => {
const side = options.side || 'bottom'
const pd = options.padding || 40
const padding = { left: pd, top: pd, right: pd, bottom: pd }
const sourceBBox = linkView.sourceBBox
const targetBBox = linkView.targetBBox
const sourcePoint = sourceBBox.center()
const targetPoint = targetBBox.center()
const sourceBBox = edgeView.sourceBBox
const targetBBox = edgeView.targetBBox
const sourcePoint = sourceBBox.getCenter()
const targetPoint = targetBBox.getCenter()

let coordinate
let dimension
let coordinate: 'x' | 'y'
let dimension: 'width' | 'height'
let direction

switch (side) {
Expand Down Expand Up @@ -53,10 +62,5 @@ export function oneSide(vertices: Point[], options: Options, linkView) {
sourcePoint[coordinate] = targetPoint[coordinate]
}

return [sourcePoint].concat(vertices, targetPoint)
}

export interface Options {
side?: 'left' | 'top' | 'right' | 'bottom'
padding?: number
return [sourcePoint.toJSON(), ...vertices, targetPoint.toJSON()]
}

0 comments on commit 762633e

Please sign in to comment.