# all files / bpmn-js/lib/features/modeling/util/ LaneUtil.js

97.56% Statements 40/41
92.86% Branches 26/28
100% Functions 8/8
97.56% Lines 40/41

    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
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154

    1×

    36×

    1×

    1×

    1154×

    1154×
    6258×
    458×

    458×

    1154×

    24×
    87×

    1103×

    36×

    36×

    36×
    36×
    36×
    36×
    36×

    36×

    100×
    36×

    64×
    64×
    64×
    64×

    64×

    64×
    22×

    22×
    9×

    64×
    19×
    4×

    19×
    6×

    64×

    49×

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

    import {
      getParent
    } from './ModelingUtil';

    import {
      asTRBL
    } from 'diagram-js/lib/layout/LayoutUtil';

    import {
      substractTRBL,
      resizeTRBL
    } from 'diagram-js/lib/features/resize/ResizeUtil';

    var abs = Math.abs;

    function getTRBLResize(oldBounds, newBounds) {
      return substractTRBL(asTRBL(newBounds), asTRBL(oldBounds));
    }

    var LANE_PARENTS = [
      'bpmn:Participant',
      'bpmn:Process',
      'bpmn:SubProcess'
    ];

    export var LANE_INDENTATION = 30;

    /**
     * Collect all lane shapes in the given paren
     *
     * @param  {djs.model.Shape} shape
     * @param  {Array<djs.model.Base>} [collectedShapes]
     *
     * @return {Array<djs.model.Base>}
     */
    export function collectLanes(shape, collectedShapes) {

      collectedShapes = collectedShapes || [];

      shape.children.filter(function(s) {
        if (is(s, 'bpmn:Lane')) {
          collectLanes(s, collectedShapes);

          collectedShapes.push(s);
        }
      });

      return collectedShapes;
    }

    /**
     * Return the lane children of the given element.
     *
     * @param {djs.model.Shape} shape
     *
     * @return {Array<djs.model.Shape>}
     */
    export function getChildLanes(shape) {
      return shape.children.filter(function(c) {
        return is(c, 'bpmn:Lane');
      });
    }

    /**
     * Return the root element containing the given lane shape
     *
     * @param {djs.model.Shape} shape
     *
     * @return {djs.model.Shape}
     */
    export function getLanesRoot(shape) {
      return getParent(shape, LANE_PARENTS) || shape;
    }

    /**
     * Compute the required resize operations for lanes
     * adjacent to the given shape, assuming it will be
     * resized to the given new bounds.
     *
     * @param {djs.model.Shape} shape
     * @param {Bounds} newBounds
     *
     * @return {Array<Object>}
     */
    export function computeLanesResize(shape, newBounds) {

      var rootElement = getLanesRoot(shape);

      var initialShapes = is(rootElement, 'bpmn:Process') ? [] : [ rootElement ];

      var allLanes = collectLanes(rootElement, initialShapes),
          shapeTrbl = asTRBL(shape),
          shapeNewTrbl = asTRBL(newBounds),
          trblResize = getTRBLResize(shape, newBounds),
          resizeNeeded = [];

      allLanes.forEach(function(other) {

        if (other === shape) {
          return;
        }

        var topResize = 0,
            rightResize = trblResize.right,
            bottomResize = 0,
            leftResize = trblResize.left;

        var otherTrbl = asTRBL(other);

        if (trblResize.top) {
          Iif (abs(otherTrbl.bottom - shapeTrbl.top) < 10) {
            bottomResize = shapeNewTrbl.top - otherTrbl.bottom;
          }

          if (abs(otherTrbl.top - shapeTrbl.top) < 5) {
            topResize = shapeNewTrbl.top - otherTrbl.top;
          }
        }

        if (trblResize.bottom) {
          if (abs(otherTrbl.top - shapeTrbl.bottom) < 10) {
            topResize = shapeNewTrbl.bottom - otherTrbl.top;
          }

          if (abs(otherTrbl.bottom - shapeTrbl.bottom) < 5) {
            bottomResize = shapeNewTrbl.bottom - otherTrbl.bottom;
          }
        }

        if (topResize || rightResize || bottomResize || leftResize) {

          resizeNeeded.push({
            shape: other,
            newBounds: resizeTRBL(other, {
              top: topResize,
              right: rightResize,
              bottom: bottomResize,
              left: leftResize
            })
          });
        }

      });

      return resizeNeeded;
    }