cytoscape.js에서 베 지어 곡선을 사용하는 방법

Sigfried

좋아, 웃지 마. 소스와 대상 사이에있는 노드 주변을 우회하는 곡선 형 가장자리를 만들려고합니다. 나는 그것을하는 방법을 알아낼 수 없었습니다 ( http://js.cytoscape.org/#style/bezier-edges를 읽었 지만 이해하지 못했습니다), 그래서 나는 도중에 빈 장소에 가짜 노드를 넣었습니다. 소스를 대상으로하고 일련의 가장자리를 만들었습니다. 결과는 매우 우스꽝 스럽습니다.

정말 나쁜 가장자리

이를 수행하는 올바른 방법은 무엇입니까? 나는 다음과 같이 약간 더 우아한 것을 목표로하고 있었다.

http://twitter.github.io/labella.js/에서 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:

  • lay out nodes on grid such that there is always an empty grid cell between any two nodes on the same row (this is less than ideal because the empty cells should preferably be as narrow as possible)
  • for every row on the grid layout between source and target nodes:
    • specify a "waypoint" closest to the direct path from source (or the previous waypoint) to target that passes through an empty grid cell,
    • convert row/col coordinates of the waypoint into pixel coordinates,
    • convert those into distance/weight values (based on function described here)
    • use those for unbundled bezier control points.

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;
  }
maxkfranz

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

UIView에서 베 지어 곡선을 그리는 방법

분류에서Dev

Flutter CustomPainter에서 베 지어 곡선을 사용하여 모양을 그리는 방법

분류에서Dev

시작 및 끝 접선 경사가 다른 호에 대한 베 지어 곡선을 만드는 방법

분류에서Dev

3 차 베 지어 곡선에서 루프를 방지하는 방법

분류에서Dev

베 지어 곡선을 사용하는 사인 곡선에 대한 WPF 경로 설명

분류에서Dev

베 지어 곡선을 사용하는 사인 곡선에 대한 WPF 경로 설명

분류에서Dev

많은 베 지어 곡선에서 만든 모양을 확장하는 방법 (JavaScript 및 캔버스)

분류에서Dev

베 지어 곡선에 SKPhysicsBody를 적용하는 방법은 무엇입니까?

분류에서Dev

D3js-Topojson : 픽셀 화에서 베 지어 곡선으로 이동하는 방법?

분류에서Dev

D3js-Topojson : 픽셀 화에서 베 지어 곡선으로 이동하는 방법?

분류에서Dev

Cytoscape.js 2.6 버전에서 사용자 지정 레이아웃을 추가하는 방법

분류에서Dev

베 지어 곡선 이후 CAKeyframeAnimation에서 animationDidStop을 호출하지 않음 (iOS)

분류에서Dev

물체를 피하는 베 지어 곡선 제어점을 계산하는 방법은 무엇입니까?

분류에서Dev

주어진 암시 적 함수를 사용하여 베 지어 곡선의 제어점을 계산하는 방법은 무엇입니까?

분류에서Dev

2 차 베 지어 곡선의 세 번째 제어점을 계산하는 방법은 무엇입니까?

분류에서Dev

AS3로 베 지어 곡선을 애니메이션하는 방법은 무엇입니까?

분류에서Dev

2D에서 베 지어 곡선의 법선 얻기

분류에서Dev

베 지어 곡선에 그라디언트를 추가하는 방법은 무엇입니까?

분류에서Dev

paper.js에서 베 지어 곡선 경로를 따라 개체를 애니메이션하는 방법은 무엇입니까?

분류에서Dev

cytoscape.js의 노드 외부에서 배경 이미지를 사용하는 방법

분류에서Dev

선을 구부리기 위해 베 지어 곡선의 제어점을 설정하는 방법은 무엇입니까?

분류에서Dev

매초마다 베 지어 곡선을 무작위로 그리는 방법은 무엇입니까? 또한 transition.dart 사용

분류에서Dev

WPF : DrawingContext를 사용하는 베 지어 곡선

