making scatter chart for symptoms downloadable

This commit is contained in:
frankknoll
2023-11-10 18:45:45 +01:00
parent acfe871d1d
commit 596eca2387
3 changed files with 53 additions and 8 deletions

View File

@@ -9,14 +9,14 @@
<meta content="width=device-width, initial-scale=1.0" name="viewport" /> <meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>Safety Signals for COVID Batches</title> <title>Safety Signals for COVID Batches</title>
<!-- Google tag (gtag.js) --> <!-- Google tag (gtag.js) -->
<!-- <script async="" src="https://www.googletagmanager.com/gtag/js?id=G-ERHYDH4P64"></script> <script async="" src="https://www.googletagmanager.com/gtag/js?id=G-ERHYDH4P64"></script>
<script> <script>
window.dataLayer = window.dataLayer || []; window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); } function gtag() { dataLayer.push(arguments); }
gtag('js', new Date()); gtag('js', new Date());
gtag('config', 'G-ERHYDH4P64'); gtag('config', 'G-ERHYDH4P64');
</script> --> </script>
<!-- Bootstrap --> <!-- Bootstrap -->
<link href="../gentelella/vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" /> <link href="../gentelella/vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.css" rel="stylesheet" type="text/css" /> <link href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
@@ -60,7 +60,8 @@
symptomVsSymptomChart: { symptomVsSymptomChart: {
symptomSelectXElement: $('#symptomSelectX'), symptomSelectXElement: $('#symptomSelectX'),
symptomSelectYElement: $('#symptomSelectY'), symptomSelectYElement: $('#symptomSelectY'),
symptomVsSymptomChartViewElement: document.querySelector('#symptomVsSymptomChartView') symptomVsSymptomChartViewElement: document.querySelector('#symptomVsSymptomChartView'),
downloadSymptomVsSymptomChartButton: document.querySelector("#downloadSymptomVsSymptomChart")
} }
} }
); );
@@ -40192,8 +40193,11 @@
<option value="pH urine normal">pH urine normal</option> <option value="pH urine normal">pH urine normal</option>
</select> </select>
</div> </div>
<div>
<canvas id="symptomVsSymptomChartView"></canvas> <canvas id="symptomVsSymptomChartView"></canvas>
</div> </div>
<button class="btn downloadButton" id="downloadSymptomVsSymptomChart">Download</button>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -8,12 +8,13 @@ class SymptomVsSymptomChartView {
} }
loadAndDisplayChart(symptomX, symptomY) { loadAndDisplayChart(symptomX, symptomY) {
Promise return Promise
.all([symptomX, symptomY].map(symptom => PrrByVaccineProvider.getPrrByVaccine(symptom))) .all([symptomX, symptomY].map(symptom => PrrByVaccineProvider.getPrrByVaccine(symptom)))
.then( .then(
([prrByLotX, prrByLotY]) => { ([prrByLotX, prrByLotY]) => {
const { labels, data } = SymptomVsSymptomChartDataProvider.getChartData({ prrByLotX, prrByLotY }); const { labels, data } = SymptomVsSymptomChartDataProvider.getChartData({ prrByLotX, prrByLotY });
this.#displayChart(symptomX, symptomY, labels, data); this.#displayChart(symptomX, symptomY, labels, data);
return { labels, data };
}); });
} }

View File

@@ -3,11 +3,15 @@ class SymptomVsSymptomChartViewInitializer {
#symptomVsSymptomChartView; #symptomVsSymptomChartView;
#symptomX; #symptomX;
#symptomY; #symptomY;
#batches;
#data;
#downloadSymptomVsSymptomChartButton;
configureSymptomVsSymptomChart( configureSymptomVsSymptomChart(
{ symptomSelectXElement, symptomSelectYElement, symptomVsSymptomChartViewElement }, { symptomSelectXElement, symptomSelectYElement, symptomVsSymptomChartViewElement, downloadSymptomVsSymptomChartButton },
initializeSelectElement) { initializeSelectElement) {
this.#initializeButton(downloadSymptomVsSymptomChartButton);
this.#symptomVsSymptomChartView = new SymptomVsSymptomChartView(symptomVsSymptomChartViewElement); this.#symptomVsSymptomChartView = new SymptomVsSymptomChartView(symptomVsSymptomChartViewElement);
{ {
initializeSelectElement( initializeSelectElement(
@@ -37,8 +41,44 @@ class SymptomVsSymptomChartViewInitializer {
} }
#loadAndDisplayChart() { #loadAndDisplayChart() {
if (this.#symptomX != null && this.#symptomY != null) { UIUtils.disableButton(this.#downloadSymptomVsSymptomChartButton);
this.#symptomVsSymptomChartView.loadAndDisplayChart(this.#symptomX, this.#symptomY); if (this.#symptomX == null || this.#symptomY == null) {
return;
} }
this.#symptomVsSymptomChartView
.loadAndDisplayChart(this.#symptomX, this.#symptomY)
.then(({ labels, data }) => {
this.#batches = labels;
this.#data = data;
UIUtils.enableButton(this.#downloadSymptomVsSymptomChartButton);
});
}
#initializeButton(downloadSymptomVsSymptomChartButton) {
this.#downloadSymptomVsSymptomChartButton = downloadSymptomVsSymptomChartButton;
UIUtils.disableButton(downloadSymptomVsSymptomChartButton);
downloadSymptomVsSymptomChartButton.addEventListener(
'click',
() => this.#downloadSymptomVsSymptomChart())
}
#downloadSymptomVsSymptomChart() {
UIUtils.downloadUrlAsFilename(
window.URL.createObjectURL(
new Blob(
[
ScatterChart2CsvConverter.convertScatterChart2Csv(
{
symptomX: this.#symptomX,
symptomY: this.#symptomY,
batches: this.#batches,
data: this.#data
}
)
],
{ type: 'text/csv' })),
`${this.#symptomX} Vs ${this.#symptomY}`
);
} }
} }