@xpyjs/gantt-core 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/x-gantt.js +2070 -1877
- package/dist/x-gantt.umd.cjs +6 -6
- package/package.json +1 -1
- package/types/models/Task.d.ts +34 -6
- package/types/rendering/chart/ChartSlider.d.ts +2 -0
- package/types/rendering/chart/ChartWeekend.d.ts +0 -5
- package/types/store/DataManager.d.ts +4 -0
- package/types/store/index.d.ts +3 -0
- package/types/store/workCalendar.d.ts +68 -0
- package/types/types/calendar.d.ts +97 -0
- package/types/types/options.d.ts +26 -32
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpyjs/gantt-core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"description": "A powerful and flexible Gantt chart component library for modern web applications with TypeScript support",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/x-gantt.umd.cjs",
|
package/types/models/Task.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Dayjs } from "dayjs";
|
|
2
2
|
import { type EventBus } from "../event";
|
|
3
3
|
import { TaskType } from "../types/options";
|
|
4
|
-
import { EmitData } from "@/types";
|
|
5
4
|
import { Store } from "@/store";
|
|
6
5
|
export declare class Task {
|
|
7
6
|
private store;
|
|
@@ -56,9 +55,12 @@ export declare class Task {
|
|
|
56
55
|
*/
|
|
57
56
|
flatIndex: number;
|
|
58
57
|
/**
|
|
59
|
-
*
|
|
58
|
+
* 工时持续时长
|
|
59
|
+
*
|
|
60
|
+
* @description 优先取原始 data 中的 duration
|
|
61
|
+
* @description 若原始数据未提供,则由 endTime - startTime 计算,仅保存在内部,不回填原始数据
|
|
60
62
|
*/
|
|
61
|
-
private
|
|
63
|
+
private _duration;
|
|
62
64
|
/**
|
|
63
65
|
* 原始数据
|
|
64
66
|
*/
|
|
@@ -66,12 +68,38 @@ export declare class Task {
|
|
|
66
68
|
private fields;
|
|
67
69
|
constructor(store: Store, event: EventBus, data: any, parent?: Task, _id?: string);
|
|
68
70
|
getField(field: string): any;
|
|
69
|
-
/**
|
|
71
|
+
/** 切换展示模式时,需要调整展示长度 */
|
|
70
72
|
updateMode(): boolean;
|
|
71
73
|
updateData(data: any): void;
|
|
72
|
-
|
|
74
|
+
/**
|
|
75
|
+
* 更新 Task 时间并修改原始 data
|
|
76
|
+
*/
|
|
77
|
+
updateTime(startTime: Dayjs, endTime: Dayjs, updateDuration?: boolean): void;
|
|
78
|
+
/**
|
|
79
|
+
* 更新 Task 持续时间并修改原始 data
|
|
80
|
+
*/
|
|
81
|
+
updateDuration(startTime: Dayjs, endTime: Dayjs): void;
|
|
82
|
+
/**
|
|
83
|
+
* 按照规则,适配任务时间
|
|
84
|
+
*
|
|
85
|
+
* 规则:
|
|
86
|
+
* - 根据 direction 判断移动内容:left - 开始时间,right - 结束时间,both - 起止时间
|
|
87
|
+
* - 同时缺失 endTime、duration 的话,直接返回
|
|
88
|
+
* - 根据 duration 重新计算 endTime
|
|
89
|
+
* - 启用了跳过非工作日模式,自动调整任务时间,使其落在工作日上
|
|
90
|
+
*/
|
|
91
|
+
fitWork(direction?: "left" | "right" | "both", options?: {
|
|
92
|
+
start?: Dayjs;
|
|
93
|
+
end?: Dayjs;
|
|
94
|
+
}): void;
|
|
95
|
+
/** 获取当前 duration */
|
|
96
|
+
get duration(): number;
|
|
73
97
|
clone(): Task;
|
|
74
|
-
getEmitData():
|
|
98
|
+
getEmitData(): {
|
|
99
|
+
data: any;
|
|
100
|
+
$index: number;
|
|
101
|
+
level: number;
|
|
102
|
+
};
|
|
75
103
|
getAllChildren(): Task[];
|
|
76
104
|
isMilestone(): boolean;
|
|
77
105
|
isSummary(): boolean;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Konva from "konva";
|
|
2
|
-
import dayjs from "../../utils/time";
|
|
3
2
|
import { IContext } from "@/types/render";
|
|
4
3
|
/**
|
|
5
4
|
* 周末周末渲染
|
|
@@ -17,10 +16,6 @@ export declare class WeekendGroup {
|
|
|
17
16
|
/** 渲染版本号,用于丢弃过期的异步结果 */
|
|
18
17
|
private renderVersion;
|
|
19
18
|
constructor(context: IContext, layer: Konva.Layer);
|
|
20
|
-
/**
|
|
21
|
-
* 检查日期是否为周末
|
|
22
|
-
*/
|
|
23
|
-
isWeekend(date: dayjs.Dayjs): boolean;
|
|
24
19
|
/**
|
|
25
20
|
* 调整周末大小
|
|
26
21
|
*/
|
|
@@ -142,6 +142,10 @@ export declare class DataManager {
|
|
|
142
142
|
toggleAllChecked(checked: boolean): void;
|
|
143
143
|
isTaskChecked(task: Task): boolean;
|
|
144
144
|
updateTaskTime(task: Task, startTime: Dayjs, endTime: Dayjs, direction?: "left" | "right" | "both", oldTasks?: Task[]): void;
|
|
145
|
+
/**
|
|
146
|
+
* 基于某个任务进行时间适配的调整,并联动其子任务
|
|
147
|
+
*/
|
|
148
|
+
fitTaskTime(task: Task, direction: "left" | "right" | "both", oldTasks?: Task[]): void;
|
|
145
149
|
setBaselines(baselines: any[]): void;
|
|
146
150
|
getBaselines(): Baseline[];
|
|
147
151
|
/** 根据ID获取基线 */
|
package/types/store/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { TimeAxis } from "./TimeAxis";
|
|
|
6
6
|
import { Dayjs } from "dayjs";
|
|
7
7
|
import { IContext } from "@/types/render";
|
|
8
8
|
import { IOptionConfig, IOptions } from "@/types";
|
|
9
|
+
import { WorkCalendar } from "./workCalendar";
|
|
9
10
|
export declare class Store {
|
|
10
11
|
private context;
|
|
11
12
|
private optionManager;
|
|
@@ -13,8 +14,10 @@ export declare class Store {
|
|
|
13
14
|
private columnManager;
|
|
14
15
|
private linkManager;
|
|
15
16
|
private timeAxis;
|
|
17
|
+
private workCalendar;
|
|
16
18
|
constructor(context: IContext, options?: IOptions);
|
|
17
19
|
getOptionManager(): OptionManager;
|
|
20
|
+
getWorkCalendar(): WorkCalendar;
|
|
18
21
|
getDataManager(): DataManager;
|
|
19
22
|
getColumnManager(): ColumnManager;
|
|
20
23
|
getLinkManager(): LinkManager;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工作日引擎工具。提供周末、节假日的判定函数,以及工作日计算能力
|
|
3
|
+
*/
|
|
4
|
+
import { type Dayjs } from '../utils/time';
|
|
5
|
+
import type { IHolidayOpts, IWeekendOpts, IWorkTimeOpts } from '../types/calendar';
|
|
6
|
+
/**
|
|
7
|
+
* 工作日历统一管理类
|
|
8
|
+
*
|
|
9
|
+
* @description 统一管理所有日期属性。可以判定、计算工作日、节假日、周末等
|
|
10
|
+
*/
|
|
11
|
+
export declare class WorkCalendar {
|
|
12
|
+
private weekendOpts?;
|
|
13
|
+
private holidayOpts?;
|
|
14
|
+
private workTimeOpts?;
|
|
15
|
+
constructor(weekendOpts?: IWeekendOpts, holidayOpts?: IHolidayOpts, workTimeOpts?: IWorkTimeOpts);
|
|
16
|
+
update(opts: {
|
|
17
|
+
weekendOpts?: IWeekendOpts;
|
|
18
|
+
holidayOpts?: IHolidayOpts;
|
|
19
|
+
workTimeOpts?: IWorkTimeOpts;
|
|
20
|
+
}): void;
|
|
21
|
+
/** 只有显式置条件判定为周末的,才会标记为周末。完整判定需要与其他方法共同完成 */
|
|
22
|
+
private _isWeekend;
|
|
23
|
+
/** 只有显式条件判定为节假日的,才会标记为节假日。完整判定需要与其他方法共同完成 */
|
|
24
|
+
private _isHoliday;
|
|
25
|
+
/** 只做特殊日期的标记,对于普通未标记的日期返回 undefined。完整判定需要与其他方法共同完成 */
|
|
26
|
+
private _isWorkTime;
|
|
27
|
+
/**
|
|
28
|
+
* 判断日期是否为工作时间
|
|
29
|
+
*
|
|
30
|
+
* @description 优先级:isWorkTime 钩子 > 节假日 > 周末
|
|
31
|
+
*/
|
|
32
|
+
isWorkTime(date: Date | Dayjs): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* 判断日期是否为周末
|
|
35
|
+
*
|
|
36
|
+
* @description 判定优先级: isWeekend 钩子 > days > 默认 [0, 6]
|
|
37
|
+
*/
|
|
38
|
+
isWeekend(date: Date | Dayjs): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* 判断日期是否为节假日
|
|
41
|
+
*
|
|
42
|
+
* @description 判定优先级: isHoliday 钩子 > holidays 列表
|
|
43
|
+
*/
|
|
44
|
+
isHoliday(date: Date | Dayjs): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* 基于一个日期,获取指定时长后的工作日期
|
|
47
|
+
*
|
|
48
|
+
* @param start - 起始日期
|
|
49
|
+
* @param n - 工作日时长(正数向后,负数向前,可为分数)
|
|
50
|
+
* @returns 目标日期
|
|
51
|
+
*/
|
|
52
|
+
workOffset(start: Date | Dayjs, n: number): Dayjs;
|
|
53
|
+
/**
|
|
54
|
+
* 基于两个日期,计算之间的工作日时长
|
|
55
|
+
*
|
|
56
|
+
* @param start - 起始日期
|
|
57
|
+
* @param end - 结束日期
|
|
58
|
+
*/
|
|
59
|
+
workDiff(start: Date | Dayjs, end: Date | Dayjs): number;
|
|
60
|
+
/**
|
|
61
|
+
* 基于两个日期,计算其中包含的非工作天数
|
|
62
|
+
*/
|
|
63
|
+
restDays(start: Date | Dayjs, end: Date | Dayjs): number;
|
|
64
|
+
/**
|
|
65
|
+
* 基于某个日期获取最近的工作日(默认向后)
|
|
66
|
+
*/
|
|
67
|
+
currentWorkTime(date: Date | Dayjs, direction?: 'after' | 'before'): Dayjs;
|
|
68
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { IPattern } from "./styles";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 周末配置选项
|
|
5
|
+
*/
|
|
6
|
+
export interface IWeekendOpts {
|
|
7
|
+
/**
|
|
8
|
+
* 自定义周末日期。默认周六、周日为周末
|
|
9
|
+
*
|
|
10
|
+
* @description 0=周日, 1=周一, ..., 6=周六(dayjs.day() 语义)
|
|
11
|
+
* @default [0, 6](周六、周日)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // 周五、周六为周末
|
|
15
|
+
* days: [5, 6]
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // 没有周末
|
|
19
|
+
* days: []
|
|
20
|
+
*/
|
|
21
|
+
days?: number[];
|
|
22
|
+
/**
|
|
23
|
+
* 完全自定义周末的判定方法
|
|
24
|
+
*
|
|
25
|
+
* @description 优先级最高
|
|
26
|
+
* @description 返回 true 表示这天是周末。没有被判定的日期可以置空
|
|
27
|
+
*/
|
|
28
|
+
isWeekend?: (date: Date) => boolean | undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 节假日配置选项
|
|
33
|
+
*/
|
|
34
|
+
export interface IHolidayOpts {
|
|
35
|
+
/**
|
|
36
|
+
* 配置节假日期。可以针对不同节假日配置不同的背景颜色。默认使用统一配置颜色
|
|
37
|
+
*/
|
|
38
|
+
holidays?: Array<
|
|
39
|
+
{
|
|
40
|
+
date: Date | number | string | Array<Date | number | string>;
|
|
41
|
+
backgroundColor?: string;
|
|
42
|
+
opacity?: number;
|
|
43
|
+
/**
|
|
44
|
+
* 自定义节假日期的文本
|
|
45
|
+
*/
|
|
46
|
+
text?: {
|
|
47
|
+
/** 是否显示文本 */
|
|
48
|
+
show?: boolean;
|
|
49
|
+
/** 文本内容 */
|
|
50
|
+
content?: string;
|
|
51
|
+
/** 文本颜色 */
|
|
52
|
+
color?: string;
|
|
53
|
+
/** 背景颜色 */
|
|
54
|
+
backgroundColor?: string;
|
|
55
|
+
/** 透明度 */
|
|
56
|
+
opacity?: number;
|
|
57
|
+
/** 文本字体大小 */
|
|
58
|
+
fontSize?: number;
|
|
59
|
+
/** 文本字体 */
|
|
60
|
+
fontFamily?: string;
|
|
61
|
+
}
|
|
62
|
+
} & IPattern
|
|
63
|
+
>;
|
|
64
|
+
/**
|
|
65
|
+
* 完全自定义节假日的判定方法
|
|
66
|
+
*
|
|
67
|
+
* @description 优先级高于 holidays 列表
|
|
68
|
+
* @description 返回 true 表示这天是节假日。没有被判定的日期可以置空
|
|
69
|
+
*/
|
|
70
|
+
isHoliday?: (date: Date) => boolean | undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 工时引擎配置选项
|
|
75
|
+
*/
|
|
76
|
+
export interface IWorkTimeOpts {
|
|
77
|
+
/**
|
|
78
|
+
* 计算日期周期时,是否跳过周末
|
|
79
|
+
* @default false
|
|
80
|
+
* @description 当置为 true 时,任务周期会自动跳过周末。此时可能 duration 时长与 startTime - endTime 长度不一致
|
|
81
|
+
*/
|
|
82
|
+
skipWeekends?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* 计算日期周期时,是否跳过节假日
|
|
85
|
+
* @default false
|
|
86
|
+
* @description 当置为 true 时,任务周期会自动跳过节假日。此时可能 duration 时长与 startTime - endTime 长度不一致
|
|
87
|
+
*/
|
|
88
|
+
skipHolidays?: boolean;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 完全自定义工作日的判定方法
|
|
92
|
+
*
|
|
93
|
+
* @description 优先级高于节假日和周末。如果将某个日期判定为工作日,那么它不会再被 holiday 与 weekend 捕获。
|
|
94
|
+
* @returns 返回 true 表示这天是工作日。没有被判定的日期可以置空
|
|
95
|
+
*/
|
|
96
|
+
isWorkTime?: (date: Date) => boolean | undefined;
|
|
97
|
+
}
|
package/types/types/options.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { IChartOptions } from "./chart";
|
|
|
3
3
|
import { ILink } from "./link";
|
|
4
4
|
import { IPattern } from "./styles";
|
|
5
5
|
import { ITableOptions } from "./table";
|
|
6
|
+
import { IHolidayOpts, IWeekendOpts, IWorkTimeOpts } from "./calendar";
|
|
6
7
|
|
|
7
8
|
export type XGanttUnit = "hour" | "day" | "week" | "month" | "quarter";
|
|
8
9
|
export type TaskType = "task" | "milestone" | "summary";
|
|
@@ -106,6 +107,21 @@ export interface IGanttOptions {
|
|
|
106
107
|
/** 结束时间字段 */
|
|
107
108
|
endTime: string;
|
|
108
109
|
|
|
110
|
+
/**
|
|
111
|
+
* 持续时间字段。
|
|
112
|
+
*
|
|
113
|
+
* @description 该字段不适用于 `day(不含)` 以下单位,仅针对单位为 `day` 及以上的情况有效
|
|
114
|
+
* @description 与 endTime 字段互斥,endTime 优先级更高
|
|
115
|
+
* @description 当 workTime.enabled = false 时,duration 按日历日解释
|
|
116
|
+
* @description 当 workTime.enabled = true 时,duration 按工作日解释
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* // 只有 duration 没有 endTime
|
|
120
|
+
* { id: 1, start: '2024-01-05', duration: 5 }
|
|
121
|
+
* // endTime 自动计算为 2024-01-10(5个日历日)
|
|
122
|
+
*/
|
|
123
|
+
duration?: string;
|
|
124
|
+
|
|
109
125
|
/** 名称字段 */
|
|
110
126
|
name: string;
|
|
111
127
|
|
|
@@ -980,7 +996,7 @@ export interface IGanttOptions {
|
|
|
980
996
|
* @default 0.1
|
|
981
997
|
*/
|
|
982
998
|
opacity: number;
|
|
983
|
-
} & IPattern;
|
|
999
|
+
} & IPattern & IWeekendOpts;
|
|
984
1000
|
|
|
985
1001
|
/** 节假日期配置 */
|
|
986
1002
|
holiday: {
|
|
@@ -992,42 +1008,20 @@ export interface IGanttOptions {
|
|
|
992
1008
|
* 背景颜色。默认使用主色
|
|
993
1009
|
*/
|
|
994
1010
|
backgroundColor?: string;
|
|
1011
|
+
|
|
995
1012
|
/**
|
|
996
1013
|
* 透明度
|
|
997
1014
|
*
|
|
998
1015
|
* @default 0.1
|
|
999
1016
|
*/
|
|
1000
1017
|
opacity: number;
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
opacity?: number;
|
|
1009
|
-
/**
|
|
1010
|
-
* 自定义节假日期的文本
|
|
1011
|
-
*/
|
|
1012
|
-
text?: {
|
|
1013
|
-
/** 是否显示文本 */
|
|
1014
|
-
show?: boolean;
|
|
1015
|
-
/** 文本内容 */
|
|
1016
|
-
content?: string;
|
|
1017
|
-
/** 文本颜色 */
|
|
1018
|
-
color?: string;
|
|
1019
|
-
/** 背景颜色 */
|
|
1020
|
-
backgroundColor?: string;
|
|
1021
|
-
/** 透明度 */
|
|
1022
|
-
opacity?: number;
|
|
1023
|
-
/** 文本字体大小 */
|
|
1024
|
-
fontSize?: number;
|
|
1025
|
-
/** 文本字体 */
|
|
1026
|
-
fontFamily?: string;
|
|
1027
|
-
}
|
|
1028
|
-
} & IPattern
|
|
1029
|
-
>;
|
|
1030
|
-
} & IPattern;
|
|
1018
|
+
|
|
1019
|
+
} & IPattern & IHolidayOpts;
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* 配置工作日模式。启用后可以将任务范围控制在工作日内
|
|
1023
|
+
*/
|
|
1024
|
+
workTime?: IWorkTimeOpts;
|
|
1031
1025
|
|
|
1032
1026
|
/** 标志配置。它用于配置一个或多个标志性日期 */
|
|
1033
1027
|
flag?: {
|
|
@@ -1129,4 +1123,4 @@ export interface IGanttOptions {
|
|
|
1129
1123
|
*/
|
|
1130
1124
|
animationDuration?: number;
|
|
1131
1125
|
};
|
|
1132
|
-
}
|
|
1126
|
+
};
|