From: Megaemce <1651451+Megaemce@users.noreply.github.com> Date: Sat, 24 Feb 2024 19:30:35 +0000 (+0700) Subject: fix #11503, autoskipping 0 ticks when min is below 0 (#11682) X-Git-Tag: v4.4.2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4068bd8c47497c3e05688d0c939b711e8c5e1c33;p=thirdparty%2FChart.js.git fix #11503, autoskipping 0 ticks when min is below 0 (#11682) --- diff --git a/src/scales/scale.radialLinear.js b/src/scales/scale.radialLinear.js index 23e207bd5..1e3f79690 100644 --- a/src/scales/scale.radialLinear.js +++ b/src/scales/scale.radialLinear.js @@ -578,7 +578,7 @@ export default class RadialLinearScale extends LinearScaleBase { if (grid.display) { this.ticks.forEach((tick, index) => { - if (index !== 0) { + if (index !== 0 || (index === 0 && this.min < 0)) { offset = this.getDistanceFromCenterForValue(tick.value); const context = this.getContext(index); const optsAtIndex = grid.setContext(context); @@ -645,7 +645,7 @@ export default class RadialLinearScale extends LinearScaleBase { ctx.textBaseline = 'middle'; this.ticks.forEach((tick, index) => { - if (index === 0 && !opts.reverse) { + if ((index === 0 && this.min >= 0) && !opts.reverse) { return; } diff --git a/test/fixtures/scale.radialLinear/ticks-below-zero.js b/test/fixtures/scale.radialLinear/ticks-below-zero.js new file mode 100644 index 000000000..75647815a --- /dev/null +++ b/test/fixtures/scale.radialLinear/ticks-below-zero.js @@ -0,0 +1,45 @@ +module.exports = { + config: { + type: 'radar', + data: { + labels: ['A', 'B', 'C', 'D', 'E'] + }, + options: { + responsive: false, + scales: { + r: { + min: -1, + max: 1, + grid: { + display: true, + color: 'blue', + lineWidth: 2 + }, + angleLines: { + color: 'rgba(255, 255, 255, 0.5)', + lineWidth: 2 + }, + pointLabels: { + display: false + }, + ticks: { + display: true, + autoSkip: false, + stepSize: 0.2, + callback: function(value) { + if (value === 0.8) { + return 'Strong'; + } + if (value === 0.4) { + return 'Weak'; + } + if (value === 0) { + return 'No'; + } + } + } + } + } + } + } +}; diff --git a/test/fixtures/scale.radialLinear/ticks-below-zero.png b/test/fixtures/scale.radialLinear/ticks-below-zero.png new file mode 100644 index 000000000..36435fd1e Binary files /dev/null and b/test/fixtures/scale.radialLinear/ticks-below-zero.png differ