* `data`
* `scale`
* `tick`
+ * `pointLabel` (only used in the radial linear scale)
* `tooltip`
Each level inherits its parent(s) and any contextual information stored in the parent is available through the child.
const valueCount = scale.getLabels().length;
for (let i = 0; i < valueCount; i++) {
- const opts = scale.options.pointLabels.setContext(scale.getContext(i));
+ const opts = scale.options.pointLabels.setContext(scale.getPointLabelContext(i));
padding[i] = opts.padding;
const pointPosition = scale.getPointPosition(i, scale.drawingArea + padding[i]);
const plFont = toFont(opts.font);
const {ctx, options: {pointLabels}} = scale;
for (let i = labelCount - 1; i >= 0; i--) {
- const optsAtIndex = pointLabels.setContext(scale.getContext(i));
+ const optsAtIndex = pointLabels.setContext(scale.getPointLabelContext(i));
const plFont = toFont(optsAtIndex.font);
const {x, y, textAlign, left, top, right, bottom} = scale._pointLabelItems[i];
const {backdropColor} = optsAtIndex;
return isNumber(param) ? param : 0;
}
+function createPointLabelContext(parent, index, label) {
+ return Object.assign(Object.create(parent), {
+ label,
+ index,
+ type: 'pointLabel'
+ });
+}
+
export default class RadialLinearScale extends LinearScaleBase {
constructor(cfg) {
return me.options.reverse ? me.max - scaledDistance : me.min + scaledDistance;
}
+ getPointLabelContext(index) {
+ const me = this;
+ const pointLabels = me._pointLabels || [];
+
+ if (index >= 0 && index < pointLabels.length) {
+ const pointLabel = pointLabels[index];
+ return createPointLabelContext(me.getContext(), index, pointLabel);
+ }
+ }
+
getPointPosition(index, distanceFromCenter) {
const me = this;
const angle = me.getIndexAngle(index) - HALF_PI;
ctx.save();
for (i = me.getLabels().length - 1; i >= 0; i--) {
- const optsAtIndex = angleLines.setContext(me.getContext(i));
+ const optsAtIndex = angleLines.setContext(me.getPointLabelContext(i));
const {color, lineWidth} = optsAtIndex;
if (!lineWidth || !color) {
--- /dev/null
+module.exports = {
+ config: {
+ type: 'radar',
+ data: {
+ labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange', 'Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange', 'Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange', 'Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
+ datasets: [{
+ label: '# of Votes',
+ data: [12, 19, 3, 5, 1, 3, 12, 19, 3, 5, 1, 3, 12, 19, 3, 5, 1, 3, 12, 19, 3, 5, 1, 3]
+ }]
+ },
+ options: {
+ scales: {
+ r: {
+ ticks: {
+ display: false,
+ },
+ angleLines: {
+ color: (ctx) => {
+ return ctx.index % 2 === 0 ? 'green' : 'red';
+ }
+ },
+ pointLabels: {
+ display: false,
+ }
+ }
+ },
+ }
+ },
+ options: {
+ spriteText: true,
+ width: 300,
+ }
+};
tick: Tick;
}
+export interface ScriptableScalePointLabelContext {
+ chart: Chart;
+ scale: Scale;
+ index: number;
+ label: string;
+}
+
+
export const Ticks: {
formatters: {
/**
* Background color of the point label.
* @default undefined
*/
- backdropColor: Scriptable<Color, ScriptableScaleContext>;
+ backdropColor: Scriptable<Color, ScriptableScalePointLabelContext>;
/**
* Padding of label backdrop.
* @default 2
*/
- backdropPadding: Scriptable<number | ChartArea, ScriptableScaleContext>;
+ backdropPadding: Scriptable<number | ChartArea, ScriptableScalePointLabelContext>;
/**
* if true, point labels are shown.
* Color of label
* @see Defaults.color
*/
- color: Scriptable<Color, ScriptableScaleContext>;
+ color: Scriptable<Color, ScriptableScalePointLabelContext>;
/**
*/
- font: Scriptable<FontSpec, ScriptableScaleContext>;
+ font: Scriptable<FontSpec, ScriptableScalePointLabelContext>;
/**
* Callback function to transform data labels to point labels. The default implementation simply returns the current string.