diff --git a/public/js/players.js b/public/js/players.js index 1eaa5db..a240457 100644 --- a/public/js/players.js +++ b/public/js/players.js @@ -4,15 +4,15 @@ let openPdgaNumber = null; // ── Delta-pill helper ───────────────────────────── function renderDeltaPill(value, extraClass) { - if (value == null) return null; - const cls = value > 0 ? 'up' : value < 0 ? 'down' : 'flat'; - const glyph = value > 0 ? '▲' : value < 0 ? '▼' : '–'; - const num = value > 0 ? '+' + value : String(value); + const isNull = (value == null); + const cls = isNull ? 'flat' : value > 0 ? 'up' : value < 0 ? 'down' : 'flat'; + const glyph = (isNull || value === 0) ? '–' : value > 0 ? '▲' : '▼'; + const num = isNull ? '—' : value > 0 ? '+' + value : String(value); return { glyph, num, cls }; } function applyDeltaPill(pillEl, value) { - if (!pillEl || value == null) return; + if (!pillEl) return; const pill = renderDeltaPill(value); pillEl.className = 'delta-pill ' + pill.cls; while (pillEl.firstChild) pillEl.removeChild(pillEl.firstChild); diff --git a/views/partials/delta-pill.ejs b/views/partials/delta-pill.ejs index 4fb7cf9..0b1c367 100644 --- a/views/partials/delta-pill.ejs +++ b/views/partials/delta-pill.ejs @@ -1,11 +1,12 @@ <%/* delta-pill.ejs — renders a Δ-pill span. Locals: - value {number|null} — the delta value + value {number|null} — the delta value (null/undefined → flat pill with '—') extraClass {string} — optional additional CSS class (e.g. 'delta-predicted-pill') */%> -<% if (typeof value !== 'undefined' && value != null) { - const _cls = value > 0 ? 'up' : value < 0 ? 'down' : 'flat'; - const _glyph = value > 0 ? '▲' : value < 0 ? '▼' : '–'; - const _num = value > 0 ? '+' + value : value.toString(); - const _xtra = (typeof extraClass !== 'undefined' && extraClass) ? ' ' + extraClass : ''; -%><%= _glyph %><%= _num %><% } %> +<% +const _isNull = (typeof value === 'undefined' || value == null); +const _cls = _isNull ? 'flat' : value > 0 ? 'up' : value < 0 ? 'down' : 'flat'; +const _glyph = (_isNull || value === 0) ? '–' : value > 0 ? '▲' : '▼'; +const _num = _isNull ? '—' : value > 0 ? '+' + value : value.toString(); +const _xtra = (typeof extraClass !== 'undefined' && extraClass) ? ' ' + extraClass : ''; +%><%= _glyph %><%= _num %> diff --git a/views/partials/player-history.ejs b/views/partials/player-history.ejs index 3e082aa..29af37b 100644 --- a/views/partials/player-history.ejs +++ b/views/partials/player-history.ejs @@ -16,9 +16,7 @@ const chartPdgaNumber = hasPlayer ? player.pdgaNumber : pdgaNumber;
Change vs last month
-
- <% if (player.ratingChange != null) { %><%- include('delta-pill', { value: player.ratingChange }) %><% } else { %>—<% } %> -
+
<%- include('delta-pill', { value: player.ratingChange }) %>
Predicted next update
@@ -26,9 +24,7 @@ const chartPdgaNumber = hasPlayer ? player.pdgaNumber : pdgaNumber;
Gap to predicted
-
- <% if (player.deltaPredicted != null) { %><%- include('delta-pill', { value: player.deltaPredicted, extraClass: 'delta-predicted-pill' }) %><% } else { %>—<% } %> -
+
<%- include('delta-pill', { value: player.deltaPredicted, extraClass: 'delta-predicted-pill' }) %>