feat(fitView): added option to exclude hidden nodes

This commit is contained in:
Eugene Samonenko
2021-02-06 12:20:20 +02:00
parent b2043a4822
commit 7324767c31
2 changed files with 4 additions and 3 deletions
+3 -3
View File
@@ -11,7 +11,7 @@ const initialZoomPanHelper: ZoomPanHelperFunctions = {
zoomOut: () => {},
zoomTo: (_: number) => {},
transform: (_: FlowTransform) => {},
fitView: (_: FitViewParams = { padding: 0.1 }) => {},
fitView: (_: FitViewParams = { padding: 0.1, excludeHidden: false }) => {},
setCenter: (_: number, __: number) => {},
fitBounds: (_: Rect) => {},
initialized: false,
@@ -53,14 +53,14 @@ const usePanZoomHelper = (): ZoomPanHelperFunctions => {
d3Zoom.transform(d3Selection, nextTransform);
},
fitView: (options: FitViewParams = { padding: 0.1 }) => {
fitView: (options: FitViewParams = { padding: 0.1, excludeHidden: false }) => {
const { nodes, width, height, minZoom, maxZoom } = store.getState();
if (!nodes.length) {
return;
}
const bounds = getRectOfNodes(nodes);
const bounds = getRectOfNodes(options.excludeHidden ? nodes.filter(node => !node.isHidden) : nodes);
const [x, y, zoom] = getTransformForBounds(bounds, width, height, minZoom, maxZoom, options.padding);
const transform = zoomIdentity.translate(x, y).scale(zoom);
+1
View File
@@ -236,6 +236,7 @@ export interface WrapNodeProps<T = any> {
export type FitViewParams = {
padding: number;
excludeHidden?: boolean;
};
export type FlowExportObject<T = any> = {