Skip to content

Commit 68a6381

Browse files
committed
Merge branch 'master' into GS-2863
2 parents f94e806 + 0d992fa commit 68a6381

File tree

125 files changed

+4743
-3035
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+4743
-3035
lines changed

data/api/gantt_addcalendar.md

Lines changed: 106 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,49 @@ addCalendar
1414
@example:
1515

1616
// adding a previously created calendar
17-
var calendarId = gantt.addCalendar(calendar);
18-
19-
// adding a calendar with a new config
20-
var calendarId = gantt.addCalendar({
21-
id:"custom", // optional
22-
worktime: {
23-
hours: ["8:00-17:00"],
24-
days: [ 1, 1, 1, 1, 1, 1 ,1]
25-
}
17+
const calendarId = gantt.addCalendar(calendar);
18+
19+
// adding a calendar with a new config (the "days" property is set as array)
20+
const calendarId = gantt.addCalendar({
21+
id: "custom", // optional
22+
worktime: {
23+
hours: ["8:00-17:00"],
24+
days: [1, 1, 1, 1, 1, 1, 1]
25+
}
2626
});
2727

28-
var calendar = gantt.getCalendar(calendarId);
28+
// adding a calendar with a new config (the "days" property is set as object)
29+
const calendarId = gantt.addCalendar({
30+
id: "global", // the calendar id is optional
31+
worktime: {
32+
hours: ["8:00-12:00", "13:00-17:00"], // global work hours for weekdays
33+
days: {
34+
weekdays: [0, 1, 1, 1, 1, 1, 0],
35+
dates: {
36+
"2025-04-06": true, // override work hours for a specific date
37+
"2025-04-08": false,
38+
"2025-04-09": ["9:00-15:00"]
39+
}
40+
},
41+
customWeeks: {
42+
lastMonthOfTheYear: {
43+
from: new Date(2025, 11, 1),
44+
to: new Date(2026, 0, 1),
45+
hours: ["9:00-13:00"],
46+
days: {
47+
weekdays: [0, 1, 1, 1, 1, 0, 0],
48+
dates: {
49+
"2025-12-08": true,
50+
"2025-12-09": false,
51+
"2025-12-10": ["9:00-15:00"]
52+
}
53+
}
54+
}
55+
}
56+
}
57+
});
58+
59+
const calendar = gantt.getCalendar(calendarId);
2960

3061
@template: api_method
3162
@descr:
@@ -34,59 +65,96 @@ The calendar configuration object can contain the following attributes:
3465
- <span class=subproperty>**id?**</span> - (*string | number*) - optional, the calendar id
3566
- <span class=subproperty>**worktime?**</span> - (*object*) - an object that sets the worktime in days and hours. It can include:
3667
- **_hours?_** - (*string[] | number[] | boolean*) - optional, an array with global working hours, sets the start and end hours of the task
37-
- **_days?_** - (*WorkDaysTuple*) - optional, an array of 7 days of the week (from 0 - Sunday, to 6 - Saturday), where 1/true stands for a working day and 0/false - a non-working day
68+
- **_days?_** - (*WorkDaysTuple* | *object*) - optional, it can be:
69+
- either an array of 7 days of the week (from 0 - Sunday, to 6 - Saturday), where 1/true stands for a working day and 0/false - a non-working day
70+
- or an object that contains weekdays and dates. It can include:
71+
- **_weekdays?_** - (*WorkDaysTuple*) optional, an array of 7 days of the week (from 0 - Sunday, to 6 - Saturday), where 1/true stands for a working day and 0/false - a non-working day
72+
- **_dates?_** - (*object*) optional, an object with working time settings for specified dates. The object can contain a number of key: value pairs where:
73+
- key is a date set as a string
74+
- value is either an array of working hours as 'from'-'to' pairs or a boolean ('false' value sets a day-off, 'true' applies the default hours (["8:00-17:00"]))
3875
- **_customWeeks?_** - (*object*) - optional, an object with different working-time rules for different periods of time. The object can contain a set of key:value pairs where key is the name of a time span and value is an object with a list of attributes.
3976
- **_[timespan: string]_** - (*object*) - the time span with the working time settings. The name of that object is used as the name of the time span
4077
- **_from_** - (*Date*) - the date when the time span is scheduled to begin
4178
- **_to_** - (*Date*) - the date when the time span is scheduled to be completed
4279
- **_hours?_** - (*Array&lt;string | number&gt;*) - optional, an array of working hours as 'from'-'to' pairs.'false' value sets a day-off, 'true' (default value) applies the default hours (["8:00-17:00"])
43-
- **_days?_** - (*WorkDaysTuple | boolean*) - optional, an array of 7 days of the week (from 0 - Sunday, to 6 - Saturday), where 1/true stands for a working day and 0/false - a non-working day.
44-
80+
- **_days?_** - (*WorkDaysTuple* | *object*) - optional, it can be:
81+
- either an array of 7 days of the week (from 0 - Sunday, to 6 - Saturday), where 1/true stands for a working day and 0/false - a non-working day
82+
- or an object that contains weekdays and dates. It can include:
83+
- **_weekdays?_** - (*WorkDaysTuple*) optional, an array of 7 days of the week (from 0 - Sunday, to 6 - Saturday), where 1/true stands for a working day and 0/false - a non-working day
84+
- **_dates?_** - (*object*) optional, an object with working time settings for specified dates. The object can contain a number of key: value pairs where:
85+
- key is a date set as a string
86+
- value is either an array of working hours as 'from'-'to' pairs or a boolean ('false' value sets a day-off, 'true' applies the default hours (["8:00-17:00"]))
4587

4688

47-
###Setting individual working hours for a day
89+
### Setting individual working hours for a day
4890

49-
Instead of the number of a week day, you can also set custom working hours for this day.<br>
50-
For example:
91+
Instead of the number of a week day, you can also set custom working hours for this day.
92+
For example:
5193

5294
~~~js
53-
var calendar = {
54-
id:"calendar1", // optional
95+
const calendar = {
96+
id: "calendar1", // optional
5597
worktime: {
5698
hours: ["8:00-17:00"],
57-
days: [ 0, 1, 1, 1, ["12:00-17:00"], 1, 0]
99+
days: [0, 1, 1, 1, ["12:00-17:00"], 1, 0] /*!*/
58100
}
59101
}
60102
~~~
61103

62104
where ["12:00-17:00"] are working hours from 12 pm to 17 pm for Thursday.
63105

64-
65106
### Setting worktime for different time intervals
66107

67-
There is the ability to configure different working time rules for different periods of time by using the **customWeeks** attribute:
108+
There is a possibility to configure different working time rules for different periods of time by using the **customWeeks** attribute:
68109

69110
~~~js
70-
// adding a calendar with a new config
71111
gantt.addCalendar({
72-
id:"default", // optional
73-
worktime: {
74-
hours: ["8:00-17:00"],
75-
days: [ 1, 1, 1, 1, 1, 1 ,1],
76-
customWeeks: {
77-
winter: {
78-
from: new Date(2020, 11, 1),// December 1st, 2020
79-
to: new Date(2021, 2, 1),// March 1st 00:00, 2021
80-
hours: ["9:00-13:00", "14:00-16:00"],
81-
days: [ 1, 1, 1, 1, 0, 0, 0]
82-
}
83-
}
84-
}
112+
id: "global", // optional
113+
worktime: {
114+
hours: ["8:00-17:00"],
115+
days: [1, 1, 1, 1, 1, 1, 1],
116+
customWeeks: {
117+
winter: {
118+
from: new Date(2025, 11, 1), // December 1st, 2025
119+
to: new Date(2026, 2, 1), // March 1st, 00:00, 2026
120+
hours: ["9:00-13:00", "14:00-16:00"],
121+
days: [1, 1, 1, 1, 0, 0, 0]
122+
}
123+
}
124+
}
85125
});
126+
~~~
127+
### Setting worktime for certain dates
86128

129+
You can also specify working hours for certain dates by setting them in the **_dates_** property of the **_days_** object (both for the **worktime** attribute and the **customWeeks** property). For example:
87130

131+
~~~js
132+
const calendar = {
133+
id: "calendar1", // optional
134+
worktime: {
135+
hours: ["8:00-17:00"],
136+
days: {
137+
dates: {
138+
"2025-04-09": ["9:00-15:00"]
139+
}
140+
},
141+
customWeeks: {
142+
winter: {
143+
from: new Date(2025, 11, 1), // December 1st, 2025
144+
to: new Date(2026, 2, 1), // March 1st, 00:00, 2026
145+
hours: ["9:00-13:00", "14:00-16:00"],
146+
days: {
147+
dates: {
148+
"2026-01-02": ["9:00-15:00"]
149+
}
150+
}
151+
}
152+
}
153+
}
154+
}
88155
~~~
89-
156+
157+
90158
@relatedsample:
91159

92160
09_worktime/06_task_calendars.html
@@ -103,5 +171,6 @@ api/gantt_calendar_other.md
103171
desktop/working_time.md#multipleworktimecalendars
104172

105173
@changelog:
106-
- the **customWeeks** property is added in v7.1;
174+
- the possibility to specify the **_days_** property as *object* with weekdays and dates is added in v9.1
175+
- the **customWeeks** property is added in v7.1
107176
- added in version 4.2

data/api/gantt_addtasklayer.md

Lines changed: 80 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,24 @@ addTaskLayer
1313

1414
@example:
1515
gantt.init("gantt_here");
16-
gantt.addTaskLayer(function draw_deadline(task) {
16+
17+
gantt.addTaskLayer((task) => {
1718
if (task.deadline) {
18-
var el = document.createElement('div');
19-
el.className = 'deadline';
20-
var sizes = gantt.getTaskPosition(task, task.deadline);
19+
const el = document.createElement("div");
20+
el.className = "deadline";
2121

22-
el.style.left = sizes.left + 'px';
23-
el.style.top = sizes.top + 'px';
22+
const sizes = gantt.getTaskPosition(task, task.deadline);
23+
el.style.left = `${sizes.left}px`;
24+
el.style.top = `${sizes.top}px`;
2425

25-
el.setAttribute('title', gantt.templates.task_date(task.deadline));
26+
el.setAttribute("title", gantt.templates.task_date(task.deadline));
2627
return el;
2728
}
2829
return false;
2930
});
3031

3132

33+
3234
@related:
3335
desktop/baselines.md
3436
desktop/how_to.md#howtoverticallyreordertasksinthetimeline (read how to vertically reorder tasks in the timeline)
@@ -119,16 +121,16 @@ To do that, you need to use the *object* parameter of the *addTaskLayer()* metho
119121

120122
~~~js
121123
gantt.addTaskLayer({
122-
renderer: {
123-
render: function(task, timeline, viewport){
124-
...
125-
return HTMLElement
126-
},
127-
getRectangle: function(task, view){
128-
....
129-
return {left, top, height, width};
130-
}
131-
}
124+
renderer: {
125+
render: (task, timeline, viewport) => {
126+
// ...
127+
return /* HTMLElement */;
128+
},
129+
getRectangle: (task, view) => {
130+
// ...
131+
return { left, top, height, width };
132+
}
133+
}
132134
});
133135
~~~
134136

@@ -141,24 +143,31 @@ The logic of rendering custom elements is the following:
141143

142144
~~~js
143145
gantt.addTaskLayer({
144-
renderer: {
145-
render: function draw_planned(task) {
146-
if (task.planned_start && task.planned_end) {
147-
var sizes = gantt.getTaskPosition(task,task.planned_start,task.planned_end);
148-
var el = document.createElement('div');
149-
el.className = 'baseline';
150-
el.style.left = sizes.left + 'px';
151-
el.style.width = sizes.width + 'px';
152-
el.style.top = sizes.top + gantt.config.task_height + 13 + 'px';
153-
return el;
154-
}
155-
return false;
156-
},
157-
// define getRectangle in order to hook layer with the smart rendering
158-
getRectangle: function(task, view){
159-
return gantt.getTaskPosition(task, task.planned_start, task.planned_end);
160-
}
161-
}
146+
renderer: {
147+
render: (task) => {
148+
if (task.planned_start && task.planned_end) {
149+
const sizes = gantt.getTaskPosition(
150+
task,
151+
task.planned_start,
152+
task.planned_end
153+
);
154+
const el = document.createElement('div');
155+
el.className = 'baseline';
156+
el.style.left = sizes.left + 'px';
157+
el.style.width = sizes.width + 'px';
158+
el.style.top = (sizes.top + gantt.config.task_height + 13) + 'px';
159+
return el;
160+
}
161+
return false;
162+
},
163+
// define getRectangle in order to hook layer with the smart rendering
164+
getRectangle: (task, view) =>
165+
gantt.getTaskPosition(
166+
task,
167+
task.planned_start,
168+
task.planned_end
169+
)
170+
}
162171
});
163172
~~~
164173

@@ -168,20 +177,20 @@ The **renderer** object of the *addTaskLayer()* method provides a possibility to
168177

169178
~~~js
170179
gantt.addTaskLayer({
171-
renderer: {
172-
render: function(task, timeline, viewport){
173-
...
174-
return HTMLElement
175-
},
176-
update: function(task, node, timeline, viewport){
177-
...
178-
// put the currently visible part of the element into node inner html
179-
},
180-
getRectangle: function(task, view){
181-
....
182-
return {left, top, height, width};
183-
}
184-
}
180+
renderer: {
181+
render: (task, timeline, viewport) => {
182+
// ...
183+
return /* HTMLElement */;
184+
},
185+
update: (task, node, timeline, viewport) => {
186+
// ...
187+
// put the currently visible part of the element into node inner html
188+
},
189+
getRectangle: (task, view) => {
190+
// ...
191+
return { left, top, height, width };
192+
}
193+
}
185194
});
186195
~~~
187196

@@ -195,20 +204,20 @@ Since v7.1.8 the **renderer** object of the *addTaskLayer()* method allows getti
195204

196205
~~~js
197206
gantt.addTaskLayer({
198-
renderer: {
199-
render: function(task, timeline, viewport){
200-
...
201-
return HTMLElement
202-
},
203-
getVisibleRange: function(){
204-
...
205-
return {
206-
start: indexStart,
207-
end: indexEnd
208-
}
209-
}
207+
renderer: {
208+
render: (task, timeline, viewport) => {
209+
// ...
210+
return /* HTMLElement */;
211+
},
212+
getVisibleRange: () => {
213+
// ...
214+
return {
215+
start: indexStart,
216+
end: indexEnd
217+
};
218+
}
210219
}
211-
});
220+
});
212221
~~~
213222

214223
- **getVisibleRange** - a function that returns an object with the start and end indexes of visible tasks rows.
@@ -222,15 +231,15 @@ The **renderer** object of the *addTaskLayer()* method provides the **onrender**
222231

223232
~~~js
224233
gantt.addTaskLayer({
225-
renderer: {
226-
render: function(task, timeline, viewport){
227-
...
228-
return HTMLElement
229-
},
230-
onrender: function(item, node, view){
231-
console.log("render", item, node)
232-
}
233-
}
234+
renderer: {
235+
render: (task, timeline, viewport) => {
236+
// ...
237+
return /* HTMLElement */;
238+
},
239+
onrender: (item, node, view) => {
240+
console.log("render", item, node);
241+
}
242+
}
234243
});
235244
~~~
236245

0 commit comments

Comments
 (0)