From e062cfaaaae3cb78c7e885805f1ac5edcbc3f16e Mon Sep 17 00:00:00 2001 From: isqua Date: Sun, 2 Jun 2024 14:24:46 +0700 Subject: [PATCH] refactor: extract text anchor constants --- src/svg.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/svg.ts b/src/svg.ts index c395d46..f54acb2 100644 --- a/src/svg.ts +++ b/src/svg.ts @@ -28,6 +28,9 @@ const viewPortWidth = 1280; const viewPortHeight = 720; const stripesEnd = 180; const minVisibleWidth = 20; +const textStartAnchor = 320; +const textMiddleAnchor = 730; +const textEndAnchor = 1180; export class SvgBuilder { private readonly nameSpace = "http://www.w3.org/2000/svg"; @@ -83,15 +86,15 @@ export class SvgBuilder { switch (options.textAlign) { case "left": - this.title.setAttribute("x", "320"); + this.title.setAttribute("x", textStartAnchor.toString()); this.title.setAttribute("text-anchor", "start"); break; case "center": - this.title.setAttribute("x", "730"); + this.title.setAttribute("x", textMiddleAnchor.toString()); this.title.setAttribute("text-anchor", "middle"); break; case "right": - this.title.setAttribute("x", "1180"); + this.title.setAttribute("x", textEndAnchor.toString()); this.title.setAttribute("text-anchor", "end"); break; }