<commit_before>require('../core/Events');
require('./services/Selection');
require('./services/Shapes');
require('./Interactivity');
require('../core/Canvas');

var Snap = require('snapsvg');

var Diagram = require('../Diagram'),
    _ = require('../util/underscore');


/**
 * @class
 *
 * A plugin that makes shapes draggable / droppable.
 * 
 * @param {Events} events the event bus
 * @param {Selection} selection the selection service
 * @param {Shapes} shapes the shapes service
 */
function Drag(events, selection, shapes, canvas) {

  var DRAG_START_THRESHOLD = 10;

  function makeDraggable(shape, graphics) {

    var dragCtx;
    var dragGroup;

    graphics.drag(function dragging(dx, dy, x, y, e) {

      var graphics = dragCtx.graphics;

      if (!dragCtx.dragging) {

        // activate visual drag once a certain threshold is reached
        if (dx > DRAG_START_THRESHOLD || dy > DRAG_START_THRESHOLD) {

          if(!dragGroup) {
            dragGroup = canvas.getContext().group();
            dragGroup.attr('class', 'djs-drag-group');
          }

          _.forEach(graphics, function(gfx) {
            var dragger = gfx.clone();
            
            dragger.attr({
              'class': 'djs-dragger',
              'x': gfx.parent().getBBox(false).x,
              'y': gfx.parent().getBBox(false).y
            });

            gfx.dragger = dragger;
            gfx.addClass('djs-dragging');

            dragGroup.add(dragger);
          });

          selection.select(null);
          dragCtx.dragging = true;

          events.fire('shape.dragstart', { element: shape, gfx: graphics, drag: dragCtx });
        }
      }
      
      // update draggers with new coordinates
      if (dragCtx.dragging) {

        var translateMatrix = new Snap.Matrix();
        translateMatrix.translate(dx,dy);
        dragGroup.transform(translateMatrix);

        var currentHover = Snap.getElementByPoint(x, y);

        if (currentHover != dragCtx.hoverShape) {
          console.log('hover changed: ', dragCtx.hoverShape);

          dragCtx.hoverShape = currentHover;
        }<commit_msg>fix(drag): correctly compute start drag threshold<commit_after>require('../core/Events');
require('./services/Selection');
require('./services/Shapes');
require('./Interactivity');
require('../core/Canvas');

var Snap = require('snapsvg');

var Diagram = require('../Diagram'),
    _ = require('../util/underscore');


/**
 * @class
 *
 * A plugin that makes shapes draggable / droppable.
 * 
 * @param {Events} events the event bus
 * @param {Selection} selection the selection service
 * @param {Shapes} shapes the shapes service
 */
function Drag(events, selection, shapes, canvas) {

  var DRAG_START_THRESHOLD = 10;

  function makeDraggable(shape, graphics) {

    var dragCtx;
    var dragGroup;

    graphics.drag(function dragging(dx, dy, x, y, e) {

      var graphics = dragCtx.graphics;

      if (!dragCtx.dragging) {

        // activate visual drag once a certain threshold is reached
        if (Math.abs(dx) > DRAG_START_THRESHOLD || Math.abs(dy) > DRAG_START_THRESHOLD) {

          if(!dragGroup) {
            dragGroup = canvas.getContext().group();
            dragGroup.attr('class', 'djs-drag-group');
          }

          _.forEach(graphics, function(gfx) {
            var dragger = gfx.clone();
            
            dragger.attr({
              'class': 'djs-dragger',
              'x': gfx.parent().getBBox(false).x,
              'y': gfx.parent().getBBox(false).y
            });

            gfx.dragger = dragger;
            gfx.addClass('djs-dragging');

            dragGroup.add(dragger);
          });

          selection.select(null);
          dragCtx.dragging = true;

          events.fire('shape.dragstart', { element: shape, gfx: graphics, drag: dragCtx });
        }
      }
      
      // update draggers with new coordinates
      if (dragCtx.dragging) {

        var translateMatrix = new Snap.Matrix();
        translateMatrix.translate(dx,dy);
        dragGroup.transform(translateMatrix);
{'fraction_non_alphanumeric': 0.13776137761377613, 'fraction_numerical': 0.0009840098400984009, 'mean_word_length': 2.305691056910569, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4513248', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1175, 'n_words': 261}