Skip to content

Commit

Permalink
Fix #51 Circles and arrows are wrong on Chrome Capa boards
Browse files Browse the repository at this point in the history
  • Loading branch information
gbtami committed Jul 24, 2024
1 parent 2be330d commit c96fdf3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chessgroundx",
"version": "10.6.1",
"version": "10.6.2",
"description": "Extended lichess.org Chess UI",
"type": "module",
"module": "chessground.js",
Expand Down
9 changes: 5 additions & 4 deletions src/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,13 @@ function arrowMargin(shorten: boolean): number {

function pos2user(pos: cg.Pos, bounds: ClientRect, bd: cg.BoardDimensions): cg.NumberPair {
let xScale, yScale;
if (bounds.width / bounds.height <= bd.width / bd.height) {
xScale = Math.min(1, bounds.width / bounds.height) * Math.max(1, bd.height / bd.width);
yScale = Math.min(1, bounds.height / bounds.width) * Math.max(1, bd.width / bd.height);
} else {
// Janggi/Xiangqi board needs different calculation
if (bd.width === 9 && bd.height === 10) {
xScale = Math.max(1, bounds.width / bounds.height) * Math.min(1, bd.height / bd.width);
yScale = Math.max(1, bounds.height / bounds.width) * (bd.width / bd.height);
} else {
xScale = Math.min(1, bounds.width / bounds.height) * Math.max(1, bd.height / bd.width);
yScale = Math.min(1, bounds.height / bounds.width) * Math.max(1, bd.width / bd.height);
}
return [(pos[0] - (bd.width - 1) / 2) * xScale, ((bd.height - 1) / 2 - pos[1]) * yScale];
}

0 comments on commit c96fdf3

Please sign in to comment.