artus9033 / chartjs-plugin-dragdata

Draggable data points plugin for Chart.js
MIT License
261 stars 55 forks source link

Implement support for floating bars #72

Closed KlemenVovk closed 3 years ago

KlemenVovk commented 3 years ago

Implement support for floating bars

Description

This adds support for dragging floating bars on both ends. Previously this was not possible. This JSFiddle demonstrates the issue.

If you try dragging the bars around you will see that one end always resets to zero - this is due to points being updated to a single integer value(normal bars have value defined as a single integer while floating bars have value defined as an interval [min, max]). Once the interval is replaced with a single value, the floating bar is turned into a normal bar.

Type of change

The new result

This JSFiddle demonstrates the new result with my changes

Now floating bars can be dragged from both ends without issues.

Documentation

I have also added two new examples demonstrating the floating bar functionality. The links are already updated for merging so they won't work yet. You can test yourself by pulling these changes and running floatingBar.html and horizontalFloatingBar.html in the docs folder.

How has this been tested

As per notes in README.md npm run build was run and all the examples have been manually tested. Everything seems to be working on my end. Furthermore, the code specifically checks if the element is a floating bar before executing my additions.

Note

This is my first open-source contribution. I am open to any suggestions.

chrispahm commented 3 years ago

Hey @KlemenVovk 👋 First of all, this is awesome! Thanks for taking the time to do a PR. I‘ll have a look at the code later, just wanted to let you know the PR didn’t go unnoticed!

chrispahm commented 3 years ago

Alright, LGTM!