From 3675ca366472999f919d9249f431fe2379d9468b Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sun, 19 Jan 2020 13:59:59 -0500 Subject: [PATCH 1/2] Proper text alignment for multiline tick labels --- src/core/core.scale.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index a68745c98be..28f6036340e 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -1129,9 +1129,12 @@ 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 = -1 * (!rotation ? (lineCount - 0.5) : (lineCount / 2)) * lineHeight; + } else { + textOffset = (!rotation ? 0.5 : -(lineCount / 2) + 0.5) * lineHeight; + } + } else { y = pixel; textOffset = (1 - lineCount) * lineHeight / 2; From ad04b27ddef26461b53e3a6c7ef752378ca2884f Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sun, 19 Jan 2020 17:58:22 -0500 Subject: [PATCH 2/2] Handle other rotations as well --- src/core/core.scale.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 28f6036340e..8941c14e0ae 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -1130,11 +1130,12 @@ class Scale extends Element { if (isHorizontal) { x = pixel; if (position === 'top') { - textOffset = -1 * (!rotation ? (lineCount - 0.5) : (lineCount / 2)) * lineHeight; + textOffset = (Math.sin(rotation) * (lineCount / 2) + 0.5) * lineHeight; + textOffset -= (rotation === 0 ? (lineCount - 0.5) : Math.cos(rotation) * (lineCount / 2)) * lineHeight; } else { - textOffset = (!rotation ? 0.5 : -(lineCount / 2) + 0.5) * lineHeight; + 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;