From f983e44d9ed2348f06893eab9587b6187d9f5aa2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 12 May 2023 12:15:54 +0900 Subject: [PATCH] fix(frontend): fix retention rate heatmap rendering --- .../src/components/MkRetentionHeatmap.vue | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/frontend/src/components/MkRetentionHeatmap.vue b/packages/frontend/src/components/MkRetentionHeatmap.vue index fc2bc5c87f..311d5c425c 100644 --- a/packages/frontend/src/components/MkRetentionHeatmap.vue +++ b/packages/frontend/src/components/MkRetentionHeatmap.vue @@ -90,8 +90,13 @@ async function renderChart() { borderRadius: 3, backgroundColor(c) { const value = c.dataset.data[c.dataIndex].v; - const a = value / max(c.dataset.data[c.dataIndex].y); - return alpha(color, a); + 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); + } }, fill: true, width(c) { @@ -170,7 +175,12 @@ async function renderChart() { }, label(context) { 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',