feat(core): add nodes option to fitView

# What's changed?

- Add `nodes` option to `fitView`
- Allows `fitView` to only fit around a certain set of specified nodeIds
This commit is contained in:
braks
2023-02-06 11:13:33 +01:00
parent 357b3f096f
commit 806c1dfa77
2 changed files with 6 additions and 1 deletions
+5 -1
View File
@@ -141,7 +141,11 @@ export function fitView(get: StoreApi<ReactFlowState>['getState'], options: Inte
if ((options.initial && !fitViewOnInitDone && fitViewOnInit) || !options.initial) {
if (d3Zoom && d3Selection) {
const nodes = getNodes().filter((n) => (options.includeHiddenNodes ? n.width && n.height : !n.hidden));
let nodes: Node[] = getNodes().filter((n) => (options.includeHiddenNodes ? n.width && n.height : !n.hidden));
if (options.nodes?.length) {
nodes = nodes.filter((n) => options.nodes?.includes(n.id))
}
const nodesInitialized = nodes.every((n) => n.width && n.height);
+1
View File
@@ -76,6 +76,7 @@ export type FitViewOptions = {
minZoom?: number;
maxZoom?: number;
duration?: number;
nodes?: string[];
};
export type OnConnectStartParams = {