-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
392 lines (368 loc) · 14.4 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
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!doctype html>
<html>
<head><title>GPERT(ß)</title>
<meta charset="UTF-8">
<link rel="icon" href="etsit.ico">
<script src="anychart-bundle.min.js"></script>
<script type="text/javascript" src="zepto.min.js"></script>
<style type="text/css">
html, body, #container {
width: 100%;
height: 100%;
margin: 2px;
padding: 2px;
font-family:"Helvetica",sans-serif;
font-size: large;
}
#formulario {
margin: 0;
padding: 0;
}
button {
background-color: #00DCDC;
font-size: medium;
}
table {
width: 97%;
background-color: #FFFF00;
font-size: small;
font-stretch: ultra-condensed;
}
table th:first-child {
width: 4.5%;
}
table th:nth-child(2) {
width: 40%;
}
table th:nth-child(3) {
width: 10%;
}
table th:nth-child(4) {
width: 10%;
}
table th:nth-child(5) {
width: 10%;
}
table th:last-child {
width: 25%;
}
.col1 {
width: 4.5%;
border-style: groove;
}
.col2 {
width: 38%;
border-style: groove;
}
.col3 {
width: 9%;
border-style: groove;
}
.col4 {
width: 9%;
border-style: groove;
}
.col5 {
width: 9%;
border-style: groove;
}
.col6 {
width: 24%;
border-style: groove;
}
</style>
<script type="text/javascript">
$(function(){
anychart.onDocumentReady(function () {
// data
var data = [];
localStorage.grafo = (localStorage.grafo || "0");
localStorage.zoom = (localStorage.zoom || "10");
localStorage.tareas = (localStorage.tareas || "0");
localStorage.posicion = (localStorage.posicion || "0");
if (localStorage.grafo === "0") {
data[0] = {"id":"1","optimistic":3,"pessimistic":11,"mostLikely":4,"name":"1","fullName":"Actividad A"};
data[1] = {"id":"2","optimistic":0,"pessimistic":8,"mostLikely":4,"name":"2","fullName":"Actividad B"};
data[2] = {"id":"3","optimistic":1,"pessimistic":9,"mostLikely":2,"name":"3","dependsOn":["1"],"fullName":"Actividad C"};
data[3] = {"id":"4","optimistic":2,"pessimistic":10,"mostLikely":3,"name":"4","dependsOn":["1"],"fullName":"Actividad D"};
localStorage.grafo = JSON.stringify(data);
} else {
data = JSON.parse(localStorage.grafo);
};
$("#formulario").hide();
if (data === null) {
alert("=> Editar para introducir los datos");
for (var i = 1; i <= parseInt(localStorage.tareas); i++) {
$("#formulario").append('<p>');
$("#formulario").append('<input type="text" class="col1" id="id'+i+'" value="'+i+'" size="3" placeholder='+i+'>');
$("#formulario").append('<input type="text" class="col2" id="name'+i+'" value="" required placeholder="Nombre Actividad '+i+'">');
$("#formulario").append('<input type="text" class="col3" id="optim'+i+'" value="" size="5" required placeholder="Optimista">');
$("#formulario").append('<input type="text" class="col4" id="pesim'+i+'" value="" size="5" required placeholder="Pesimista">');
$("#formulario").append('<input type="text" class="col5" id="maspro'+i+'" value="" size="5" required placeholder="Más Probable">');
$("#formulario").append('<input type="text" class="col6" id="preced'+i+'" value="" placeholder="Prelaciones, entre comas">');
};
} else {
localStorage.tareas = data.length;
for (var i = 1; i <= parseInt(localStorage.tareas); i++) {
$("#formulario").append('<p>');
$("#formulario").append('<input type="text" class="col1" id="id'+i+'" value="'+i+'" size="3" placeholder='+i+'>');
$("#formulario").append('<input type="text" class="col2" id="name'+i+'" value="'+data[i-1]["fullName"]+'" required placeholder="Nombre Actividad '+i+'">');
$("#formulario").append('<input type="text" class="col3" id="optim'+i+'" value="'+data[i-1]["optimistic"]+'" size="5" required placeholder="Optimista">');
$("#formulario").append('<input type="text" class="col4" id="pesim'+i+'" value="'+data[i-1]["pessimistic"]+'" size="5" required placeholder="Pesimista">');
$("#formulario").append('<input type="text" class="col5" id="maspro'+i+'" value="'+data[i-1]["mostLikely"]+'" size="5" required placeholder="Más Probable">');
if (data[i-1]["dependsOn"]) {
$("#formulario").append('<input type="text" class="col6" id="preced'+i+'" value="'+data[i-1]["dependsOn"]+'" placeholder="Prelaciones, entre comas">');
} else {
$("#formulario").append('<input type="text" class="col6" id="preced'+i+'" value="" placeholder="Prelaciones, entre comas">');
};
};
};
// set filling method for tree
var treeData = anychart.data.tree(data, anychart.enums.TreeFillingMethod.AS_TABLE);
// create PERT chart
chart = anychart.pert();
// set spacing between milestones
chart.horizontalSpacing(localStorage.zoom+'%');
// set padding for chart
chart.padding([25, 50+parseInt(localStorage.posicion), 50, 50-parseInt(localStorage.posicion)]);
// set data
chart.data(treeData);
// get duration project
var duration = Math.ceil(chart.getStat(anychart.enums.Statistics.PERT_CHART_PROJECT_DURATION));
// get deviation project
var deviation = Math.ceil(chart.getStat(anychart.enums.Statistics.PERT_CHART_CRITICAL_PATH_STANDARD_DEVIATION));
// set title text
var title = chart.title();
title.enabled(true);
title.text(
"Grafo PERT/CPM" +
"<br>" + "Duración estimada del proyecto: " +
duration + '±' +
deviation + ' semanas'
).useHtml(true);
title.padding([0, 0, 35, 0]);
// set settings for tasks
var tasks = chart.tasks();
// format upper label tasks
tasks.upperLabels().textFormatter(function () {
return this.item.get('fullName');
});
// format lower label tasks
tasks.lowerLabels().textFormatter(function () {
// format time for tasks
return timeTask(this.duration);
});
// create tasks tooltip
var tasksTooltip = tasks.tooltip();
// tooltip settings
tasksTooltip.separator().enabled(true);
tasksTooltip.titleFormatter(function () {
// return fullName from data
return this.item.get('fullName');
}).title().useHtml('true');
// set settings for milestones
var milestones = chart.milestones();
// set milestones color
milestones.color('#2795FF');
// hoverFill color for milestones item
milestones.hoverFill(function () {
return anychart.color.lighten(this.sourceColor, 0.25);
});
// set milestones item size
milestones.size('4.5%');
milestones.tooltip().textFormatter(defuaultMilesoneTooltipTextFormatter);
// set settings for critical milestones
var critMilestones = chart.criticalPath().milestones();
// set shape
critMilestones.shape('circle');
// set color
critMilestones.color('#FF0000');
// set container id for the chart
chart.container('container');
// initiate chart drawing
chart.draw();
});
function timeTask(duration) {
var weeks = 0;
var days = 0;
var hours = 0;
if (duration >= 0) {
weeks = Math.floor(duration);
// days = Math.floor(duration - weeks * 7);
// hours = Math.ceil((24 * (duration - weeks * 7 - days)));
} else {
days = Math.floor(duration - weeks * 7);
hours = Math.ceil(24 * (duration - weeks * 7 - days));
}
var weeksPart = weeks != 0 ? 'w:' + weeks + ' ' : '';
var daysPart = days != 0 ? 'd:' + days + ' ' : '';
var hoursPart = hours != 0 ? 'h:' + hours + ' ' : '';
return weeksPart + daysPart + hoursPart;
}
function defuaultMilesoneTooltipTextFormatter() {
var result = '';
var i = 0;
if (this['successors'] && this['successors'].length) {
result += 'Successors:';
for (i = 0; i < this['successors'].length; i++) {
result += '\n - ' + this['successors'][i].get('fullName');
}
if (this['predecessors'] && this['predecessors'].length)
result += '\n\n';
}
if (this['predecessors'] && this['predecessors'].length) {
result += 'Predecessors:';
for (i = 0; i < this['predecessors'].length; i++) {
result += '\n - ' + this['predecessors'][i].get('fullName');
}
}
return result;
}
$("#borrar").on('click', function(){
$("#container").hide();
$("#formulario").show();
if (confirm("VAS A BORRAR EL GRAFO ACTUAL !!!\nEstás seguro?")) {
localStorage.tareas = (prompt("Número total de Actividades:") || "0");
localStorage.grafo = "null";
location.reload();
} else {
$("#formulario").hide();
$("#container").show();
};
});
$("#editar").on('click', function(){
$("#container").hide();
$("#formulario").show();
});
$("#pintar").on('click', function(){
var data = [];
for (var i = 1; i <= parseInt(localStorage.tareas); i++) {
data[i-1] = {"id":i.toString(10),"optimistic":parseInt($("#optim"+i).val()),"pessimistic":parseInt($("#pesim"+i).val()),"mostLikely":parseInt($("#maspro"+i).val()),"name":i.toString(10),"dependsOn":[$("#preced"+i).val()],"fullName":$("#name"+i).val()};
if ($("#preced"+i).val() === "") {
data[i-1]["dependsOn"] = null;
} else {
var cadena = $("#preced"+i).val().match(/[0-9]+/g);
data[i-1]["dependsOn"] = cadena;
};
};
if (data.length > 0) {
localStorage.grafo = JSON.stringify(data);
location.reload();
};
});
$("#demo").on('click', function(){
localStorage.grafo = "0";
location.reload();
});
$("#volver").on('click', function(){
$("#formulario").hide();
$("#container").show();
});
$("#guardar").on('click', function(){
var nom = prompt("Nombre del archivo:");
if (nom === "" || nom === null) {
nom = "grafo";
};
// grab the content of the form field and place it into a variable
var textToWrite = localStorage.grafo;
// create a new Blob (html5 magic) that conatins the data from your form feild
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
// Specify the name of the file to be saved
var fileNameToSaveAs = nom+".json";
// create a link for our script to 'click'
var downloadLink = document.createElement("a");
// supply the name of the file (from the var above)
downloadLink.download = fileNameToSaveAs;
// provide text for the link. This will be hidden so you
// can actually use anything you want.
downloadLink.innerHTML = "My Hidden Link";
// allow our code to work in webkit & Gecko based browsers
// without the need for a if / else block.
window.URL = window.URL || window.webkitURL;
// Create the link Object.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
// when link is clicked call a function to remove it from
// the DOM in case user wants to save a second file.
downloadLink.onclick = destroyClickedElement;
// make sure the link is hidden.
downloadLink.style.display = "none";
// add the link to the DOM
document.body.appendChild(downloadLink);
// click the new link
downloadLink.click();
});
$("#ampliar").on('click', function(){
var z = parseInt(localStorage.zoom) + 1;
localStorage.zoom = z.toString(10);
location.reload();
});
$("#reducir").on('click', function(){
var z = parseInt(localStorage.zoom) - 1;
localStorage.zoom = z.toString(10);
location.reload();
});
$("#derecha").on('click', function(){
var x = parseInt(localStorage.posicion) - 100;
localStorage.posicion = x.toString(10);
location.reload();
});
$("#centro").on('click', function(){
localStorage.posicion = "0";
location.reload();
});
$("#izquierda").on('click', function(){
var x = parseInt(localStorage.posicion) + 100;
localStorage.posicion = x.toString(10);
location.reload();
});
function destroyClickedElement(event) {
// remove the link from the DOM
document.body.removeChild(event.target);
};
window.addEventListener('load', evento, false);
function evento() {
document.getElementById('archivo').addEventListener('change', cargar, false);
};
function cargar(ev) {
var arch = new FileReader();
arch.addEventListener('load',leer,false);
arch.readAsText(ev.target.files[0]);
};
function leer(ev) {
localStorage.grafo = ev.target.result;
location.reload();
};
});
</script>
</head>
<body>
<h3><span id="nuevo">Elije entre las opciones siguientes del Grafo:</span></h3>
<button type="button" id="borrar"> Nuevo </button>
<button type="button" id="editar"> Editar </button>
<button type="button" id="guardar"> Descargar </button>
<label>Cargar Archivo:
<input type="file" name="anexo" id="archivo">
</label>
<div id="formulario">
<p><button type="button" id="demo"> Demo </button>
<button type="button" id="pintar"> Pintar Grafo </button>
<button type="button" id="volver"> Volver </button>
<table border="3">
<tr>
<th>Id</th>
<th>Nombre</th>
<th>Optimista</th>
<th>Pesimista</th>
<th>Más Prob.</th>
<th>Prelaciones</th>
</tr>
</table>
</div>
<p><button type="button" id="ampliar"> + Ancho </button>
<button type="button" id="reducir"> - Ancho </button>
<button type="button" id="izquierda"> << </button>
<button type="button" id="centro"> ¤ </button>
<button type="button" id="derecha"> >> </button>
<div id="container"></div>
</body>
</html>