Skip to content

keep non-zero rects visible #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/marks/rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions test/output/athletesWeightCumulative.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.