refactoring
This commit is contained in:
@@ -12,64 +12,10 @@ class SymptomVsSymptomChartView {
|
|||||||
Promise
|
Promise
|
||||||
.all([symptomX, symptomY].map(symptom => PrrByVaccineProvider.getPrrByVaccine(symptom)))
|
.all([symptomX, symptomY].map(symptom => PrrByVaccineProvider.getPrrByVaccine(symptom)))
|
||||||
.then(
|
.then(
|
||||||
([prrByLotX, prrByLotY]) =>
|
([prrByLotX, prrByLotY]) => {
|
||||||
this.#displayChart(
|
const { labels, data } = SymptomVsSymptomChartDataProvider.getChartData({ prrByLotX, prrByLotY });
|
||||||
{ symptom: symptomX, prrByLot: prrByLotX },
|
this.#displayChart(symptomX, symptomY, labels, data);
|
||||||
{ symptom: symptomY, prrByLot: prrByLotY }));
|
});
|
||||||
}
|
|
||||||
|
|
||||||
#displayChart(
|
|
||||||
{ symptom: symptomX, prrByLot: prrByLotX },
|
|
||||||
{ symptom: symptomY, prrByLot: prrByLotY }) {
|
|
||||||
if (this.#chart != null) {
|
|
||||||
this.#chart.destroy();
|
|
||||||
}
|
|
||||||
const chartData = SymptomVsSymptomChartDataProvider.getChartData({ prrByLotX, prrByLotY });
|
|
||||||
const data = {
|
|
||||||
datasets:
|
|
||||||
[
|
|
||||||
{
|
|
||||||
labels: chartData.labels,
|
|
||||||
data: chartData.data,
|
|
||||||
backgroundColor: 'rgb(0, 0, 255)'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
const config = {
|
|
||||||
type: 'scatter',
|
|
||||||
data: data,
|
|
||||||
options: {
|
|
||||||
scales: {
|
|
||||||
x: {
|
|
||||||
type: 'linear',
|
|
||||||
position: 'bottom',
|
|
||||||
title: {
|
|
||||||
display: true,
|
|
||||||
text: 'PRR ratio of Batch for ' + symptomX
|
|
||||||
}
|
|
||||||
},
|
|
||||||
y: {
|
|
||||||
title: {
|
|
||||||
display: true,
|
|
||||||
text: 'PRR ratio of Batch for ' + symptomY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
plugins: {
|
|
||||||
legend: {
|
|
||||||
display: false
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
callbacks: {
|
|
||||||
label: function (context) {
|
|
||||||
return 'Batch: ' + context.dataset.labels[context.dataIndex];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.#chart = new Chart(this.#canvas, config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setData(histoDescr) {
|
setData(histoDescr) {
|
||||||
@@ -78,48 +24,58 @@ class SymptomVsSymptomChartView {
|
|||||||
this.#chart.update();
|
this.#chart.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
#getData(ADRDescr) {
|
#displayChart(symptomX, symptomY, labels, data) {
|
||||||
|
if (this.#chart != null) {
|
||||||
|
this.#chart.destroy();
|
||||||
|
}
|
||||||
|
const config = {
|
||||||
|
type: 'scatter',
|
||||||
|
data: this.#getData(labels, data),
|
||||||
|
options: this.#getOptions(symptomX, symptomY)
|
||||||
|
};
|
||||||
|
this.#chart = new Chart(this.#canvas, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
#getData(labels, data) {
|
||||||
return {
|
return {
|
||||||
labels: [
|
datasets:
|
||||||
'Deaths',
|
[
|
||||||
'Disabilities',
|
{
|
||||||
'Life Threatening Illnesses',
|
labels: labels,
|
||||||
'Other Adverse Events'
|
data: data,
|
||||||
],
|
backgroundColor: 'rgb(0, 0, 255)'
|
||||||
datasets: [{
|
}
|
||||||
// FK-TODO: refactor
|
]
|
||||||
label: 'Batch ' + ADRDescr['batchcode'],
|
|
||||||
data: [
|
|
||||||
ADRDescr['Deaths'],
|
|
||||||
ADRDescr['Disabilities'],
|
|
||||||
ADRDescr['Life Threatening Illnesses'],
|
|
||||||
ADRDescr['Adverse Reaction Reports'] - (ADRDescr['Deaths'] + ADRDescr['Disabilities'] + ADRDescr['Life Threatening Illnesses'])
|
|
||||||
],
|
|
||||||
backgroundColor: '#1a73e8'
|
|
||||||
}]
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#getOptions() {
|
#getOptions(symptomX, symptomY) {
|
||||||
return {
|
return {
|
||||||
plugins: {
|
|
||||||
datalabels: {
|
|
||||||
anchor: 'end',
|
|
||||||
align: 'top'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
display: true,
|
|
||||||
position: 'top'
|
|
||||||
},
|
|
||||||
scales: {
|
scales: {
|
||||||
y: {
|
x: {
|
||||||
ticks: {
|
type: 'linear',
|
||||||
precision: 0
|
position: 'bottom',
|
||||||
},
|
|
||||||
title: {
|
title: {
|
||||||
display: true,
|
display: true,
|
||||||
text: 'Frequency'
|
text: 'PRR ratio of Batch for ' + symptomX
|
||||||
|
}
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: 'PRR ratio of Batch for ' + symptomY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: false
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
callbacks: {
|
||||||
|
label: function (context) {
|
||||||
|
return 'Batch: ' + context.dataset.labels[context.dataIndex];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user