From e146a63be82d859a5fc1091a85c35ecc8533653d Mon Sep 17 00:00:00 2001 From: moklick Date: Mon, 7 Oct 2019 21:58:22 +0200 Subject: [PATCH] feat(editor): add gridSize and showGrid params --- dist/ReactGraph.js | 19 ++++++++++++++----- examples/advanced/scripts/ExampleGraph.js | 1 + examples/basic/scripts/ExampleGraph.js | 1 + src/container/GraphView/index.js | 4 ++-- src/container/ReactFlow/index.js | 9 +++++++-- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/dist/ReactGraph.js b/dist/ReactGraph.js index 22e94c7b..080ae1c0 100644 --- a/dist/ReactGraph.js +++ b/dist/ReactGraph.js @@ -9169,7 +9169,9 @@ deleteKeyCode = _ref.deleteKeyCode, elements = _ref.elements, onConnect = _ref.onConnect, - gridColor = _ref.gridColor; + gridColor = _ref.gridColor, + showGrid = _ref.showGrid, + gridGap = _ref.gridGap; var zoomPane = React.useRef(); var rendererNode = React.useRef(); var state = useStoreState(function (s) { @@ -9232,7 +9234,8 @@ return React__default.createElement("div", { className: "react-flow__renderer", ref: rendererNode - }, React__default.createElement(GridRenderer, { + }, showGrid && React__default.createElement(GridRenderer, { + gap: gridGap, strokeColor: gridColor }), React__default.createElement(NodeRenderer, { nodeTypes: nodeTypes, @@ -9929,7 +9932,9 @@ connectionLineStyle = _ref.connectionLineStyle, deleteKeyCode = _ref.deleteKeyCode, selectionKeyCode = _ref.selectionKeyCode, - gridColor = _ref.gridColor; + gridColor = _ref.gridColor, + showGrid = _ref.showGrid, + gridGap = _ref.gridGap; var nodeTypesParsed = React.useMemo(function () { return createNodeTypes(nodeTypes); }, []); @@ -9955,7 +9960,9 @@ deleteKeyCode: deleteKeyCode, elements: elements, onConnect: onConnect, - gridColor: gridColor + gridColor: gridColor, + gridGap: gridGap, + showGrid: showGrid }), children)); }; @@ -9981,7 +9988,9 @@ connectionLineStyle: {}, deleteKeyCode: 8, selectionKeyCode: 16, - gridColor: '#999' + gridColor: '#999', + gridGap: 24, + showGrid: true }; var baseStyle = { diff --git a/examples/advanced/scripts/ExampleGraph.js b/examples/advanced/scripts/ExampleGraph.js index 4d23c50e..7f5b0b8f 100644 --- a/examples/advanced/scripts/ExampleGraph.js +++ b/examples/advanced/scripts/ExampleGraph.js @@ -146,6 +146,7 @@ class App extends PureComponent { connectionLineStyle={{ stroke: '#ddd', strokeWidth: 2 }} connectionLineType="bezier" gridColor="#aaa" + gridGap={16} > ); } diff --git a/src/container/GraphView/index.js b/src/container/GraphView/index.js index f31e4a15..54811490 100644 --- a/src/container/GraphView/index.js +++ b/src/container/GraphView/index.js @@ -17,7 +17,7 @@ const GraphView = memo(({ nodeTypes, edgeTypes, onMove, onLoad, onElementClick, onNodeDragStop, connectionLineType, connectionLineStyle, selectionKeyCode, onElementsRemove, deleteKeyCode, elements, - onConnect, gridColor + onConnect, gridColor, showGrid, gridGap }) => { const zoomPane = useRef(); const rendererNode = useRef(); @@ -68,7 +68,7 @@ const GraphView = memo(({ return (
- + {showGrid && } { const nodeTypesParsed = useMemo(() => createNodeTypes(nodeTypes), []); const edgeTypesParsed = useMemo(() => createEdgeTypes(edgeTypes), []); @@ -48,6 +49,8 @@ const ReactFlow = ({ elements={elements} onConnect={onConnect} gridColor={gridColor} + gridGap={gridGap} + showGrid={showGrid} /> {children} @@ -78,7 +81,9 @@ ReactFlow.defaultProps = { connectionLineStyle: {}, deleteKeyCode: 8, selectionKeyCode: 16, - gridColor: '#999' + gridColor: '#999', + gridGap: 24, + showGrid: true }; export default ReactFlow;