Skip to content

Commit e9be3c1

Browse files
Add labels for axes for charts
1 parent ec226e1 commit e9be3c1

File tree

1 file changed

+104
-86
lines changed

1 file changed

+104
-86
lines changed

script.js

Lines changed: 104 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -707,102 +707,107 @@ function showTimeLog(output, outputDiv) {
707707
}
708708

709709
function showRoundRobinChart(outputDiv) {
710-
if (selectedAlgorithm.value == 'rr') {
710+
let roundRobinInput = new Input();
711+
setInput(roundRobinInput);
712+
let maxTimeQuantum = 0;
713+
roundRobinInput.processTime.forEach(processTimeArray => {
714+
processTimeArray.forEach((time, index) => {
715+
if (index % 2 == 0) {
716+
maxTimeQuantum = Math.max(maxTimeQuantum, time);
717+
}
718+
});
719+
});
720+
let roundRobinChartData = [
721+
[],
722+
[],
723+
[],
724+
[],
725+
[]
726+
];
727+
let timeQuantumArray = [];
728+
for (let timeQuantum = 1; timeQuantum <= maxTimeQuantum; timeQuantum++) {
729+
timeQuantumArray.push(timeQuantum);
711730
let roundRobinInput = new Input();
712731
setInput(roundRobinInput);
713-
let maxTimeQuantum = 0;
714-
roundRobinInput.processTime.forEach(processTimeArray => {
715-
processTimeArray.forEach((time, index) => {
716-
if (index % 2 == 0) {
717-
maxTimeQuantum = Math.max(maxTimeQuantum, time);
718-
}
719-
});
720-
});
721-
let roundRobinChartData = [
722-
[],
723-
[],
724-
[],
725-
[],
726-
[]
727-
];
728-
let timeQuantumArray = [];
729-
for (let timeQuantum = 1; timeQuantum <= maxTimeQuantum; timeQuantum++) {
730-
timeQuantumArray.push(timeQuantum);
731-
let roundRobinInput = new Input();
732-
setInput(roundRobinInput);
733-
setAlgorithmNameType(roundRobinInput, 'rr');
734-
roundRobinInput.timeQuantum = timeQuantum;
735-
let roundRobinUtility = new Utility();
736-
setUtility(roundRobinInput, roundRobinUtility);
737-
let roundRobinOutput = new Output();
738-
CPUScheduler(roundRobinInput, roundRobinUtility, roundRobinOutput);
739-
setOutput(roundRobinInput, roundRobinOutput);
740-
for (let i = 0; i < 4; i++) {
741-
roundRobinChartData[i].push(roundRobinOutput.averageTimes[i]);
742-
}
743-
roundRobinChartData[4].push(roundRobinOutput.contextSwitches);
732+
setAlgorithmNameType(roundRobinInput, 'rr');
733+
roundRobinInput.timeQuantum = timeQuantum;
734+
let roundRobinUtility = new Utility();
735+
setUtility(roundRobinInput, roundRobinUtility);
736+
let roundRobinOutput = new Output();
737+
CPUScheduler(roundRobinInput, roundRobinUtility, roundRobinOutput);
738+
setOutput(roundRobinInput, roundRobinOutput);
739+
for (let i = 0; i < 4; i++) {
740+
roundRobinChartData[i].push(roundRobinOutput.averageTimes[i]);
744741
}
745-
let roundRobinChartCanvas = document.createElement('canvas');
746-
roundRobinChartCanvas.id = "round-robin-chart";
747-
let roundRobinChartDiv = document.createElement('div');
748-
roundRobinChartDiv.id = "round-robin-chart-div";
749-
roundRobinChartDiv.appendChild(roundRobinChartCanvas);
750-
outputDiv.appendChild(roundRobinChartDiv);
742+
roundRobinChartData[4].push(roundRobinOutput.contextSwitches);
743+
}
744+
let roundRobinChartCanvas = document.createElement('canvas');
745+
roundRobinChartCanvas.id = "round-robin-chart";
746+
let roundRobinChartDiv = document.createElement('div');
747+
roundRobinChartDiv.id = "round-robin-chart-div";
748+
roundRobinChartDiv.appendChild(roundRobinChartCanvas);
749+
outputDiv.appendChild(roundRobinChartDiv);
751750

752-
new Chart(document.getElementById('round-robin-chart'), {
753-
type: 'line',
754-
data: {
755-
labels: timeQuantumArray,
756-
datasets: [{
757-
label: "Completion Time",
758-
borderColor: '#3366CC',
759-
data: roundRobinChartData[0]
760-
},
761-
{
762-
label: "Turn Around Time",
763-
borderColor: '#DC3912',
764-
data: roundRobinChartData[1]
765-
},
766-
{
767-
label: "Waiting Time",
768-
borderColor: '#FF9900',
769-
data: roundRobinChartData[2]
770-
},
771-
{
772-
label: "Response Time",
773-
borderColor: '#109618',
774-
data: roundRobinChartData[3]
775-
},
776-
{
777-
label: "Context Switches",
778-
borderColor: '#990099',
779-
data: roundRobinChartData[4]
780-
},
781-
]
782-
},
783-
options: {
784-
title: {
785-
display: true,
786-
text: ['Round Robin', 'Comparison of Completion, Turn Around, Waiting, Response Time and Context Switches', 'The Lower The Better']
751+
new Chart(document.getElementById('round-robin-chart'), {
752+
type: 'line',
753+
data: {
754+
labels: timeQuantumArray,
755+
datasets: [{
756+
label: "Completion Time",
757+
borderColor: '#3366CC',
758+
data: roundRobinChartData[0]
787759
},
788-
scales: {
789-
yAxes: [{
790-
ticks: {
791-
beginAtZero: true
792-
}
793-
}]
760+
{
761+
label: "Turn Around Time",
762+
borderColor: '#DC3912',
763+
data: roundRobinChartData[1]
764+
},
765+
{
766+
label: "Waiting Time",
767+
borderColor: '#FF9900',
768+
data: roundRobinChartData[2]
769+
},
770+
{
771+
label: "Response Time",
772+
borderColor: '#109618',
773+
data: roundRobinChartData[3]
774+
},
775+
{
776+
label: "Context Switches",
777+
borderColor: '#990099',
778+
data: roundRobinChartData[4]
794779
},
795-
legend: {
796-
display: true,
797-
labels: {
798-
fontColor: 'black'
780+
]
781+
},
782+
options: {
783+
title: {
784+
display: true,
785+
text: ['Round Robin', 'Comparison of Completion, Turn Around, Waiting, Response Time and Context Switches', 'The Lower The Better']
786+
},
787+
scales: {
788+
yAxes: [{
789+
ticks: {
790+
beginAtZero: true
791+
}
792+
}],
793+
xAxes: [{
794+
scaleLabel: {
795+
display: true,
796+
labelString: 'Time Quantum'
799797
}
798+
}]
799+
},
800+
legend: {
801+
display: true,
802+
labels: {
803+
fontColor: 'black'
800804
}
801805
}
802-
});
803-
}
806+
}
807+
});
804808
}
805809

810+
806811
function showAlgorithmChart(outputDiv) {
807812
let algorithmArray = ["fcfs", "sjf", "srtf", "ljf", "lrtf", "rr", "hrrn", "pnp", "pp"];
808813
let algorithmNameArray = ["FCFS", "SJF", "SRTF", "LJF", "LRTF", "RR", "HRRN", "PNP", "PP"];
@@ -869,6 +874,12 @@ function showAlgorithmChart(outputDiv) {
869874
ticks: {
870875
beginAtZero: true
871876
}
877+
}],
878+
xAxes: [{
879+
scaleLabel: {
880+
display: true,
881+
labelString: 'Algorithms'
882+
}
872883
}]
873884
},
874885
legend: {
@@ -883,10 +894,17 @@ function showAlgorithmChart(outputDiv) {
883894

884895
function showOutput(input, output, outputDiv) {
885896
showGanttChart(output, outputDiv);
897+
outputDiv.insertAdjacentHTML("beforeend", "<hr>");
886898
showTimelineChart(output, outputDiv);
899+
outputDiv.insertAdjacentHTML("beforeend", "<hr>");
887900
showFinalTable(input, output, outputDiv);
901+
outputDiv.insertAdjacentHTML("beforeend", "<hr>");
888902
showTimeLog(output, outputDiv);
889-
showRoundRobinChart(outputDiv);
903+
outputDiv.insertAdjacentHTML("beforeend", "<hr>");
904+
if (selectedAlgorithm.value == "rr") {
905+
showRoundRobinChart(outputDiv);
906+
outputDiv.insertAdjacentHTML("beforeend", "<hr>");
907+
}
890908
showAlgorithmChart(outputDiv);
891909
}
892910

0 commit comments

Comments
 (0)