Skip to content

Commit

Permalink
Handle center position for vertical axes
Browse files Browse the repository at this point in the history
  • Loading branch information
etimberg committed Jul 15, 2021
1 parent 59c2f13 commit 28651bb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/core/core.scale.js
Expand Up @@ -137,6 +137,7 @@ function titleArgs(scale, offset, position, align) {
let rotation = 0;
let maxWidth, titleX, titleY;
const height = bottom - top;
const width = right - left;

if (scale.isHorizontal()) {
titleX = _alignStartEnd(align, left, right);
Expand All @@ -148,11 +149,19 @@ function titleArgs(scale, offset, position, align) {
} else if (position === 'center') {
titleY = (chartArea.bottom + chartArea.top) / 2 + height - offset;
} else {
titleY = offsetFromEdge(scale, position, offset);
titleY = offsetFromEdge(scale, position, offset);
}
maxWidth = right - left;
} else {
titleX = offsetFromEdge(scale, position, offset);
if (isObject(position)) {
const positionAxisID = Object.keys(position)[0];
const value = position[positionAxisID];
titleX = scales[positionAxisID].getPixelForValue(value) - width + offset;
} else if (position === 'center') {
titleX = (chartArea.left + chartArea.right) / 2 - width + offset;
} else {
titleX = offsetFromEdge(scale, position, offset);
}
titleY = _alignStartEnd(align, bottom, top);
rotation = position === 'left' ? -HALF_PI : HALF_PI;
}
Expand Down

0 comments on commit 28651bb

Please sign in to comment.