highcharts / draggable-points

MIT License
32 stars 34 forks source link

Option to enable/disable mouseleave event listener #76

Closed ZachMilne closed 6 years ago

ZachMilne commented 6 years ago

If the mouse inadvertently leaves the chart container while dragging, an undesirable drop event occurs. I propose a dropOnMouseleave option. Default: true

pawelfus commented 6 years ago

Thank you for the suggestion.

At this moment it's possible to unbind Highcharts events in chart.events.load callback, for example: https://jsfiddle.net/15xkuykt/

  chart: {
    renderTo: 'container',
    events: {
      load: function() {

        Highcharts.removeEvent(
          this.container,
          'mouseleave',
          Highcharts.grep(
            this.container.hcEvents.mouseleave,
            function(fun) {
              return this.name === 'drop'; // draggable point adds "drop" function
            }
          )[0]
        );

      }
    }
  },

The only problem is that index for mouseleave

TorsteinHonsi commented 6 years ago

I just did a change I've been planning already - to allow returning false from the drop event handler to cancel the drop. Now you can check the event arguments to cancel in your case:

                        if (e.originalEvent.type === 'mouseleave') {
                            return false;
                        }

https://jsfiddle.net/highcharts/15xkuykt/2/

ZachMilne commented 6 years ago

That will work well. Thanks for the quick responses and implementation.