Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add label alignment option to axis label title #6521

Merged
merged 11 commits into from
Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/axes/labelling.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The scale label configuration is nested under the scale configuration in the `sc
| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
| `display` | `boolean` | `false` | If true, display the axis title.
| `labelAlign` | `string` | `'center'` | Alignment of the axis title. Possible options are `'start'`, `'center'` and `'end'`
| `align` | `string` | `'center'` | Alignment of the axis title. Possible options are `'start'`, `'center'` and `'end'`
| `labelString` | `string` | `''` | The text for the title. (i.e. "# of People" or "Response Choices").
| `lineHeight` | <code>number&#124;string</code> | `1.2` | Height of an individual line of text (see [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height)).
| `fontColor` | `Color` | `'#666'` | Font color for scale title.
Expand Down
6 changes: 3 additions & 3 deletions src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -1205,14 +1205,14 @@ var Scale = Element.extend({
var scaleLabelFont = helpers.options._parseFont(scaleLabel);
var scaleLabelPadding = helpers.options.toPadding(scaleLabel.padding);
var halfLineHeight = scaleLabelFont.lineHeight / 2;
var scaleLabelAlign = scaleLabel.labelAlign;
var scaleAlign = scaleLabel.align;
el marked this conversation as resolved.
Show resolved Hide resolved
var position = options.position;
var rotation = 0;
var scaleLabelX, scaleLabelY, textAlign;
var isReverse = me.options.ticks.reverse;
el marked this conversation as resolved.
Show resolved Hide resolved

if (me.isHorizontal()) {
switch (scaleLabelAlign) {
switch (scaleAlign) {
case 'start':
scaleLabelX = me.left;
el marked this conversation as resolved.
Show resolved Hide resolved
textAlign = isReverse ? 'right' : 'left';
Expand All @@ -1234,7 +1234,7 @@ var Scale = Element.extend({
scaleLabelX = isLeft
? me.left + halfLineHeight + scaleLabelPadding.top
: me.right - halfLineHeight - scaleLabelPadding.top;
switch (scaleLabelAlign) {
switch (scaleAlign) {
case 'start':
scaleLabelY = me.top + (startsAtBottom ? me.height : 0);
textAlign = (startsAtBottom ^ !isLeft) ? 'left' : 'right';
el marked this conversation as resolved.
Show resolved Hide resolved
Expand Down