refactor(positions): remove unused node origins

This commit is contained in:
moklick
2024-06-27 15:03:35 +02:00
parent 1a51428bd4
commit 609f7ed792
12 changed files with 64 additions and 69 deletions
+1 -2
View File
@@ -7,7 +7,7 @@ import type { ZoomBehavior } from 'd3-zoom';
import type { Transition } from 'd3-transition';
import type { XYPosition, Rect } from './utils';
import type { InternalNodeBase, NodeBase, NodeDragItem, NodeOrigin } from './nodes';
import type { InternalNodeBase, NodeBase, NodeDragItem } from './nodes';
import type { ConnectingHandle, HandleType } from './handles';
import { PanZoomInstance } from './panzoom';
import { EdgeBase } from '..';
@@ -63,7 +63,6 @@ export type FitViewParamsBase<NodeType extends NodeBase> = {
panZoom: PanZoomInstance;
minZoom: number;
maxZoom: number;
nodeOrigin?: NodeOrigin;
};
export type FitViewOptionsBase<NodeType extends NodeBase = NodeBase> = {
+9 -13
View File
@@ -147,7 +147,6 @@ export const getNodesBounds = (nodes: NodeBase[], params: GetNodesBoundsParams =
};
export type GetInternalNodesBoundsParams<NodeType> = {
nodeOrigin?: NodeOrigin;
useRelativePosition?: boolean;
filter?: (node: NodeType) => boolean;
};
@@ -158,9 +157,7 @@ export type GetInternalNodesBoundsParams<NodeType> = {
*/
export const getInternalNodesBounds = <NodeType extends InternalNodeBase | NodeDragItem>(
nodeLookup: Map<string, NodeType>,
params: GetInternalNodesBoundsParams<NodeType> = {
nodeOrigin: [0, 0],
}
params: GetInternalNodesBoundsParams<NodeType> = {}
): Rect => {
if (nodeLookup.size === 0) {
return { x: 0, y: 0, width: 0, height: 0 };
@@ -170,7 +167,7 @@ export const getInternalNodesBounds = <NodeType extends InternalNodeBase | NodeD
nodeLookup.forEach((node) => {
if (params.filter == undefined || params.filter(node)) {
const nodeBox = nodeToBox(node as InternalNodeBase, params.nodeOrigin);
const nodeBox = nodeToBox(node as InternalNodeBase);
box = getBoundsOfBoxes(box, nodeBox);
}
});
@@ -184,8 +181,7 @@ export const getNodesInside = <NodeType extends NodeBase = NodeBase>(
[tx, ty, tScale]: Transform = [0, 0, 1],
partially = false,
// set excludeNonSelectableNodes if you want to pay attention to the nodes "selectable" attribute
excludeNonSelectableNodes = false,
nodeOrigin: NodeOrigin = [0, 0]
excludeNonSelectableNodes = false
): InternalNodeBase<NodeType>[] => {
const paneRect = {
...pointToRendererPoint(rect, [tx, ty, tScale]),
@@ -204,7 +200,7 @@ export const getNodesInside = <NodeType extends NodeBase = NodeBase>(
continue;
}
const overlappingArea = getOverlappingArea(paneRect, nodeToRect(node, nodeOrigin));
const overlappingArea = getOverlappingArea(paneRect, nodeToRect(node));
const notInitialized = width === null || height === null;
const partiallyVisible = partially && overlappingArea > 0;
@@ -238,22 +234,22 @@ export const getConnectedEdges = <NodeType extends NodeBase = NodeBase, EdgeType
};
export function fitView<Params extends FitViewParamsBase<NodeBase>, Options extends FitViewOptionsBase<NodeBase>>(
{ nodeLookup, width, height, panZoom, minZoom, maxZoom, nodeOrigin = [0, 0] }: Params,
{ nodeLookup, width, height, panZoom, minZoom, maxZoom }: Params,
options?: Options
) {
const filteredNodes: InternalNodeBase[] = [];
const filteredNodes: Map<string, InternalNodeBase> = new Map();
const optionNodeIds = options?.nodes ? new Set(options.nodes.map((node) => node.id)) : null;
nodeLookup.forEach((n) => {
const isVisible = n.measured.width && n.measured.height && (options?.includeHiddenNodes || !n.hidden);
if (isVisible && (!optionNodeIds || optionNodeIds.has(n.id))) {
filteredNodes.push(n);
filteredNodes.set(n.id, n);
}
});
if (filteredNodes.length > 0) {
const bounds = getNodesBounds(filteredNodes, { nodeOrigin });
if (filteredNodes.size > 0) {
const bounds = getInternalNodesBounds(filteredNodes);
const viewport = getViewportForBounds(
bounds,
+1 -1
View File
@@ -124,7 +124,7 @@ export function XYDrag<OnNodeDrag extends (e: any, nodes: any, node: any) => voi
let nodesBox: Box = { x: 0, y: 0, x2: 0, y2: 0 };
if (dragItems.size > 1 && nodeExtent) {
const rect = getInternalNodesBounds(dragItems, { nodeOrigin });
const rect = getInternalNodesBounds(dragItems);
nodesBox = rectToBox(rect);
}