fix(minZoom,maxZoom): pass min- maxZoom for initial view closes #2343
This commit is contained in:
@@ -18,8 +18,8 @@ import ColorSelectorNode from './ColorSelectorNode';
|
|||||||
|
|
||||||
const onInit = (reactFlowInstance: ReactFlowInstance) => {
|
const onInit = (reactFlowInstance: ReactFlowInstance) => {
|
||||||
console.log('flow loaded:', reactFlowInstance);
|
console.log('flow loaded:', reactFlowInstance);
|
||||||
reactFlowInstance.fitView();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onNodeDragStop = (_: MouseEvent, node: Node) => console.log('drag stop', node);
|
const onNodeDragStop = (_: MouseEvent, node: Node) => console.log('drag stop', node);
|
||||||
const onNodeClick = (_: MouseEvent, node: Node) => console.log('click', node);
|
const onNodeClick = (_: MouseEvent, node: Node) => console.log('click', node);
|
||||||
|
|
||||||
@@ -117,8 +117,9 @@ const CustomNodeFlow = () => {
|
|||||||
connectionLineStyle={connectionLineStyle}
|
connectionLineStyle={connectionLineStyle}
|
||||||
snapToGrid={true}
|
snapToGrid={true}
|
||||||
snapGrid={snapGrid}
|
snapGrid={snapGrid}
|
||||||
defaultZoom={1.5}
|
defaultZoom={0.3}
|
||||||
fitView
|
minZoom={0.3}
|
||||||
|
maxZoom={2}
|
||||||
>
|
>
|
||||||
<MiniMap
|
<MiniMap
|
||||||
nodeStrokeColor={(n: Node): string => {
|
nodeStrokeColor={(n: Node): string => {
|
||||||
|
|||||||
@@ -48,8 +48,11 @@ const FlowRenderer = ({
|
|||||||
panOnScrollMode,
|
panOnScrollMode,
|
||||||
zoomOnDoubleClick,
|
zoomOnDoubleClick,
|
||||||
panOnDrag,
|
panOnDrag,
|
||||||
defaultPosition,
|
translateExtent,
|
||||||
|
minZoom,
|
||||||
|
maxZoom,
|
||||||
defaultZoom,
|
defaultZoom,
|
||||||
|
defaultPosition,
|
||||||
preventScrolling,
|
preventScrolling,
|
||||||
onSelectionContextMenu,
|
onSelectionContextMenu,
|
||||||
noWheelClassName,
|
noWheelClassName,
|
||||||
@@ -84,8 +87,11 @@ const FlowRenderer = ({
|
|||||||
panOnScrollMode={panOnScrollMode}
|
panOnScrollMode={panOnScrollMode}
|
||||||
zoomOnDoubleClick={zoomOnDoubleClick}
|
zoomOnDoubleClick={zoomOnDoubleClick}
|
||||||
panOnDrag={panOnDrag}
|
panOnDrag={panOnDrag}
|
||||||
defaultPosition={defaultPosition}
|
translateExtent={translateExtent}
|
||||||
|
minZoom={minZoom}
|
||||||
|
maxZoom={maxZoom}
|
||||||
defaultZoom={defaultZoom}
|
defaultZoom={defaultZoom}
|
||||||
|
defaultPosition={defaultPosition}
|
||||||
zoomActivationKeyCode={zoomActivationKeyCode}
|
zoomActivationKeyCode={zoomActivationKeyCode}
|
||||||
preventScrolling={preventScrolling}
|
preventScrolling={preventScrolling}
|
||||||
noWheelClassName={noWheelClassName}
|
noWheelClassName={noWheelClassName}
|
||||||
|
|||||||
@@ -5,7 +5,14 @@ import NodeRenderer from '../NodeRenderer';
|
|||||||
import EdgeRenderer from '../EdgeRenderer';
|
import EdgeRenderer from '../EdgeRenderer';
|
||||||
import Viewport from '../Viewport';
|
import Viewport from '../Viewport';
|
||||||
import useOnInitHandler from '../../hooks/useOnInitHandler';
|
import useOnInitHandler from '../../hooks/useOnInitHandler';
|
||||||
import { NodeTypesWrapped, EdgeTypesWrapped, ConnectionLineType, KeyCode, ReactFlowProps } from '../../types';
|
import {
|
||||||
|
NodeTypesWrapped,
|
||||||
|
EdgeTypesWrapped,
|
||||||
|
ConnectionLineType,
|
||||||
|
KeyCode,
|
||||||
|
ReactFlowProps,
|
||||||
|
CoordinateExtent,
|
||||||
|
} from '../../types';
|
||||||
|
|
||||||
export interface GraphViewProps
|
export interface GraphViewProps
|
||||||
extends Omit<ReactFlowProps, 'onSelectionChange' | 'nodes' | 'edges' | 'nodeTypes' | 'edgeTypes'> {
|
extends Omit<ReactFlowProps, 'onSelectionChange' | 'nodes' | 'edges' | 'nodeTypes' | 'edgeTypes'> {
|
||||||
@@ -16,6 +23,9 @@ export interface GraphViewProps
|
|||||||
multiSelectionKeyCode: KeyCode | null;
|
multiSelectionKeyCode: KeyCode | null;
|
||||||
connectionLineType: ConnectionLineType;
|
connectionLineType: ConnectionLineType;
|
||||||
onlyRenderVisibleElements: boolean;
|
onlyRenderVisibleElements: boolean;
|
||||||
|
translateExtent: CoordinateExtent;
|
||||||
|
minZoom: number;
|
||||||
|
maxZoom: number;
|
||||||
defaultZoom: number;
|
defaultZoom: number;
|
||||||
defaultPosition: [number, number];
|
defaultPosition: [number, number];
|
||||||
defaultMarkerColor: string;
|
defaultMarkerColor: string;
|
||||||
@@ -52,6 +62,9 @@ const GraphView = ({
|
|||||||
onlyRenderVisibleElements,
|
onlyRenderVisibleElements,
|
||||||
elementsSelectable,
|
elementsSelectable,
|
||||||
selectNodesOnDrag,
|
selectNodesOnDrag,
|
||||||
|
translateExtent,
|
||||||
|
minZoom,
|
||||||
|
maxZoom,
|
||||||
defaultZoom,
|
defaultZoom,
|
||||||
defaultPosition,
|
defaultPosition,
|
||||||
preventScrolling,
|
preventScrolling,
|
||||||
@@ -102,8 +115,11 @@ const GraphView = ({
|
|||||||
panOnScrollSpeed={panOnScrollSpeed}
|
panOnScrollSpeed={panOnScrollSpeed}
|
||||||
panOnScrollMode={panOnScrollMode}
|
panOnScrollMode={panOnScrollMode}
|
||||||
panOnDrag={panOnDrag}
|
panOnDrag={panOnDrag}
|
||||||
defaultPosition={defaultPosition}
|
translateExtent={translateExtent}
|
||||||
|
minZoom={minZoom}
|
||||||
|
maxZoom={maxZoom}
|
||||||
defaultZoom={defaultZoom}
|
defaultZoom={defaultZoom}
|
||||||
|
defaultPosition={defaultPosition}
|
||||||
onSelectionContextMenu={onSelectionContextMenu}
|
onSelectionContextMenu={onSelectionContextMenu}
|
||||||
preventScrolling={preventScrolling}
|
preventScrolling={preventScrolling}
|
||||||
noDragClassName={noDragClassName}
|
noDragClassName={noDragClassName}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import GraphView from '../GraphView';
|
|||||||
import { createNodeTypes } from '../NodeRenderer/utils';
|
import { createNodeTypes } from '../NodeRenderer/utils';
|
||||||
import { injectStyle, useNodeOrEdgeTypes } from './utils';
|
import { injectStyle, useNodeOrEdgeTypes } from './utils';
|
||||||
import Wrapper from './Wrapper';
|
import Wrapper from './Wrapper';
|
||||||
|
import { infiniteExtent } from '../../store/initialState';
|
||||||
|
|
||||||
if (__INJECT_STYLES__) {
|
if (__INJECT_STYLES__) {
|
||||||
injectStyle(css as unknown as string);
|
injectStyle(css as unknown as string);
|
||||||
@@ -103,11 +104,11 @@ const ReactFlow = forwardRef<ReactFlowRefType, ReactFlowProps>(
|
|||||||
nodesDraggable,
|
nodesDraggable,
|
||||||
nodesConnectable,
|
nodesConnectable,
|
||||||
elementsSelectable,
|
elementsSelectable,
|
||||||
minZoom,
|
minZoom = 0.5,
|
||||||
maxZoom,
|
maxZoom = 2,
|
||||||
defaultZoom = 1,
|
defaultZoom = 1,
|
||||||
defaultPosition = initDefaultPosition,
|
defaultPosition = initDefaultPosition,
|
||||||
translateExtent,
|
translateExtent = infiniteExtent,
|
||||||
preventScrolling = true,
|
preventScrolling = true,
|
||||||
nodeExtent,
|
nodeExtent,
|
||||||
defaultMarkerColor = '#b1b1b7',
|
defaultMarkerColor = '#b1b1b7',
|
||||||
@@ -177,6 +178,9 @@ const ReactFlow = forwardRef<ReactFlowRefType, ReactFlowProps>(
|
|||||||
zoomActivationKeyCode={zoomActivationKeyCode}
|
zoomActivationKeyCode={zoomActivationKeyCode}
|
||||||
onlyRenderVisibleElements={onlyRenderVisibleElements}
|
onlyRenderVisibleElements={onlyRenderVisibleElements}
|
||||||
selectNodesOnDrag={selectNodesOnDrag}
|
selectNodesOnDrag={selectNodesOnDrag}
|
||||||
|
translateExtent={translateExtent}
|
||||||
|
minZoom={minZoom}
|
||||||
|
maxZoom={maxZoom}
|
||||||
defaultZoom={defaultZoom}
|
defaultZoom={defaultZoom}
|
||||||
defaultPosition={defaultPosition}
|
defaultPosition={defaultPosition}
|
||||||
preventScrolling={preventScrolling}
|
preventScrolling={preventScrolling}
|
||||||
|
|||||||
@@ -45,8 +45,11 @@ const ZoomPane = ({
|
|||||||
selectionKeyPressed,
|
selectionKeyPressed,
|
||||||
elementsSelectable,
|
elementsSelectable,
|
||||||
panOnDrag = true,
|
panOnDrag = true,
|
||||||
defaultPosition = [0, 0],
|
translateExtent,
|
||||||
|
minZoom,
|
||||||
|
maxZoom,
|
||||||
defaultZoom = 1,
|
defaultZoom = 1,
|
||||||
|
defaultPosition = [0, 0],
|
||||||
zoomActivationKeyCode,
|
zoomActivationKeyCode,
|
||||||
preventScrolling = true,
|
preventScrolling = true,
|
||||||
children,
|
children,
|
||||||
@@ -56,6 +59,7 @@ const ZoomPane = ({
|
|||||||
const store = useStoreApi();
|
const store = useStoreApi();
|
||||||
const isZoomingOrPanning = useRef(false);
|
const isZoomingOrPanning = useRef(false);
|
||||||
const zoomPane = useRef<HTMLDivElement>(null);
|
const zoomPane = useRef<HTMLDivElement>(null);
|
||||||
|
const initialized = useRef(false);
|
||||||
const prevTransform = useRef<Viewport>({ x: 0, y: 0, zoom: 0 });
|
const prevTransform = useRef<Viewport>({ x: 0, y: 0, zoom: 0 });
|
||||||
const { d3Zoom, d3Selection, d3ZoomHandler } = useStore(selector, shallow);
|
const { d3Zoom, d3Selection, d3ZoomHandler } = useStore(selector, shallow);
|
||||||
const zoomActivationKeyPressed = useKeyPress(zoomActivationKeyCode);
|
const zoomActivationKeyPressed = useKeyPress(zoomActivationKeyCode);
|
||||||
@@ -63,8 +67,8 @@ const ZoomPane = ({
|
|||||||
useResizeHandler(zoomPane);
|
useResizeHandler(zoomPane);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (zoomPane.current) {
|
if (zoomPane.current && !initialized.current) {
|
||||||
const { minZoom, maxZoom, translateExtent } = store.getState();
|
initialized.current = true;
|
||||||
const d3ZoomInstance = zoom().scaleExtent([minZoom, maxZoom]).translateExtent(translateExtent);
|
const d3ZoomInstance = zoom().scaleExtent([minZoom, maxZoom]).translateExtent(translateExtent);
|
||||||
const selection = select(zoomPane.current as Element).call(d3ZoomInstance);
|
const selection = select(zoomPane.current as Element).call(d3ZoomInstance);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user