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

@@ -3,11 +3,15 @@ class SymptomVsSymptomChartViewInitializer {
#symptomVsSymptomChartView;
#symptomX;
#symptomY;
#batches;
#data;
#downloadSymptomVsSymptomChartButton;
configureSymptomVsSymptomChart(
{ symptomSelectXElement, symptomSelectYElement, symptomVsSymptomChartViewElement },
{ symptomSelectXElement, symptomSelectYElement, symptomVsSymptomChartViewElement, downloadSymptomVsSymptomChartButton },
initializeSelectElement) {
this.#initializeButton(downloadSymptomVsSymptomChartButton);
this.#symptomVsSymptomChartView = new SymptomVsSymptomChartView(symptomVsSymptomChartViewElement);
{
initializeSelectElement(
@@ -37,8 +41,44 @@ class SymptomVsSymptomChartViewInitializer {
}
#loadAndDisplayChart() {
if (this.#symptomX != null && this.#symptomY != null) {
this.#symptomVsSymptomChartView.loadAndDisplayChart(this.#symptomX, this.#symptomY);
UIUtils.disableButton(this.#downloadSymptomVsSymptomChartButton);
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}`
);
}
}