# all files / bpmn-js/lib/features/interaction-events/ BpmnInteractionEvents.js

100% Statements 32/32
100% Branches 10/10
100% Functions 5/5
100% Lines 32/32

    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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106

    1×
    1×

    58×

    58×

    58×

    549×
    549×

    549×
    27×

    522×
    21×
    18×

    3×

    501×
    30×
    29×

    1×

    1×

    1×
    4×

    4×

    4×

    1×

    45×

    45×

    45×

    45×

    1×

    29×

    29×

    29×

    29×
     import { is } from '../../util/ModelUtil';

    import { isExpanded } from '../../util/DiUtil';

    var LABEL_WIDTH = 30,
        LABEL_HEIGHT = 30;

    /**
     * BPMN-specific hit zones and interaction fixes.
     *
     * @param {EventBus} eventBus
     * @param {InteractionEvents} interactionEvents
     */
    export default function BpmnInteractionEvents(eventBus, interactionEvents) {

      this._interactionEvents = interactionEvents;

      var self = this;

      eventBus.on([
        'interactionEvents.createHit',
        'interactionEvents.updateHit'
      ], function(context) {
        var element = context.element,
            gfx = context.gfx;

        if (is(element, 'bpmn:Lane')) {
          return self.createParticipantHit(element, gfx);
        } else

        if (is(element, 'bpmn:Participant')) {
          if (isExpanded(element)) {
            return self.createParticipantHit(element, gfx);
          } else {
            return self.createDefaultHit(element, gfx);
          }
        } else

        if (is(element, 'bpmn:SubProcess')) {
          if (isExpanded(element)) {
            return self.createSubProcessHit(element, gfx);
          } else {
            return self.createDefaultHit(element, gfx);
          }
        }
      });

    }

    BpmnInteractionEvents.$inject = [
      'eventBus',
      'interactionEvents'
    ];

    BpmnInteractionEvents.prototype.createDefaultHit = function(element, gfx) {
      this._interactionEvents.removeHits(gfx);

      this._interactionEvents.createDefaultHit(element, gfx);

      // indicate that we created a hit
      return true;
    };

    BpmnInteractionEvents.prototype.createParticipantHit = function(element, gfx) {

      // remove existing hits
      this._interactionEvents.removeHits(gfx);

      // add outline hit
      this._interactionEvents.createBoxHit(gfx, 'click-stroke', {
        width: element.width,
        height: element.height
      });

      // add label hit
      this._interactionEvents.createBoxHit(gfx, 'all', {
        width: LABEL_WIDTH,
        height: element.height
      });

      // indicate that we created a hit
      return true;
    };

    BpmnInteractionEvents.prototype.createSubProcessHit = function(element, gfx) {

      // remove existing hits
      this._interactionEvents.removeHits(gfx);

      // add outline hit
      this._interactionEvents.createBoxHit(gfx, 'click-stroke', {
        width: element.width,
        height: element.height
      });

      // add label hit
      this._interactionEvents.createBoxHit(gfx, 'all', {
        width: element.width,
        height: LABEL_HEIGHT
      });

      // indicate that we created a hit
      return true;
    };