mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Fix point label counting in radialLinear scale (#6280)
This commit is contained in:
parent
e35b8891ce
commit
9482ee55eb
@ -59,11 +59,6 @@ var defaultConfig = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function getValueCount(scale) {
|
|
||||||
var opts = scale.options;
|
|
||||||
return opts.angleLines.display || opts.pointLabels.display ? scale.chart.data.labels.length : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTickBackdropHeight(opts) {
|
function getTickBackdropHeight(opts) {
|
||||||
var tickOpts = opts.ticks;
|
var tickOpts = opts.ticks;
|
||||||
|
|
||||||
@ -153,7 +148,7 @@ function fitWithPointLabels(scale) {
|
|||||||
scale.ctx.font = plFont.string;
|
scale.ctx.font = plFont.string;
|
||||||
scale._pointLabelSizes = [];
|
scale._pointLabelSizes = [];
|
||||||
|
|
||||||
var valueCount = getValueCount(scale);
|
var valueCount = scale.chart.data.labels.length;
|
||||||
for (i = 0; i < valueCount; i++) {
|
for (i = 0; i < valueCount; i++) {
|
||||||
pointPosition = scale.getPointPosition(i, scale.drawingArea + 5);
|
pointPosition = scale.getPointPosition(i, scale.drawingArea + 5);
|
||||||
textSize = measureLabelSize(scale.ctx, plFont.lineHeight, scale.pointLabels[i]);
|
textSize = measureLabelSize(scale.ctx, plFont.lineHeight, scale.pointLabels[i]);
|
||||||
@ -234,7 +229,7 @@ function drawPointLabels(scale) {
|
|||||||
ctx.font = plFont.string;
|
ctx.font = plFont.string;
|
||||||
ctx.textBaseline = 'middle';
|
ctx.textBaseline = 'middle';
|
||||||
|
|
||||||
for (var i = getValueCount(scale) - 1; i >= 0; i--) {
|
for (var i = scale.chart.data.labels.length - 1; i >= 0; i--) {
|
||||||
// Extra pixels out for some label spacing
|
// Extra pixels out for some label spacing
|
||||||
var extra = (i === 0 ? tickBackdropHeight / 2 : 0);
|
var extra = (i === 0 ? tickBackdropHeight / 2 : 0);
|
||||||
var pointLabelPosition = scale.getPointPosition(i, outerDistance + extra + 5);
|
var pointLabelPosition = scale.getPointPosition(i, outerDistance + extra + 5);
|
||||||
@ -255,7 +250,7 @@ function drawPointLabels(scale) {
|
|||||||
function drawRadiusLine(scale, gridLineOpts, radius, index) {
|
function drawRadiusLine(scale, gridLineOpts, radius, index) {
|
||||||
var ctx = scale.ctx;
|
var ctx = scale.ctx;
|
||||||
var circular = gridLineOpts.circular;
|
var circular = gridLineOpts.circular;
|
||||||
var valueCount = getValueCount(scale);
|
var valueCount = scale.chart.data.labels.length;
|
||||||
var lineColor = valueAtIndexOrDefault(gridLineOpts.color, index - 1);
|
var lineColor = valueAtIndexOrDefault(gridLineOpts.color, index - 1);
|
||||||
var lineWidth = valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
|
var lineWidth = valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
|
||||||
var pointPosition;
|
var pointPosition;
|
||||||
@ -403,8 +398,9 @@ module.exports = LinearScaleBase.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getIndexAngle: function(index) {
|
getIndexAngle: function(index) {
|
||||||
var angleMultiplier = 360 / getValueCount(this);
|
var chart = this.chart;
|
||||||
var options = this.chart.options || {};
|
var angleMultiplier = 360 / chart.data.labels.length;
|
||||||
|
var options = chart.options || {};
|
||||||
var startAngle = options.startAngle || 0;
|
var startAngle = options.startAngle || 0;
|
||||||
|
|
||||||
// Start from the top instead of right, so remove a quarter of the circle
|
// Start from the top instead of right, so remove a quarter of the circle
|
||||||
@ -488,7 +484,7 @@ module.exports = LinearScaleBase.extend({
|
|||||||
ctx.lineDashOffset = resolve([angleLineOpts.borderDashOffset, gridLineOpts.borderDashOffset, 0.0]);
|
ctx.lineDashOffset = resolve([angleLineOpts.borderDashOffset, gridLineOpts.borderDashOffset, 0.0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = getValueCount(me) - 1; i >= 0; i--) {
|
for (i = me.chart.data.labels.length - 1; i >= 0; i--) {
|
||||||
offset = me.getDistanceFromCenterForValue(opts.ticks.reverse ? me.min : me.max);
|
offset = me.getDistanceFromCenterForValue(opts.ticks.reverse ? me.min : me.max);
|
||||||
position = me.getPointPosition(i, offset);
|
position = me.getPointPosition(i, offset);
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
|
28
test/fixtures/scale.radialLinear/anglelines-disable.json
vendored
Normal file
28
test/fixtures/scale.radialLinear/anglelines-disable.json
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"type": "radar",
|
||||||
|
"data": {
|
||||||
|
"labels": ["A", "B", "C", "D", "E"]
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"responsive": false,
|
||||||
|
"legend": false,
|
||||||
|
"title": false,
|
||||||
|
"scale": {
|
||||||
|
"gridLines": {
|
||||||
|
"color": "rgb(0, 0, 0)",
|
||||||
|
"lineWidth": 1
|
||||||
|
},
|
||||||
|
"angleLines": {
|
||||||
|
"display": false
|
||||||
|
},
|
||||||
|
"pointLabels": {
|
||||||
|
"display": false
|
||||||
|
},
|
||||||
|
"ticks": {
|
||||||
|
"display": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
test/fixtures/scale.radialLinear/anglelines-disable.png
vendored
Normal file
BIN
test/fixtures/scale.radialLinear/anglelines-disable.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
28
test/fixtures/scale.radialLinear/gridlines-disable.json
vendored
Normal file
28
test/fixtures/scale.radialLinear/gridlines-disable.json
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"type": "radar",
|
||||||
|
"data": {
|
||||||
|
"labels": ["A", "B", "C", "D", "E"]
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"responsive": false,
|
||||||
|
"legend": false,
|
||||||
|
"title": false,
|
||||||
|
"scale": {
|
||||||
|
"gridLines": {
|
||||||
|
"display": false
|
||||||
|
},
|
||||||
|
"angleLines": {
|
||||||
|
"color": "rgb(0, 0, 0)",
|
||||||
|
"lineWidth": 1
|
||||||
|
},
|
||||||
|
"pointLabels": {
|
||||||
|
"display": false
|
||||||
|
},
|
||||||
|
"ticks": {
|
||||||
|
"display": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
test/fixtures/scale.radialLinear/gridlines-disable.png
vendored
Normal file
BIN
test/fixtures/scale.radialLinear/gridlines-disable.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Loading…
Reference in New Issue
Block a user