From 135d999e1a51255d1a1ed845a71064dc0f3cb9fa Mon Sep 17 00:00:00 2001 From: James Hadfield Date: Tue, 9 Mar 2021 17:07:02 +1300 Subject: [PATCH] [frequencies panel] Don't round frequencies below 1% When a frequency value is below 1% we now display "<1%" rather than rounding to the nearest integer which could lead to confusing output of "frequency: 0%". Closes #1279 --- src/components/frequencies/functions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/frequencies/functions.js b/src/components/frequencies/functions.js index 41efa4377..f7d1497d5 100644 --- a/src/components/frequencies/functions.js +++ b/src/components/frequencies/functions.js @@ -277,7 +277,8 @@ export const drawStream = ( /* what's the closest pivot? */ const date = scales.x.invert(mousex); const pivotIdx = pivots.reduce((closestIdx, val, idx, arr) => Math.abs(val - date) < Math.abs(arr[closestIdx] - date) ? idx : closestIdx, 0); - const freqVal = Math.round((d[pivotIdx][1] - d[pivotIdx][0]) * 100) + "%"; + const frequency = (d[pivotIdx][1] - d[pivotIdx][0]) * 100; + const freqVal = frequency < 1 ? "<1%" : Math.round(frequency) + "%"; const xValueOfPivot = scales.x(pivots[pivotIdx]); const y1ValueOfPivot = scales.y(d[pivotIdx][1]); const y2ValueOfPivot = scales.y(d[pivotIdx][0]);