From: Ivan Gamboa Ultreras <36210451+Zivangu9@users.noreply.github.com> Date: Wed, 3 Aug 2022 17:27:17 +0000 (-0500) Subject: Fix offset on doughnut charts (#10469) X-Git-Tag: v4.0.0~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ab50e6313f4233bd561c1824c2c7aec28c8e379;p=thirdparty%2FChart.js.git Fix offset on doughnut charts (#10469) Fix offset on doughnut charts --- diff --git a/src/elements/element.arc.js b/src/elements/element.arc.js index 3ec9091b7..439c025ab 100644 --- a/src/elements/element.arc.js +++ b/src/elements/element.arc.js @@ -332,7 +332,7 @@ export default class ArcElement extends Element { draw(ctx) { const {options, circumference} = this; - const offset = (options.offset || 0) / 2; + const offset = (options.offset || 0) / 4; const spacing = (options.spacing || 0) / 2; const circular = options.circular; this.pixelMargin = (options.borderAlign === 'inner') ? 0.33 : 0; @@ -344,15 +344,10 @@ export default class ArcElement extends Element { ctx.save(); - let radiusOffset = 0; - if (offset) { - radiusOffset = offset / 2; - const halfAngle = (this.startAngle + this.endAngle) / 2; - ctx.translate(Math.cos(halfAngle) * radiusOffset, Math.sin(halfAngle) * radiusOffset); - if (this.circumference >= PI) { - radiusOffset = offset; - } - } + const halfAngle = (this.startAngle + this.endAngle) / 2; + ctx.translate(Math.cos(halfAngle) * offset, Math.sin(halfAngle) * offset); + const fix = 1 - Math.sin(Math.min(PI, circumference || 0)); + const radiusOffset = offset * fix; ctx.fillStyle = options.backgroundColor; ctx.strokeStyle = options.borderColor; diff --git a/test/fixtures/controller.doughnut/doughnut-offset.png b/test/fixtures/controller.doughnut/doughnut-offset.png index e4e23f6ec..a45212d6b 100644 Binary files a/test/fixtures/controller.doughnut/doughnut-offset.png and b/test/fixtures/controller.doughnut/doughnut-offset.png differ diff --git a/test/fixtures/controller.doughnut/doughnut-spacing-and-offset.png b/test/fixtures/controller.doughnut/doughnut-spacing-and-offset.png index e78e313dd..0a68820fa 100644 Binary files a/test/fixtures/controller.doughnut/doughnut-spacing-and-offset.png and b/test/fixtures/controller.doughnut/doughnut-spacing-and-offset.png differ diff --git a/test/fixtures/controller.doughnut/pie-offset.png b/test/fixtures/controller.doughnut/pie-offset.png index c2cf18bf5..6697d8acd 100644 Binary files a/test/fixtures/controller.doughnut/pie-offset.png and b/test/fixtures/controller.doughnut/pie-offset.png differ