How to use the diagram-js/lib/features/snapping/SnapUtil.mid function in diagram-js

To help you get started, we’ve selected a few diagram-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bpmn-io / bpmn-js / test / spec / features / snapping / BpmnCreateMoveSnappingSpec.js View on Github external
it('should snap to bottom-left', inject(function(dragging) {

          // when
          dragging.move(canvasEvent({ x: 90, y: 190 }));

          dragging.end();

          // then
          var boundaryEvent = getBoundaryEvent(task);

          expect(mid(boundaryEvent)).to.eql({
            x: 100, // 90 snapped to 100
            y: 180 // 190 snapped to 180
          });
        }));
github bpmn-io / bpmn-js / lib / features / snapping / BpmnSnapping.js View on Github external
context.sourcePosition = mid(source);

      // snap target
      snapToPosition(event, mid(target));
    } else

    if (connection.type === 'bpmn:MessageFlow') {

      if (is(source, 'bpmn:Event')) {
        // snap source
        context.sourcePosition = mid(source);
      }

      if (is(target, 'bpmn:Event')) {
        // snap target
        snapToPosition(event, mid(target));
      }
    }

    else {
      // otherwise reset source snap
      context.sourcePosition = context.initialSourcePosition;
    }

  });
}
github bpmn-io / bpmn-js / lib / features / snapping / BpmnSnapping.js View on Github external
BpmnSnapping.prototype.addTargetSnaps = function(snapPoints, shape, target) {

  // snap shape to itself
  if (isNumber(shape.x) && isNumber(shape.y)) {
    snapPoints.add('mid', mid(shape));
  }

  // use target parent as snap target
  if (is(shape, 'bpmn:BoundaryEvent') && shape.type !== 'label') {
    target = target.parent;
  }

  // add sequence flow parents as snap targets
  if (is(target, 'bpmn:SequenceFlow')) {
    this.addTargetSnaps(snapPoints, shape, target.parent);
  }

  var siblings = this.getSiblings(shape, target) || [];

  forEach(siblings, function(sibling) {
github bpmn-io / bpmn-js / lib / features / snapping / BpmnConnectSnapping.js View on Github external
if (!context.initialConnectionStart) {
      context.initialConnectionStart = context.connectionStart;
    }

    // snap hover
    if (canExecute && hover) {
      snapToShape(event, hover, getTargetBoundsPadding(hover));
    }

    if (hover && isAnyType(canExecute, [
      'bpmn:Association',
      'bpmn:DataInputAssociation',
      'bpmn:DataOutputAssociation',
      'bpmn:SequenceFlow'
    ])) {
      context.connectionStart = mid(start);

      // snap hover
      if (isAny(hover, [ 'bpmn:Event', 'bpmn:Gateway' ])) {
        snapToPosition(event, mid(hover));
      }

      // snap hover
      if (isAny(hover, [ 'bpmn:Task', 'bpmn:SubProcess' ])) {
        snapToTargetMid(event, hover);
      }

      // snap source and target
      if (is(source, 'bpmn:BoundaryEvent') && target === source.host) {
        snapBoundaryEventLoop(event);
      }
github bpmn-io / bpmn-js / lib / features / snapping / BpmnSnapping.js View on Github external
connection.type === 'bpmn:DataInputAssociation' ||
        connection.type === 'bpmn:SequenceFlow'
      )
    ) {
      // snap source
      context.sourcePosition = mid(source);

      // snap target
      snapToPosition(event, mid(target));
    } else

    if (connection.type === 'bpmn:MessageFlow') {

      if (is(source, 'bpmn:Event')) {
        // snap source
        context.sourcePosition = mid(source);
      }

      if (is(target, 'bpmn:Event')) {
        // snap target
        snapToPosition(event, mid(target));
      }
    }

    else {
      // otherwise reset source snap
      context.sourcePosition = context.initialSourcePosition;
    }

  });
}
github bpmn-io / bpmn-js / lib / features / snapping / BpmnConnectSnapping.js View on Github external
function snapBoundaryEventLoop(event) {
  var context = event.context,
      source = context.source,
      target = context.target;

  if (isReverse(context)) {
    return;
  }

  var sourceMid = mid(source),
      orientation = getOrientation(sourceMid, target, -10),
      axes = [];

  if (/top|bottom/.test(orientation)) {
    axes.push('x');
  }

  if (/left|right/.test(orientation)) {
    axes.push('y');
  }

  axes.forEach(function(axis) {
    var coordinate = event[ axis ], newCoordinate;

    if (abs(coordinate - sourceMid[ axis ]) < BOUNDARY_TO_HOST_THRESHOLD) {
      if (coordinate > sourceMid[ axis ]) {
github bpmn-io / bpmn-js / lib / features / snapping / BpmnSnapping.js View on Github external
forEach(shape.outgoing, function(c) {

    if (siblings.indexOf(c.target) === -1) {
      snapPoints.add('mid', mid(c.target));
    }

    var docking = c.waypoints[c.waypoints.length - 1];
    snapPoints.add(c.id + '-docking', docking.original || docking);
  });
};
github bpmn-io / bpmn-js / lib / features / snapping / BpmnSnapping.js View on Github external
forEach(shape.incoming, function(c) {

    if (siblings.indexOf(c.source) === -1) {
      snapPoints.add('mid', mid(c.source));
    }

    var docking = c.waypoints[0];
    snapPoints.add(c.id + '-docking', docking.original || docking);
  });
github bpmn-io / bpmn-js / lib / features / snapping / BpmnConnectSnapping.js View on Github external
function snapToTargetMid(event, target) {
  var targetMid = mid(target);

  AXES.forEach(function(axis) {
    if (isMid(event, target, axis)) {
      setSnapped(event, axis, targetMid[ axis ]);
    }
  });
}
github bpmn-io / bpmn-js / lib / features / snapping / BpmnSnapping.js View on Github external
var docking = c.waypoints[c.waypoints.length - 1];

      docking = docking.original || docking;

      snapContext.setSnapOrigin(c.id + '-docking', {
        x: docking.x - event.x,
        y: docking.y - event.y
      });
    });

  }

  var source = context.source;

  if (source) {
    snapContext.addDefaultSnap('mid', mid(source));
  }
};