Skip to content

Commit 19d6df2

Browse files
committed
Fix pointRadius and pointHitRadius settings for radar charts
1 parent 254bd4b commit 19d6df2

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/controllers/controller.radar.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ module.exports = function(Chart) {
7979
var pointElementOptions = me.chart.options.elements.point;
8080
var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
8181

82+
// Compatibility: If the properties are defined with only the old name, use those values
83+
if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
84+
dataset.pointRadius = dataset.radius;
85+
}
86+
if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
87+
dataset.pointHitRadius = dataset.hitRadius;
88+
}
89+
8290
helpers.extend(point, {
8391
// Utility
8492
_datasetIndex: me.index,
@@ -99,7 +107,7 @@ module.exports = function(Chart) {
99107
pointStyle: custom.pointStyle ? custom.pointStyle : helpers.getValueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle),
100108

101109
// Tooltip
102-
hitRadius: custom.hitRadius ? custom.hitRadius : helpers.getValueAtIndexOrDefault(dataset.hitRadius, index, pointElementOptions.hitRadius)
110+
hitRadius: custom.hitRadius ? custom.hitRadius : helpers.getValueAtIndexOrDefault(dataset.pointHitRadius, index, pointElementOptions.hitRadius)
103111
}
104112
});
105113

@@ -150,7 +158,7 @@ module.exports = function(Chart) {
150158
var model = point._model;
151159
var pointElementOptions = this.chart.options.elements.point;
152160

153-
model.radius = custom.radius ? custom.radius : helpers.getValueAtIndexOrDefault(dataset.radius, index, pointElementOptions.radius);
161+
model.radius = custom.radius ? custom.radius : helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius);
154162
model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor);
155163
model.borderColor = custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor);
156164
model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth);

test/specs/controller.radar.tests.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ describe('Radar controller tests', function() {
415415
expect(point._model.radius).toBe(1.01);
416416

417417
// Can set hover style per dataset
418-
chart.data.datasets[0].radius = 3.3;
418+
chart.data.datasets[0].pointRadius = 3.3;
419419
chart.data.datasets[0].pointBackgroundColor = 'rgb(77, 79, 81)';
420420
chart.data.datasets[0].pointBorderColor = 'rgb(123, 125, 127)';
421421
chart.data.datasets[0].pointBorderWidth = 2.1;
@@ -457,4 +457,26 @@ describe('Radar controller tests', function() {
457457
var point = meta.data[0];
458458
expect(point._model.borderWidth).toBe(0);
459459
});
460+
461+
it('should use the pointRadius setting over the radius setting', function() {
462+
var chart = window.acquireChart({
463+
type: 'radar',
464+
data: {
465+
datasets: [{
466+
data: [10, 15, 0, 4],
467+
pointRadius: 10,
468+
radius: 15,
469+
}, {
470+
data: [20, 20, 20, 20],
471+
radius: 20
472+
}],
473+
labels: ['label1', 'label2', 'label3', 'label4']
474+
}
475+
});
476+
477+
var meta0 = chart.getDatasetMeta(0);
478+
var meta1 = chart.getDatasetMeta(1);
479+
expect(meta0.data[0]._model.radius).toBe(10);
480+
expect(meta1.data[0]._model.radius).toBe(20);
481+
});
460482
});

0 commit comments

Comments
 (0)