How to use the diagram-js/lib/layout/LayoutUtil.getMid 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 / auto-place / AutoPlaceSpec.js View on Github external
expect(event.source).to.equal(source);

          return {
            x: 0,
            y: 0
          };
        });

        eventBus.on('autoPlace', listener);

        // when
        autoPlace.append(source, element);

        expect(listener).to.have.been.called;

        expect(getMid(element)).to.eql({
          x: 0,
          y: 0
        });
      }
    ));
github bpmn-io / bpmn-js / lib / features / modeling / behavior / AdaptiveLabelPositioningBehavior.js View on Github external
function getTakenHostAlignments(element) {

  var hostElement = element.host,
      elementMid = getMid(element),
      hostOrientation = getOrientation(elementMid, hostElement);

  var freeAlignments;

  // check whether there is a multi-orientation, e.g. 'top-left'
  if (hostOrientation.indexOf('-') >= 0) {
    freeAlignments = hostOrientation.split('-');
  } else {
    freeAlignments = [ hostOrientation ];
  }

  var takenAlignments = ALIGNMENTS.filter(function(alignment) {

    return freeAlignments.indexOf(alignment) === -1;
  });
github bpmn-io / bpmn-js / lib / features / modeling / behavior / AdaptiveLabelPositioningBehavior.js View on Github external
function adjustLabelPosition(element, orientation) {

    var elementMid = getMid(element),
        label = element.label,
        labelMid = getMid(label);

    // ignore labels that are being created
    if (!label.parent) {
      return;
    }

    var elementTrbl = asTRBL(element);

    var newLabelMid;

    switch (orientation) {
    case 'top':
      newLabelMid = {
        x: elementMid.x,
github bpmn-io / bpmn-js / lib / features / modeling / behavior / AdaptiveLabelPositioningBehavior.js View on Github external
function getTakenConnectionAlignments(element) {

  var elementMid = getMid(element);

  var takenAlignments = [].concat(
    element.incoming.map(function(c) {
      return c.waypoints[c.waypoints.length - 2 ];
    }),
    element.outgoing.map(function(c) {
      return c.waypoints[1];
    })
  ).map(function(point) {
    return getApproximateOrientation(elementMid, point);
  });

  return takenAlignments;
}
github bpmn-io / bpmn-js / lib / import / BpmnImporter.js View on Github external
function getWaypoints(bo, source, target) {

  var waypoints = bo.di.waypoint;

  if (!waypoints || waypoints.length < 2) {
    return [ getMid(source), getMid(target) ];
  }

  return waypoints.map(function(p) {
    return { x: p.x, y: p.y };
  });
}
github bpmn-io / bpmn-js / lib / features / auto-place / AutoPlaceUtil.js View on Github external
export function getFlowNodePosition(source, element) {

  var sourceTrbl = asTRBL(source);
  var sourceMid = getMid(source);

  var horizontalDistance = getFlowNodeDistance(source, element);

  var orientation = 'left',
      rowSize = 80,
      margin = 30;

  if (is(source, 'bpmn:BoundaryEvent')) {
    orientation = getOrientation(source, source.host, -25);

    if (orientation.indexOf('top') !== -1) {
      margin *= -1;
    }
  }

  function getVerticalDistance(orient) {
github bpmn-io / cmmn-js / lib / features / snapping / CmmnCreateMoveSnapping.js View on Github external
forEach(shape.incoming, function(connection) {

    if (!includes(snapTargets, connection.source)) {
      snapPoints.add('mid', getMid(connection.source));
    }

    var docking = connection.waypoints[0];

    snapPoints.add(connection.id + '-docking', docking.original || docking);
  });
github bpmn-io / bpmn-js / lib / features / modeling / BpmnLayouter.js View on Github external
function shouldConnectToSameSide(axis, source, target, end) {
  var threshold = BOUNDARY_TO_HOST_THRESHOLD;

  return !(
    areCloseOnAxis(axis, end, target, threshold) ||
    areCloseOnAxis(axis, end, {
      x: target.x + target.width,
      y: target.y + target.height
    }, threshold) ||
    areCloseOnAxis(axis, end, getMid(source), threshold)
  );
}