From 08110af6f1fca377fc413fc869fe1cf8c0cb1e2b Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Wed, 22 Jan 2020 11:13:43 -0500 Subject: [PATCH] Proper text alignment for multiline tick labels (#6988) * Proper text alignment for multiline tick labels * Handle other rotations as well --- src/core/core.scale.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index a68745c98..8941c14e0 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -1129,9 +1129,13 @@ class Scale extends Element { if (isHorizontal) { x = pixel; - textOffset = position === 'top' - ? ((!rotation ? 0.5 : 1) - lineCount) * lineHeight - : (!rotation ? 0.5 : 0) * lineHeight; + if (position === 'top') { + textOffset = (Math.sin(rotation) * (lineCount / 2) + 0.5) * lineHeight; + textOffset -= (rotation === 0 ? (lineCount - 0.5) : Math.cos(rotation) * (lineCount / 2)) * lineHeight; + } else { + textOffset = Math.sin(rotation) * (lineCount / 2) * lineHeight; + textOffset += (rotation === 0 ? 0.5 : Math.cos(rotation) * (lineCount / 2)) * lineHeight; + } } else { y = pixel; textOffset = (1 - lineCount) * lineHeight / 2; -- 2.47.2