Skip to content

Commit

Permalink
add warning about enabling WDL (closes #443)
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Dec 5, 2024
1 parent f46f861 commit b8bfefd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 37 deletions.
87 changes: 50 additions & 37 deletions src/components/common/EvalChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "@/utils/treeReducer";
import { AreaChart } from "@mantine/charts";
import {
Alert,
Box,
LoadingOverlay,
Paper,
Expand All @@ -20,12 +21,13 @@ import {
} from "@mantine/core";
import equal from "fast-deep-equal";
import { useAtom } from "jotai";
import { useContext } from "react";
import { useContext, useMemo } from "react";
import { useTranslation } from "react-i18next";
import type { CategoricalChartFunc } from "recharts/types/chart/generateCategoricalChart";
import { useStore } from "zustand";
import * as classes from "./EvalChart.css";
import { TreeStateContext } from "./TreeStateContext";
import { IconInfoCircle } from "@tabler/icons-react";

interface EvalChartProps {
isAnalysing: boolean;
Expand Down Expand Up @@ -168,6 +170,12 @@ function EvalChart(props: EvalChartProps) {

const [chartType, setChartType] = useAtom(reportTypeAtom);

const isWDLDisabled = useMemo(() => {
return !data.some(
(point) => point.White !== 0 || point.Black !== 0 || point.Draw !== 0,
);
}, [data]);

return (
<Stack>
<Box pos="relative">
Expand Down Expand Up @@ -215,42 +223,47 @@ function EvalChart(props: EvalChartProps) {
}}
/>
)}
{chartType === "WDL" && (
<AreaChart
h={150}
curveType="monotone"
data={data}
dataKey={"name"}
series={[
{ name: "White", color: "white" },
{ name: "Draw", color: "gray" },
{ name: "Black", color: "black" },
]}
connectNulls={false}
withXAxis={false}
withYAxis={false}
type="percent"
fillOpacity={0.8}
activeDotProps={{ r: 3, strokeWidth: 1 }}
dotProps={{ r: 0 }}
referenceLines={[
{
x: currentPositionName,
color: theme.colors[theme.primaryColor][7],
},
]}
areaChartProps={{
onClick: onChartClick,
style: { cursor: "pointer" },
}}
gridAxis="none"
tooltipProps={{
content: ({ payload, active }) => (
<CustomTooltip active={active} payload={payload} type="wdl" />
),
}}
/>
)}
{chartType === "WDL" &&
(isWDLDisabled ? (
<Alert variant="outline" title="Enable WDL" mt="sm">
{t("Board.Analysis.EnableWDL")}
</Alert>
) : (
<AreaChart
h={150}
curveType="monotone"
data={data}
dataKey={"name"}
series={[
{ name: "White", color: "white" },
{ name: "Draw", color: "gray" },
{ name: "Black", color: "black" },
]}
connectNulls={false}
withXAxis={false}
withYAxis={false}
type="percent"
fillOpacity={0.8}
activeDotProps={{ r: 3, strokeWidth: 1 }}
dotProps={{ r: 0 }}
referenceLines={[
{
x: currentPositionName,
color: theme.colors[theme.primaryColor][7],
},
]}
areaChartProps={{
onClick: onChartClick,
style: { cursor: "pointer" },
}}
gridAxis="none"
tooltipProps={{
content: ({ payload, active }) => (
<CustomTooltip active={active} payload={payload} type="wdl" />
),
}}
/>
))}
</Box>
</Stack>
);
Expand Down
2 changes: 2 additions & 0 deletions src/translation/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export const en_US = {
"Board.Analysis.Analyze": "Analyze",
"Board.Analysis.Advantage": "Advantage",
"Board.Analysis.Accuracy": "Accuracy",
"Board.Analysis.EnableWDL":
"You have to enable UCI_ShowWDL in the engine settings to use this feature.",
"Board.Database.Local": "Local",
"Board.Database.LichessAll": "Lichess All",
"Board.Database.LichessMaster": "Lichess Masters",
Expand Down

0 comments on commit b8bfefd

Please sign in to comment.