# all files / Github/diagram-js/lib/features/grid-snapping/behavior/ SpaceToolBehavior.js

30% Statements 3/10
0% Branches 0/4
50% Functions 1/2
30% Lines 3/10

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    341×

    74×

    1×

     var HIGH_PRIORITY = 2000;

    /**
     * Integrates space tool with grid snapping.
     */
    export default function SpaceToolBehavior(eventBus, gridSnapping) {
      eventBus.on([
        'spaceTool.move',
        'spaceTool.end'
      ], HIGH_PRIORITY, function(event) {
        var context = event.context;

        if (!context.initialized) {
          return;
        }

        var axis = context.axis;

        if (axis === 'x') {

          // snap delta x to multiple of 10
          event.dx = gridSnapping.snapValue(event.dx);
        } else {

          // snap delta y to multiple of 10
          event.dy = gridSnapping.snapValue(event.dy);
        }
      });
    }

    SpaceToolBehavior.$inject = [
      'eventBus',
      'gridSnapping'
    ];