Skip to content

Commit 3908ff9

Browse files
committed
Update tick backdrop padding options
1 parent 6a3b11e commit 3908ff9

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

docs/docs/axes/radial/linear.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ Namespace: `options.scales[scaleId].ticks`
3434
| Name | Type | Scriptable | Default | Description
3535
| ---- | ---- | ------- | ------- | -----------
3636
| `backdropColor` | [`Color`](../../general/colors.md) | Yes | `'rgba(255, 255, 255, 0.75)'` | Color of label backdrops.
37-
| `backdropPaddingX` | `number` | | `2` | Horizontal padding of label backdrop.
38-
| `backdropPaddingY` | `number` | | `2` | Vertical padding of label backdrop.
37+
| `backdropPadding` | `number`\|`{top: number, bottom: number}` | | `2` | Padding of label backdrop.
3938
| `format` | `object` | | | The [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) options used by the default label formatter
4039
| `maxTicksLimit` | `number` | | `11` | Maximum number of ticks and gridlines to show.
4140
| `precision` | `number` | | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places.

docs/docs/getting-started/v3-migration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ Animation system was completely rewritten in Chart.js v3. Each property can now
235235
* `options.ticks.fixedStepSize` is no longer used. Use `options.ticks.stepSize`.
236236
* `options.ticks.major` and `options.ticks.minor` were replaced with scriptable options for tick fonts.
237237
* `Chart.Ticks.formatters.linear` was renamed to `Chart.Ticks.formatters.numeric`.
238+
* `options.ticks.backdropPaddingX` and `options.ticks.backdropPaddingY` were replaced with `options.ticks.backdropPadding` in the radial linear scale.
238239

239240
#### Tooltip
240241

src/scales/scale.radialLinear.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ function getTickBackdropHeight(opts) {
1010
const tickOpts = opts.ticks;
1111

1212
if (tickOpts.display && opts.display) {
13-
return valueOrDefault(tickOpts.font && tickOpts.font.size, defaults.font.size) + tickOpts.backdropPaddingY * 2;
13+
const padding = toPadding(tickOpts.backdropPadding);
14+
return valueOrDefault(tickOpts.font && tickOpts.font.size, defaults.font.size) + padding.height;
1415
}
1516
return 0;
1617
}
@@ -540,12 +541,12 @@ export default class RadialLinearScale extends LinearScaleBase {
540541
width = ctx.measureText(tick.label).width;
541542
ctx.fillStyle = optsAtIndex.backdropColor;
542543

543-
const {backdropPaddingX, backdropPaddingY} = optsAtIndex;
544+
const padding = toPadding(optsAtIndex.backdropPadding);
544545
ctx.fillRect(
545-
-width / 2 - backdropPaddingX,
546-
-offset - tickFont.size / 2 - backdropPaddingY,
547-
width + backdropPaddingX * 2,
548-
tickFont.size + backdropPaddingY * 2
546+
-width / 2 - padding.left,
547+
-offset - tickFont.size / 2 - padding.top,
548+
width + padding.width,
549+
tickFont.size + padding.height
549550
);
550551
}
551552

@@ -596,11 +597,8 @@ RadialLinearScale.defaults = {
596597
// String - The colour of the label backdrop
597598
backdropColor: 'rgba(255,255,255,0.75)',
598599

599-
// Number - The backdrop padding above & below the label in pixels
600-
backdropPaddingY: 2,
601-
602-
// Number - The backdrop padding to the side of the label in pixels
603-
backdropPaddingX: 2,
600+
// Number/Object - The backdrop padding of the label in pixels
601+
backdropPadding: 2,
604602

605603
callback: Ticks.formatters.numeric
606604
},

test/specs/scale.radialLinear.tests.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ describe('Test the radial linear scale', function() {
3737
color: Chart.defaults.color,
3838
showLabelBackdrop: true,
3939
backdropColor: 'rgba(255,255,255,0.75)',
40-
backdropPaddingY: 2,
41-
backdropPaddingX: 2,
40+
backdropPadding: 2,
4241
callback: defaultConfig.ticks.callback
4342
},
4443

types/index.esm.d.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,15 +3054,10 @@ export type RadialLinearScaleOptions = CoreScaleOptions & {
30543054
*/
30553055
backdropColor: Scriptable<Color, ScriptableScaleContext>;
30563056
/**
3057-
* Horizontal padding of label backdrop.
3058-
* @default 2
3059-
*/
3060-
backdropPaddingX: number;
3061-
/**
3062-
* Vertical padding of label backdrop.
3057+
* Padding of label backdrop.
30633058
* @default 2
30643059
*/
3065-
backdropPaddingY: number;
3060+
backdropPadding: number | ChartArea;
30663061

30673062
/**
30683063
* The Intl.NumberFormat options used by the default label formatter

0 commit comments

Comments
 (0)