Fix offset on doughnut charts (#10469)

Fix offset on doughnut charts
This commit is contained in:
Ivan Gamboa Ultreras 2022-08-03 12:27:17 -05:00 committed by GitHub
parent 9224e57d93
commit 9ab50e6313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 10 deletions

View File

@ -332,7 +332,7 @@ export default class ArcElement extends Element {
draw(ctx) { draw(ctx) {
const {options, circumference} = this; const {options, circumference} = this;
const offset = (options.offset || 0) / 2; const offset = (options.offset || 0) / 4;
const spacing = (options.spacing || 0) / 2; const spacing = (options.spacing || 0) / 2;
const circular = options.circular; const circular = options.circular;
this.pixelMargin = (options.borderAlign === 'inner') ? 0.33 : 0; this.pixelMargin = (options.borderAlign === 'inner') ? 0.33 : 0;
@ -344,15 +344,10 @@ export default class ArcElement extends Element {
ctx.save(); ctx.save();
let radiusOffset = 0; const halfAngle = (this.startAngle + this.endAngle) / 2;
if (offset) { ctx.translate(Math.cos(halfAngle) * offset, Math.sin(halfAngle) * offset);
radiusOffset = offset / 2; const fix = 1 - Math.sin(Math.min(PI, circumference || 0));
const halfAngle = (this.startAngle + this.endAngle) / 2; const radiusOffset = offset * fix;
ctx.translate(Math.cos(halfAngle) * radiusOffset, Math.sin(halfAngle) * radiusOffset);
if (this.circumference >= PI) {
radiusOffset = offset;
}
}
ctx.fillStyle = options.backgroundColor; ctx.fillStyle = options.backgroundColor;
ctx.strokeStyle = options.borderColor; ctx.strokeStyle = options.borderColor;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 28 KiB