Skip to content
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

Fix "original" scale limits with nonlinear pan #774

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

joshkel
Copy link
Contributor

@joshkel joshkel commented Jul 25, 2023

Nonlinear scales failed to resolve "original" within panNumericalScale.

To fix this:

  • Resolving "original" within panNumericalScale seemed redundant, when updateRange was already doing it, so I instead moved the logic into updateRange and control it with a new special value for the zoom parameter. (Hopefully the use of a special string like this is acceptable as long as JSDoc calls it out - if I should use another approach, please let me know.)
  • This change put updateRange over the configured ESLint complexity limit, so I extracted a new getScaleLimits function to reduce complexity.

Add unit tests, both for this bug and for the preexisting but untested "original" feature.

I wanted JSDoc + TypeScript checks to help validate and document these changes, but that exposed apparent limitations of Chart.js core's type definitions. I'll open a separate PR for those.

These currently raise spurious errors, due to limitations in Chart.js types.
Nonlinear scales failed to resolve "original" within panNumericalScale.

To fix this:

* Resolving "original" within panNumericalScale seemed redundant, when
  updateRange was already doing it, so I instead moved the logic into
  updateRange and control it with a new special value for the `zoom`
  parameter.  (Hopefully the use of a special string like this is
  acceptable as long as JSDoc calls it out - if I should use another
  approach, please let me know.)
* This change put updateRange over the configured ESLint complexity
  limit, so I extracted a new getScaleLimits function to reduce
  complexity.

Add unit tests, both for this bug and for the preexisting but untested
"original" feature.
joshkel added a commit to joshkel/Chart.js that referenced this pull request Jul 25, 2023
While adding some type definitions to chartjs-plugin-zoom
(see chartjs/chartjs-plugin-zoom#774), I noticed
a few limitations in Chart.js's scale types:

* The zoom plugin calls `Scale.parse` with no index parameter.  Scale's
  JSDoc allows this, but its TypeScript definitions did not.
* The zoom plugin alters scale options' min and max.  The specific types
  of these depend on which scale is in use, but every scale has them, so
  `unknown` seems appropriate
etimberg pushed a commit to chartjs/Chart.js that referenced this pull request Jul 25, 2023
While adding some type definitions to chartjs-plugin-zoom
(see chartjs/chartjs-plugin-zoom#774), I noticed
a few limitations in Chart.js's scale types:

* The zoom plugin calls `Scale.parse` with no index parameter.  Scale's
  JSDoc allows this, but its TypeScript definitions did not.
* The zoom plugin alters scale options' min and max.  The specific types
  of these depend on which scale is in use, but every scale has them, so
  `unknown` seems appropriate
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.

None yet

2 participants