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:
[
this.#getColumnIndex('Batch'),
this.#getColumnIndex('Company'),
this.#getColumnIndex('Countries')
this.#getColumnIndex('Company')
]
},
{
@@ -75,8 +74,13 @@ class BatchCodeTableInitializer {
},
{
width: "1000px",
render: function (data, type, row, meta) {
return null;
render: (data, type, row, meta) => {
if (type === 'sort') {
return this.#getJensenShannonDistance(
row[this.#getColumnIndex('Batch')],
barChartDescriptions);
}
return data;
},
createdCell: (cell, cellData, row, rowIndex, colIndex) => {
if (showCountriesColumn) {
@@ -93,7 +97,6 @@ class BatchCodeTableInitializer {
});
}
#getColumnIndex(columnName) {
switch (columnName) {
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) {
if (batchcode in barChartDescriptions.barChartDescriptions) {
new BatchcodeByCountryBarChartView(uiContainer)
.displayBatchcodeByCountryBarChart(this.#getBarChartDescription(barChartDescriptions, batchcode));
const barChartDescription = this.#getBarChartDescription(barChartDescriptions, batchcode);
if (barChartDescription !== null) {
new BatchcodeByCountryBarChartView(uiContainer).displayBatchcodeByCountryBarChart(barChartDescription);
}
}
#getBarChartDescription(barChartDescriptions, batchcode) {
if (!(batchcode in barChartDescriptions.barChartDescriptions)) {
return null;
}
const barChartDescription = barChartDescriptions.barChartDescriptions[batchcode];
barChartDescription.batchcode = batchcode;
barChartDescription['date range guessed'] = barChartDescriptions['date range guessed'];

View File

@@ -31,7 +31,8 @@ class BatchcodeByCountryBarChart {
labels: barChartDescription.countries,
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"]
},
{