-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support fs,ff,ss,sf link types (#194)
- Loading branch information
1 parent
67d56af
commit 175508c
Showing
18 changed files
with
387 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { GanttDate } from '../utils/date'; | ||
import { GanttItem } from './item'; | ||
|
||
export enum GanttLinkType { | ||
fs = 1, | ||
ff = 2, | ||
ss = 3, | ||
sf = 4 | ||
} | ||
|
||
export enum GanttLinkLineType { | ||
curve = 'curve', | ||
straight = 'straight' | ||
} | ||
|
||
export enum LinkColors { | ||
default = '#cacaca', | ||
blocked = '#FF7575', | ||
active = '#348FE4' | ||
} | ||
|
||
export interface GanttLink { | ||
type: GanttLinkType; | ||
link: string; | ||
color?: string; | ||
} | ||
|
||
export interface GanttLinkItem { | ||
id: string; | ||
before: { x: number; y: number }; | ||
after: { x: number; y: number }; | ||
start: GanttDate; | ||
end: GanttDate; | ||
origin: GanttItem; | ||
links: GanttLink[]; | ||
} | ||
|
||
export interface LinkInternal { | ||
path: string; | ||
source: GanttItem; | ||
target: GanttItem; | ||
color: string; | ||
type: GanttLinkType; | ||
} | ||
|
||
export interface GanttLinkOptions { | ||
dependencyTypes?: GanttLinkType[]; | ||
showArrow?: boolean; | ||
lineType?: GanttLinkLineType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { Inject } from '@angular/core'; | ||
import { GanttLinkItem, GanttLinkType } from '../../../class/link'; | ||
import { GanttUpper, GANTT_UPPER_TOKEN } from '../../../gantt-upper'; | ||
import { GanttLinkLine } from './line'; | ||
|
||
export class GanttLinkLineCurve extends GanttLinkLine { | ||
private bezierWeight = -0.5; | ||
|
||
constructor(@Inject(GANTT_UPPER_TOKEN) private ganttUpper: GanttUpper) { | ||
super(); | ||
} | ||
|
||
generateSSPath(source: GanttLinkItem, target: GanttLinkItem) { | ||
const x1 = source.before.x; | ||
const y1 = source.before.y; | ||
const x4 = target.before.x; | ||
const y4 = target.before.y; | ||
const isMirror = y4 > y1 ? 0 : 1; | ||
const radius = Math.abs(y4 - y1) / 2; | ||
|
||
if (x4 > x1) { | ||
return `M ${x1} ${y1} | ||
A ${radius} ${radius} 0 1 ${isMirror} ${x1} ${y4} | ||
L ${x4} ${y4}`; | ||
} else { | ||
return `M ${x1} ${y1} | ||
L ${x4} ${y1} | ||
A ${radius} ${radius} 0 1 ${isMirror} ${x4} ${y4}`; | ||
} | ||
} | ||
generateFFPath(source: GanttLinkItem, target: GanttLinkItem) { | ||
const x1 = source.after.x; | ||
const y1 = source.after.y; | ||
const x4 = target.after.x; | ||
const y4 = target.after.y; | ||
const isMirror = y4 > y1 ? 1 : 0; | ||
const radius = Math.abs(y4 - y1) / 2; | ||
if (x4 > x1) { | ||
return `M ${x1} ${y1} | ||
L ${x4} ${y1} | ||
A ${radius} ${radius} 0 1 ${isMirror} ${x4} ${y4}`; | ||
} else { | ||
return `M ${x1} ${y1} | ||
A ${radius} ${radius} 0 1 ${isMirror} ${x1} ${y4} | ||
L ${x4} ${y4}`; | ||
} | ||
} | ||
|
||
generateFSAndSFPath(source: GanttLinkItem, target: GanttLinkItem, type?: GanttLinkType) { | ||
let x1 = source.after.x; | ||
let y1 = source.after.y; | ||
let x4 = target.before.x; | ||
let y4 = target.before.y; | ||
|
||
if (type === GanttLinkType.sf) { | ||
x1 = target.after.x; | ||
y1 = target.after.y; | ||
x4 = source.before.x; | ||
y4 = source.before.y; | ||
} | ||
|
||
const dx = Math.abs(x4 - x1) * this.bezierWeight; | ||
|
||
const x2 = x1 - dx; | ||
const x3 = x4 + dx; | ||
const centerX = (x1 + x4) / 2; | ||
const centerY = (y1 + y4) / 2; | ||
|
||
let controlX = this.ganttUpper.styles.lineHeight / 2; | ||
const controlY = this.ganttUpper.styles.lineHeight / 2; | ||
|
||
if (x1 >= x4) { | ||
if (y4 > y1) { | ||
if (Math.abs(y4 - y1) <= this.ganttUpper.styles.lineHeight) { | ||
return `M ${x1} ${y1} | ||
C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 + controlX} ${x1} ${y1 + controlY} | ||
L ${x4} ${y4 - controlY} | ||
C ${x4 - controlY} ${y4 - controlY} ${x4 - controlX} ${y4} ${x4} ${y4}`; | ||
} else { | ||
controlX = this.ganttUpper.styles.lineHeight; | ||
return `M ${x1} ${y1} | ||
C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 + controlX} ${centerX} ${centerY} | ||
C ${x4 - controlX} ${y4 - controlX} ${x4 - controlX} ${y4} ${x4} ${y4} | ||
`; | ||
} | ||
} else { | ||
if (Math.abs(y4 - y1) <= this.ganttUpper.styles.lineHeight) { | ||
return `M ${x1} ${y1} | ||
C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 - controlX} ${x1} ${y1 - controlY} | ||
L ${x4} ${y4 + controlY} | ||
C ${x4 - controlY} ${y4 + controlY} ${x4 - controlX} ${y4} ${x4} ${y4} | ||
`; | ||
} else { | ||
controlX = this.ganttUpper.styles.lineHeight; | ||
return `M ${x1} ${y1} | ||
C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 - controlX} ${centerX} ${centerY} | ||
C ${x4 - controlX} ${y4 + controlX} ${x4 - controlX} ${y4} ${x4} ${y4} | ||
`; | ||
} | ||
} | ||
} else if (this.ganttUpper.linkOptions?.showArrow && x4 - x1 < 100) { | ||
const radius = Math.abs(y4 - y1) / 4; | ||
let lindWidth = x4 - x1 - radius; | ||
lindWidth = Math.max(lindWidth, radius); | ||
|
||
return `M ${x1} ${y1} | ||
L ${x1 + lindWidth} ${y1} | ||
A ${radius} ${radius} 0 1 ${y4 > y1 ? 1 : 0} ${x1 + lindWidth} ${y4 > y1 ? y1 + 2 * radius : y1 - 2 * radius} | ||
L ${x4 - lindWidth} ${y4 > y1 ? y1 + 2 * radius : y1 - 2 * radius} | ||
A ${radius} ${radius} 0 1 ${y4 > y1 ? 0 : 1} ${x4 - lindWidth} ${y4} | ||
L ${x4} ${y4} | ||
`; | ||
} | ||
return `M ${x1} ${y1} C ${x2} ${y1} ${x3} ${y4} ${x4} ${y4}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { GanttLinkLineType } from '../../../class/link'; | ||
import { GanttUpper } from '../../../gantt-upper'; | ||
import { GanttLinkLineCurve } from './curve'; | ||
import { GanttLinkLineStraight } from './straight'; | ||
|
||
export function createLineGenerator(type: GanttLinkLineType, ganttUpper?: GanttUpper) { | ||
switch (type) { | ||
case GanttLinkLineType.curve: | ||
return new GanttLinkLineCurve(ganttUpper); | ||
case GanttLinkLineType.straight: | ||
return new GanttLinkLineStraight(); | ||
default: | ||
throw new Error('gantt link path type invalid'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { GanttLinkItem, GanttLinkType } from '../../../class/link'; | ||
|
||
export abstract class GanttLinkLine { | ||
constructor() {} | ||
|
||
abstract generateSSPath(source: GanttLinkItem, target: GanttLinkItem): string; | ||
|
||
abstract generateFFPath(source: GanttLinkItem, target: GanttLinkItem): string; | ||
|
||
abstract generateFSAndSFPath(source: GanttLinkItem, target: GanttLinkItem, type?: GanttLinkType): string; | ||
|
||
generatePath(source: GanttLinkItem, target: GanttLinkItem, type: GanttLinkType) { | ||
if (source.before && source.after && target.before && target.after) { | ||
let path = ''; | ||
|
||
switch (type) { | ||
case GanttLinkType.ss: | ||
path = this.generateSSPath(source, target); | ||
break; | ||
case GanttLinkType.ff: | ||
path = this.generateFFPath(source, target); | ||
break; | ||
|
||
case GanttLinkType.sf: | ||
path = this.generateFSAndSFPath(source, target, type); | ||
break; | ||
default: | ||
path = this.generateFSAndSFPath(source, target); | ||
} | ||
|
||
return path; | ||
} | ||
} | ||
} |
Oops, something went wrong.