Skip to content

Commit

Permalink
feat: more readable style names
Browse files Browse the repository at this point in the history
exitX => sourceAnchorX, exitY => sourceAnchorY, entryX=> targetAnchorX ...
  • Loading branch information
bubkoo committed Dec 19, 2019
1 parent 36a6bd2 commit e4bf07b
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 127 deletions.
2 changes: 1 addition & 1 deletion packages/x6/src/core/view.ts
Expand Up @@ -649,7 +649,7 @@ export class View extends Primer<View.EventArgs> {

if (
direction != null &&
terminalState.style.anchorPointDirection !== false
terminalState.style.anchorWithDirection !== false
) {
if (direction === 'north') {
r1 += 270
Expand Down
56 changes: 32 additions & 24 deletions packages/x6/src/graph/connection-manager.ts
Expand Up @@ -83,9 +83,9 @@ export class ConnectionManager extends BaseManager {
const style = edgeState.style

// connection point specified in style
const x = isSource ? style.exitX : style.entryX
const x = isSource ? style.sourceAnchorX : style.targetAnchorX
if (x != null) {
const y = isSource ? style.exitY : style.entryY
const y = isSource ? style.sourceAnchorY : style.targetAnchorY
if (y != null) {
point = new Point(x, y)
}
Expand All @@ -97,11 +97,11 @@ export class ConnectionManager extends BaseManager {

if (point != null) {
perimeter =
(isSource ? style.exitPerimeter : style.entryPerimeter) !== false
(isSource ? style.sourcePerimeter : style.targetPerimeter) !== false

// Add entry/exit offset
dx = (isSource ? style.exitDx : style.entryDx) as number
dy = (isSource ? style.exitDy : style.entryDy) as number
dx = (isSource ? style.sourceAnchorDx : style.targetAnchorDx) as number
dy = (isSource ? style.sourceAnchorDy : style.targetAnchorDy) as number

dx = isFinite(dx) ? dx : 0
dy = isFinite(dy) ? dy : 0
Expand All @@ -125,55 +125,63 @@ export class ConnectionManager extends BaseManager {
if (anchor != null) {
this.model.batchUpdate(() => {
if (anchor == null || anchor.position == null) {
this.graph.updateCellsStyle(isSource ? 'exitX' : 'entryX', null, [
edge,
])
this.graph.updateCellsStyle(isSource ? 'exitY' : 'entryY', null, [
edge,
])
this.graph.updateCellsStyle(isSource ? 'exitDx' : 'entryDx', null, [
edge,
])
this.graph.updateCellsStyle(isSource ? 'exitDy' : 'entryDy', null, [
edge,
])
this.graph.updateCellsStyle(
isSource ? 'exitPerimeter' : 'entryPerimeter',
isSource ? 'sourceAnchorX' : 'targetAnchorX',
null,
[edge],
)
this.graph.updateCellsStyle(
isSource ? 'sourceAnchorY' : 'targetAnchorY',
null,
[edge],
)
this.graph.updateCellsStyle(
isSource ? 'sourceAnchorDx' : 'targetAnchorDx',
null,
[edge],
)
this.graph.updateCellsStyle(
isSource ? 'sourceAnchorDx' : 'targetAnchorDy',
null,
[edge],
)
this.graph.updateCellsStyle(
isSource ? 'sourcePerimeter' : 'targetPerimeter',
null,
[edge],
)
} else if (anchor.position != null) {
this.graph.updateCellsStyle(
isSource ? 'exitX' : 'entryX',
isSource ? 'sourceAnchorX' : 'targetAnchorX',
`${anchor.position.x}`,
[edge],
)
this.graph.updateCellsStyle(
isSource ? 'exitY' : 'entryY',
isSource ? 'sourceAnchorY' : 'targetAnchorY',
`${anchor.position.y}`,
[edge],
)
this.graph.updateCellsStyle(
isSource ? 'exitDx' : 'entryDx',
isSource ? 'sourceAnchorDx' : 'targetAnchorDx',
`${anchor.dx}`,
[edge],
)
this.graph.updateCellsStyle(
isSource ? 'exitDy' : 'entryDy',
isSource ? 'sourceAnchorDx' : 'targetAnchorDy',
`${anchor.dy}`,
[edge],
)

// Only writes `false` since `true` is default
if (!anchor.perimeter) {
this.graph.updateCellsStyle(
isSource ? 'exitPerimeter' : 'entryPerimeter',
isSource ? 'sourcePerimeter' : 'targetPerimeter',
false,
[edge],
)
} else {
this.graph.updateCellsStyle(
isSource ? 'exitPerimeter' : 'entryPerimeter',
isSource ? 'sourcePerimeter' : 'targetPerimeter',
null,
[edge],
)
Expand Down
12 changes: 6 additions & 6 deletions packages/x6/src/handler/connection/preview.ts
Expand Up @@ -269,16 +269,16 @@ export class Preview extends Disposable {
}

if (this.sourceAnchor != null && this.sourceAnchor.position != null) {
this.edgeState.style.exitX = this.sourceAnchor.position.x
this.edgeState.style.exitY = this.sourceAnchor.position.y
this.edgeState.style.sourceAnchorX = this.sourceAnchor.position.x
this.edgeState.style.sourceAnchorY = this.sourceAnchor.position.y
}

if (currentAnchor != null && currentAnchor.position != null) {
this.edgeState.style.entryX = currentAnchor.position.x
this.edgeState.style.entryY = currentAnchor.position.y
this.edgeState.style.targetAnchorX = currentAnchor.position.x
this.edgeState.style.targetAnchorY = currentAnchor.position.y
} else {
delete this.edgeState.style.entryX
delete this.edgeState.style.entryY
delete this.edgeState.style.targetAnchorX
delete this.edgeState.style.targetAnchorY
}

this.edgeState.absolutePoints = [
Expand Down
16 changes: 8 additions & 8 deletions packages/x6/src/handler/edge/handler.ts
Expand Up @@ -1031,19 +1031,19 @@ export class EdgeHandler extends MouseHandler {
if (this.isSourceHandle || this.isTargetHandle) {
if (anchor != null && anchor.position != null) {
if (this.isSourceHandle) {
edgeState.style.exitX = anchor.position.x
edgeState.style.exitY = anchor.position.y
edgeState.style.sourceAnchorX = anchor.position.x
edgeState.style.sourceAnchorY = anchor.position.y
} else {
edgeState.style.entryX = anchor.position.x
edgeState.style.entryY = anchor.position.y
edgeState.style.targetAnchorX = anchor.position.x
edgeState.style.targetAnchorY = anchor.position.y
}
} else {
if (this.isSourceHandle) {
delete edgeState.style.exitX
delete edgeState.style.exitY
delete edgeState.style.sourceAnchorX
delete edgeState.style.sourceAnchorY
} else {
delete edgeState.style.entryX
delete edgeState.style.entryY
delete edgeState.style.targetAnchorX
delete edgeState.style.targetAnchorY
}
}
}
Expand Down

0 comments on commit e4bf07b

Please sign in to comment.