Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
🐛 Fix centering of tick labels
Browse files Browse the repository at this point in the history
  • Loading branch information
aarthificial authored and hhenrichsen committed Nov 30, 2023
1 parent 696cc1e commit 51fbf87
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Plot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ export class Plot extends Layout {

context.fillStyle = resolveCanvasStyle(this.xAxisTextColor(), context);
context.font = `${this.tickLabelSize().y}px sans-serif`;
context.textAlign = 'right';
context.textAlign = 'center';
context.textBaseline = 'top';
context.fillText(
`${this.xLabelFormatter(this.mapToX(i / this.ticks().x))}`,
startPosition.x,
Expand Down Expand Up @@ -203,13 +204,14 @@ export class Plot extends Layout {
context.fillStyle = resolveCanvasStyle(this.yAxisTextColor(), context);
context.font = `${this.tickLabelSize().y}px ${this.fontFamily()}`;
context.textAlign = 'right';
context.textBaseline = 'middle';
context.fillText(
`${this.yLabelFormatter(this.mapToY(i / this.ticks().y))}`,
tl.x -
this.tickLabelSize().y -
this.tickOverflow().y -
this.axisStrokeWidth().y,
startPosition.y + this.tickLabelSize().y / 2,
startPosition.y,
);
}

Expand Down Expand Up @@ -247,6 +249,7 @@ export class Plot extends Layout {
context.fillStyle = resolveCanvasStyle(this.xAxisTextColor(), context);
context.font = `${this.labelSize().y}px ${this.fontFamily()}`;
context.textAlign = 'center';
context.textBaseline = 'alphabetic';
context.fillText(
this.xAxisLabel(),
this.edgePadding().x / 2,
Expand All @@ -257,6 +260,7 @@ export class Plot extends Layout {
context.fillStyle = resolveCanvasStyle(this.yAxisTextColor(), context);
context.font = `${this.labelSize().y}px ${this.fontFamily()}`;
context.textAlign = 'center';
context.textBaseline = 'alphabetic';
context.save();
context.translate(
-halfSize.x + this.labelPadding().y / 2 + this.labelSize().y,
Expand Down

0 comments on commit 51fbf87

Please sign in to comment.