From: Jukka Kurkela Date: Sat, 18 Jan 2020 00:06:51 +0000 (+0200) Subject: Fix bar border artifacts (#6972) X-Git-Tag: v3.0.0-alpha~120 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35adcd6c2b26022cdd936b75bc85108d8aa0a15e;p=thirdparty%2FChart.js.git Fix bar border artifacts (#6972) --- diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index c4ad49a9e..85d957a52 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -135,25 +135,23 @@ class Rectangle extends Element { } draw(ctx) { - var options = this.options; - var rects = boundingRects(this); - var outer = rects.outer; - var inner = rects.inner; + const options = this.options; + const {inner, outer} = boundingRects(this); - ctx.fillStyle = options.backgroundColor; - ctx.fillRect(outer.x, outer.y, outer.w, outer.h); + ctx.save(); - if (outer.w === inner.w && outer.h === inner.h) { - return; + if (outer.w !== inner.w || outer.h !== inner.h) { + ctx.beginPath(); + ctx.rect(outer.x, outer.y, outer.w, outer.h); + ctx.clip(); + ctx.rect(inner.x, inner.y, inner.w, inner.h); + ctx.fillStyle = options.borderColor; + ctx.fill('evenodd'); } - ctx.save(); - ctx.beginPath(); - ctx.rect(outer.x, outer.y, outer.w, outer.h); - ctx.clip(); - ctx.fillStyle = options.borderColor; - ctx.rect(inner.x, inner.y, inner.w, inner.h); - ctx.fill('evenodd'); + ctx.fillStyle = options.backgroundColor; + ctx.fillRect(inner.x, inner.y, inner.w, inner.h); + ctx.restore(); } diff --git a/test/fixtures/controller.bar/horizontal-borders.png b/test/fixtures/controller.bar/horizontal-borders.png index d6a10eab0..1cd6913ac 100644 Binary files a/test/fixtures/controller.bar/horizontal-borders.png and b/test/fixtures/controller.bar/horizontal-borders.png differ