Skip to content

Commit

Permalink
Remove chart, test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
KostyalBalint committed Apr 23, 2021
1 parent 880f1f5 commit fa458a2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 66 deletions.
9 changes: 0 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<title></title>
<link rel="stylesheet" href="bootstrap.min.css">
<script src="matter.js" type="text/javascript"></script>
<script src="chart.js" type="text/javascript"></script>
<script src="index.js" type="text/javascript"></script>
</head>
<body class="bg-dark">
Expand Down Expand Up @@ -38,11 +37,6 @@ <h5 class="m-3 text-white">
<label class="form-label m-0" id="label-left">Left: 100 Pcs</label> -
<label class="form-label m-0" id="label-right">Right 0 Pcs</label>
</h5>
</div>
<div class="card d-flex justify-content-center mb-3" style="background-color: var(--secondary)">
<h5 class="m-3 text-white">
<label class="form-label m-0" id="label-avg">Avg: 0</label>
</h5>
</div>
<div class="card d-flex justify-content-center mb-5" style="background-color : var(--secondary)">
<h5 class="text-white m-3" id="timer">Time: </h5>
Expand All @@ -52,9 +46,6 @@ <h5 class="text-white m-3" id="timer">Time: </h5>
<div class="col-12 col-md-8">
<div id="canvas-container" class="d-flex justify-content-center align-items-center mb-3"></div>
</div>
<div class="card pl-2 pt-1" style="background-color : var(--secondary)">
<canvas id="myChart" width="400" height="400"></canvas>
</div>
</div>
</div>

Expand Down
59 changes: 2 additions & 57 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ window.onload = () => {
window.amp = 20;

var freqchange;
var rates = [];
var labels = [];
var prev_sec = 1000;

//Add event listeners
Events.on(engine, 'beforeUpdate', (event) =>{
Expand All @@ -138,7 +135,7 @@ window.onload = () => {
Composite.remove(engine.world, objects[i]);
objects.splice(i, 1);
}
};
}

//update ground and separator velocity and position
if(groundActive){
Expand All @@ -148,7 +145,7 @@ window.onload = () => {
//var py = 600 + window.amp * Math.sin((engine.timing.timestamp / 1000) * omega);
var py = 600 + ((engine.timing.timestamp / 1000) % (1/freq))* v ;

if (window.freq == freqchange){ //Frequency change doesnt effect marbles
if (window.freq === freqchange){ //Frequency change doesnt effect marbles
Body.setVelocity(ground, { x: 0, y: v/100 });
}
Body.setPosition(ground, { x: ground.position.x, y: py });
Expand All @@ -168,52 +165,7 @@ window.onload = () => {
});
document.getElementById("label-left").innerHTML = "Left: " + left + " Pcs";
document.getElementById("label-right").innerHTML = "Right: " + right + " Pcs";

// expand chart
if ((engine.timing.timestamp) > prev_sec){
prev_sec += 2800;
rates.push(right * 100 / marblecount);
labels.push(prev_sec / 1000 - 1);
myChart.update();
}


var total = 0;
for(var i = 0; i < rates.length; i++) {
total += rates[i];
}
var avg = total / rates.length;

document.getElementById("label-avg").innerHTML = "Avg: " + avg.toFixed(2) + "%";
});

// chart declaration
var ctx = document.getElementById('myChart');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,//[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],
datasets: [{
label: '% of particles on the right',
data: rates,
backgroundColor: [
'rgba(255, 99, 132, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true,
max: 100
}
}
}
});

//frequency slider
document.getElementById("range-freq").addEventListener('input', () => {
Expand Down Expand Up @@ -278,13 +230,6 @@ window.onload = () => {
btn.classList.add("btn-success");
btn.classList.remove("btn-info");

// reset chart
labels = []; rates = [];
myChart.data.datasets[0].data = rates;
myChart.data.labels = labels;

prev_sec = 1000;
myChart.update();
})

};

0 comments on commit fa458a2

Please sign in to comment.