chore(core): cleanup node filter fn

This commit is contained in:
braks
2023-02-06 14:06:27 +01:00
parent 23424ea675
commit 3d65627de5
+9 -4
View File
@@ -141,11 +141,16 @@ export function fitView(get: StoreApi<ReactFlowState>['getState'], options: Inte
if ((options.initial && !fitViewOnInitDone && fitViewOnInit) || !options.initial) { if ((options.initial && !fitViewOnInitDone && fitViewOnInit) || !options.initial) {
if (d3Zoom && d3Selection) { if (d3Zoom && d3Selection) {
let nodes: Node[] = getNodes().filter((n) => (options.includeHiddenNodes ? n.width && n.height : !n.hidden)); const nodes = getNodes().filter((n) => {
const isVisible = (options.includeHiddenNodes ? n.width && n.height : !n.hidden);
let shouldInclude = true;
if (options.nodes?.length) { if (options.nodes?.length) {
nodes = nodes.filter((n) => options.nodes?.includes(n.id)) shouldInclude = options.nodes.includes(n.id);
} }
return isVisible && shouldInclude;
});
const nodesInitialized = nodes.every((n) => n.width && n.height); const nodesInitialized = nodes.every((n) => n.width && n.height);