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