gantt-canvas-chart 1.0.0

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present, chandq
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # Gantt Canvas Chart
2
+
3
+ A high-performance Gantt chart implementation using HTML5 Canvas with virtual rendering for optimal performance. This component is framework-agnostic and can be integrated into any web application regardless of the technology stack.
4
+
5
+ ## Features
6
+
7
+ ### High-Performance Virtual Rendering
8
+
9
+ - Utilizes HTML5 Canvas for efficient rendering
10
+ - Implements virtual scrolling to handle large datasets without performance degradation
11
+ - Only renders visible elements, optimizing both memory and CPU usage
12
+ - Smooth scrolling experience even with thousands of tasks
13
+
14
+ ### Framework Agnostic
15
+
16
+ - Pure TypeScript implementation with no framework dependencies
17
+ - Can be easily integrated into React, Vue, Angular, or vanilla JavaScript projects
18
+ - Simple API for initialization and data updates
19
+ - Lightweight and fast integration
20
+
21
+ ### Comprehensive Gantt Functionality
22
+
23
+ - **Multiple View Modes**: Day, Week, Month, and Year views
24
+ - **Task Visualization**: Plan vs Actual progress comparison
25
+ - **Dependency Lines**: Visualize task dependencies with smart routing
26
+ - **Customizable Styling**: Configurable colors and appearance
27
+ - **Interactive Elements**: Tooltip support with detailed information
28
+ - **Today Indicator**: Clear visualization of current date
29
+ - **Grid Lines**: Toggle row and column lines for better readability
30
+ - **Responsive Design**: Automatically adapts to container size changes
31
+
32
+ ### Rich Visualization Options
33
+
34
+ - Plan timelines with customizable border colors
35
+ - Actual progress bars with configurable background colors
36
+ - Support for different task types including leave/vacation tasks
37
+ - Multiple annotation options (left, center, right remarks)
38
+ - Custom CSS classes for specific styling needs
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ npm install gantt-canvas-chart
44
+ ```
45
+
46
+ Or include directly via CDN:
47
+
48
+ ```html
49
+ <script src="https://cdn.jsdelivr.net/npm/gantt-canvas-chart/dist/gantt-chart.min.js"></script>
50
+ ```
51
+
52
+ ## Usage Example
53
+
54
+ ```typescript
55
+ import { GanttChart } from 'gantt-canvas-chart';
56
+
57
+ // Prepare your data
58
+ const ganttData = [
59
+ {
60
+ name: 'Project Phase 1',
61
+ tasks: [
62
+ {
63
+ id: '1',
64
+ name: 'Research',
65
+ planStart: '2023-06-01',
66
+ planEnd: '2023-06-15',
67
+ actualStart: '2023-06-01',
68
+ actualEnd: '2023-06-17',
69
+ dependencies: []
70
+ },
71
+ {
72
+ id: '2',
73
+ name: 'Design',
74
+ planStart: '2023-06-16',
75
+ planEnd: '2023-06-30',
76
+ actualStart: '2023-06-18',
77
+ actualEnd: '2023-07-05',
78
+ dependencies: ['1']
79
+ }
80
+ ]
81
+ },
82
+ {
83
+ name: 'Project Phase 2',
84
+ tasks: [
85
+ {
86
+ id: '3',
87
+ name: 'Implementation',
88
+ planStart: '2023-07-01',
89
+ planEnd: '2023-07-31',
90
+ actualStart: '2023-07-06',
91
+ actualEnd: '2023-07-28',
92
+ dependencies: ['2']
93
+ }
94
+ ]
95
+ }
96
+ ];
97
+
98
+ // Configuration options
99
+ const config = {
100
+ viewMode: 'Month',
101
+ rowHeight: 48,
102
+ headerHeight: 56,
103
+ showPlan: true,
104
+ showActual: true,
105
+ showTooltip: true
106
+ };
107
+
108
+ // Initialize the chart
109
+ const container = document.getElementById('gantt-container');
110
+ const ganttChart = new GanttChart(container, ganttData, config);
111
+
112
+ // Update data dynamically
113
+ ganttChart.setData(newData);
114
+
115
+ // Update configuration
116
+ ganttChart.updateConfig({ viewMode: 'Week' });
117
+ ```
@@ -0,0 +1,14 @@
1
+ export declare class DateUtils {
2
+ static readonly ONE_DAY_MS: number;
3
+ static format(date: Date, format?: string): string;
4
+ static addDays(date: Date, days: number): Date;
5
+ static addMonths(date: Date, months: number): Date;
6
+ static addYears(date: Date, years: number): Date;
7
+ static diffDays(date1: Date, date2: Date): number;
8
+ static diffDaysInclusive(date1: Date, date2: Date): number;
9
+ static getDaysInMonth(year: number, month: number): number;
10
+ static getWeekNumber(d: Date): number;
11
+ static getStartOfWeek(d: Date): Date;
12
+ static getStartOfMonth(d: Date): Date;
13
+ static getStartOfYear(d: Date): Date;
14
+ }
@@ -0,0 +1,61 @@
1
+ import { GanttData, GanttConfig } from './types';
2
+
3
+ export declare class GanttChart {
4
+ private rootContainer;
5
+ private container;
6
+ private data;
7
+ private config;
8
+ private headerCanvas;
9
+ private mainCanvas;
10
+ private scrollDummy;
11
+ private tooltip;
12
+ private headerCtx;
13
+ private mainCtx;
14
+ private timelineStart;
15
+ private timelineEnd;
16
+ private pixelsPerDay;
17
+ private scrollLeft;
18
+ private scrollTop;
19
+ private visibleDateRange;
20
+ private today;
21
+ private devicePixelRatio;
22
+ private viewportWidth;
23
+ private viewportHeight;
24
+ private totalWidth;
25
+ private totalHeight;
26
+ private resizeObserver;
27
+ private taskPositions;
28
+ private taskMap;
29
+ constructor(rootContainer: HTMLElement, data: GanttData, config?: GanttConfig);
30
+ private init;
31
+ private buildTaskMap;
32
+ private setupEvents;
33
+ updateConfig(newConfig: GanttConfig): void;
34
+ setData(newData: GanttData): void;
35
+ destroy(): void;
36
+ private calculateFullTimeline;
37
+ private updatePixelsPerDay;
38
+ private dateToX;
39
+ private xToDate;
40
+ private handleResize;
41
+ private handleScroll;
42
+ setScrollTop(scrollTop: number): void;
43
+ private updateVirtualRanges;
44
+ private updateDimensions;
45
+ private setupCanvas;
46
+ private calculateAllTaskPositions;
47
+ private getIterationStartDate;
48
+ render(): void;
49
+ private renderHeader;
50
+ private renderMain;
51
+ private drawArrow;
52
+ private drawAllDependencies;
53
+ private drawAllTasks;
54
+ private drawGrid;
55
+ private drawToday;
56
+ private drawTask;
57
+ private getTaskStyles;
58
+ private handleMouseMove;
59
+ private getTaskTooltipHtml;
60
+ private handleMouseLeave;
61
+ }
@@ -0,0 +1,52 @@
1
+ export interface Task {
2
+ id: string;
3
+ name: string;
4
+ type?: 'task' | 'leave';
5
+ planStart?: string;
6
+ planEnd?: string;
7
+ actualStart?: string;
8
+ actualEnd?: string;
9
+ dependencies?: string[];
10
+ leftRemark?: string;
11
+ rightRemark?: string;
12
+ centerRemark?: string;
13
+ styleClass?: string;
14
+ planBorderColor?: string;
15
+ actualBgColor?: string;
16
+ }
17
+ export interface Row {
18
+ id: string;
19
+ name: string;
20
+ tasks: Task[];
21
+ }
22
+ export type GanttData = Row[];
23
+ export interface GanttConfig {
24
+ viewMode?: 'Day' | 'Week' | 'Month' | 'Year';
25
+ planBorderColor?: string;
26
+ actualBgColor?: string;
27
+ rowHeight?: number;
28
+ headerHeight?: number;
29
+ showPlan?: boolean;
30
+ showActual?: boolean;
31
+ showRowLines?: boolean;
32
+ showColLines?: boolean;
33
+ showLeftRemark?: boolean;
34
+ showRightRemark?: boolean;
35
+ showCenterRemark?: boolean;
36
+ showTooltip?: boolean;
37
+ tooltipColor?: 'black' | 'white';
38
+ offsetTop?: number;
39
+ offsetLeft?: number;
40
+ }
41
+ export interface TaskPosition {
42
+ x_plan_start: number;
43
+ x_plan_end: number;
44
+ x_actual_start: number | null;
45
+ x_actual_end: number | null;
46
+ y: number;
47
+ row: number;
48
+ }
49
+ export interface VisibleDateRange {
50
+ start: Date;
51
+ end: Date;
52
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 获取第一个有效值
3
+ * @param args 有效值可选项
4
+ * @returns
5
+ */
6
+ export declare function firstValidValue(...args: any[]): any;