Skip to content

Commit 413117e

Browse files
Error in animation of timelog
1 parent 2ca25ec commit 413117e

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

script.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ function showGanttChart(output, outputDiv) {
342342
output.schedule.forEach((element) => {
343343
if (element[0] == -2) { //context switch
344344
ganttChartData.push([
345-
"Row",
345+
"Time",
346346
"CS",
347347
"grey",
348348
startGantt * 1000,
@@ -351,16 +351,16 @@ function showGanttChart(output, outputDiv) {
351351

352352
} else if (element[0] == -1) { //nothing
353353
ganttChartData.push([
354-
"Row",
355-
"",
354+
"Time",
355+
"Empty",
356356
"black",
357357
startGantt * 1000,
358358
(startGantt + element[1]) * 1000
359359
]);
360360

361361
} else { //process
362362
ganttChartData.push([
363-
"Row",
363+
"Time",
364364
"P" + element[0],
365365
"",
366366
startGantt * 1000,
@@ -369,7 +369,6 @@ function showGanttChart(output, outputDiv) {
369369
}
370370
startGantt += element[1];
371371
});
372-
ganttChartData.sort((a, b) => parseInt(a[1].substring(1, a[1].length)) - parseInt(b[1].substring(1, b[1].length)));
373372
let ganttChart = document.createElement("div");
374373
ganttChart.id = "gantt-chart";
375374

@@ -788,6 +787,8 @@ function CPUScheduler(input, utility, output) {
788787
moveElement(element, currentTimeLog.remain, currentTimeLog.ready);
789788
moveElement(element, currentTimeLog.block, currentTimeLog.ready);
790789
});
790+
output.timeLog.push(JSON.parse(JSON.stringify(currentTimeLog)));
791+
currentTimeLog.move = [];
791792
}
792793
let currentTimeLog = new TimeLog();
793794
currentTimeLog.remain = input.processId;
@@ -798,10 +799,6 @@ function CPUScheduler(input, utility, output) {
798799
let timeQuantum = Number(document.querySelector("#tq").value);
799800
while (utility.done.some((element) => element == false)) {
800801
updateReadyQueue(currentTimeLog);
801-
if (currentTimeLog.ready.length > 0) {
802-
output.timeLog.push(JSON.parse(JSON.stringify(currentTimeLog)));
803-
currentTimeLog.move = [];
804-
}
805802
let found = -1;
806803
if (currentTimeLog.running.length == 1) {
807804
found = currentTimeLog.running[0];
@@ -866,16 +863,18 @@ function CPUScheduler(input, utility, output) {
866863
moveElement(found, currentTimeLog.running, currentTimeLog.block);
867864
currentTimeLog.move.push(4);
868865
}
866+
output.timeLog.push(JSON.parse(JSON.stringify(currentTimeLog)));
867+
currentTimeLog.move = [];
869868
updateReadyQueue(currentTimeLog);
870869
} else {
871870
updateReadyQueue(currentTimeLog);
872871
moveElement(found, currentTimeLog.running, currentTimeLog.ready);
873872
currentTimeLog.move.push(3);
873+
output.timeLog.push(JSON.parse(JSON.stringify(currentTimeLog)));
874+
currentTimeLog.move = [];
874875
}
875876
output.schedule.push([-2, contextSwitch]);
876877
for (let i = 0; i < contextSwitch; i++, currentTimeLog.time++) {
877-
output.timeLog.push(JSON.parse(JSON.stringify(currentTimeLog)));
878-
currentTimeLog.move = [];
879878
updateReadyQueue(currentTimeLog);
880879
}
881880
}
@@ -897,11 +896,12 @@ function CPUScheduler(input, utility, output) {
897896
moveElement(found, currentTimeLog.running, currentTimeLog.ready);
898897
currentTimeLog.move.push(3);
899898
}
899+
output.timeLog.push(JSON.parse(JSON.stringify(currentTimeLog)));
900+
currentTimeLog.move = [];
900901
if (currentTimeLog.running.length == 0) //context switch
901902
{
902903
output.schedule.push([-2, contextSwitch]);
903904
for (let i = 0; i < contextSwitch; i++, currentTimeLog.time++) {
904-
output.timeLog.push(JSON.parse(JSON.stringify(currentTimeLog)));
905905
updateReadyQueue(currentTimeLog);
906906
}
907907
}
@@ -910,7 +910,6 @@ function CPUScheduler(input, utility, output) {
910910
output.schedule.push([-1, 1]);
911911
}
912912
output.timeLog.push(JSON.parse(JSON.stringify(currentTimeLog)));
913-
currentTimeLog.move = [];
914913
}
915914
output.schedule.pop();
916915
}

style.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ button {
7777
}
7878

7979
#gantt-chart {
80-
height: 100px;
80+
height: 250px;
8181
overflow-x: scroll;
8282
overflow-y: hidden;
8383
width: 1200px;
@@ -87,7 +87,7 @@ button {
8787
overflow-x: scroll;
8888
overflow-y: hidden;
8989
width: 1200px;
90-
height: 200px;
90+
height: 250px;
9191
}
9292

9393
#output {

0 commit comments

Comments
 (0)