From 0fe3817c20b6914309e1ce7de40539e3567d3cde Mon Sep 17 00:00:00 2001 From: tmont Date: Thu, 30 Apr 2020 23:54:24 -0700 Subject: [PATCH] name sorting fixes, tooltip positioned in the middle --- generate.js | 3 +++ tmpl/master.pug | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/generate.js b/generate.js index 7743f64..403474f 100755 --- a/generate.js +++ b/generate.js @@ -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 diff --git a/tmpl/master.pug b/tmpl/master.pug index 52eb4a8..5e5674e 100644 --- a/tmpl/master.pug +++ b/tmpl/master.pug @@ -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); }