cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
119 lines (118 loc) • 3.98 kB
JavaScript
import { quadraticSubdivide, quadraticAt as quadraticAt$1 } from "../../../../zrender/lib/core/curve.mjs";
import { clone, copy, sub, normalize, scaleAndAdd, distSquare } from "../../../../zrender/lib/core/vector.mjs";
import { getSymbolSize } from "./graphHelper.mjs";
var v1 = [];
var v2 = [];
var v3 = [];
var quadraticAt = quadraticAt$1;
var v2DistSquare = distSquare;
var mathAbs = Math.abs;
function intersectCurveCircle(curvePoints, center, radius) {
var p0 = curvePoints[0];
var p1 = curvePoints[1];
var p2 = curvePoints[2];
var d = Infinity;
var t;
var radiusSquare = radius * radius;
var interval = 0.1;
for (var _t = 0.1; _t <= 0.9; _t += 0.1) {
v1[0] = quadraticAt(p0[0], p1[0], p2[0], _t);
v1[1] = quadraticAt(p0[1], p1[1], p2[1], _t);
var diff = mathAbs(v2DistSquare(v1, center) - radiusSquare);
if (diff < d) {
d = diff;
t = _t;
}
}
for (var i = 0; i < 32; i++) {
var next = t + interval;
v2[0] = quadraticAt(p0[0], p1[0], p2[0], t);
v2[1] = quadraticAt(p0[1], p1[1], p2[1], t);
v3[0] = quadraticAt(p0[0], p1[0], p2[0], next);
v3[1] = quadraticAt(p0[1], p1[1], p2[1], next);
var diff = v2DistSquare(v2, center) - radiusSquare;
if (mathAbs(diff) < 0.01) {
break;
}
var nextDiff = v2DistSquare(v3, center) - radiusSquare;
interval /= 2;
if (diff < 0) {
if (nextDiff >= 0) {
t = t + interval;
} else {
t = t - interval;
}
} else {
if (nextDiff >= 0) {
t = t - interval;
} else {
t = t + interval;
}
}
}
return t;
}
function adjustEdge(graph, scale) {
var tmp0 = [];
var quadraticSubdivide$1 = quadraticSubdivide;
var pts = [[], [], []];
var pts2 = [[], []];
var v = [];
scale /= 2;
graph.eachEdge(function(edge, idx) {
var linePoints = edge.getLayout();
var fromSymbol = edge.getVisual("fromSymbol");
var toSymbol = edge.getVisual("toSymbol");
if (!linePoints.__original) {
linePoints.__original = [clone(linePoints[0]), clone(linePoints[1])];
if (linePoints[2]) {
linePoints.__original.push(clone(linePoints[2]));
}
}
var originalPoints = linePoints.__original;
if (linePoints[2] != null) {
copy(pts[0], originalPoints[0]);
copy(pts[1], originalPoints[2]);
copy(pts[2], originalPoints[1]);
if (fromSymbol && fromSymbol !== "none") {
var symbolSize = getSymbolSize(edge.node1);
var t = intersectCurveCircle(pts, originalPoints[0], symbolSize * scale);
quadraticSubdivide$1(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
pts[0][0] = tmp0[3];
pts[1][0] = tmp0[4];
quadraticSubdivide$1(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
pts[0][1] = tmp0[3];
pts[1][1] = tmp0[4];
}
if (toSymbol && toSymbol !== "none") {
var symbolSize = getSymbolSize(edge.node2);
var t = intersectCurveCircle(pts, originalPoints[1], symbolSize * scale);
quadraticSubdivide$1(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
pts[1][0] = tmp0[1];
pts[2][0] = tmp0[2];
quadraticSubdivide$1(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
pts[1][1] = tmp0[1];
pts[2][1] = tmp0[2];
}
copy(linePoints[0], pts[0]);
copy(linePoints[1], pts[2]);
copy(linePoints[2], pts[1]);
} else {
copy(pts2[0], originalPoints[0]);
copy(pts2[1], originalPoints[1]);
sub(v, pts2[1], pts2[0]);
normalize(v, v);
if (fromSymbol && fromSymbol !== "none") {
var symbolSize = getSymbolSize(edge.node1);
scaleAndAdd(pts2[0], pts2[0], v, symbolSize * scale);
}
if (toSymbol && toSymbol !== "none") {
var symbolSize = getSymbolSize(edge.node2);
scaleAndAdd(pts2[1], pts2[1], v, -symbolSize * scale);
}
copy(linePoints[0], pts2[0]);
copy(linePoints[1], pts2[1]);
}
});
}
export { adjustEdge as default };