-
Notifications
You must be signed in to change notification settings - Fork 56
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
Dragging does not work with panning plugin #43
Comments
Hi! Thanks for the inquiry! I remember discussing a similar matter here: #21 (comment) It basically boils down to the question of which implementation would be best from a UI perspective. Currently, both the zoom plugin and this plugin use the same gestures, so there is no way to detect whether the user wants to drag a point or zoom the chart. In your example, zooming is triggered by dbl clicking the chart. As far as I know, the zoom plugin does not support this method. So you could either open an issue there or use the workaround I proposed in the other issue. Merry Christmas and good luck, |
Thanks for the quick reply. I opened an issue at the zoom plugin project (chartjs/chartjs-plugin-zoom#308) However, I wonder whether it is possible to detect if the dragging gesture is made on a data point or somewhere else in the plotting area. In the first case dragging the data point would be natural, in the latter, one would expect scrolling/panning the plotting area. Thank you and happy holidays! |
Alright, so I had another look at the source code of the zoom plugin: chartInstance.$zoom._mouseDownHandler = function(event) {
// Disable zoom when click happened on a chart element
if (chartInstance.getElementAtEvent(event).length > 0) return
node.addEventListener('mousemove', chartInstance.$zoom._mouseMoveHandler);
chartInstance.$zoom._dragZoomStart = event;
}; But unfortunately, that's not all there is to it. The If an event listener was already registered for the same type and name, the existing listener is removed before the new listener is added. There may be ways to circumvent this, but as I If you are eager to get these two plugins to work fine together, and are willing to go the extra mile, I would propose you to
I wish you all the best luck with this, please keep me posted when you come up with something! |
PS: An excellent example of how the drag plugin can be used in combination with the zoom plugin was done by @imartinezl I think this demo shows how an innovative UI can make data approachable and easy to understand, without overwhelming the user. |
Hi @Zuckerbrot, in an issue similar to this one, @yoelz55 mentioned that the plugins: {
zoom: {
pan: {
enabled: true,
mode: function({chart }) {
// check if gesture was made over a data point
return 'xy' // or ''
}
}, with this in mind, you could add a var eventOutsideDataPoint = true
chartCanvas.onmousemove = function(evt) {
var activePoints = yourChart.getElementsAtEvent(evt);
eventOutsideDataPoint = activePoints && activePoints.length ? false : true
};
//
var chartConfig: {
...
plugins: {
zoom: {
pan: {
enabled: true,
mode: function({chart }) {
if (eventOutsideDataPoint) {
return 'xy';
}
return ''
}
},
....
} Here is a fiddle showcasing this workaround. Since the From a UI perspective, I'd still argue that this is rather cumbersome though... |
I will close this as answered (see above comment for a working example). Please re-open if necessary. |
Hi, thanks for this great plugin.
Is it possible to make it compatible with the zoom/panning plugin?
https://github.com/chartjs/chartjs-plugin-zoom
I can only get either panning or data-dragging to work.
Example (works in Safari):
https://jsfiddle.net/zpq8an40/1/
Would be nice to have both, like eg here
http://bl.ocks.org/stepheneb/1182434
Is there any workaround available?
Thank you!
The text was updated successfully, but these errors were encountered: