Skip to content

Commit 2f25086

Browse files
feat: made moves by rating graph and MoveMap graph response on mobile devices
1 parent b64b3e4 commit 2f25086

File tree

5 files changed

+54
-40
lines changed

5 files changed

+54
-40
lines changed

src/components/Analysis/AnalysisGameList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const AnalysisGameList: React.FC<AnalysisGameListProps> = ({
8181
}, [selected])
8282

8383
return analysisTournamentList ? (
84-
<div className="flex h-full flex-col items-start justify-start overflow-hidden rounded bg-background-1">
84+
<div className="flex h-full flex-col items-start justify-start overflow-hidden bg-background-1 md:rounded">
8585
<div className="flex h-full w-full flex-col">
8686
<div className="grid select-none grid-cols-5 border-b-2 border-white border-opacity-10">
8787
<Header

src/components/Analysis/ConfigurableScreens.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const ConfigurableScreens: React.FC<Props> = ({
3535
const [screen, setScreen] = useState(screens[0])
3636

3737
return (
38-
<div className="flex w-full flex-1 flex-col overflow-hidden rounded bg-background-1/60 md:w-auto">
38+
<div className="flex w-full flex-1 flex-col overflow-hidden bg-background-1/60 md:w-auto md:rounded">
3939
<div className="flex flex-row border-b border-white/10">
4040
{screens.map((s) => {
4141
const selected = s.id === screen.id

src/components/Analysis/MoveMap.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import {
99
CartesianGrid,
1010
ResponsiveContainer,
1111
} from 'recharts'
12+
import { useContext } from 'react'
1213
import { ColorSanMapping } from 'src/types'
1314
import type { Key } from 'chessground/types'
1415
import type { DrawShape } from 'chessground/draw'
16+
import { WindowSizeContext } from 'src/contexts'
1517
import { ContentType } from 'recharts/types/component/Label'
1618

1719
interface Props {
@@ -26,6 +28,8 @@ export const MoveMap: React.FC<Props> = ({
2628
colorSanMapping,
2729
setHoverArrow,
2830
}: Props) => {
31+
const { isMobile } = useContext(WindowSizeContext)
32+
2933
const onMouseEnter = (move: string) => {
3034
setHoverArrow({
3135
orig: move.slice(0, 2) as Key,
@@ -38,7 +42,7 @@ export const MoveMap: React.FC<Props> = ({
3842
}
3943

4044
return (
41-
<div className="flex h-64 max-h-full flex-col overflow-hidden rounded bg-background-1/60 md:h-full">
45+
<div className="flex h-64 max-h-full flex-col overflow-hidden bg-background-1/60 md:h-full md:rounded">
4246
<p className="p-3 text-primary md:text-lg">Move Map</p>
4347
<div className="flex h-full w-full flex-col">
4448
<ResponsiveContainer width="100%" height="100%">
@@ -52,10 +56,10 @@ export const MoveMap: React.FC<Props> = ({
5256
value: 'SF Loss',
5357
fill: '#76ADDD',
5458
position: 'insideBottom',
55-
fontSize: 18,
59+
fontSize: isMobile ? 14 : 18,
5660
fontWeight: 600,
5761
offset: -8,
58-
dx: -12,
62+
dx: isMobile ? -6 : -12,
5963
}}
6064
tickCount={5}
6165
tickLine={false}
@@ -71,7 +75,7 @@ export const MoveMap: React.FC<Props> = ({
7175
fontSize={12}
7276
fontWeight={500}
7377
dy={10}
74-
dx={-18}
78+
dx={isMobile ? -40 : -18}
7579
/>
7680
<Label
7781
value="Best Moves →"
@@ -92,10 +96,10 @@ export const MoveMap: React.FC<Props> = ({
9296
fill: '#FE7F6D',
9397
position: 'insideLeft',
9498
angle: -90,
95-
fontSize: 16,
99+
fontSize: isMobile ? 14 : 16,
96100
fontWeight: 600,
97-
dx: 10,
98-
dy: 32,
101+
dx: isMobile ? 5 : 10,
102+
dy: isMobile ? 20 : 32,
99103
}}
100104
tickCount={4}
101105
tick={{
@@ -113,7 +117,7 @@ export const MoveMap: React.FC<Props> = ({
113117
angle={-90}
114118
fontSize={12}
115119
fontWeight={500}
116-
dy={140}
120+
dy={isMobile ? 100 : 140}
117121
position="insideLeft"
118122
fill="#BF5F52"
119123
/>
@@ -125,14 +129,14 @@ export const MoveMap: React.FC<Props> = ({
125129
dx={10}
126130
angle={-90}
127131
fontWeight={500}
128-
dy={-56}
132+
dy={isMobile ? -30 : -56}
129133
/>
130134
</YAxis>
131135
<Scatter name="Moves" data={moveMap}>
132136
<LabelList
133137
dataKey="move"
134138
position="top"
135-
fontSize={12}
139+
fontSize={isMobile ? 10 : 12}
136140
fill="white"
137141
content={
138142
(({
@@ -151,10 +155,12 @@ export const MoveMap: React.FC<Props> = ({
151155
x={x}
152156
y={y}
153157
key={index}
154-
fontSize={12}
158+
fontSize={isMobile ? 10 : 12}
155159
textAnchor="middle"
156-
dx={x < 100 ? 22 : -15}
157-
dy={8}
160+
dx={
161+
x < 100 ? (isMobile ? 15 : 22) : isMobile ? -10 : -15
162+
}
163+
dy={isMobile ? 6 : 8}
158164
fill={colorSanMapping[value]?.color ?? '#fff'}
159165
>
160166
{colorSanMapping[value]?.san ?? value}

src/components/Analysis/MovesByRating.tsx

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
CartesianGrid,
99
ResponsiveContainer,
1010
} from 'recharts'
11+
import { useContext } from 'react'
1112
import { ColorSanMapping } from 'src/types'
13+
import { WindowSizeContext } from 'src/contexts'
1214

1315
interface Props {
1416
moves: { [key: string]: number }[] | undefined
@@ -19,6 +21,8 @@ export const MovesByRating: React.FC<Props> = ({
1921
moves,
2022
colorSanMapping,
2123
}: Props) => {
24+
const { isMobile } = useContext(WindowSizeContext)
25+
2226
const maxValue = moves
2327
? Math.max(
2428
...moves.flatMap((move) =>
@@ -36,7 +40,15 @@ export const MovesByRating: React.FC<Props> = ({
3640
<div className="flex h-64 w-full flex-col rounded bg-background-1/60 md:h-full">
3741
<p className="p-3 text-primary md:text-lg">Moves by Rating</p>
3842
<ResponsiveContainer width="100%" height="100%">
39-
<AreaChart data={moves} margin={{ left: 0, right: 50, bottom: 0 }}>
43+
<AreaChart
44+
data={moves}
45+
margin={{
46+
left: 0,
47+
right: isMobile ? 40 : 50,
48+
bottom: 0,
49+
top: isMobile ? 5 : 0,
50+
}}
51+
>
4052
<CartesianGrid strokeDasharray="3 3" stroke="#3C3C3C" />
4153
<XAxis
4254
dataKey="rating"
@@ -46,7 +58,11 @@ export const MovesByRating: React.FC<Props> = ({
4658
fontSize: 11,
4759
}}
4860
tickMargin={4}
49-
ticks={[1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900]}
61+
ticks={
62+
isMobile
63+
? [1100, 1300, 1500, 1700, 1900]
64+
: [1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900]
65+
}
5066
/>
5167
<YAxis
5268
yAxisId="left"
@@ -67,8 +83,8 @@ export const MovesByRating: React.FC<Props> = ({
6783
fontWeight: 600,
6884
fontSize: 14,
6985
}}
70-
tickCount={5}
71-
tickMargin={2}
86+
tickCount={isMobile ? 4 : 5}
87+
tickMargin={isMobile ? 1 : 2}
7288
tickLine={false}
7389
tickFormatter={(value) => `${value}%`}
7490
/>
@@ -144,13 +160,13 @@ export const MovesByRating: React.FC<Props> = ({
144160
yAxisId="left"
145161
dataKey={move}
146162
dot={{
147-
r: 3,
163+
r: isMobile ? 2 : 3,
148164
stroke: colorSanMapping[move]?.color ?? '#fff',
149-
strokeWidth: 3,
165+
strokeWidth: isMobile ? 2 : 3,
150166
}}
151167
stroke={colorSanMapping[move]?.color ?? '#fff'}
152168
fill={`url(#color${move})`}
153-
strokeWidth={3}
169+
strokeWidth={isMobile ? 2 : 3}
154170
animationDuration={300}
155171
name={san}
156172
label={(props: {
@@ -179,7 +195,7 @@ export const MovesByRating: React.FC<Props> = ({
179195
)
180196

181197
let adjustment = 0
182-
const minLabelHeight = 16
198+
const minLabelHeight = isMobile ? 14 : 16
183199

184200
if (currentIndex > 0) {
185201
const prevEndPoint =
@@ -200,9 +216,9 @@ export const MovesByRating: React.FC<Props> = ({
200216

201217
return (
202218
<text
203-
x={props.x + 10}
219+
x={props.x + (isMobile ? 6 : 10)}
204220
y={props.y - adjustment}
205-
dy={4}
221+
dy={isMobile ? 3 : 4}
206222
fontSize={11}
207223
fontWeight={600}
208224
fill={colorSanMapping[move]?.color ?? '#fff'}
@@ -260,7 +276,11 @@ export const MovesByRating: React.FC<Props> = ({
260276
<Legend
261277
align="right"
262278
verticalAlign="top"
263-
wrapperStyle={{ top: -14, right: 20, fontSize: 14 }}
279+
wrapperStyle={{
280+
top: isMobile ? -10 : -14,
281+
right: isMobile ? 10 : 20,
282+
fontSize: 14,
283+
}}
264284
iconSize={0}
265285
formatter={(value) => {
266286
return colorSanMapping[value as string]?.san ?? value

src/pages/analysis/[...id].tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -474,23 +474,11 @@ const Analysis: React.FC<Props> = ({
474474
<span className="font-medium text-primary/80">½-½</span>
475475
) : (
476476
<span className="font-medium">
477-
<span
478-
className={
479-
analyzedGame.termination.winner === 'white'
480-
? 'text-engine-3'
481-
: 'text-primary/70'
482-
}
483-
>
477+
<span className="text-primary/70">
484478
{analyzedGame.termination.winner === 'white' ? '1' : '0'}
485479
</span>
486480
<span className="text-primary/70">-</span>
487-
<span
488-
className={
489-
analyzedGame.termination.winner === 'black'
490-
? 'text-engine-3'
491-
: 'text-primary/70'
492-
}
493-
>
481+
<span className="text-primary/70">
494482
{analyzedGame.termination.winner === 'black' ? '1' : '0'}
495483
</span>
496484
</span>

0 commit comments

Comments
 (0)