Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions docs/axes/radial/linear.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Namespace: `options.scales[scaleId].pointLabels`
| ---- | ---- | ------- | ------- | -----------
| `backdropColor` | [`Color`](../../general/colors.md) | `true` | `undefined` | Background color of the point label.
| `backdropPadding` | [`Padding`](../../general/padding.md) | | `2` | Padding of label backdrop.
| `borderRadius` | `number`\|`object` | `true` | `0` | Border radius of the point label
| `display` | `boolean` | | `true` | If true, point labels are shown.
| `callback` | `function` | | | Callback function to transform data labels to point labels. The default implementation simply returns the current string.
| `color` | [`Color`](../../general/colors.md) | Yes | `Chart.defaults.color` | Color of label.
Expand Down
25 changes: 22 additions & 3 deletions src/scales/scale.radialLinear.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import defaults from '../core/core.defaults';
import {_longestText, renderText} from '../helpers/helpers.canvas';
import {_longestText, addRoundedRectPath, renderText} from '../helpers/helpers.canvas';
import {HALF_PI, TAU, toDegrees, toRadians, _normalizeAngle, PI} from '../helpers/helpers.math';
import LinearScaleBase from './scale.linearbase';
import Ticks from '../core/core.ticks';
import {valueOrDefault, isArray, isFinite, callback as callCallback, isNullOrUndef} from '../helpers/helpers.core';
import {createContext, toFont, toPadding} from '../helpers/helpers.options';
import {createContext, toFont, toPadding, toTRBLCorners} from '../helpers/helpers.options';

function getTickBackdropHeight(opts) {
const tickOpts = opts.ticks;
Expand Down Expand Up @@ -208,9 +208,28 @@ function drawPointLabels(scale, labelCount) {
const {backdropColor} = optsAtIndex;

if (!isNullOrUndef(backdropColor)) {
const borderRadius = toTRBLCorners(optsAtIndex.borderRadius);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a default value of 0 added for this new setting after line 606, but then the option failed to work. The proxy always showed the default value instead of what was specified. Not sure why that was the case, but leaving no default also worked

const padding = toPadding(optsAtIndex.backdropPadding);
ctx.fillStyle = backdropColor;
ctx.fillRect(left - padding.left, top - padding.top, right - left + padding.width, bottom - top + padding.height);

const backdropLeft = left - padding.left;
const backdropTop = top - padding.top;
const backdropWidth = right - left + padding.width;
const backdropHeight = bottom - top + padding.height;

if (Object.values(borderRadius).some(v => v !== 0)) {
ctx.beginPath();
addRoundedRectPath(ctx, {
x: backdropLeft,
y: backdropTop,
w: backdropWidth,
h: backdropHeight,
radius: borderRadius,
});
ctx.fill();
} else {
ctx.fillRect(backdropLeft, backdropTop, backdropWidth, backdropHeight);
}
}

renderText(
Expand Down
51 changes: 51 additions & 0 deletions test/fixtures/scale.radialLinear/pointLabels/border-radius.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module.exports = {
tolerance: 0.01,
config: {
type: 'radar',
data: {
labels: [
['VENTE ET', 'COMMERCIALISATION'],
['GESTION', 'FINANCIÈRE'],
'NUMÉRIQUE',
['ADMINISTRATION', 'ET OPÉRATION'],
['RESSOURCES', 'HUMAINES'],
'INNOVATION'
],
datasets: [
{
backgroundColor: '#E43E51',
label: 'Compétences entrepreunariales',
data: [3, 2, 2, 1, 3, 1]
}
]
},
options: {
plugins: {
legend: false,
tooltip: false,
filler: false
},
scales: {
r: {
min: 0,
max: 3,
pointLabels: {
backdropColor: 'blue',
backdropPadding: {left: 5, right: 5, top: 2, bottom: 2},
borderRadius: 10,
},
ticks: {
display: false,
stepSize: 1,
maxTicksLimit: 1
}
}
},
responsive: true,
maintainAspectRatio: false
}
},
options: {
spriteText: true
}
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions types/index.esm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3380,6 +3380,13 @@ export type RadialLinearScaleOptions = CoreScaleOptions & {
*/
backdropPadding: Scriptable<number | ChartArea, ScriptableScalePointLabelContext>;

/**
* Border radius
* @default 0
* @since 3.8.0
*/
borderRadius: Scriptable<number | BorderRadius, ScriptableScalePointLabelContext>;

/**
* if true, point labels are shown.
* @default true
Expand Down