mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-01-11 09:36:07 +00:00
parent
7d896855a9
commit
83f55b1fb1
@ -112,7 +112,7 @@ function getLabelAdjustment(label, newWaypoints, oldWaypoints, hints) {
|
||||
oldLabelLineIndex = attachment.segmentIndex,
|
||||
newLabelLineIndex = findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints);
|
||||
|
||||
if ( newLabelLineIndex === null ) {
|
||||
if (newLabelLineIndex === null) {
|
||||
return { x: x, y: y };
|
||||
}
|
||||
|
||||
@ -210,8 +210,9 @@ function getLine(waypoints, idx) {
|
||||
}
|
||||
|
||||
function getRelativeFootPosition(line, foot) {
|
||||
|
||||
var length = getDistancePointPoint(line[0], line[1]),
|
||||
lengthToFoot = getDistancePointPoint(line[0], foot);
|
||||
|
||||
return lengthToFoot / length;
|
||||
return length === 0 ? 0 : lengthToFoot / length;
|
||||
}
|
||||
|
@ -151,10 +151,12 @@ function getCircleSegmentIntersections(s1, s2, cc, cr) {
|
||||
|
||||
var disc = pBy2 * pBy2 - q;
|
||||
|
||||
// round disc to 10 digits to work around
|
||||
// check against negative value to work around
|
||||
// negative, very close to zero results (-4e-15)
|
||||
// being produced in some environments
|
||||
disc = round(disc, 10);
|
||||
if (disc < 0 && disc > -0.000001) {
|
||||
disc = 0;
|
||||
}
|
||||
|
||||
if (disc < 0) {
|
||||
return [];
|
||||
@ -220,26 +222,6 @@ function mid(p1, p2) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Round number to precision
|
||||
*
|
||||
* @param {Number} number
|
||||
* @param {Integer} [precision=1]
|
||||
*
|
||||
* @return {Number}
|
||||
*/
|
||||
function round(number, precision) {
|
||||
|
||||
if (typeof precision === 'undefined') {
|
||||
return Math.round(number);
|
||||
}
|
||||
|
||||
var factor = Math.pow(10, precision);
|
||||
var tempNumber = number * factor;
|
||||
var roundedTempNumber = Math.round(tempNumber);
|
||||
return roundedTempNumber / factor;
|
||||
}
|
||||
|
||||
var EQUAL_THRESHOLD = 0.1;
|
||||
|
||||
function pointsEqual(p1, p2) {
|
||||
|
@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
var getLabelAdjustment = require('lib/features/modeling/behavior/util/LabelLayoutUtil').getLabelAdjustment;
|
||||
|
||||
|
||||
describe('modeling/behavior/util - LabelLayoutUtil#getLabelAdjustment', function() {
|
||||
|
||||
describe('should recognize on the line label', function() {
|
||||
|
||||
var newLine = [
|
||||
{ x: 10, y: 10 },
|
||||
// -
|
||||
{ x: 15, y: 10 },
|
||||
// |
|
||||
{ x: 15, y: 5 },
|
||||
// -
|
||||
{ x: 30, y: 5 }
|
||||
];
|
||||
|
||||
|
||||
it('horizontal', function() {
|
||||
|
||||
// given
|
||||
var line = [
|
||||
{ x: 10, y: 10 },
|
||||
// -
|
||||
{ x: 20, y: 10 }
|
||||
];
|
||||
|
||||
// label with center { x: 5, y: 10 }
|
||||
|
||||
var label = {
|
||||
x: 0,
|
||||
y: 5,
|
||||
width: 10,
|
||||
height: 10
|
||||
};
|
||||
|
||||
// when
|
||||
var delta = getLabelAdjustment(label, newLine, line, { connectionStart: true });
|
||||
|
||||
// then
|
||||
expect(delta).to.eql({ x: 0, y: 0 });
|
||||
});
|
||||
|
||||
|
||||
it('zero-length line', function() {
|
||||
|
||||
// given
|
||||
var line = [
|
||||
{ x: 10, y: 10 },
|
||||
// -
|
||||
{ x: 10, y: 10 }
|
||||
];
|
||||
|
||||
// label with center { x: 5, y: 10 }
|
||||
|
||||
var label = {
|
||||
x: 0,
|
||||
y: 5,
|
||||
width: 10,
|
||||
height: 10
|
||||
};
|
||||
|
||||
// when
|
||||
var delta = getLabelAdjustment(label, newLine, line, { connectionStart: true });
|
||||
|
||||
// then
|
||||
expect(delta).to.eql({ x: 0, y: 0 });
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user