Skip to content

Commit

Permalink
fix: circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Jun 9, 2020
1 parent 849f947 commit 53d4fd7
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 64 deletions.
9 changes: 6 additions & 3 deletions packages/x6/src/addon/clipboard/index.ts
@@ -1,7 +1,10 @@
import { ArrayExt } from '../../util'
import { Config } from '../../global'
import { Graph } from '../../graph'
import { Cell, Edge, Node, Model } from '../../model'
import { Config } from '../../global/config'
import { Graph } from '../../graph/graph'
import { Cell } from '../../model/cell'
import { Edge } from '../../model/edge'
import { Node } from '../../model/node'
import { Model } from '../../model/model'

export class Clipboard {
protected options: Clipboard.Options
Expand Down
4 changes: 2 additions & 2 deletions packages/x6/src/addon/minimap/index.ts
@@ -1,7 +1,7 @@
import { DeepPartial } from 'utility-types'
import { FunctionExt } from '../../util'
import { View } from '../../view'
import { Graph } from '../../graph'
import { View } from '../../view/view'
import { Graph } from '../../graph/graph'
import { EventArgs } from '../../graph/events'
import { Scroller } from '../scroller'

Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/common/localstorage.ts
@@ -1,4 +1,4 @@
import { Config } from '../global'
import { Config } from '../global/config'
import { StringExt, FunctionExt } from '../util'

export namespace LocalStorage {
Expand Down
3 changes: 2 additions & 1 deletion packages/x6/src/connection/marker/async.ts
@@ -1,4 +1,5 @@
import { Path } from '../../geometry'
import { normalizeMarker } from './util'
import { Marker } from './index'

export interface AsyncMarkerOptions {
Expand Down Expand Up @@ -31,7 +32,7 @@ export const async: Marker.Definition<AsyncMarkerOptions> = (options) => {
result.fill = 'none'
}

result.d = Marker.normalize(path.serialize(), {
result.d = normalizeMarker(path.serialize(), {
x: options.offset || -width / 2,
y: flip ? -height / 2 : height / 2,
})
Expand Down
3 changes: 2 additions & 1 deletion packages/x6/src/connection/marker/circle.ts
@@ -1,4 +1,5 @@
import { Path } from '../../geometry'
import { normalizeMarker } from './util'
import { Marker } from './index'

export interface CircleMarkerOptions {
Expand Down Expand Up @@ -29,7 +30,7 @@ export const circlePlus: Marker.Definition<CircleMarkerOptions> = (options) => {
},
{
type: 'path',
d: Marker.normalize(path.serialize()),
d: normalizeMarker(path.serialize()),
},
] as any,
}
Expand Down
3 changes: 2 additions & 1 deletion packages/x6/src/connection/marker/classic.ts
@@ -1,5 +1,6 @@
import { Path } from '../../geometry'
import { NumberExt } from '../../util'
import { normalizeMarker } from './util'
import { Marker } from './index'

interface Common {
Expand Down Expand Up @@ -59,7 +60,7 @@ function createClassicMarker(
return {
...attrs,
type: 'path',
d: Marker.normalize(path.serialize(), {
d: normalizeMarker(path.serialize(), {
x: options.offset || (open ? -width / 2 : 0),
}),
}
Expand Down
3 changes: 2 additions & 1 deletion packages/x6/src/connection/marker/cross.ts
@@ -1,4 +1,5 @@
import { Path } from '../../geometry'
import { normalizeMarker } from './util'
import { Marker } from './index'

export interface CrossMarkerOptions {
Expand All @@ -19,6 +20,6 @@ export const cross: Marker.Definition<CrossMarkerOptions> = (options) => {
return {
type: 'path',
fill: 'none',
d: Marker.normalize(path.serialize(), options.offset || -width / 2),
d: normalizeMarker(path.serialize(), options.offset || -width / 2),
}
}
3 changes: 2 additions & 1 deletion packages/x6/src/connection/marker/diamond.ts
@@ -1,4 +1,5 @@
import { Path } from '../../geometry'
import { normalizeMarker } from './util'
import { Marker } from './index'

export interface DiamondMarkerOptions {
Expand All @@ -23,6 +24,6 @@ export const diamond: Marker.Definition<DiamondMarkerOptions> = (options) => {

return {
type: 'path',
d: Marker.normalize(path.serialize(), options.offset),
d: normalizeMarker(path.serialize(), options.offset),
}
}
48 changes: 2 additions & 46 deletions packages/x6/src/connection/marker/index.ts
@@ -1,7 +1,7 @@
import { KeyValue } from '../../types'
import { Registry } from '../../common'
import { Path } from '../../geometry'
import { Attr } from '../../definition'
import { normalizeMarker } from './util'
import * as markers from './main'

export namespace Marker {
Expand Down Expand Up @@ -44,49 +44,5 @@ export namespace Marker {
}

export namespace Marker {
/**
* Normalizes marker's path data by translate the center
* of an arbitrary path at <0 + offset,0>.
*/
export function normalize(
d: string,
offset: { x?: number; y?: number },
): string
export function normalize(
d: string,
offsetX?: number,
offsetY?: number,
): string
export function normalize(
d: string,
offset1?: number | { x?: number; y?: number },
offset2?: number,
) {
let offsetX: number | undefined
let offsetY: number | undefined
if (typeof offset1 === 'object') {
offsetX = offset1.x
offsetY = offset1.y
} else {
offsetX = offset1
offsetY = offset2
}

const path = Path.parse(Path.normalize(d))
const bbox = path.bbox()
if (bbox) {
let ty = -bbox.height / 2 - bbox.y
let tx = -bbox.width / 2 - bbox.x
if (typeof offsetX === 'number') {
tx -= offsetX
}
if (typeof offsetY === 'number') {
ty -= offsetY
}

path.translate(tx, ty)
}

return path.serialize()
}
export const normalize = normalizeMarker
}
3 changes: 2 additions & 1 deletion packages/x6/src/connection/marker/path.ts
@@ -1,3 +1,4 @@
import { normalizeMarker } from './util'
import { Marker } from './index'

export interface PathMarkerOptions {
Expand All @@ -9,6 +10,6 @@ export interface PathMarkerOptions {
export const path: Marker.Definition<PathMarkerOptions> = (options) => {
return {
type: 'path',
d: Marker.normalize(options.d, options.offsetX, options.offsetY),
d: normalizeMarker(options.d, options.offsetX, options.offsetY),
}
}
47 changes: 47 additions & 0 deletions packages/x6/src/connection/marker/util.ts
@@ -0,0 +1,47 @@
import { Path } from '../../geometry'

/**
* Normalizes marker's path data by translate the center
* of an arbitrary path at <0 + offset,0>.
*/
export function normalizeMarker(
d: string,
offset: { x?: number; y?: number },
): string
export function normalizeMarker(
d: string,
offsetX?: number,
offsetY?: number,
): string
export function normalizeMarker(
d: string,
offset1?: number | { x?: number; y?: number },
offset2?: number,
) {
let offsetX: number | undefined
let offsetY: number | undefined
if (typeof offset1 === 'object') {
offsetX = offset1.x
offsetY = offset1.y
} else {
offsetX = offset1
offsetY = offset2
}

const path = Path.parse(Path.normalize(d))
const bbox = path.bbox()
if (bbox) {
let ty = -bbox.height / 2 - bbox.y
let tx = -bbox.width / 2 - bbox.x
if (typeof offsetX === 'number') {
tx -= offsetX
}
if (typeof offsetY === 'number') {
ty -= offsetY
}

path.translate(tx, ty)
}

return path.serialize()
}
6 changes: 3 additions & 3 deletions packages/x6/src/connection/router/manhattan/util.ts
@@ -1,7 +1,7 @@
import { Point, Line, Angle, Rectangle } from '../../../geometry'
import { KeyValue } from '../../../types'
import { EdgeView } from '../../../view'
import { Util } from '../../../global'
import { Util } from '../../../global/util'
import { Point, Line, Angle, Rectangle } from '../../../geometry'
import { EdgeView } from '../../../view/edge'
import { ResolvedOptions, Direction } from './options'

export function getSourceBBox(view: EdgeView, options: ResolvedOptions) {
Expand Down
4 changes: 2 additions & 2 deletions packages/x6/src/view/cell.ts
@@ -1,8 +1,8 @@
import { Registry } from '../common'
import { Nilable, KeyValue } from '../types'
import { Rectangle, Point } from '../geometry'
import { ArrayExt, ObjectExt, Dom } from '../util'
import { Registry } from '../common'
import { Attr } from '../definition'
import { Attr } from '../definition/attr'
import { Cell } from '../model/cell'
import { Edge } from '../model/edge'
import { Model } from '../model/model'
Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/view/tool.ts
@@ -1,6 +1,6 @@
import { KeyValue } from '../types'
import { Dom, ObjectExt, StringExt } from '../util'
import { NodeTool, EdgeTool } from '../definition'
import { NodeTool, EdgeTool } from '../definition/tool'
import { View } from './view'
import { CellView } from './cell'
import { Markup } from './markup'
Expand Down

0 comments on commit 53d4fd7

Please sign in to comment.