4 var Bezier = function(params) {
8 _super = jsPlumb.Connectors.AbstractConnector.apply(this, arguments),
9 stub = params.stub || 50,
10 majorAnchor = params.curviness || 150,
14 this.getCurviness = function() { return majorAnchor; };
16 this._findControlPoint = function(point, sourceAnchorPosition, targetAnchorPosition, sourceEndpoint, targetEndpoint) {
17 // determine if the two anchors are perpendicular to each other in their orientation. we swap the control
18 // points around if so (code could be tightened up)
19 var soo = sourceEndpoint.anchor.getOrientation(sourceEndpoint),
20 too = targetEndpoint.anchor.getOrientation(targetEndpoint),
21 perpendicular = soo[0] != too[0] || soo[1] == too[1],
25 if (soo[0] === 0) // X
26 p.push(sourceAnchorPosition[0] < targetAnchorPosition[0] ? point[0] + minorAnchor : point[0] - minorAnchor);
27 else p.push(point[0] - (majorAnchor * soo[0]));
29 if (soo[1] === 0) // Y
30 p.push(sourceAnchorPosition[1] < targetAnchorPosition[1] ? point[1] + minorAnchor : point[1] - minorAnchor);
31 else p.push(point[1] + (majorAnchor * too[1]));
34 if (too[0] === 0) // X
35 p.push(targetAnchorPosition[0] < sourceAnchorPosition[0] ? point[0] + minorAnchor : point[0] - minorAnchor);
36 else p.push(point[0] + (majorAnchor * too[0]));
38 if (too[1] === 0) // Y
39 p.push(targetAnchorPosition[1] < sourceAnchorPosition[1] ? point[1] + minorAnchor : point[1] - minorAnchor);
40 else p.push(point[1] + (majorAnchor * soo[1]));
46 this._compute = function(paintInfo, p) {
49 _w = Math.abs(sp[0] - tp[0]),
50 _h = Math.abs(sp[1] - tp[1]),
51 _sx = sp[0] < tp[0] ? _w : 0,
52 _sy = sp[1] < tp[1] ? _h : 0,
53 _tx = sp[0] < tp[0] ? 0 : _w,
54 _ty = sp[1] < tp[1] ? 0 : _h,
55 _CP = self._findControlPoint([_sx, _sy], sp, tp, p.sourceEndpoint, p.targetEndpoint),
56 _CP2 = self._findControlPoint([_tx, _ty], tp, sp, p.targetEndpoint, p.sourceEndpoint);
58 _super.addSegment(this, "Bezier", {
59 x1:_sx, y1:_sy, x2:_tx, y2:_ty,
60 cp1x:_CP[0], cp1y:_CP[1], cp2x:_CP2[0], cp2y:_CP2[1]
65 jsPlumb.registerConnectorType(Bezier, "Bezier");