-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
123 lines (118 loc) · 3.81 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="A simple, free tool to generate Gantt charts from your task data. Easily manage project schedules and dependencies."
/>
<meta name="author" content="Joseph Na" />
<title>Simple Gantt Chart Generator</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/frappe-gantt/0.6.1/frappe-gantt.min.css"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/frappe-gantt/0.6.1/frappe-gantt.min.js"></script>
<link rel="icon" href="favicon_io/favicon.ico" />
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.input-field,
.instructions {
margin-bottom: 20px;
}
textarea {
width: 100%;
height: 150px;
}
button {
background-color: #4caf50;
color: white;
padding: 10px 15px;
border: none;
cursor: pointer;
margin-right: 5px;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<nav>
<a href="https://josephna76.github.io">Home</a>
</nav>
<h2>Simple Gantt Chart Generator</h2>
<p class="instructions">
Instructions: Paste your task details in the following format: Task Title,
Start Date, End Date, Duration (Days), Dependencies (ID). Each task should
be on a new line. Dependencies are optional and can be multiple, separated
by a comma.
</p>
<div class="input-field">
<textarea
id="taskInput"
placeholder="Paste your task details here..."
></textarea>
</div>
<button id="generateBtn">Generate Gantt Chart</button>
<button id="exportSVG">Export Gantt Chart as SVG</button>
<div id="gantt"></div>
<script>
document.addEventListener("DOMContentLoaded", function () {
const generateBtn = document.getElementById("generateBtn");
const exportSVG = document.getElementById("exportSVG");
let gantt;
generateBtn.addEventListener("click", function () {
const tasks = parseTasks(document.getElementById("taskInput").value);
if (tasks && tasks.length > 0) {
gantt = new Gantt("#gantt", tasks, {
on_click: (task) => {
alert(`Task: ${task.name}`);
},
view_mode: "Day",
language: "en",
});
}
});
exportSVG.addEventListener("click", function () {
if (!gantt) {
alert("Please generate a Gantt chart first.");
return;
}
const svgContent = gantt.$svg.outerHTML;
const blob = new Blob([svgContent], { type: "image/svg+xml" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "gantt-chart.svg";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
function parseTasks(input) {
return input
.split("\n")
.map((line, index) => {
if (line.trim() === "") return null;
const parts = line.split("\t").map((part) => part.trim());
if (parts.length < 3) return null;
const [name, start, end] = parts;
return {
id: `${index}`,
name,
start,
end,
progress: 100,
dependencies: parts[4] ? parts[4].split(",") : [],
};
})
.filter((task) => task !== null);
}
});
</script>
</body>
</html>