Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<link rel="stylesheet" href="inc/bootstrap-4.4.1/bootstrap.min.css">
<link rel="stylesheet" href="inc/bootswatch-flatly/bootstrap.min.css">

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>
<script src="lib.js"></script>
<script src="classes.js"></script>
<script src="simulator.js"></script>
Expand Down Expand Up @@ -40,7 +41,8 @@
</style>

<script>
var templateHTML = null;
var templateHTML = null;
var currentCharts = [];

loadWebResource("results template.html", function(results) {
templateHTML = results;
Expand Down Expand Up @@ -71,8 +73,39 @@
coronaSimSettings.populationInt = getSliderValue("populationCapSlider");

/* Note: this is where all of the magic happens, this method makes a simulator, steps through the sim, and returns html output */
el("simulationOutput").innerHTML = generateSimulationOutput(templateHTML, coronaSimSettings);
const tableData = generateSimulationOutput(coronaSimSettings);

el("simulationOutput").innerHTML = generateTableHTML(tableData, templateHTML, coronaSimSettings)
window.scrollBy(0, 200);
console.log(tableData);
window.tableData=tableData
var ctx = document.getElementById('myChart').getContext('2d');
currentCharts.forEach(function(cc){
cc.destroy();
})
var infectionsChart = new Chart(ctx, {
type: 'line',
data: {
labels: tableData.map(a=>a.dayStats.dayNumberInt),
datasets: [{
label: 'Infections',
backgroundColor: 'red',
borderColor: 'red',
data: tableData.map(a=>a.dayStats.infectionsInt),
fill: false,
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
currentCharts=[myChart];
}

document.addEventListener('DOMContentLoaded', function() {
Expand Down Expand Up @@ -221,7 +254,9 @@ <h3>The Simulator</h3>
<button type='submit' class="btn btn-primary">Run Simulation</button>
</div>
</form>
<div class='simulationOutput pt-3' id='simulationOutput' />
<canvas id="myChart" width="400" height="400"></canvas>

<div class='simulationOutput pt-3' id='simulationOutput' ></div>
</div>
</div>
</body>
Expand Down
6 changes: 5 additions & 1 deletion lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function populateTemplate(template, dayStats, totalStats, currentHospitalizedInt
return templateCopy;
}

function generateSimulationOutput(template, coronaSimSettings) {
function generateSimulationOutput(coronaSimSettings) {
var simulator = new CoronaSimulator(coronaSimSettings);

var tableDataArray = [];
Expand All @@ -225,6 +225,10 @@ function generateSimulationOutput(template, coronaSimSettings) {
break;
}
}
return tableDataArray;
}

function generateTableHTML(tableDataArray, template, coronaSimSettings) {
var html = "<div class='testResults'>\n";
for (var tableEntry of tableDataArray) {
html += populateTemplate(template, tableEntry.dayStats, tableEntry.totalStats,
Expand Down