Skip to content

Commit

Permalink
refactor: extract text anchor constants
Browse files Browse the repository at this point in the history
  • Loading branch information
isqua committed Jun 2, 2024
1 parent 433ddd6 commit e062cfa
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e062cfa

Please sign in to comment.