분류에서Dev

베 지어 곡선을 다른 도면에 결합

분류에서Dev

C #에서 작동하지 않는 재귀 베 지어 곡선 알고리즘

분류에서Dev

2 차 베 지어 곡선 코드를 3 차 베 지어 곡선으로 변환하는 방법은 무엇입니까?

분류에서Dev

pylab (pyplot)에서 계단 선 (단계 곡선)을 사용하여 두 가지 색상으로 영역을 채우는 방법은 무엇입니까?

분류에서Dev

파이썬을 사용하여 여러 지수 곡선을 맞추는 방법

분류에서Dev

베 지어 곡선에서 가중치가 적용된 제어점 보정

Related 관련 기사

  1. 1

    UIView에서 베 지어 곡선을 그리는 방법

  2. 2

    Flutter CustomPainter에서 베 지어 곡선을 사용하여 모양을 그리는 방법

  3. 3

    시작 및 끝 접선 경사가 다른 호에 대한 베 지어 곡선을 만드는 방법

  4. 4

    3 차 베 지어 곡선에서 루프를 방지하는 방법

  5. 5

    베 지어 곡선을 사용하는 사인 곡선에 대한 WPF 경로 설명

  6. 6

    베 지어 곡선을 사용하는 사인 곡선에 대한 WPF 경로 설명

  7. 7

    많은 베 지어 곡선에서 만든 모양을 확장하는 방법 (JavaScript 및 캔버스)

  8. 8

    베 지어 곡선에 SKPhysicsBody를 적용하는 방법은 무엇입니까?

  9. 9

    D3js-Topojson : 픽셀 화에서 베 지어 곡선으로 이동하는 방법?

  10. 10

    D3js-Topojson : 픽셀 화에서 베 지어 곡선으로 이동하는 방법?

  11. 11

    Cytoscape.js 2.6 버전에서 사용자 지정 레이아웃을 추가하는 방법

  12. 12

    베 지어 곡선 이후 CAKeyframeAnimation에서 animationDidStop을 호출하지 않음 (iOS)

  13. 13

    물체를 피하는 베 지어 곡선 제어점을 계산하는 방법은 무엇입니까?

  14. 14

    주어진 암시 적 함수를 사용하여 베 지어 곡선의 제어점을 계산하는 방법은 무엇입니까?

  15. 15

    2 차 베 지어 곡선의 세 번째 제어점을 계산하는 방법은 무엇입니까?

  16. 16

    AS3로 베 지어 곡선을 애니메이션하는 방법은 무엇입니까?

  17. 17

    2D에서 베 지어 곡선의 법선 얻기

  18. 18

    베 지어 곡선에 그라디언트를 추가하는 방법은 무엇입니까?

  19. 19

    paper.js에서 베 지어 곡선 경로를 따라 개체를 애니메이션하는 방법은 무엇입니까?

  20. 20

    cytoscape.js의 노드 외부에서 배경 이미지를 사용하는 방법

  21. 21

    선을 구부리기 위해 베 지어 곡선의 제어점을 설정하는 방법은 무엇입니까?

  22. 22

    매초마다 베 지어 곡선을 무작위로 그리는 방법은 무엇입니까? 또한 transition.dart 사용

  23. 23

    WPF : DrawingContext를 사용하는 베 지어 곡선

  24. 24

    베 지어 곡선을 다른 도면에 결합

  25. 25

    C #에서 작동하지 않는 재귀 베 지어 곡선 알고리즘

  26. 26

    2 차 베 지어 곡선 코드를 3 차 베 지어 곡선으로 변환하는 방법은 무엇입니까?

  27. 27

    pylab (pyplot)에서 계단 선 (단계 곡선)을 사용하여 두 가지 색상으로 영역을 채우는 방법은 무엇입니까?

  28. 28

    파이썬을 사용하여 여러 지수 곡선을 맞추는 방법

  29. 29

    베 지어 곡선에서 가중치가 적용된 제어점 보정

뜨겁다태그

보관