Skip to content

Prevent negative radius in drawBox when dimensions are non-positive - #999

Open
chiragbitoni wants to merge 1 commit into
chartjs:masterfrom
chiragbitoni:fix/avoid-negative-radius-box-draw
Open

chiragbitoni wants to merge 1 commit into
chartjs:masterfrom
chiragbitoni:fix/avoid-negative-radius-box-draw

Conversation

@chiragbitoni

Copy link
Copy Markdown

Resolves #986

When a box annotation has negative or zero dimensions (e.g. inverted coordinates or zero width/height), Math.min(width, height) / 2 evaluates to non-positive or negative values. When passed to clampAll, this could produce a negative radius, causing canvas arc() calls to throw an IndexSizeError in browsers.

This change:

  1. Returns early from drawBox if width <= 0 or height <= 0.
  2. Clamps the radius upper bound with Math.max(0, Math.min(width, height) / 2) to guarantee a non-negative radius.
  3. Adds tests in test/specs/box.spec.js asserting that drawing boxes with zero or negative dimensions does not throw.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: IndexSizeError: negative radius passed to canvas.arc when drawing box/label with non-positive size

1 participant