making Countries column orderable

This commit is contained in:
frankknoll
2023-08-24 01:09:01 +02:00
parent 5eac6f749a
commit fb56aed2c2
2 changed files with 26 additions and 9 deletions

View File

@@ -59,8 +59,7 @@ class BatchCodeTableInitializer {
targets: targets:
[ [
this.#getColumnIndex('Batch'), this.#getColumnIndex('Batch'),
this.#getColumnIndex('Company'), this.#getColumnIndex('Company')
this.#getColumnIndex('Countries')
] ]
}, },
{ {
@@ -75,8 +74,13 @@ class BatchCodeTableInitializer {
}, },
{ {
width: "1000px", width: "1000px",
render: function (data, type, row, meta) { render: (data, type, row, meta) => {
return null; if (type === 'sort') {
return this.#getJensenShannonDistance(
row[this.#getColumnIndex('Batch')],
barChartDescriptions);
}
return data;
}, },
createdCell: (cell, cellData, row, rowIndex, colIndex) => { createdCell: (cell, cellData, row, rowIndex, colIndex) => {
if (showCountriesColumn) { if (showCountriesColumn) {
@@ -93,7 +97,6 @@ class BatchCodeTableInitializer {
}); });
} }
#getColumnIndex(columnName) { #getColumnIndex(columnName) {
switch (columnName) { switch (columnName) {
case 'Batch': case 'Batch':
@@ -117,14 +120,27 @@ class BatchCodeTableInitializer {
} }
} }
#getJensenShannonDistance(batchcode, barChartDescriptions) {
const barChartDescription = this.#getBarChartDescription(barChartDescriptions, batchcode);
const maximally_different = 1;
if (barChartDescription === null) {
return maximally_different;
}
const jensenShannonDistance = barChartDescription['Jensen-Shannon distance'];
return jensenShannonDistance === null ? maximally_different : jensenShannonDistance;
}
#displayBatchcodeByCountryBarChart(batchcode, barChartDescriptions, uiContainer) { #displayBatchcodeByCountryBarChart(batchcode, barChartDescriptions, uiContainer) {
if (batchcode in barChartDescriptions.barChartDescriptions) { const barChartDescription = this.#getBarChartDescription(barChartDescriptions, batchcode);
new BatchcodeByCountryBarChartView(uiContainer) if (barChartDescription !== null) {
.displayBatchcodeByCountryBarChart(this.#getBarChartDescription(barChartDescriptions, batchcode)); new BatchcodeByCountryBarChartView(uiContainer).displayBatchcodeByCountryBarChart(barChartDescription);
} }
} }
#getBarChartDescription(barChartDescriptions, batchcode) { #getBarChartDescription(barChartDescriptions, batchcode) {
if (!(batchcode in barChartDescriptions.barChartDescriptions)) {
return null;
}
const barChartDescription = barChartDescriptions.barChartDescriptions[batchcode]; const barChartDescription = barChartDescriptions.barChartDescriptions[batchcode];
barChartDescription.batchcode = batchcode; barChartDescription.batchcode = batchcode;
barChartDescription['date range guessed'] = barChartDescriptions['date range guessed']; barChartDescription['date range guessed'] = barChartDescriptions['date range guessed'];

View File

@@ -31,7 +31,8 @@ class BatchcodeByCountryBarChart {
labels: barChartDescription.countries, labels: barChartDescription.countries,
datasets: [ datasets: [
{ {
label: `Known (${this.#dateRange2str(barChartDescription['date range known'])})`, // FK-TODO: do not display Jensen-Shannon distance here or do not display at all
label: `Known (${this.#dateRange2str(barChartDescription['date range known'])}) ${barChartDescription['Jensen-Shannon distance']}`,
data: barChartDescription["Adverse Reaction Reports known"] data: barChartDescription["Adverse Reaction Reports known"]
}, },
{ {