gantt-canvas-chart 1.6.1 → 1.6.2

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/README.md CHANGED
@@ -46,11 +46,14 @@ npm install gantt-canvas-chart
46
46
  Or include directly via CDN:
47
47
 
48
48
  ```html
49
- <script src="https://cdn.jsdelivr.net/npm/gantt-canvas-chart/dist/gantt-chart.min.js"></script>
49
+ <script src="https://cdn.jsdelivr.net/npm/gantt-canvas-chart/dist/index.umd.js"></script>
50
50
  ```
51
51
 
52
52
  ## Usage Example
53
53
 
54
+ ![Project plan](/assets/project-plan.jpg)
55
+ ![Project member tasks](/assets/project-member-task.jpg)
56
+
54
57
  ```typescript
55
58
  import { GanttChart } from 'gantt-canvas-chart';
56
59
 
@@ -115,3 +118,68 @@ ganttChart.setData(newData);
115
118
  // Update configuration
116
119
  ganttChart.updateConfig({ viewMode: 'Week' });
117
120
  ```
121
+
122
+ ## Full options list
123
+
124
+ ```typescript
125
+ interface Task {
126
+ id: string;
127
+ name: string;
128
+ type?: 'task' | 'leave' | 'overtime' | string;
129
+ planStart?: string; // Plan start date, date separated by '/'
130
+ planEnd?: string;
131
+ actualStart?: string;
132
+ actualEnd?: string;
133
+ dependencies?: string[];
134
+ leftRemark?: string;
135
+ rightRemark?: string;
136
+ centerRemark?: string;
137
+ styleClass?: string;
138
+ planBorderColor?: string;
139
+ actualBgColor?: string;
140
+ hide?: boolean; // Whether to hide this data, default false
141
+ _data?: any; // Store custom data
142
+ planOffsetPercent?: [number, number]; // Draw daily task progress (plan) based on [start coordinate offset percentage, progress percentage]
143
+ actualOffsetPercent?: [number, number]; // Draw daily task progress (actual) based on [start coordinate offset percentage, progress percentage]
144
+ }
145
+
146
+ interface Row {
147
+ id: string;
148
+ name: string;
149
+ hide?: boolean; // Whether to hide this row
150
+ tasks: Task[];
151
+ }
152
+
153
+ type GanttData = Row[];
154
+
155
+ type LoadMoreDirection = 'left' | 'right' | 'bottom';
156
+
157
+ interface GanttConfig {
158
+ viewMode?: 'Day' | 'Week' | 'Month' | 'Year';
159
+ planBorderColor?: string;
160
+ actualBgColor?: string;
161
+ headerBgColor?: string;
162
+ rowHeight?: number;
163
+ headerHeight?: number;
164
+ showPlan?: boolean;
165
+ showActual?: boolean;
166
+ showRowLines?: boolean;
167
+ showColLines?: boolean;
168
+ showLeftRemark?: boolean;
169
+ showRightRemark?: boolean;
170
+ showCenterRemark?: boolean;
171
+ showTooltip?: boolean;
172
+ tooltipColor?: 'black' | 'white';
173
+ todayColor?: string;
174
+ weekendBgColor?: string; // Weekend/holiday header background color
175
+ holidays?: string[]; // Collection of holiday dates, recommended format yyyy/MM/dd
176
+ dateSeparator?: string; // Date format separator in GanttData, default '/'
177
+ offsetTop?: number; // Tooltip position top offset (when embedded in micro frontend framework, child app page elements have offset relative to main app)
178
+ offsetLeft?: number; // Tooltip position left offset (when embedded in micro frontend framework, child app page elements have offset relative to main app)
179
+ scrollEdgeThresholds?: number; // Scroll edge threshold to trigger load more
180
+ xGap?: number; // Gap between tasks, default 0
181
+ enabledLoadMore?: [LoadMoreDirection?, LoadMoreDirection?, LoadMoreDirection?];
182
+ viewFactors?: { Day: number; Week: number; Month: number; Year: number };
183
+ tooltipFormat?: null | ((task: Row, date: Date, config: GanttConfig) => string);
184
+ }
185
+ ```
package/dist/index.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * gantt-canvas-chart v1.6.1
2
+ * gantt-canvas-chart v1.6.2
3
3
  * (c) 2025-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -203,6 +203,8 @@ class GanttChart {
203
203
  showRightRemark: false,
204
204
  showCenterRemark: false,
205
205
  showTooltip: true,
206
+ queryStartDate: null,
207
+ queryEndDate: null,
206
208
  tooltipFormat: null,
207
209
  tooltipColor: "black",
208
210
  todayColor: "#ff4d4f",
@@ -358,9 +360,10 @@ class GanttChart {
358
360
  const currentYear = this.today.getFullYear();
359
361
  let minDate = new Date(9999, 0, 1);
360
362
  let maxDate = new Date(1e3, 0, 1);
363
+ const { queryStartDate, queryEndDate } = this.config;
361
364
  if (this.data.length === 0) {
362
- minDate = /* @__PURE__ */ new Date();
363
- maxDate = DateUtils.addDays(/* @__PURE__ */ new Date(), 60);
365
+ minDate = queryStartDate ? queryStartDate : /* @__PURE__ */ new Date();
366
+ maxDate = DateUtils.addDays(queryEndDate ? queryEndDate : /* @__PURE__ */ new Date(), 60);
364
367
  } else {
365
368
  this.taskMap.forEach(({ task }) => {
366
369
  if (task.hide) {
@@ -380,6 +383,12 @@ class GanttChart {
380
383
  }
381
384
  this.minDate = minDate;
382
385
  this.maxDate = maxDate;
386
+ if (queryStartDate && queryStartDate < minDate) {
387
+ minDate = queryStartDate;
388
+ }
389
+ if (queryEndDate && queryEndDate > maxDate) {
390
+ maxDate = queryEndDate;
391
+ }
383
392
  const minYear = minDate.getFullYear();
384
393
  const maxYear = maxDate.getFullYear();
385
394
  minDate = DateUtils.addDays(minYear === 9999 ? new Date(currentYear, 0, 1) : minDate, -7);
@@ -597,9 +606,9 @@ class GanttChart {
597
606
  return ctx;
598
607
  }
599
608
  /**
600
- * 辅助函数:像素对齐(确保MAC/Windows等不同设备上1px线条清晰)
601
- * 用于 1px 线条,使其落在 x.5 位置,填满一个物理像素,避免模糊
602
- */
609
+ * Helper function: Pixel alignment (ensures 1px lines are crisp on different devices like MAC/Windows)
610
+ * Used for 1px lines to position them at x.5 coordinates, filling a physical pixel to avoid blurriness
611
+ */
603
612
  snap(val) {
604
613
  return Math.floor(val) + 0.5;
605
614
  }
@@ -1204,9 +1213,9 @@ class GanttChart {
1204
1213
  this.showTooltip = false;
1205
1214
  }
1206
1215
  /**
1207
- * 计算任务宽度占的百分比(方便绘制精确到具体时间的每日任务)
1208
- * @param diffMilliseconds 距离目标日期时间的差异毫秒数
1209
- * @param pixelsPerDay 每日的像素数
1216
+ * Calculate the percentage width of a task (convenient for drawing daily tasks accurate to specific times)
1217
+ * @param diffMilliseconds The difference in milliseconds from the target date
1218
+ * @param pixelsPerDay Number of pixels per day
1210
1219
  * @returns
1211
1220
  */
1212
1221
  static getTaskWidthPercent(diffMilliseconds, pixelsPerDay) {
package/dist/index.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * gantt-canvas-chart v1.6.1
2
+ * gantt-canvas-chart v1.6.2
3
3
  * (c) 2025-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/index.d.ts CHANGED
@@ -121,8 +121,8 @@ export declare class GanttChart {
121
121
  private updateDimensions;
122
122
  private setupCanvas;
123
123
  /**
124
- * 辅助函数:像素对齐(确保MAC/Windows等不同设备上1px线条清晰)
125
- * 用于 1px 线条,使其落在 x.5 位置,填满一个物理像素,避免模糊
124
+ * Helper function: Pixel alignment (ensures 1px lines are crisp on different devices like MAC/Windows)
125
+ * Used for 1px lines to position them at x.5 coordinates, filling a physical pixel to avoid blurriness
126
126
  */
127
127
  snap(val: number): number;
128
128
  private calculateAllTaskPositions;
@@ -142,9 +142,9 @@ export declare class GanttChart {
142
142
  private getTaskTooltipHtml;
143
143
  private handleMouseLeave;
144
144
  /**
145
- * 计算任务宽度占的百分比(方便绘制精确到具体时间的每日任务)
146
- * @param diffMilliseconds 距离目标日期时间的差异毫秒数
147
- * @param pixelsPerDay 每日的像素数
145
+ * Calculate the percentage width of a task (convenient for drawing daily tasks accurate to specific times)
146
+ * @param diffMilliseconds The difference in milliseconds from the target date
147
+ * @param pixelsPerDay Number of pixels per day
148
148
  * @returns
149
149
  */
150
150
  static getTaskWidthPercent(diffMilliseconds: number, pixelsPerDay: number): number;
@@ -180,6 +180,8 @@ export declare interface GanttConfig {
180
180
  showRightRemark?: boolean;
181
181
  showCenterRemark?: boolean;
182
182
  showTooltip?: boolean;
183
+ queryStartDate?: Date | null;
184
+ queryEndDate?: Date | null;
183
185
  tooltipColor?: 'black' | 'white';
184
186
  todayColor?: string;
185
187
  weekendBgColor?: string;
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * gantt-canvas-chart v1.6.1
2
+ * gantt-canvas-chart v1.6.2
3
3
  * (c) 2025-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -201,6 +201,8 @@ class GanttChart {
201
201
  showRightRemark: false,
202
202
  showCenterRemark: false,
203
203
  showTooltip: true,
204
+ queryStartDate: null,
205
+ queryEndDate: null,
204
206
  tooltipFormat: null,
205
207
  tooltipColor: "black",
206
208
  todayColor: "#ff4d4f",
@@ -356,9 +358,10 @@ class GanttChart {
356
358
  const currentYear = this.today.getFullYear();
357
359
  let minDate = new Date(9999, 0, 1);
358
360
  let maxDate = new Date(1e3, 0, 1);
361
+ const { queryStartDate, queryEndDate } = this.config;
359
362
  if (this.data.length === 0) {
360
- minDate = /* @__PURE__ */ new Date();
361
- maxDate = DateUtils.addDays(/* @__PURE__ */ new Date(), 60);
363
+ minDate = queryStartDate ? queryStartDate : /* @__PURE__ */ new Date();
364
+ maxDate = DateUtils.addDays(queryEndDate ? queryEndDate : /* @__PURE__ */ new Date(), 60);
362
365
  } else {
363
366
  this.taskMap.forEach(({ task }) => {
364
367
  if (task.hide) {
@@ -378,6 +381,12 @@ class GanttChart {
378
381
  }
379
382
  this.minDate = minDate;
380
383
  this.maxDate = maxDate;
384
+ if (queryStartDate && queryStartDate < minDate) {
385
+ minDate = queryStartDate;
386
+ }
387
+ if (queryEndDate && queryEndDate > maxDate) {
388
+ maxDate = queryEndDate;
389
+ }
381
390
  const minYear = minDate.getFullYear();
382
391
  const maxYear = maxDate.getFullYear();
383
392
  minDate = DateUtils.addDays(minYear === 9999 ? new Date(currentYear, 0, 1) : minDate, -7);
@@ -595,9 +604,9 @@ class GanttChart {
595
604
  return ctx;
596
605
  }
597
606
  /**
598
- * 辅助函数:像素对齐(确保MAC/Windows等不同设备上1px线条清晰)
599
- * 用于 1px 线条,使其落在 x.5 位置,填满一个物理像素,避免模糊
600
- */
607
+ * Helper function: Pixel alignment (ensures 1px lines are crisp on different devices like MAC/Windows)
608
+ * Used for 1px lines to position them at x.5 coordinates, filling a physical pixel to avoid blurriness
609
+ */
601
610
  snap(val) {
602
611
  return Math.floor(val) + 0.5;
603
612
  }
@@ -1202,9 +1211,9 @@ class GanttChart {
1202
1211
  this.showTooltip = false;
1203
1212
  }
1204
1213
  /**
1205
- * 计算任务宽度占的百分比(方便绘制精确到具体时间的每日任务)
1206
- * @param diffMilliseconds 距离目标日期时间的差异毫秒数
1207
- * @param pixelsPerDay 每日的像素数
1214
+ * Calculate the percentage width of a task (convenient for drawing daily tasks accurate to specific times)
1215
+ * @param diffMilliseconds The difference in milliseconds from the target date
1216
+ * @param pixelsPerDay Number of pixels per day
1208
1217
  * @returns
1209
1218
  */
1210
1219
  static getTaskWidthPercent(diffMilliseconds, pixelsPerDay) {
package/dist/index.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * gantt-canvas-chart v1.6.1
2
+ * gantt-canvas-chart v1.6.2
3
3
  * (c) 2025-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -205,6 +205,8 @@
205
205
  showRightRemark: false,
206
206
  showCenterRemark: false,
207
207
  showTooltip: true,
208
+ queryStartDate: null,
209
+ queryEndDate: null,
208
210
  tooltipFormat: null,
209
211
  tooltipColor: "black",
210
212
  todayColor: "#ff4d4f",
@@ -360,9 +362,10 @@
360
362
  const currentYear = this.today.getFullYear();
361
363
  let minDate = new Date(9999, 0, 1);
362
364
  let maxDate = new Date(1e3, 0, 1);
365
+ const { queryStartDate, queryEndDate } = this.config;
363
366
  if (this.data.length === 0) {
364
- minDate = /* @__PURE__ */ new Date();
365
- maxDate = DateUtils.addDays(/* @__PURE__ */ new Date(), 60);
367
+ minDate = queryStartDate ? queryStartDate : /* @__PURE__ */ new Date();
368
+ maxDate = DateUtils.addDays(queryEndDate ? queryEndDate : /* @__PURE__ */ new Date(), 60);
366
369
  } else {
367
370
  this.taskMap.forEach(({ task }) => {
368
371
  if (task.hide) {
@@ -382,6 +385,12 @@
382
385
  }
383
386
  this.minDate = minDate;
384
387
  this.maxDate = maxDate;
388
+ if (queryStartDate && queryStartDate < minDate) {
389
+ minDate = queryStartDate;
390
+ }
391
+ if (queryEndDate && queryEndDate > maxDate) {
392
+ maxDate = queryEndDate;
393
+ }
385
394
  const minYear = minDate.getFullYear();
386
395
  const maxYear = maxDate.getFullYear();
387
396
  minDate = DateUtils.addDays(minYear === 9999 ? new Date(currentYear, 0, 1) : minDate, -7);
@@ -599,9 +608,9 @@
599
608
  return ctx;
600
609
  }
601
610
  /**
602
- * 辅助函数:像素对齐(确保MAC/Windows等不同设备上1px线条清晰)
603
- * 用于 1px 线条,使其落在 x.5 位置,填满一个物理像素,避免模糊
604
- */
611
+ * Helper function: Pixel alignment (ensures 1px lines are crisp on different devices like MAC/Windows)
612
+ * Used for 1px lines to position them at x.5 coordinates, filling a physical pixel to avoid blurriness
613
+ */
605
614
  snap(val) {
606
615
  return Math.floor(val) + 0.5;
607
616
  }
@@ -1206,9 +1215,9 @@
1206
1215
  this.showTooltip = false;
1207
1216
  }
1208
1217
  /**
1209
- * 计算任务宽度占的百分比(方便绘制精确到具体时间的每日任务)
1210
- * @param diffMilliseconds 距离目标日期时间的差异毫秒数
1211
- * @param pixelsPerDay 每日的像素数
1218
+ * Calculate the percentage width of a task (convenient for drawing daily tasks accurate to specific times)
1219
+ * @param diffMilliseconds The difference in milliseconds from the target date
1220
+ * @param pixelsPerDay Number of pixels per day
1212
1221
  * @returns
1213
1222
  */
1214
1223
  static getTaskWidthPercent(diffMilliseconds, pixelsPerDay) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gantt-canvas-chart",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "High performance Gantt chart component based on Canvas, can be applied to any framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.es.js",