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

RQ: Enhancement request on drag callBacks / updateData #93

Open
bdorninger opened this issue Feb 4, 2022 · 2 comments
Open

RQ: Enhancement request on drag callBacks / updateData #93

bdorninger opened this issue Feb 4, 2022 · 2 comments

Comments

@bdorninger
Copy link

bdorninger commented Feb 4, 2022

Describe the bug
Not a bug....
Currently, drag can be limited by the onDrag callback returning false.
On weakly performing devices and/or quickly done drag interactions, this may result in inconvenient user experience, because drag is stopping before an intended limit.

To Reproduce
Limit drag within the callback, switch on CPU throttling and/or do a swift drag of a datapoint.

Expected behavior
Regardless, how fast the drag is made, the dragged point shall align to the intended limit, if pointer is moved beyond that limit

Proposed Change
Allow the onDrag callback to return not just false, but optionally a datapoint. A little like your magnet.to function. But the magnet is applied too late for my purpose
Just a quick sample code snippet, how I would like to see it
At the end of updataData:

........
...
..
if (!callback || typeof callback === 'function') {
      const ret = callback(e, curDatasetIndex, curIndex, dataPoint);
      if (ret != undefined && typeof dataPoint === typeof ret) {
        chartInstance.data.datasets[curDatasetIndex].data[curIndex] = ret;
        chartInstance.update('none');
      } else if (ret !== false) {
        chartInstance.data.datasets[curDatasetIndex].data[curIndex] = dataPoint;
        chartInstance.update('none');
      }
    }

Could also be restricted to the onDrag callback, but I suppose that needs more code changes, since you do not distinguish between the different configurable callbacks. But using this for endDrag as well, could make the magnet.to obsolete

If this sounds feasible for you, I could issue a PR.

@bdorninger
Copy link
Author

Any comment on this, Chris ?

regards,
Bernhard

@chrispahm
Copy link
Collaborator

Sorry, super busy right now ☹️

I wanted to review #86 done by @artus9033, who did a great job improving the code quality of this project together with the added benefit of type annotations. Maybe you can have a look as well and probably issue the PR as a follow up of the code-cleanup?

Another thing I have to get done before accepting PRs is finishing the test cases. The possible combinations of options the plugin provides today by far exceed what I originally intended, so I think we might even want to consider unit tests...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants