좋아, 웃지 마. 소스와 대상 사이에있는 노드 주변을 우회하는 곡선 형 가장자리를 만들려고합니다. 나는 그것을하는 방법을 알아낼 수 없었습니다 ( http://js.cytoscape.org/#style/bezier-edges를 읽었 지만 이해하지 못했습니다), 그래서 나는 도중에 빈 장소에 가짜 노드를 넣었습니다. 소스를 대상으로하고 일련의 가장자리를 만들었습니다. 결과는 매우 우스꽝 스럽습니다.
이를 수행하는 올바른 방법은 무엇입니까? 나는 다음과 같이 약간 더 우아한 것을 목표로하고 있었다.
에서 http://twitter.github.io/labella.js/
를 기반으로 @maxkfranz 내가 가까이 많이 얻었다 아래의 조언 :
but finally decided to give up. It's taking too long. Going back to straight edges. If anyone ever reads this and can describe a way to accomplish my goal in Cytoscape.js or some other tool, I'd love to hear it.
To be clear about what I'm doing before giving up, I:
Here's the most relevant part of my code:
function waypoints(from, to) {
let stubPoint = { row: from.data().row, col: from.data().col,
distance: 0, weight: .5, };
if (from.data().layer === to.data().layer)
return [stubPoint];
let fromCol = from.data().col,
curCol = fromCol,
toCol = to.data().col,
fromRow = from.data().row,
curRow = fromRow,
toRow = to.data().row,
fromX = from.position().x,
fromY = from.position().y,
toX = to.position().x,
toY = to.position().y,
x = d3.scaleLinear().domain([fromCol,toCol]).range([fromX,toX]),
y = d3.scaleLinear().domain([fromRow,toRow]).range([fromY,toY]);
let rowsBetween = _.range(fromRow, toRow).slice(1);
let edgeLength = pointToPointDist(x(fromCol),y(fromRow),x(toCol),y(toRow));
let points = rowsBetween.map(
(nextRow,i) => {
let colsRemaining = toCol - curCol;
let colsNow = Math.ceil(colsRemaining / Math.abs(toRow - curRow));
let nextCol = findEmptyGridCol(nextRow, curCol, curCol + colsNow);
let curX = x(curCol), curY = y(curRow),
nextX = x(nextCol), nextY = y(nextRow);
let [distanceFromEdge, distanceOnEdge] =
perpendicular_coords(curX, curY, toX, toY, nextX, nextY);
let point = {curCol, curRow,
toCol, toRow,
nextCol, nextRow,
curX, curY, toX, toY, nextX, nextY,
edgeLength,
colsNow,
//wayCol, wayRow,
distance:-distanceFromEdge * 2,
weight:distanceOnEdge / edgeLength,
};
curCol = nextCol;
curRow = nextRow;
return point;
});
if (points.length === 0)
return [stubPoint];
return points;
}
The set of control points for an edge is defined by N weights (w1, w2, ... wN) and N respective distances (d1, d2, ... dN).
The weight defines how close a point is to the source or target, and the distance controls how far away from a source-target line the point should be. The sign of the distance controls the side of the source-target line that the curve lies on (i.e the handedness). See the docs for more info: http://js.cytoscape.org/#style/bezier-edges
The following diagram summarises the values for a single point for simplicity, but you could extend this to multiple points:
Note that the above image assumes edge-distances: node-position
, whereas the following diagram assumes edge-distances: intersection
(default):
For complex usecases, edge-distances: node-position
makes calculations easier -- but you have to be more careful to not specify points in the node body. The end result is almost the same for these examples, so I didn't update the curve. Larger nodes of different sizes would make the difference between these cases more apparent.
베 지어의 제어점은 제어점과 교차하지 않습니다. 제어점은 곡선을 점을 향해 "당깁니다". Cytoscape와 같은 2 차 베 지어의 경우 곡선의 거리는 제어점의 절반이됩니다. 베 지어에 대한 자세한 내용은 Wikipedia를 참조하십시오. https://en.wikipedia.org/wiki/B%C3%A9zier_curve
반면에 세그먼트 가장자리는 일련의 직선이기 때문에 지정한 점과 교차합니다. http://js.cytoscape.org/#style/segments-edges
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다