fix(frontend): fix retention rate heatmap rendering

This commit is contained in:
syuilo 2023-05-12 12:15:54 +09:00
parent 5be6438bbc
commit f983e44d9e
1 changed files with 13 additions and 3 deletions

View File

@ -90,8 +90,13 @@ async function renderChart() {
borderRadius: 3, borderRadius: 3,
backgroundColor(c) { backgroundColor(c) {
const value = c.dataset.data[c.dataIndex].v; const value = c.dataset.data[c.dataIndex].v;
const a = value / max(c.dataset.data[c.dataIndex].y); const m = max(c.dataset.data[c.dataIndex].y);
if (m === 0) {
return alpha(color, 0);
} else {
const a = value / m;
return alpha(color, a); return alpha(color, a);
}
}, },
fill: true, fill: true,
width(c) { width(c) {
@ -170,7 +175,12 @@ async function renderChart() {
}, },
label(context) { label(context) {
const v = context.dataset.data[context.dataIndex]; const v = context.dataset.data[context.dataIndex];
return [`Active: ${v.v} (${Math.round((v.v / max(v.y)) * 100)}%)`]; const m = max(v.y);
if (m === 0) {
return [`Active: ${v.v} (-%)`];
} else {
return [`Active: ${v.v} (${Math.round((v.v / m) * 100)}%)`];
}
}, },
}, },
//mode: 'index', //mode: 'index',