252 Commits

Author SHA1 Message Date
Josh Kelley
2898a6d1c7 Use integer canvas dimensions (#12142) 2025-11-16 19:42:40 +01:00
Bojidar Marinov
5feebdf7b7 Fix charts shinking in size on certain Zoom values in Chrome (#12097) 2025-07-11 21:38:17 +02:00
Adrian Cerbaro
3dffb4fb8e fix: respect dataset clipping area when filling line charts (#12057)
* fix(plugin.filler): respect dataset clipping area when filling line charts

The filling area must respect the dataset's clipping area when clipping is enabled. Before this change, the line would be clipped according to the dataset's area but the fill would overlap other datasets.

Closes #12052

* chore(plugin.filler): use @ts-expect-error instead of @ts-ignore
2025-04-14 15:41:14 +02:00
Josh Kelley
2f425290ee [fix] Handle non-primitives in isNumber (#12034)
While investigating https://github.com/chartjs/chartjs-plugin-zoom/issues/928, I found that `isNonPrimitive` will throw TypeError on a Moment.js object after it's passed through Chart.js's options proxy, because the object has its `Symbol.toPrimitive`, `toString`, and `valueOf` all set to null.

(See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion for background reading.)

Since isNumber appears to be a low-level function that can take any arbitrary input, it seems worth letting it handle this case.
2025-02-16 12:24:26 -05:00
Josh Kelley
370f6c385d Fix helpers Chart type (#12012)
helpers.dom.ts functions referenced the internal `Chart` JavaScript class rather than the published `Chart<TType, TData, TLabel>` TypeScript definition. This causes errors when outside code tries to call helper functions.

The two `Chart` interfaces are incompatible - the `width`, `height`, and `currentDevicePixelRatio` properties are declared as readonly in the TS declaration but are manipulated by helpers.dom.ts functions, and helpers.dom.ts functions need to be invoked both by internal Chart.js code (which uses the JS class) and by outside code (which uses the TS types). To address this, I'm importing the JS version as `PrivateChart`. There may be a better solution.

It's my understanding that the comment about "typedefs are auto-exported" is obsolete now that helpers.dom is a native TS file.

Fixes #11153
2025-01-30 10:29:19 +01:00
Mariss Tubelis
a77a63b16b Bugfix: return nearest non-null point on interaction when spanGaps=true (#11986)
* First step in fixing the bug of spanGaps null point interaction

* Complete bugfix of spanGaps null point interaction

* Add two tests in core.interaction.tests for the bugfix change

* Remove odd line break

* Use isNullOrUndef helper for point value checks

* Add 10 more test cases for nearest interaction when spanGaps=true
2025-01-03 10:50:56 -05:00
Mariss Tubelis
1e3d6e5711 Bugfix: span gaps over null values beyond scale limits (#11984)
* Bugfix: spanGaps not working near min and max limits

* Fix error when meta.dataset.options = null

* Add tests for correct setting of line controller properties _drawStart and _drawCount

* Fix spacing in controller line tests

* Add tension to test

* Add a better test case

* Avoid the use of FindLastIndex

* Avoid taking 0 for null value and improve naming
2025-01-02 19:17:24 -05:00
Mikhail
49256c6149 simplify check undefinded (#11501) 2024-11-18 15:24:43 -05:00
Arun Philip
e7b8fa290f do not attempt to clear canvas if one does not exist (#11764)
* do not attempt to clear canvas if one does not exist

* update test to explicitly run clearCanvas method to ensure it doesn't throw an error

* explicitly set canvas and ctx to null in test since the helper in test code didn't

* Update test/specs/helpers.canvas.tests.js

---------

Co-authored-by: Jacco van den Berg <jaccoberg2281@gmail.com>
2024-05-17 08:16:58 -04:00
EricWittrock
f785882aeb Fix error when object prototype is frozen (#11754) 2024-04-29 06:42:05 +02:00
Arun Philip
1777f959e5 platform.isAttached should return false if canvas is false-y (#11707)
* platform.isAttached should return false if canvas is false-y

* change styling to conform to codeclimate linter
2024-03-11 09:57:07 +01:00
Kevin Read
e92d10445b fix: Guard access to window in helpers.dom.ts for browserless rendering (#11588) 2023-11-17 16:34:20 +01:00
Bogdan Korshunov
132324f5b8 BorderRadius of Bar Chart issue on Firefox 116 (#11435)
Co-authored-by: bogdankorshunov <korshunov.oren@gmail.com>
2023-08-07 20:16:32 +02:00
stockiNail
cc7ee8ade1 Fix curve path if scale limits are set for line chart (#11377)
* Fix curve path if scale limits are set for line chart

* add scale limits test case
2023-07-24 19:58:23 +02:00
stockiNail
ee7e928cfe Enable applying of gradients and pattern on line segments (#11217)
* Enable applying of gradients and pattern on line segments

* add test case

* improve replacer
2023-04-27 18:25:13 -04:00
Dan Onoshko
c0bf05f87d refactor: rewrite config helpers to ts (#11121)
* refactor: rewrite config helpers to ts

* refactor: review fixes
2023-03-21 16:03:15 -04:00
Dan Onoshko
1324672637 refactor: rewrite canvas helpers to ts (#11100)
* refactor: rewrite canvas helpers to ts

* refactor: review fixes

* refactor: rm src/helpers/types.ts temporary entry point
2023-02-15 09:26:49 -05:00
Mikhail
22c6906bbe Simplify _arrayUnique (#11145) 2023-02-15 09:20:29 -05:00
Guy B
9306d7fd49 fix: avoid resize loop when browser zoom is set to 90% (#10971)
* test: new test to reproduce issue #10951

* test:  validate the canvas style too

* fix: Avoid reassigning the the chart size. For specific values of pixelRatio the assignment would cause the size to reduce by 1px. Since it's called from the ResizeObserver it will be stuck in a loop that constantly reduce the size of the chart and canvas.

* Revert "fix: Avoid reassigning the the chart size. For specific values of pixelRatio the assignment would cause the size to reduce by 1px. Since it's called from the ResizeObserver it will be stuck in a loop that constantly reduce the size of the chart and canvas."

This reverts commit ed7a34814d.

* fix: Avoid the resize loop by fixing the rounding error in the retinaScale function.

* fix: getMaximumSize was flooring non-integer height values unnecessarily.

* Revert "fix: Avoid the resize loop by fixing the rounding error in the retinaScale function."

This reverts commit 23525abc6a.

* fix: Avoid the resize loop by fixing the rounding error in the retinaScale function.
2022-12-17 09:41:21 -05:00
Dan Onoshko
64a027874c fix: move types to src dir to escape src / dist dirs in paths (#10993) 2022-12-16 07:56:06 -05:00
Dan Onoshko
185bb97d2e fix: turn on types linting (#10962) 2022-12-16 01:09:14 +02:00
Evert Timberg
b491554995 Ensure that args are saved inside of the throttled helper (#10942)
* Ensure that args are saved inside of the throttled helper

* Capture args in outer scope

* Simplify capture
2022-12-10 08:21:41 -05:00
Jacco van den Berg
9a9ff6fdbd Pointstyle false (#10886)
* fix-#10755

* none to false

* str to bool

* str to bool

* 10/10

* fix test

Co-authored-by: puneetkathar1 <puneetkathar1@gmail.com>
Co-authored-by: Puneet Kathar <73285338+puneetkathar1@users.noreply.github.com>
2022-11-18 13:14:47 -05:00
Dan Onoshko
51441272a7 refactor: move to esm in sources (#10879) 2022-11-17 08:08:44 -05:00
Lucca Miranda
24745fac51 refactor: migrate helpers.options to typescript (#10753)
* refactor: migrate helpers.options to typescript

* chore: nitpicks
2022-11-04 11:17:09 -04:00
cmcnulty
fbf3427ca2 Fix #10749 - backdrops with rotated labels (#10759)
* Fix #10749 - backdrops with rotated labels

* remove translation adjustment
Because backdrop now occurs after translation, we don't want to double-adjust the position.

* increase tolerance slightly due to anti-aliasing

Co-authored-by: Charles McNulty <charles.mcnulty@tasconline.com>
2022-10-12 07:08:22 -04:00
Lucca Miranda
b0160e138a refactor: migrate helpers.dom to typescript (#10734) 2022-10-09 09:21:12 -04:00
Evert Timberg
41612d1320 Convert the curve helpers to TS (#10733)
* Convert the curve helpers to TS
* Remove old type
2022-10-07 08:28:24 -04:00
Evert Timberg
e6892a92cb Convert helpers.extra to TS (#10728)
Co-authored-by: Chart.js <>
2022-10-06 15:37:42 -04:00
Dan Onoshko
d1e118aea8 refactor: move batch of helpers to ts (#10722)
* refactor: move batch of helpers to ts

* refactor: review fixes
2022-09-30 09:48:12 -04:00
Dan Onoshko
52cf8e8a94 fix: aspect ratio calc (#10693) 2022-09-28 15:31:19 -04:00
Jacco van den Berg
fbaf28e4f8 Use guard clause typings (#10683)
* Use guard clasue

* use function type instead of build in function
2022-09-27 14:00:48 +03:00
Dan Onoshko
22f32af1bc fix: calc visible points on update (#10667) 2022-09-24 17:01:47 -04:00
stockiNail
d4e106cc9c Provide an empty object when the target of the resolver is undefined (#10655)
* Provide an empty object when the target of the proxy is undefined

* changes check on subGetTarget function

* adds test case

* fixes lint
2022-09-15 12:12:35 -04:00
Dan Onoshko
0c51ecd451 fix: respect aspect ratio with container height (#10646)
* fix: respect aspect ratio with container height

* docs: add info into migration guide
2022-09-02 08:03:41 -04:00
Dominic Jean
0edb2ac604 enable pointStyleWidth for all legend style (#10639) 2022-09-01 06:37:12 -04:00
Evert Timberg
b95ba3d5c3 Convert the easing helpers to typescript (#10627)
Co-authored-by: Chart.js <>
2022-08-31 09:53:54 -04:00
Dan Onoshko
2031cdf051 Preparing the project for TypeScript (#10595)
* Add Typescript to the build
* Converts the `helpers.core` to Typescript as an example
* Converts the `core.element` to Typescript
2022-08-22 11:58:57 -04:00
Jon Dufresne
eaee1ad63b Use the element's window in getComputedstyle (#10608) 2022-08-22 17:29:36 +02:00
Dan Onoshko
ce375a6876 feat: add ESM support (#10525)
* feat: add ESM support

* build: rename UMD bundle

* chore: edit supbackages description

* style: disable es/no-import-meta linter rule

* test: dynamic import in cjs module

* docs: edit integrations page

* docs: review fixes

* chore: remove useless regex in webpack config

* ci: test size-limit only for ESM bundle
2022-08-04 18:43:26 -04:00
Slava Terekhov
03e9194be5 feat: remove line element from scatter controller (#10439)
* feat: remove line element from scatter controller default config

* feat: move common controllers methods to helpers and add types

* feat: mark methods for scatter and line conntrollers as private

* fix: fix error when showline is true at root options and add tests

* feat: remove else inside scatter controller update

* fix: update getStartAndCountOFVisiblePoints helper code
2022-08-01 22:39:09 +03:00
Dan Onoshko
e800b46ab9 fix: calc visible points on update #10467 (#10523) 2022-07-28 07:46:00 -04:00
Jukka Kurkela
a4114e84d9 parsing: support dot(s) in object keys (#10517) 2022-07-26 08:30:52 -04:00
Dominic Jean
5452502b8c Add pointStyleWidth option for legend (#10412)
* add pointStyleWidth for legend

* add drawPointLegend to keep drawPoint signature
2022-07-18 06:49:08 -04:00
Jacco van den Berg
2c268f0943 Resolve canvasGradient is undefined in node (#10328)
* Resolve canvasgradient is not defined in node

* Remove trailing white space

* export isPaternOrGradient helper with typings

* fix lint failure, single qoute

* Allow for string inputs too to function
2022-05-03 08:21:43 -04:00
Josh Kelley
c057c96693 Interaction functions (#10046)
* Refactor get...Items functions to take events rather than positions

To work toward exposing something like the get...Items functions.

* Switch getAxisItems to use optimizedEvaluateItems

optimizedEvaluateItems falls back to evaluating all items for unsorted items, and sorting / optimizing ought to be okay, so this ought to be equivalent.

* Performance

* Consolidate getRelativePosition

helpers.dom.js's getRelativePosition already had logic to handle ChartEvent vs. Event (as demonstrated by the `native` check within `getCanvasPosition`), so it's redundant for core.interaction.js to have its own `native` check.

Update `getRelativePosition` to use the same `native` check as core.interaction.js's version.  As best as I can tell, the ChartEvent's x and y are populated from `getRelativePosition`, so the previous `getCanvasPosition` was effectively just duplicating `getRelativePosition'`s work.  I added a test to verify this; it depends on a local, not-yet-submitted change in chartjs-test-utils' `triggerMouseEvent` to return the mouse event that it triggers.

* Add an API to refactor duplicate isPointInArea

* Rename and update JSDoc to prepare for making this public

* Give functions a consistent, generic interface

* Export functions for discussion

* Code review feedback

Add a non-null assertion, as requested in code review.

Add JSDoc to clarify that `getCanvasPosition` now expects a native `Event`, not a `ChartEvent`.  Add `@ts-ignore`; `getCanvasPosition` relied on some loose conversions between `Event`, `TouchEvent`, and `Touch` that would require several changes to make TypeScript happy.

* Code review feedback

Return the event directly, to speed up the code a bit.  Add JSDoc to help communicate its intent.  Update various comments.

* Finalize exports; add docs and TypeScript

* Update src/helpers/helpers.dom.js

* Update src/helpers/helpers.dom.js

Only thing needed actually is the update of chartjs-test-utils to 0.4.0

* Bump chartjs-test-utils dependency

To get supporting work from https://github.com/chartjs/chartjs-test-utils/pull/19

Co-authored-by: Jukka Kurkela <jukka.kurkela@gmail.com>
2022-03-24 09:02:30 -04:00
CommanderRoot
acc7d9e04a Replace deprecated String.prototype.substr() (#10243)
String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with similar functions which aren't deprecated.
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
2022-03-18 17:38:28 -04:00
Jacco van den Berg
ed68557a99 Make object notation usable for polarArea and radar (#10088)
* start to make object notation usable for polarArea
* enable object notation also for radar chart, test default key
2022-02-12 10:23:31 -05:00
Dimitri Papadopoulos Orfanos
a7d98fb1a0 Fix typos found by codespell (#10103) 2022-01-27 09:24:55 -05:00
Jukka Kurkela
ba6b446b04 Limit active element changes to chartArea (#9970)
* Limit active element changes to chartArea

* CC, remove duplicate ChartEvent interface

* CC2
2021-12-08 16:44:45 +02:00