Skip to content

Commit 279b6ae

Browse files
authored
Enable multi-line axis titles (#8579)
1 parent a23f1de commit 279b6ae

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

docs/docs/axes/labelling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Namespace: `options.scales[scaleId].title`, it defines options for the scale tit
1212
| ---- | ---- | ------- | -----------
1313
| `display` | `boolean` | `false` | If true, display the axis title.
1414
| `align` | `string` | `'center'` | Alignment of the axis title. Possible options are `'start'`, `'center'` and `'end'`
15-
| `text` | `string` | `''` | The text for the title. (i.e. "# of People" or "Response Choices").
15+
| `text` | `string`\|`string[]` | `''` | The text for the title. (i.e. "# of People" or "Response Choices").
1616
| `color` | [`Color`](../general/colors.md) | `Chart.defaults.color` | Color of label.
1717
| `font` | `Font` | `Chart.defaults.font` | See [Fonts](../general/fonts.md)
1818
| `padding` | `number`\|`object` | `4` | Padding to apply around scale labels. Only `top` and `bottom` are implemented.

src/core/core.scale.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ function getTitleHeight(options, fallback) {
177177

178178
const font = toFont(options.font, fallback);
179179
const padding = toPadding(options.padding);
180+
const lines = isArray(options.text) ? options.text.length : 1;
180181

181-
return font.lineHeight + padding.height;
182+
return (lines * font.lineHeight) + padding.height;
182183
}
183184

184185
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = {
2+
config: {
3+
type: 'line',
4+
data: {
5+
datasets: [{
6+
data: [1, -1, 3],
7+
}],
8+
labels: ['Label1', 'Label2', 'Label3']
9+
},
10+
options: {
11+
scales: {
12+
y: {
13+
title: {
14+
display: true,
15+
text: [
16+
'Line 1',
17+
'Line 2',
18+
'Line 3',
19+
]
20+
}
21+
}
22+
}
23+
}
24+
},
25+
options: {
26+
spriteText: true,
27+
canvas: {
28+
height: 256,
29+
width: 512
30+
}
31+
}
32+
};
17.3 KB
Loading

types/index.esm.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,7 @@ export interface CartesianScaleOptions extends CoreScaleOptions {
26982698

26992699
title: {
27002700
display: boolean;
2701-
text: string;
2701+
text: string | string[];
27022702
color: Color;
27032703
font: FontSpec;
27042704
padding: {

0 commit comments

Comments
 (0)