-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
175 lines (143 loc) · 3.48 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Svelte app</title>
</head>
<body>
<div id="wrapper">
<div id="teste"></div>
</div>
</body>
<script type="module" src="./index.js"></script>
<script type="module">
import utils from "./src/utils.js";
const rowsCount = 5;
const padding = 360;
const today = new Date();
let startTime = utils.addDays(today, -padding);
//startTime.setHours(0, 0, 0, 0);
startTime = startTime.getTime();
let endTime = utils.addDays(today, padding);
//endTime.setHours(0, 0, 0, 0);
endTime = endTime.getTime();
let rows = [];
for (let i = 0; i < rowsCount; i++) {
rows.push(getRow(i, i.toString()));
}
const initialDate = utils.addDays(new Date(), -30);
const gantt = new Gantt({
target: document.getElementById("teste"),
props: {
startTime,
endTime,
rows,
zoom: "day",
//scrollBehavior: "smooth"
//slider: document.getElementById("wrapper")
},
});
gantt.$on("click", console.log);
gantt.$on("load", () => {
gantt.goto(initialDate, "smooth");
//coloring the column
const relativeDate = gantt.getRelativeDate(initialDate);
const slices = document.querySelectorAll(`.slice[starttime="${relativeDate}"]`);
Array.from(slices).slice(1).forEach(s => s.classList.add("goto"));
});
function getRandomDateRange() {
const getHours = (timespan) => {
return timespan / 1000 / 60 / 60;
};
let diff = endTime - startTime;
let start = Math.floor(Math.random() * diff) + 1;
diff = endTime - startTime - start;
const end = getHours(Math.floor(Math.random() * diff));
start = getHours(start);
return {
startTime: utils.addHours(startTime, start),
endTime: utils.addHours(startTime, start + end),
};
}
function getRandomItems(i) {
const items = [];
const numberOfItems = Math.floor(Math.random() * 2) + 1; //1 a 5
for (let j = 0; j < numberOfItems; j++) {
const randomRange = getRandomDateRange();
items.push({
content: `Item ${i}: ${j}`,
title: `Item ${i}: ${j}`,
class: i % 2 ? "even" : "odd",
startTime: randomRange.startTime,
endTime: randomRange.endTime,
});
}
return items;
}
function getRandomChildrens(i, id) {
const childrens = [];
if (id.length > 4) {
return childrens;
}
const numberOfChildren = i % 2 ? Math.floor(Math.random() * 3) + 1 : 0;
for (let j = 0; j < numberOfChildren; j++) {
childrens.push(getRow(j, id + "-" + j));
}
return childrens;
}
function getRow(i, id) {
return {
headers: [
{
title: `Row ${id}`,
content: `${" ".repeat(id.length - 1)} Row ${id}`,
},
],
items: getRandomItems(id),
expanded: false,
children: getRandomChildrens(i, id),
};
}
function getGroupsDays(columns) {
const groups = [];
let currentGroup;
let currentMonth = -1;
columns.forEach((column) => {
const month = column.date.getMonth();
if (month !== currentMonth) {
currentGroup = {
colspan: 1,
month,
date: column.date,
};
groups.push(currentGroup);
currentMonth = month;
} else {
currentGroup.colspan++;
}
});
return groups;
}
</script>
<style>
/* testes */
body {
margin: 0 0;
}
.goto {
background-color: yellow;
}
.svelte-gantt .item.odd>.content {
background-color: green;
}
.svelte-gantt .has-child {
background-color: #ddd;
cursor: pointer;
}
.svelte-gantt .has-child::before {
content: '\21b5';
transform: scale(-1, 1);
}
</style>
</html>