diff --git a/src/components/boards/EvalBar.tsx b/src/components/boards/EvalBar.tsx
index fd5530c7..cc270880 100644
--- a/src/components/boards/EvalBar.tsx
+++ b/src/components/boards/EvalBar.tsx
@@ -39,7 +39,7 @@ function EvalBar({
py={3}
mt={orientation === "black" ? "auto" : undefined}
>
- {score.value <= 0 && formatScore(score, 1).replace(/\+|-/, "")}
+ {score.value <= 0 && formatScore(score, false).replace(/\+|-/, "")}
,
- {score.value > 0 && formatScore(score, 1).slice(1)}
+ {score.value > 0 && formatScore(score, false).slice(1)}
,
];
diff --git a/src/components/panels/analysis/BestMoves.tsx b/src/components/panels/analysis/BestMoves.tsx
index 32e9ace5..037232c9 100644
--- a/src/components/panels/analysis/BestMoves.tsx
+++ b/src/components/panels/analysis/BestMoves.tsx
@@ -370,7 +370,7 @@ function EngineTop({
Eval
- {formatScore(engineVariations[0].score.value, 1) ?? 0}
+ {formatScore(engineVariations[0].score.value, false) ?? 0}
diff --git a/src/components/panels/analysis/ScoreBubble.tsx b/src/components/panels/analysis/ScoreBubble.tsx
index dbc8122b..a3640546 100644
--- a/src/components/panels/analysis/ScoreBubble.tsx
+++ b/src/components/panels/analysis/ScoreBubble.tsx
@@ -1,6 +1,6 @@
import type { Score } from "@/bindings";
import { formatScore } from "@/utils/score";
-import { Box, Progress, Text } from "@mantine/core";
+import { Box, Progress, Text, Tooltip } from "@mantine/core";
import * as classes from "./ScoreBubble.css";
function ScoreBubble({
@@ -23,7 +23,7 @@ function ScoreBubble({
style={(theme) => ({
borderRadius: theme.radius.sm,
boxShadow: theme.shadows.md,
- width: size === "md" ? "4rem" : "3.5rem",
+ width: size === "md" ? "5.0rem" : "3.5rem",
height: size === "md" ? "1.85rem" : "1.6rem",
})}
fz="0.5rem"
@@ -66,22 +66,31 @@ function ScoreBubble({
textAlign: "center",
padding: "0.15rem",
borderRadius: theme.radius.sm,
- width: size === "md" ? "4rem" : "3.5rem",
+ width: size === "md" ? "5.0rem" : "3.5rem",
height: size === "md" ? "1.85rem" : "1.6rem",
boxShadow: theme.shadows.md,
})}
>
- = 0 ? "black" : "white"}
- size={size}
- ta="center"
- style={(theme) => ({
- fontFamily: theme.fontFamilyMonospace,
- })}
+
- {formatScore(score.value)}
-
+ = 0 ? "black" : "white"}
+ size={size}
+ ta="center"
+ style={(theme) => ({
+ fontFamily: theme.fontFamilyMonospace,
+ textOverflow: "ellipsis",
+ overflow: "hidden",
+ whiteSpace: "nowrap",
+ })}
+ >
+ {formatScore(score.value)}
+
+
);
}
diff --git a/src/utils/score.ts b/src/utils/score.ts
index 7087e932..22903a13 100644
--- a/src/utils/score.ts
+++ b/src/utils/score.ts
@@ -14,9 +14,17 @@ export const INITIAL_SCORE: Score = {
const CP_CEILING = 1000;
-export function formatScore(score: ScoreValue, precision = 2): string {
+export function formatScore(score: ScoreValue, precise = true): string {
let scoreText = match(score.type)
- .with("cp", () => Math.abs(score.value / 100).toFixed(precision))
+ .with("cp", () => {
+ const absScore = Math.abs(score.value);
+ return (
+ precise
+ ? (absScore / 100).toFixed(2)
+ : // idea from: https://github.com/lichess-org/lila/blob/e110605c/ui/ceval/src/util.ts#L8
+ Math.min(Math.round(absScore / 10) / 10, 99).toFixed(1)
+ ).toString();
+ })
.with("mate", () => `M${Math.abs(score.value)}`)
.with("dtz", () => `DTZ${Math.abs(score.value)}`)
.exhaustive();
diff --git a/src/utils/tests/score.test.ts b/src/utils/tests/score.test.ts
index 8ae15a6e..0c952f89 100644
--- a/src/utils/tests/score.test.ts
+++ b/src/utils/tests/score.test.ts
@@ -15,6 +15,10 @@ test("should format a negative cp score correctly", () => {
expect(formatScore({ type: "cp", value: -50 })).toBe("-0.50");
});
+test("should truncate a large cp score correctly", () => {
+ expect(formatScore({ type: "cp", value: 20000 }, false)).toBe("+99.0");
+});
+
test("should format a mate score correctly", () => {
expect(formatScore({ type: "mate", value: 5 })).toBe("+M5");
expect(formatScore({ type: "mate", value: -5 })).toBe("-M5");