all files / Github/bpmn-js/lib/features/modeling/behavior/ AppendBehavior.js

100% Statements 10/10
100% Branches 4/4
100% Functions 2/2
100% Lines 10/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 34 35 36 37 38 39 40 41 42                  1128×       1128×   52× 52×   52×   21×         17×                          
import inherits from 'inherits';
 
import { is } from '../../../util/ModelUtil';
 
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
 
 
export default function AppendBehavior(eventBus, elementFactory, bpmnRules) {
 
  CommandInterceptor.call(this, eventBus);
 
  // assign correct shape position unless already set
 
  this.preExecute('shape.append', function(context) {
 
    var source = context.source,
        shape = context.shape;
 
    if (!context.position) {
 
      if (is(shape, 'bpmn:TextAnnotation')) {
        context.position = {
          x: source.x + source.width / 2 + 75,
          y: source.y - (50) - shape.height / 2
        };
      } else {
        context.position = {
          x: source.x + source.width + 80 + shape.width / 2,
          y: source.y + source.height / 2
        };
      }
    }
  }, true);
}
 
inherits(AppendBehavior, CommandInterceptor);
 
AppendBehavior.$inject = [
  'eventBus',
  'elementFactory',
  'bpmnRules'
];