From 4fa9e87cf8a4b656d0a05151ef4c1960c450a260 Mon Sep 17 00:00:00 2001 From: ekatwikz Date: Wed, 15 May 2024 16:40:33 +0200 Subject: [PATCH] score formatting: truncate optionally --- src/components/boards/EvalBar.tsx | 2 +- src/components/common/EvalChart.tsx | 2 +- src/components/panels/analysis/ScoreBubble.tsx | 2 +- src/utils/score.ts | 15 ++++++++++----- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/components/boards/EvalBar.tsx b/src/components/boards/EvalBar.tsx index 51d9e7ce..f3cfb7f1 100644 --- a/src/components/boards/EvalBar.tsx +++ b/src/components/boards/EvalBar.tsx @@ -78,7 +78,7 @@ function EvalBar({ - Math.min(Math.round(Math.abs(score.value) / 10) / 10, 99).toFixed(1), - ) + .with("cp", () => { + const absScore = Math.abs(score.value); + return ( + truncate + ? // idea from: https://github.com/lichess-org/lila/blob/e110605c138c1f6fec417ab9317968b32a928a16/ui/ceval/src/util.ts#L8 + Math.min(Math.round(absScore / 10) / 10, 99).toFixed(1) + : (absScore / 100).toFixed(2) + ).toString(); + }) .with("mate", () => `M${Math.abs(score.value)}`) .with("dtz", () => `DTZ${Math.abs(score.value)}`) .exhaustive();