From 2be330dfc8ab1ea6731a687a170773baf62d556d Mon Sep 17 00:00:00 2001 From: gbtami Date: Mon, 1 Jul 2024 01:12:21 +0200 Subject: [PATCH] Fix Janggi arrows and circles --- package.json | 2 +- src/svg.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index df5d9ea..0f41191 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chessgroundx", - "version": "10.6.0", + "version": "10.6.1", "description": "Extended lichess.org Chess UI", "type": "module", "module": "chessground.js", diff --git a/src/svg.ts b/src/svg.ts index 2a8f5c7..c6d616b 100644 --- a/src/svg.ts +++ b/src/svg.ts @@ -191,7 +191,7 @@ function renderCircle( ): SVGElement { const o = pos2user(pos, bounds, bd), widths = circleWidth(), - radius = (bounds.width + bounds.height) / (4 * Math.max(bounds.width, bounds.height)); + radius = Math.min(bd.width / (2 * bd.height), (bounds.width / bd.width) / (2 * bounds.height / bd.height)); return setAttributes(createElement('circle'), { stroke: brush.color, 'stroke-width': widths[current ? 0 : 1], @@ -289,7 +289,13 @@ function arrowMargin(shorten: boolean): number { } function pos2user(pos: cg.Pos, bounds: ClientRect, bd: cg.BoardDimensions): cg.NumberPair { - const xScale = Math.min(1, bounds.width / bounds.height) * Math.max(1, bd.height / bd.width); - const yScale = Math.min(1, bounds.height / bounds.width) * Math.max(1, bd.width / bd.height); + 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 { + 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); + } return [(pos[0] - (bd.width - 1) / 2) * xScale, ((bd.height - 1) / 2 - pos[1]) * yScale]; }