From 71c5566f2b20bddc00158ce7232248e3773d8f9e Mon Sep 17 00:00:00 2001 From: d11n Date: Fri, 2 Feb 2024 11:29:35 +0100 Subject: [PATCH] Dashboard: Tooltip for balance on a particular day (#5650) Closes #5617. --- .../StoreWalletBalance/Default.cshtml | 21 +- BTCPayServer/Views/UIStores/Dashboard.cshtml | 2 + .../chartist/chartist-plugin-tooltip.css | 58 +++ .../chartist/chartist-plugin-tooltip.js | 464 ++++++++++++++++++ 4 files changed, 538 insertions(+), 7 deletions(-) create mode 100644 BTCPayServer/wwwroot/vendor/chartist/chartist-plugin-tooltip.css create mode 100644 BTCPayServer/wwwroot/vendor/chartist/chartist-plugin-tooltip.js diff --git a/BTCPayServer/Components/StoreWalletBalance/Default.cshtml b/BTCPayServer/Components/StoreWalletBalance/Default.cshtml index 70cf19e4b..83e9f7f5c 100644 --- a/BTCPayServer/Components/StoreWalletBalance/Default.cshtml +++ b/BTCPayServer/Components/StoreWalletBalance/Default.cshtml @@ -64,13 +64,14 @@ const id = `StoreWalletBalance-${storeId}`; const baseUrl = @Safe.Json(Url.Action("WalletHistogram", "UIWallets", new { walletId = Model.WalletId, type = WalletHistogramType.Week })); + const valueTransform = value => rate + ? DashboardUtils.displayDefaultCurrency(value, rate, defaultCurrency, divisibility).toString() + : value const chartOpts = { fullWidth: true, showArea: true, axisY: { - labelInterpolationFnc: value => rate - ? DashboardUtils.displayDefaultCurrency(value, rate, defaultCurrency, divisibility).toString() - : value + labelInterpolationFnc: valueTransform } }; @@ -80,16 +81,22 @@ document.querySelectorAll(`#${id} .currency`).forEach(c => c.innerText = currency) document.querySelectorAll(`#${id} [data-balance]`).forEach(c => { const value = Number.parseFloat(c.dataset.balance); - c.innerText = rate - ? DashboardUtils.displayDefaultCurrency(value, rate, currency, divisibility) - : value + c.innerText = valueTransform(value) }); if (!series) return; const min = Math.min(...series); const max = Math.max(...series); const low = Math.max(min - ((max - min) / 5), 0); - const renderOpts = Object.assign({}, chartOpts, { low }); + const tooltip = Chartist.plugins.tooltip2({ + template: '{{value}}', + offset: { + x: 0, + y: -16 + }, + valueTransformFunction: valueTransform + }) + const renderOpts = Object.assign({}, chartOpts, { low, plugins: [tooltip] }); const chart = new Chartist.Line(`#${id} .ct-chart`, { labels, series: [series] diff --git a/BTCPayServer/Views/UIStores/Dashboard.cshtml b/BTCPayServer/Views/UIStores/Dashboard.cshtml index 94d555d75..fb466458f 100644 --- a/BTCPayServer/Views/UIStores/Dashboard.cshtml +++ b/BTCPayServer/Views/UIStores/Dashboard.cshtml @@ -24,7 +24,9 @@ { /* include chart library inline so that it instantly renders */ + +