fix(examples): use computed attribute
This commit is contained in:
@@ -4,8 +4,12 @@ import { Node, Position, MarkerType, XYPosition } from '@xyflow/react';
|
|||||||
// of the line between the center of the intersectionNode and the target node
|
// of the line between the center of the intersectionNode and the target node
|
||||||
function getNodeIntersection(intersectionNode: Node, targetNode: Node) {
|
function getNodeIntersection(intersectionNode: Node, targetNode: Node) {
|
||||||
// https://math.stackexchange.com/questions/1724792/an-algorithm-for-finding-the-intersection-point-between-a-center-of-vision-and-a
|
// https://math.stackexchange.com/questions/1724792/an-algorithm-for-finding-the-intersection-point-between-a-center-of-vision-and-a
|
||||||
const { width: intersectionNodeWidth, height: intersectionNodeHeight } = intersectionNode;
|
|
||||||
const intersectionNodePosition = intersectionNode.computed?.positionAbsolute!;
|
const {
|
||||||
|
width: intersectionNodeWidth,
|
||||||
|
height: intersectionNodeHeight,
|
||||||
|
positionAbsolute: intersectionNodePosition,
|
||||||
|
} = intersectionNode.computed || {};
|
||||||
const targetPosition = targetNode.computed?.positionAbsolute!;
|
const targetPosition = targetNode.computed?.positionAbsolute!;
|
||||||
|
|
||||||
const w = intersectionNodeWidth! / 2;
|
const w = intersectionNodeWidth! / 2;
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import { Position, XYPosition, Node, Edge } from '@xyflow/react';
|
|||||||
function getNodeIntersection(intersectionNode: Node, targetNode: Node): XYPosition {
|
function getNodeIntersection(intersectionNode: Node, targetNode: Node): XYPosition {
|
||||||
// https://math.stackexchange.com/questions/1724792/an-algorithm-for-finding-the-intersection-point-between-a-center-of-vision-and-a
|
// https://math.stackexchange.com/questions/1724792/an-algorithm-for-finding-the-intersection-point-between-a-center-of-vision-and-a
|
||||||
|
|
||||||
const {
|
const { position: intersectionNodePosition } = intersectionNode;
|
||||||
width: intersectionNodeWidth,
|
const { width: intersectionNodeWidth, height: intersectionNodeHeight } = intersectionNode.computed ?? {
|
||||||
height: intersectionNodeHeight,
|
width: 0,
|
||||||
position: intersectionNodePosition,
|
height: 0,
|
||||||
} = intersectionNode;
|
};
|
||||||
const targetPosition = targetNode.position;
|
const targetPosition = targetNode.position;
|
||||||
|
|
||||||
const w = (intersectionNodeWidth ?? 0) / 2;
|
const w = (intersectionNodeWidth ?? 0) / 2;
|
||||||
@@ -60,6 +60,8 @@ export function getEdgeParams(source: Node, target: Node) {
|
|||||||
const sourceIntersectionPoint = getNodeIntersection(source, target);
|
const sourceIntersectionPoint = getNodeIntersection(source, target);
|
||||||
const targetIntersectionPoint = getNodeIntersection(target, source);
|
const targetIntersectionPoint = getNodeIntersection(target, source);
|
||||||
|
|
||||||
|
console.log(sourceIntersectionPoint, targetIntersectionPoint);
|
||||||
|
|
||||||
const sourcePos = getEdgePosition(source, sourceIntersectionPoint);
|
const sourcePos = getEdgePosition(source, sourceIntersectionPoint);
|
||||||
const targetPos = getEdgePosition(target, targetIntersectionPoint);
|
const targetPos = getEdgePosition(target, targetIntersectionPoint);
|
||||||
|
|
||||||
|
|||||||
@@ -48,8 +48,10 @@ const initialEdges: Edge[] = [
|
|||||||
|
|
||||||
const setHidden = (hidden: boolean) => (els: any[]) =>
|
const setHidden = (hidden: boolean) => (els: any[]) =>
|
||||||
els.map((e: any) => {
|
els.map((e: any) => {
|
||||||
e.hidden = hidden;
|
return {
|
||||||
return e;
|
...e,
|
||||||
|
hidden,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const HiddenFlow = () => {
|
const HiddenFlow = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user