refactoring

This commit is contained in:
frankknoll
2023-01-28 16:18:19 +01:00
parent 4875fd503b
commit b797d210c5
3 changed files with 28 additions and 19 deletions

25
docs/HistogramView.js Normal file
View File

@@ -0,0 +1,25 @@
class HistogramView {
constructor() {
}
show(batchcode, div) {
fetch(`data/histograms/${batchcode}.json`)
.then(response => response.json())
.then(json => {
const data = json.histograms[3].histogram;
new Chart(
div.querySelector('#symptomByBatchcodeHisto'),
{
type: 'bar',
data: {
datasets: [{
label: 'Acquisitions by year',
data: data
}]
}
}
);
});
}
}

View File

@@ -11,6 +11,7 @@
<script charset="utf8" src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.2.0/dist/chart.umd.min.js"></script>
<script src="./batchCodeTable.js"></script>
<script src="./HistogramView.js"></script>
<script>
$(document).ready(function () {
const batchCodeTableInitializer =

View File

@@ -15,7 +15,7 @@ class BatchCodeTableInitializer {
this.#batchCodeTable = this.#createEmptyBatchCodeTable();
this.#countrySelect.addEventListener('change', event => this.#displayCountry(event.target.value));
this.#displayCountry('Global')
// FK-TODO: refactor
const histogramView = new HistogramView();
function createDiv() {
const div = document.createElement("div");
const canvas = document.createElement("canvas");
@@ -37,24 +37,7 @@ class BatchCodeTableInitializer {
const div = createDiv();
row.child(div).show();
tr.addClass('shown');
const batchcode = 'FD6840';
fetch(`data/histograms/${batchcode}.json`)
.then(response => response.json())
.then(json => {
const data = json.histograms[3].histogram;
new Chart(
div.querySelector('#symptomByBatchcodeHisto'),
{
type: 'bar',
data: {
datasets: [{
label: 'Acquisitions by year',
data: data
}]
}
}
);
});
histogramView.show('FD6840', div);
}
});
}