Skip to content

Commit 4c3e992

Browse files
authored
RadialLinear: add padding option for point labels (#8604)
* RadialLinear: add padding option for point labels * lint * only resolve padding once
1 parent c27c27a commit 4c3e992

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

docs/docs/axes/radial/linear.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Namespace: `options.scales[scaleId].pointLabels`
130130
| `callback` | `function` | | | Callback function to transform data labels to point labels. The default implementation simply returns the current string.
131131
| `color` | [`Color`](../../general/colors.md) | Yes | `Chart.defaults.color` | Color of label.
132132
| `font` | `Font` | Yes | `Chart.defaults.font` | See [Fonts](./general/fonts.md)
133+
| `padding` | `number` | Yes | 5 | Padding between chart and point labels.
133134

134135
The scriptable context is described in [Options](../../general/options.md#scale) section.
135136

src/scales/scale.radialLinear.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ function fitWithPointLabels(scale) {
9191
let i, textSize, pointPosition;
9292

9393
const labelSizes = [];
94+
const padding = [];
9495

9596
const valueCount = scale.chart.data.labels.length;
9697
for (i = 0; i < valueCount; i++) {
97-
pointPosition = scale.getPointPosition(i, scale.drawingArea + 5);
9898
const opts = scale.options.pointLabels.setContext(scale.getContext(i));
99+
padding[i] = opts.padding;
100+
pointPosition = scale.getPointPosition(i, scale.drawingArea + padding[i]);
99101
const plFont = toFont(opts.font);
100102
scale.ctx.font = plFont.string;
101103
textSize = measureLabelSize(scale.ctx, plFont.lineHeight, scale._pointLabels[i]);
@@ -140,7 +142,7 @@ function fitWithPointLabels(scale) {
140142
for (i = 0; i < valueCount; i++) {
141143
// Extra pixels out for some label spacing
142144
const extra = (i === 0 ? tickBackdropHeight / 2 : 0);
143-
const pointLabelPosition = scale.getPointPosition(i, outerDistance + extra + 5);
145+
const pointLabelPosition = scale.getPointPosition(i, outerDistance + extra + padding[i]);
144146

145147
const angle = toDegrees(scale.getIndexAngle(i));
146148
const size = labelSizes[i];
@@ -592,7 +594,10 @@ RadialLinearScale.defaults = {
592594
// Function - Used to convert point labels
593595
callback(label) {
594596
return label;
595-
}
597+
},
598+
599+
// Number - Additionl padding between scale and pointLabel
600+
padding: 5
596601
}
597602
};
598603

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module.exports = {
2+
config: {
3+
type: 'radar',
4+
data: {
5+
labels: [
6+
['VENTE ET', 'COMMERCIALISATION'],
7+
['GESTION', 'FINANCIÈRE'],
8+
'NUMÉRIQUE',
9+
['ADMINISTRATION', 'ET OPÉRATION'],
10+
['RESSOURCES', 'HUMAINES'],
11+
'INNOVATION'
12+
],
13+
datasets: [
14+
{
15+
radius: 12,
16+
backgroundColor: '#E43E51',
17+
label: 'Compétences entrepreunariales',
18+
data: [3, 2, 2, 1, 3, 1]
19+
}
20+
]
21+
},
22+
options: {
23+
plugins: {
24+
legend: false,
25+
tooltip: false,
26+
filler: false
27+
},
28+
scales: {
29+
r: {
30+
min: 0,
31+
max: 3,
32+
pointLabels: {
33+
padding: 30
34+
},
35+
ticks: {
36+
display: false,
37+
stepSize: 1,
38+
maxTicksLimit: 1
39+
}
40+
}
41+
},
42+
responsive: true,
43+
maintainAspectRatio: false
44+
}
45+
},
46+
options: {
47+
spriteText: true
48+
}
49+
};
Loading

test/specs/scale.radialLinear.tests.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ describe('Test the radial linear scale', function() {
4848
font: {
4949
size: 10
5050
},
51-
callback: defaultConfig.pointLabels.callback
51+
callback: defaultConfig.pointLabels.callback,
52+
padding: 5
5253
}
5354
});
5455

0 commit comments

Comments
 (0)