Date: Thu, 3 Apr 2025 06:39:12 +0100
Subject: [PATCH 11/14] fixes grouping example
---
index.html | 49 ++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 38 insertions(+), 11 deletions(-)
diff --git a/index.html b/index.html
index b66e4e225..7675dca03 100644
--- a/index.html
+++ b/index.html
@@ -31,7 +31,7 @@
font-size: 0.775em;
}
-
+
@@ -338,22 +338,20 @@
Frappe Gantt - for you.
{
start: daysSince(-2),
end: daysSince(2),
- name: 'Write new content',
- id: 'Task 1',
- progress: 5,
- // important: true,
- group: 0,
- },
- {
name: 'Redesign website',
id: 'Task 0',
progress: random(),
- group: 0,
},
{
start: daysSince(3),
+ duration: '6d',
+ name: 'Write new content',
+ id: 'Task 1',
progress: random(),
+ important: true,
dependencies: 'Task 0',
+ },
+ {
start: daysSince(4),
duration: '2d',
name: 'Apply new styles',
@@ -376,6 +374,15 @@ Frappe Gantt - for you.
name: 'Redesign website',
id: 'Task 0',
progress: random(),
+ group : 0,
+ },
+ {
+ start: daysSince(-5),
+ end: daysSince(0),
+ name: 'Redesign website - part 2',
+ id: 'Task 0',
+ progress: random(),
+ group : 0,
},
{
start: daysSince(-15),
@@ -384,6 +391,16 @@ Frappe Gantt - for you.
id: 'Task 1',
progress: random(),
important: true,
+ group : 1,
+ },
+ {
+ start: daysSince(7),
+ duration: '2d',
+ name: 'Edit new content',
+ id: 'Task 1',
+ progress: random(),
+ important: true,
+ group : 1,
},
{
start: daysSince(10),
@@ -391,6 +408,7 @@ Frappe Gantt - for you.
name: 'Review',
id: 'Task 3',
progress: random(),
+ group : 2,
},
{
start: daysSince(-3),
@@ -398,6 +416,7 @@ Frappe Gantt - for you.
name: 'Publish',
id: 'Task 4',
progress: random(),
+ group : 3,
},
];
@@ -463,6 +482,7 @@ Frappe Gantt - for you.
duration: '7d',
name: 'Create prototype',
id: 'Task 3',
+ dependencies: 'Task 2',
progress: random(),
},
{
@@ -474,9 +494,11 @@ Frappe Gantt - for you.
progress: random(),
important: true,
},
+ {
start: daysSince(5),
end: daysSince(10),
name: 'Write technical documentation',
+ id: 'Task 5',
progress: random(),
},
{
@@ -508,6 +530,7 @@ Frappe Gantt - for you.
id: 'Task 9',
progress: random(),
important: true,
+ },
];
const HOLIDAYS = [
@@ -534,6 +557,8 @@ Frappe Gantt - for you.
today_button: true,
view_mode_select: true,
holidays: null,
+ enable_grouping: true,
+ groups: [0, 1, 2, 3],
});
const holidays = new Gantt('#holidays', tasksSpread, {
@@ -541,8 +566,8 @@ Frappe Gantt - for you.
'#bfdbfe': [],
'#a3e635': HOLIDAYS,
},
- enable_grouping: true,
- groups: [0,1,2,3,4],
+ enable_grouping: true,
+ groups: [0, 1, 2, 3],
});
const ignore = new Gantt('#ignore', tasks, {
@@ -562,6 +587,8 @@ Frappe Gantt - for you.
snap_at: '1d',
auto_move_label: false,
scroll_to: 'today',
+ enable_grouping: true,
+ groups: [0, 1, 2, 3],
});
const UPDATES = [
From a37bf67b78414cd466498e5294e6652648865d12 Mon Sep 17 00:00:00 2001
From: "Stephen J. Maher"
Date: Thu, 3 Apr 2025 10:22:12 +0100
Subject: [PATCH 12/14] enables the setting of arbitrary groups and missing
groups
---
index.html | 3 +--
src/index.js | 29 ++++++++++++++++++++---------
2 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/index.html b/index.html
index 7675dca03..0fb9712e6 100644
--- a/index.html
+++ b/index.html
@@ -416,7 +416,6 @@ Frappe Gantt - for you.
name: 'Publish',
id: 'Task 4',
progress: random(),
- group : 3,
},
];
@@ -567,7 +566,7 @@ Frappe Gantt - for you.
'#a3e635': HOLIDAYS,
},
enable_grouping: true,
- groups: [0, 1, 2, 3],
+ groups: [0, 1, 2],
});
const ignore = new Gantt('#ignore', tasks, {
diff --git a/src/index.js b/src/index.js
index a5a789a37..ba3fa2540 100644
--- a/src/index.js
+++ b/src/index.js
@@ -165,11 +165,6 @@ export default class Gantt {
// cache index
task._index = i;
- // enables singe row grouping
- if (this.options.enable_grouping && typeof task.group === 'number') {
- task._index = task.group;
- }
-
// if hours is not set, assume the last day is full day
// e.g: 2018-09-09 becomes 2018-09-09 23:59:59
const task_end_values = date_utils.get_date_values(task._end);
@@ -201,19 +196,35 @@ export default class Gantt {
task.id = `${task.id}`;
}
+ // setting a dummy group if the group is not specified
+ if (typeof task.group == 'undefined') {
+ task.group = 'group-' + task.id;
+ }
+
return task;
})
.filter((t) => t);
this.groups = this.tasks;
if (this.options?.enable_grouping) {
+ // the groups are the union of the specified groups and the groups
+ // from the tasks.
+ let groupset = new Set()
if (this.options?.groups) {
- this.groups = this.options.groups;
- } else {
- this.groups = [...new Set(this.tasks.map((t) => t.group))];
+ groupset = groupset.union(new Set(this.options.groups));
+ }
+ const extendedset = groupset.union(new Set(this.tasks.map((t) => t.group)));
+ this.groups = Array.from(extendedset);
+
+ // the index of the tasks depend on the groups array. This allows
+ // for arbitrary naming of groups (not only numeric). Further, if
+ // the group is not specified, then the index of the task is
+ // updated correctly.
+ for (let task of this.tasks) {
+ task._index = this.groups.indexOf(task.group);
}
- }
+ }
this.setup_dependencies();
}
From d185a8887128d4edff58c01c13e1ad7e45c673c1 Mon Sep 17 00:00:00 2001
From: "Stephen J. Maher"
Date: Mon, 7 Jul 2025 11:40:48 +0100
Subject: [PATCH 13/14] removes union from group creation
---
src/index.js | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/index.js b/src/index.js
index ba3fa2540..46167cfb3 100644
--- a/src/index.js
+++ b/src/index.js
@@ -204,17 +204,13 @@ export default class Gantt {
return task;
})
.filter((t) => t);
-
+
this.groups = this.tasks;
if (this.options?.enable_grouping) {
// the groups are the union of the specified groups and the groups
// from the tasks.
- let groupset = new Set()
- if (this.options?.groups) {
- groupset = groupset.union(new Set(this.options.groups));
- }
- const extendedset = groupset.union(new Set(this.tasks.map((t) => t.group)));
- this.groups = Array.from(extendedset);
+ let groups = this.options?.groups ? this.options.groups : [];
+ this.groups = Array.from(new Set([...groups, ...this.tasks.map((t) => t.group)]));
// the index of the tasks depend on the groups array. This allows
// for arbitrary naming of groups (not only numeric). Further, if
From 6a664593f303e1e1e2c439fe8caa17c4fd926544 Mon Sep 17 00:00:00 2001
From: "Stephen J. Maher"
Date: Sun, 12 Oct 2025 12:42:30 +0100
Subject: [PATCH 14/14] fixes example
---
index.html | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/index.html b/index.html
index 0fb9712e6..af2f8d16d 100644
--- a/index.html
+++ b/index.html
@@ -380,7 +380,7 @@ Frappe Gantt - for you.
start: daysSince(-5),
end: daysSince(0),
name: 'Redesign website - part 2',
- id: 'Task 0',
+ id: 'Task 1',
progress: random(),
group : 0,
},
@@ -388,7 +388,7 @@ Frappe Gantt - for you.
start: daysSince(-15),
duration: '21d',
name: 'Write new content',
- id: 'Task 1',
+ id: 'Task 2',
progress: random(),
important: true,
group : 1,
@@ -397,7 +397,7 @@ Frappe Gantt - for you.
start: daysSince(7),
duration: '2d',
name: 'Edit new content',
- id: 'Task 1',
+ id: 'Task 3',
progress: random(),
important: true,
group : 1,
@@ -406,7 +406,7 @@ Frappe Gantt - for you.
start: daysSince(10),
duration: '14d',
name: 'Review',
- id: 'Task 3',
+ id: 'Task 4',
progress: random(),
group : 2,
},
@@ -414,7 +414,7 @@ Frappe Gantt - for you.
start: daysSince(-3),
duration: '4d',
name: 'Publish',
- id: 'Task 4',
+ id: 'Task 5',
progress: random(),
},
];