From 315120eff96b3339e0eaf101f4e5feba8d14f98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Sat, 29 May 2021 18:17:00 +0200 Subject: [PATCH] When drawing a rect with an inset, leave a sliver of matter (here 0.1px), unless the original width or height is 0. See discussion in #417 --- src/marks/rect.js | 8 ++++++-- test/output/athletesWeightCumulative.svg | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/marks/rect.js b/src/marks/rect.js index cb8d55aaf4..f5ebd26ef5 100644 --- a/src/marks/rect.js +++ b/src/marks/rect.js @@ -76,8 +76,8 @@ export class Rect extends Mark { .call(applyDirectStyles, this) .attr("x", i => Math.min(X1[i], X2[i]) + this.insetLeft) .attr("y", i => Math.min(Y1[i], Y2[i]) + this.insetTop) - .attr("width", i => Math.max(0, Math.abs(X2[i] - X1[i]) - this.insetLeft - this.insetRight)) - .attr("height", i => Math.max(0, Math.abs(Y1[i] - Y2[i]) - this.insetTop - this.insetBottom)) + .attr("width", i => sliver(X2[i] - X1[i], this.insetLeft + this.insetRight)) + .attr("height", i => sliver(Y1[i] - Y2[i], this.insetTop + this.insetBottom)) .call(applyAttr, "fill", F && (i => F[i])) .call(applyAttr, "fill-opacity", FO && (i => FO[i])) .call(applyAttr, "stroke", S && (i => S[i])) @@ -89,6 +89,10 @@ export class Rect extends Mark { } } +function sliver(x, inset) { + return Math.max((x = Math.abs(x)) ? 0.1 : 0, x - inset); +} + export function rect(data, options) { return new Rect(data, options); } diff --git a/test/output/athletesWeightCumulative.svg b/test/output/athletesWeightCumulative.svg index 8325d3041c..2016a28772 100644 --- a/test/output/athletesWeightCumulative.svg +++ b/test/output/athletesWeightCumulative.svg @@ -58,8 +58,8 @@ weight → - - + +