Skip to content

Commit

Permalink
Dashboard: Tooltip for balance on a particular day (#5650)
Browse files Browse the repository at this point in the history
Closes #5617.
  • Loading branch information
dennisreimann committed Feb 2, 2024
1 parent 6621859 commit 71c5566
Show file tree
Hide file tree
Showing 4 changed files with 538 additions and 7 deletions.
21 changes: 14 additions & 7 deletions BTCPayServer/Components/StoreWalletBalance/Default.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};

This comment was marked as spam.

Copy link
@dmcclure803

dmcclure803 Feb 4, 2024

ok

h18c90e6bba55029c419_20231222_105227.mp4

you mam now me as a man or boy

Expand All @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions BTCPayServer/Views/UIStores/Dashboard.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
{
/* include chart library inline so that it instantly renders */
<link rel="stylesheet" href="~/vendor/chartist/chartist.css" asp-append-version="true">
<link rel="stylesheet" href="~/vendor/chartist/chartist-plugin-tooltip.css" asp-append-version="true">
<script src="~/vendor/chartist/chartist.min.js" asp-append-version="true"></script>
<script src="~/vendor/chartist/chartist-plugin-tooltip.js" asp-append-version="true"></script>
<script>
const DashboardUtils = {
toDefaultCurrency(amount, rate) {
Expand Down
58 changes: 58 additions & 0 deletions BTCPayServer/wwwroot/vendor/chartist/chartist-plugin-tooltip.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Chartist.js plugin to display a tooltip on top of a chart.
* @author Antonia Ciocodeica
* @version 0.1 22 Nov 2016
*/
.chartist-tooltip {
position: absolute;
left: 0;
top: 0;
z-index: 1000;
display: block;
padding: var(--btcpay-space-xs) var(--btcpay-space-s);
visibility: hidden;
transform: translateY(3em);
opacity: 0;
border-radius: var(--btcpay-border-radius);
border: 1px solid var(--btcpay-body-border-light);
color: var(--btcpay-body-text);
background-color: var(--btcpay-bg-tile);
transition: transform var(--btcpay-transition-duration-fast) ease-in-out;
}
.chartist-tooltip:not([hidden]) {
margin: 0;
visibility: visible;
transform: none;
opacity: 1;
}

/* Tooltip arrow */
.chartist-tooltip::before {
content: '\25BC';
position: absolute;
left: calc(50% - .5em);
top: 100%;
z-index: -1;
font-size: 1.3em;
line-height: .5em;
font-family: Arial, sans-serif;
color: var(--btcpay-body-border-light);
transform: scaleY(0.7);
text-shadow: 0 0.25em 0.35em rgba(0, 0, 0, 0.1);
}
.chartist-tooltip--left::before {
left: 0.75em;
}
.chartist-tooltip--right::before {
left: auto;
right: 0.75em;
}

/* Adds a small point transition (line charts) when the point is active */
.ct-point {
transition: all 0.2s ease-in-out;
}
/* Increased specificity intended to overwrite the default chartist style */
.ct-chart-line.ct-chart-line .ct-point--hover {
stroke-width: 1.25em;
}

0 comments on commit 71c5566

Please sign in to comment.