2018-06-05 23:58:10 +08:00
|
|
|
/**
|
2018-06-11 17:19:09 +08:00
|
|
|
* @fileOverview extend quadraticCurve
|
|
|
|
* model configurable:
|
|
|
|
* cpd control point distance detail {number} could be 0 ~ 1
|
2018-06-05 23:58:10 +08:00
|
|
|
* @author huangtonger@aliyun.com
|
|
|
|
*/
|
2018-06-13 17:38:00 +08:00
|
|
|
const G6 = require('../../src/index');
|
2018-06-11 17:19:09 +08:00
|
|
|
const Util = G6.Util;
|
2018-06-11 21:29:00 +08:00
|
|
|
|
2018-06-05 23:58:10 +08:00
|
|
|
G6.registerEdge('quadraticCurve', {
|
|
|
|
getPath(item) {
|
|
|
|
const points = item.getPoints();
|
2018-06-11 17:19:09 +08:00
|
|
|
const model = item.getModel();
|
2018-06-05 23:58:10 +08:00
|
|
|
const start = points[0];
|
|
|
|
const source = item.getSource();
|
|
|
|
const target = item.getTarget();
|
|
|
|
const end = points[points.length - 1];
|
2018-06-11 17:19:09 +08:00
|
|
|
const cpd = !Util.isNil(model.cpd) ? model.cpd : 0.5; // 向量方向长度系数
|
|
|
|
const v1 = [ (end.x + start.x) * 0.5 - start.x, (end.y + start.y) * 0.5 - start.y ];
|
|
|
|
const v2 = [ -v1[1] * cpd, v1[0] * cpd ];
|
2018-06-11 21:29:00 +08:00
|
|
|
|
2018-06-05 23:58:10 +08:00
|
|
|
// 控制点
|
|
|
|
const cp = {
|
2018-06-11 17:19:09 +08:00
|
|
|
x: v1[0] + v2[0] + start.x,
|
2018-06-11 21:29:00 +08:00
|
|
|
y: v1[1] + v2[1] + start.y
|
2018-06-05 23:58:10 +08:00
|
|
|
};
|
|
|
|
const sp = source.getLinkPoints(cp)[0];
|
|
|
|
const tp = target.getLinkPoints(cp)[0];
|
|
|
|
return [
|
|
|
|
[ 'M', sp.x, sp.y ],
|
|
|
|
[ 'Q', cp.x, cp.y, tp.x, tp.y ]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|