feat(helper): export project function closes #237
This commit is contained in:
@@ -12,7 +12,7 @@ import useD3Zoom from '../../hooks/useD3Zoom';
|
||||
import useGlobalKeyHandler from '../../hooks/useGlobalKeyHandler';
|
||||
import useElementUpdater from '../../hooks/useElementUpdater';
|
||||
import { getDimensions } from '../../utils';
|
||||
import { fitView, zoomIn, zoomOut } from '../../utils/graph';
|
||||
import { fitView, zoomIn, zoomOut, project } from '../../utils/graph';
|
||||
import { Elements, NodeTypesType, EdgeTypesType, GridType, OnLoadFunc, Node, Edge, Connection } from '../../types';
|
||||
|
||||
export interface GraphViewProps {
|
||||
@@ -115,6 +115,7 @@ const GraphView = memo(
|
||||
fitView,
|
||||
zoomIn,
|
||||
zoomOut,
|
||||
project,
|
||||
});
|
||||
}
|
||||
}, [state.d3Initialised]);
|
||||
|
||||
@@ -133,11 +133,13 @@ export type FitViewParams = {
|
||||
padding: number;
|
||||
};
|
||||
export type FitViewFunc = (fitViewOptions: FitViewParams) => void;
|
||||
export type ProjectFunc = (position: XYPosition) => XYPosition;
|
||||
|
||||
type OnLoadParams = {
|
||||
zoomIn: () => void;
|
||||
zoomOut: () => void;
|
||||
fitView: FitViewFunc;
|
||||
project: ProjectFunc;
|
||||
};
|
||||
|
||||
export type OnLoadFunc = (params: OnLoadParams) => void;
|
||||
|
||||
@@ -74,6 +74,12 @@ export const pointToRendererPoint = (
|
||||
return position;
|
||||
};
|
||||
|
||||
export const project = (position: XYPosition): XYPosition => {
|
||||
const { transform, snapToGrid, snapGrid } = store.getState();
|
||||
|
||||
return pointToRendererPoint(position, transform, snapToGrid, snapGrid);
|
||||
};
|
||||
|
||||
export const parseElement = (element: Node | Edge): Node | Edge => {
|
||||
if (!element.id) {
|
||||
throw new Error('All elements (nodes and edges) need to have an id.');
|
||||
|
||||
Reference in New Issue
Block a user