Skip to content

Commit

Permalink
feat: added MoveMap, MoveRecommendations, color mappings, and Moves b…
Browse files Browse the repository at this point in the history
…y Rating
  • Loading branch information
kevinjosethomas committed Jan 21, 2025
1 parent 20c54d5 commit ca5b9c6
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 47 deletions.
154 changes: 154 additions & 0 deletions src/components/Analysis/MoveMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import {
Cell,
Label,
XAxis,
YAxis,
Scatter,
LabelList,
ScatterChart,
CartesianGrid,
ResponsiveContainer,
} from 'recharts'

interface Props {
moveMap?: { move: string; x: number; y: number }[]
colorSanMapping: {
[move: string]: {
san: string
color: string
}
}
}

export const MoveMap: React.FC<Props> = ({
moveMap,
colorSanMapping,
}: Props) => {
console.log(moveMap)
return (
<div className="flex h-full max-h-full flex-col overflow-hidden rounded bg-background-1/60">
<p className="p-4 text-lg text-white">Move Map</p>
<div className="flex h-full w-full flex-col">
<ResponsiveContainer width="100%" height="100%">
<ScatterChart margin={{ left: -14, top: 0, right: 30, bottom: 10 }}>
<CartesianGrid strokeDasharray="3 3" stroke="#3C3C3C" />
<YAxis
dataKey="y"
type="number"
axisLine={false}
label={{
value: 'Maia',
position: 'insideLeft',
fill: '#FE7F6D',
angle: -90,
fontSize: 14,
fontWeight: 600,
offset: 26,
dy: 20,
}}
tickCount={4}
tickLine={false}
tickMargin={0}
tick={{ fill: 'white', fontSize: 10 }}
tickFormatter={(value) => `${value}%`}
domain={([dataMin, dataMax]) => [0, dataMax > 75 ? 100 : 75]}
>
<Label
value="← Unlikely"
position="insideBottomLeft"
offset={32}
angle={-90}
fontSize={10}
fontWeight={500}
fill="#BF5F52"
dy={60}
/>
<Label
value="Likely →"
position="insideTopLeft"
offset={24}
angle={-90}
fontSize={10}
fontWeight={500}
fill="#BF5F52"
dy={14}
/>
</YAxis>
<XAxis
scale="sqrt"
dataKey="x"
type="number"
axisLine={false}
domain={[-4, 0]}
label={{
value: 'SF Eval Loss',
position: 'insideBottom',
fill: '#76ADDD',
fontSize: 14,
fontWeight: 600,
offset: 0,
dx: -12,
}}
ticks={[-4, -2, -1, 0]}
tick={{
fill: 'white',
fontSize: 10,
}}
tickMargin={0}
tickLine={false}
>
<Label
value="← Blunders"
position="insideLeft"
fontSize={10}
fontWeight={500}
fill="#5A9DD7"
dy={11}
offset={-20}
/>
<Label
value="Best Moves →"
position="insideRight"
fontSize={10}
fontWeight={500}
fill="#5A9DD7"
dy={11}
offset={-10}
/>
</XAxis>
<Scatter name="Moves" data={moveMap}>
<LabelList
dataKey="move"
position="top"
fontSize={12}
fill="white"
content={({ x, y, value, index }: any) => {

Check warning on line 125 in src/components/Analysis/MoveMap.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
return (
<text
x={x}
y={y}
key={index}
fontSize={12}
textAnchor="middle"
dx={x < 100 ? 24 : 0}
dy={x < 100 ? 0 : y < 55 ? 24 : -5}
fill={colorSanMapping[value].color || '#fff'}
>
{colorSanMapping[value].san}
</text>
)
}}
/>
{moveMap?.map((entry, index) => (
<Cell
key={`cell-${entry.move}${index}`}
fill={colorSanMapping[entry.move].color || '#fff'}
/>
))}
</Scatter>
</ScatterChart>
</ResponsiveContainer>
</div>
</div>
)
}
74 changes: 74 additions & 0 deletions src/components/Analysis/MoveRecommendations.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
interface Props {
recommendations: {
maia?: { move: string; prob: number }[]
stockfish?: { move: string; cp: number }[]
}
colorSanMapping: {
[move: string]: {
san: string
color: string
}
}
}

