all files / bpmn-js/lib/features/auto-place/ AutoPlace.js

100% Statements 9/9
100% Branches 2/2
100% Functions 3/3
100% Lines 9/9
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                          56×                       65×     28×         28× 19×     28×     28×       28×              
import { getNewShapePosition } from './AutoPlaceUtil';
 
 
/**
 * A service that places elements connected to existing ones
 * to an appropriate position in an _automated_ fashion.
 *
 * @param {EventBus} eventBus
 * @param {Modeling} modeling
 */
export default function AutoPlace(eventBus, modeling) {
 
  function emit(event, payload) {
    return eventBus.fire(event, payload);
  }
 
 
  /**
   * Append shape to source at appropriate position.
   *
   * @param {djs.model.Shape} source
   * @param {djs.model.Shape} shape
   *
   * @return {djs.model.Shape} appended shape
   */
  this.append = function(source, shape) {
 
    // allow others to provide the position
    var position = emit('autoPlace', {
      source: source,
      shape: shape
    });
 
    if (!position) {
      position = getNewShapePosition(source, shape);
    }
 
    var newShape = modeling.appendShape(source, shape, position, source.parent);
 
    // notify interested parties on new shape placed
    emit('autoPlace.end', {
      shape: newShape
    });
 
    return newShape;
  };
 
}
 
AutoPlace.$inject = [
  'eventBus',
  'modeling'
];