From fcd542d60044fec88de481abf2432c59866e7643 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 10 Aug 2022 14:57:41 +0200 Subject: [PATCH] Improve handling of low commit counts in repo activity Signed-off-by: Sebastian Martinez --- src/Diagram.svelte | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Diagram.svelte b/src/Diagram.svelte index ea77fabdb..16211e776 100644 --- a/src/Diagram.svelte +++ b/src/Diagram.svelte @@ -22,6 +22,9 @@ // The highest value on the y axis let commitCountArray: number[] = []; + // The minimal amplitude shown e.g. commitCount = 1 => `minimalHeight` points of height in the SVG. + let minimalHeight = 5; + let week = 0; for (const point of points) { @@ -43,10 +46,15 @@ // Normalizes the values to the viewBox dimensions let normalizedArray = - commitCountArray.map(c => - // When max and min value are 0 we want to make sure the normalization is not being run since it would return NaN - c === 0 ? 0 : (viewBoxHeight - 0) * (c - minValue) / (maxValue - minValue) - ); + commitCountArray.map(c => { + // If we are not crossing the `viewBoxHeight` we want to return the actual value, + // and don't want to normalize <`minimalHeight` commit counts as huge spikes. + if (maxValue < viewBoxHeight && c >= minimalHeight) { return c; } + // If the value is 0..minimalHeight though we don't want to set it to the minimalHeight. + else if (c > 0 && c < minimalHeight) { return minimalHeight; } + // If the count is 0 we have to make sure the normalization is not being run since it would return NaN + else { return c === 0 ? 0 : (viewBoxHeight - 0) * (c - minValue) / (maxValue - minValue); } + }); let path = normalizedArray .slice(1) @@ -77,8 +85,13 @@ - - - - + {#if points.length > 0} + + + + + {:else} + + + {/if}