export const MoveRecommendations: React.FC<Props> = ({
recommendations,
colorSanMapping,
}: Props) => {
return (
<div className="col-span-2 grid h-full max-h-full grid-cols-2 flex-col overflow-hidden rounded">
<div className="flex flex-col gap-2 bg-background-1 p-5">
<p className="text-lg text-white">Maia 1800 Predictions</p>
<div className="flex flex-col gap-1">
<div className="flex items-center justify-between">
<p className="font-mono text-sm font-extralight text-secondary/60">
move
</p>
<p className="font-mono text-sm font-extralight text-secondary/60">
%
</p>
</div>
{recommendations.maia?.map(({ move, prob }, index) => (
<div
key={index}
className="flex items-center justify-between"
style={{
color: colorSanMapping[move].color,
}}
>
<p className="font-mono">{colorSanMapping[move].san}</p>
<p className="font-mono text-sm">
{Math.round(prob * 1000) / 10}%
</p>
</div>
))}
</div>
</div>
<div className="flex flex-col gap-2 bg-background-1/60 p-5">
<p className="text-lg text-white">Stockfish Moves</p>
<div className="flex flex-col gap-1">
<div className="flex items-center justify-between">
<p className="font-mono text-sm font-extralight text-secondary/60">
move
</p>
<p className="font-mono text-sm font-extralight text-secondary/60">
eval
</p>
</div>
{recommendations.stockfish?.map(({ move, cp }, index) => (
<div
key={index}
className="flex items-center justify-between"
style={{
color: colorSanMapping[move].color,
}}
>
<p className="font-mono">{colorSanMapping[move].san}</p>
<p className="font-mono text-sm">{cp / 100}</p>
</div>
))}
</div>
</div>
</div>
)
}
37 changes: 23 additions & 14 deletions src/components/Analysis/MovesByRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,33 @@ import {

interface Props {
moves: { [key: string]: number }[] | undefined
colorSanMapping: {
[move: string]: {
san: string
color: string
}
}
}

export const MovesByRating: React.FC<Props> = ({ moves }: Props) => {
export const MovesByRating: React.FC<Props> = ({
moves,
colorSanMapping,
}: Props) => {
return (
<div className="col-span-2 flex h-full max-h-full flex-col rounded bg-background-1/60 pb-4">
<p className="p-4 text-xl text-white">Moves by Rating</p>
<div className="col-span-2 flex h-full max-h-full flex-col rounded bg-background-1/60">
<p className="p-4 text-lg text-white">Moves by Rating</p>
<div className="flex h-full w-full flex-col">
<ResponsiveContainer width="100%" height="100%">
<AreaChart data={moves} margin={{ left: 20, right: 0 }}>
<AreaChart data={moves} margin={{ left: -5, right: 0, bottom: 0 }}>
<CartesianGrid strokeDasharray="3 3" stroke="#3C3C3C" />
<XAxis
dataKey="rating"
axisLine={false}
tick={{
fill: 'white',
fontSize: 14,
fontSize: 10,
}}
tickMargin={6}
tickMargin={4}
ticks={[1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900]}
/>
<YAxis
Expand All @@ -37,20 +46,20 @@ export const MovesByRating: React.FC<Props> = ({ moves }: Props) => {
domain={[0, 100]}
tick={{
fill: 'white',
fontSize: 14,
fontSize: 10,
}}
label={{
value: 'Maia Probability',
angle: -90,
fill: '#ff0000',
fill: '#FE7F6D',
position: 'insideLeft',
dy: 46,
offset: 4,
offset: 20,
fontWeight: 600,
fontSize: 14,
}}
tickCount={4}
tickMargin={5}
tickMargin={2}
tickLine={false}
tickFormatter={(value) => `${value}%`}
/>
Expand All @@ -61,7 +70,7 @@ export const MovesByRating: React.FC<Props> = ({ moves }: Props) => {
domain={[0, 100]}
tick={{
fill: 'white',
fontSize: 14,
fontSize: 10,
}}
tickCount={4}
tickMargin={5}
Expand All @@ -79,11 +88,11 @@ export const MovesByRating: React.FC<Props> = ({ moves }: Props) => {
yAxisId="left"
dataKey={move}
dot={{
stroke: '#fff',
stroke: colorSanMapping[move].color,
strokeWidth: 1,
}}
stroke={'#fff'}
fill={'#fff'}
stroke={colorSanMapping[move].color}
fill={colorSanMapping[move].color}
fillOpacity={0.1}
strokeWidth={3}
/>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Analysis/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './MoveMap'
export * from './MovePlot'
export * from './Tournament'
export * from './BlunderMeter'
Expand All @@ -7,3 +8,4 @@ export * from './HorizontalEvaluationBar'
export * from './PositionEvaluationContainer'
export * from './VerticalEvaluationBar'
export * from './MovesByRating'
export * from './MoveRecommendations'
Loading

0 comments on commit ca5b9c6

Please sign in to comment.