-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gantt_single_input.html
368 lines (320 loc) · 12.1 KB
/
Gantt_single_input.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<!DOCTYPE html>
<html>
<head>
<title>Gantt Chart Creator - Single Input</title>
<meta charset="utf-8">
<link rel="stylesheet" href="./css/font-awesome.min.css">
<link rel="stylesheet" href="./css/style.css">
<link rel="stylesheet" href="./css/unsemantic.css">
<link rel="stylesheet" href="./css/common.css">
<link rel="stylesheet" href="./css/demo.css">
<link rel="stylesheet" href="./css/vis.css">
<script src="./js/jquery.min.js"></script>
<script src="./js/papaparse.js"></script>
<script src="./js/vis.js"></script>
<script src="./js/html2canvas.js"></script>
</head>
<body>
<br>
<h1>Gantt Chart Creator</h1>
<div class="grid-container">
<div class="grid-65 text-center">
TASKS: <textarea id="input" placeholder="Input">id,content,group,start,end,type,className
1,Task 1,Common,2016-12-02,2017-03-17,point,redpoint
2,Task 2,Common,2016-12-02,,box,green
3,Task 3,Common,2016-12-02,2017-03-17,range,blue
4,<br><br><br><br><br><br><br>Background spanning <br>across all groups,,2016-12-02,2017-02-17,background,
5,Group Specific background,Section 1,2017-03-17,2017-05-07,background,
6,Task 6,Common,2017-03-17,2017-04-27,range,red
7,Task 7,Section 2,2017-04-07,2017-04-27,box,orange
8,Task 8,Section 2,2017-05-07,2017-05-17,box,green
9,Overflow for Task 9,Section 3,2017-06-07,2017-06-20,range,blueoverflow
10,Task 10,Section 3,2017-07-07,2017-07-31,point,orangepoint</textarea>
</div>
<div class="grid-35 text-center">
Custom CSS:
<textarea id="custom_css">.vis-item.redpoint {
border-color: darkred;
}
.vis-item.orangepoint {
border-color: darkorange;
}
.vis-item.greenpoint {
border-color: darkgreen;
}
.vis-item.blueoverflow .vis-item-overflow {
color: darkgrey;
background-color: blue;
border-color: darkblue;
overflow: visible;
}
.vis-item.greenoverflow .vis-item-overflow {
color: darkgrey;
background-color: green;
border-color: darkgreen;
overflow: visible;
}
.vis-item.redoverflow .vis-item-overflow {
color: darkgrey;
background-color: red;
border-color: darkred;
overflow: visible;
}
.vis-item.orangeoverflow .vis-item-overflow {
color: darkgrey;
background-color: orange;
border-color: darkorange;
overflow: visible;
}
.vis-item.red {
color: white;
background-color: red;
border-color: darkred;
}
.vis-item.green {
color: white;
background-color: green;
border-color: darkgreen;
}
.vis-item.blue {
color: white;
background-color: blue;
border-color: darkblue;
}
.vis-item.orange {
color: white;
background-color: orange;
border-color: darkorange;
}
</textarea>
</div>
<br>
<center>
<button id="submit-parse" class="green">Create Gantt</button>
<button id="submit-clear" onClick="window.location.reload()">Clear</button>
<button id="btnSave" class="green">Take Screenshot</button>
</center>
<br>
<span id="widget">
<div id="visualizationcontainer" class="text-center"></div>
<!-- Start: Code to get Modal display for screenshot -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p style="color:green;"> To save this image, right click on it and select "Save image as".
Please note "Copy Image" option will not work.</p>
<div id="visualizationcontainer_img" class="text-center"></div>
</div>
</div>
<!-- END: Code to get Modal display for screenshot -->
</span>
</br>
<br>
</br>
<script>
$(function()
{
$('#submit-parse').click(function()
{
document.getElementById('visualizationcontainer_img').innerHTML = "";
document.getElementById("visualizationcontainer").innerHTML = "";
var txt = $('#input').val();
var visualisation = document.createElement('div');
visualisation.innerHTML = '<div id="visualization">'+'</div>';
document.getElementById('visualizationcontainer').appendChild(visualisation);
/** START: Codeblock for including Custom CSS **/
var style = document.createElement('style')
style.type = 'text/css'
//style.innerHTML = '.vis-item.vis-dot {border-color: #F991A3; background-color: pink;font-size: 15pt;color: purple;box-shadow: 5px 5px 20px rgba(128,128,128, 0.5);}'
style.innerHTML = $('#custom_css').val();
document.getElementsByTagName('head')[0].appendChild(style);
/** END: Codeblock for including Custom CSS **/
//var tab2csv = txt.replace(/ /g, ",");
//console.log(tab2csv);
//var results = Papa.parse(tab2csv, {header: "TRUE",skipEmptyLines:"TRUE", Delimiter:"auto"});
var results = Papa.parse(txt, {header: "TRUE",skipEmptyLines:"TRUE", Delimiter:"auto"});
var items = new vis.DataSet();
var groups = new vis.DataSet();
//Add chart options
var chart_opts = document.createElement('div');
var body = document.getElementById('visualization');
body.appendChild(chart_opts);
// 1. Create the option
var axisorientationlabel = document.createElement('div');
axisorientationlabel.className = 'grid-35 text-center';
axisorientationlabel.innerHTML = '<b>'+'Axis Orientation: '+'</b>';
var axisorientation = document.createElement('select');
axisorientation.innerHTML = '<select id="axis-orientation">'+
'<option value="both" selected>both</option>'+'<option value="bottom">bottom</option>'+'<option value="none">none</option>'+
'<option value="top">top</option>'+'</select>';
var itemorientationlabel = document.createElement('div');
itemorientationlabel.className = 'grid-35 text-center';
itemorientationlabel.innerHTML = '<b>'+'Item Orientation: '+'</b>';
var itemorientation = document.createElement('select');
itemorientation.innerHTML = '<select id="item-orientation">'+
'<option value="bottom" selected>bottom</option>'+'<option value="top">top</option>'+'</select>';
var axisscalelabel = document.createElement('div');
axisscalelabel.className = 'grid-30 text-center';
axisscalelabel.innerHTML = '<b>'+'Axis Scale: '+'</b>'
var axisscale = document.createElement('select');
axisscale.innerHTML = '<select id="timeaxis-scale">'+'<option value="year">Year'+'</option>'
+'<option value="month" selected>Month'+'</option>'
+'<option value="day">Day'+'</option>'
+'<option value="week">Week'+'</option>'
+'<option value="weekday">Weekday'+'</option>'
+'<option value="hour">Hour'+'</option>'
+'<option value="minute">Minute'+'</option>'
+'<option value="second">Second'+'</option>'
+'<option value="millisecond">Millisecond'+'</option>'
+'</select>';
// 2. Append to Gantt
document.getElementById('visualization').appendChild(axisorientationlabel);
axisorientationlabel.appendChild(axisorientation);
document.getElementById('visualization').appendChild(itemorientationlabel);
itemorientationlabel.appendChild(itemorientation);
document.getElementById('visualization').appendChild(axisscalelabel);
axisscalelabel.appendChild(axisscale);
// 3. Add event handler
axisorientation.addEventListener ('change', function() {
timeline.setOptions({ orientation: {axis: axisorientation.value} });
});
itemorientation.addEventListener ('change', function() {
timeline.setOptions({ orientation: {axis: itemorientation.value} });
});
axisscale.addEventListener ('change', function() {
if (axisscale.value == "week") {
timeline.setOptions({ timeAxis: {scale: 'day', step: 7} });
} else {
timeline.setOptions({ timeAxis: {scale: axisscale.value} });
}
});
/*Start: Add Zoom button*/
// 1. Create the button
var zoomin = document.createElement("button");
zoomin.innerHTML = "+";
// 2. Append to Gantt
var body = document.getElementById('visualization');
body.appendChild(zoomin);
// 3. Add event handler
zoomin.addEventListener ("click", function() {
//alert("Zoom In");
timeline.zoomIn( 0.2);
});
// 1. Create the button
var zoomout = document.createElement("button");
zoomout.innerHTML = "-";
// 2. Append to Gantt
var body = document.getElementById('visualization');
body.appendChild(zoomout);
// 3. Add event handler
zoomout.addEventListener ("click", function() {
//alert("Zoom Out");
timeline.zoomOut( 0.2);
});
/*End: Add Zoom button*/
// create a timeline
var container = document.getElementById('visualization');
var options = {
editable: true,
//clickToUse: true,
orientation: {axis:'both'}
};
/*console.log("----------------RESULT--------------");
console.log(results.data);
console.log("--------------------------------------");*/
/* START: fix for removing null or empty value from csv data in json*/
/*
This code block fixes null value for json to ensures that csv data in "" does not
get included in the resulting serialisation.
This is particularly important when group for a background item is empty and expectation
is that the task as bacground will span across all groups.
Basically this code block ensures that following csv:
id,content,group,start,end,type,className
2,Task 2,,2016-12-02,,box,green
results in following dataset:
[{"id":"2"},{"content":"Task2"},{"start":"2016-12-02"},{"type":"box"},{"className":"green"}]
*/
var jsonObj = results.data;
items.clear();
$.each(jsonObj, function(key, value){
var jsonobjchild = value;
$.each(jsonobjchild, function(key,value){
if (value === "" || value === null){
// console.log(jsonobjchild[key]);
delete jsonobjchild[key];
}
});
items.add(jsonobjchild);
});
/* END: fix for removing null or empty value from csv data in json*/
/* console.log("------------Distinct Groups------------------");
console.log(items.distinct('group'));
console.log("--------------------------------------");
console.log("------------ITEMS------------------");
console.log(items);
console.log("--------------------------------------"); */
groups.clear();
$.each(items.distinct('group'), function(key,value){
groups.add(
{
id: items.distinct('group')[key],
content: items.distinct('group')[key],
style: 'font-weight:bold'
});
});
/*console.log("------------Groups------------------");
console.log(groups);
console.log(groups.length);
console.log("--------------------------------------");*/
if (groups.length == 0) {
var timeline = new vis.Timeline(container, items, options);
//console.log(groups.length);
} else {
var timeline = new vis.Timeline(container, items, groups, options);
//console.log("in else loop")
}
timeline.fit();
});
});
// Using the example from https://www.w3schools.com/howto/howto_css_modals.asp
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("btnSave");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
$("#btnSave").click(function() {
document.getElementById('visualizationcontainer_img').innerHTML = "";
html2canvas(document.getElementById('visualization')).then(function(canvas) {
modal.style.display = "block";
document.getElementById('visualizationcontainer_img').appendChild(canvas);
});
});
</script>
<!-- </div> -->
</div>
<footer>
<div class="footer-main">
<center>
<img src="./img//DumatiLogo50x50.png">
<br>
Gantt Chart Creator by <a href="https://mgw.dumatics.com">Ankit Mittal</a>
</center>
<br>
</div>
</footer>
</body>
</html>