name sorting fixes, tooltip positioned in the middle

This commit is contained in:
tmont 2020-04-30 23:54:24 -07:00
parent 38a8191744
commit 0fe3817c20
2 changed files with 15 additions and 11 deletions

View File

@ -386,6 +386,9 @@ const processGlobalDeaths = async () => {
if (record.county) {
record.name = record.county;
record.safeName = toSafeName(record.county);
} else if (record.state) {
record.name = record.state;
record.safeName = toSafeName(record.state);
}
// roll up up state/county data

View File

@ -57,6 +57,14 @@ html
}
});
Chart.Tooltip.positioners.middle = function(elements, eventPosition) {
const chartArea = this._chartInstance.chartArea;
return {
x: eventPosition.x,
y: chartArea.top + ((chartArea.bottom - chartArea.top) / 2),
};
};
const charts = {
logarithmic: false,
heroChart: null,
@ -228,7 +236,7 @@ html
},
tooltips: {
intersect: false,
position: 'nearest',
position: 'middle',
axis: 'x',
},
scales: {
@ -353,8 +361,8 @@ html
const last7 = getValue(1) - getValue(7);
const last30 = getValue(1) - getValue(30);
tr(
id=("row-" + item.safeName)
data-name=item.name
id=("row-" + (item.safeName || '_'))
data-name=(item.name || '_')
data-population=item.population
data-total=item.total
data-million=item.deathsPerMillion
@ -423,11 +431,8 @@ html
for (let i = allRows.length - 1; i >= 0; i--) {
const row = allRows[i];
if (!row) {
console.log(i + ' no row!');
continue;
}
const name = row.getAttribute('data-name');
console.log(row.id, name, !name && row);
const cells = [].slice.call(row.querySelectorAll('td'));
cells.forEach((cell, i) => {
if (i !== highlightedIndex) {
@ -444,7 +449,6 @@ html
row.querySelector('.sort-order').textContent = (i + 1).toString();
nextChild = row;
}
console.log('---');
};
const handleSort = (value, dir) => {
@ -456,7 +460,7 @@ html
if (aValue === bValue) {
const aName = a.getAttribute('data-name');
const bName = b.getAttribute('data-name');
return aName && bName ? aName.localeCompare(bName) : -1;
return aName.localeCompare(bName);
}
return aValue < bValue ?
@ -471,9 +475,6 @@ html
allRows.sort((a, b) => {
const aName = a.getAttribute('data-name');
const bName = b.getAttribute('data-name');
if (!aName || !bName) {
return -1;
}
if (newSortDir === 'asc') {
return aName.localeCompare(bName);
}