feat(editor): add gridSize and showGrid params

This commit is contained in:
moklick
2019-10-07 21:58:22 +02:00
parent 2eda8134a8
commit e146a63be8
5 changed files with 25 additions and 9 deletions
+14 -5
View File
@@ -9169,7 +9169,9 @@
deleteKeyCode = _ref.deleteKeyCode, deleteKeyCode = _ref.deleteKeyCode,
elements = _ref.elements, elements = _ref.elements,
onConnect = _ref.onConnect, onConnect = _ref.onConnect,
gridColor = _ref.gridColor; gridColor = _ref.gridColor,
showGrid = _ref.showGrid,
gridGap = _ref.gridGap;
var zoomPane = React.useRef(); var zoomPane = React.useRef();
var rendererNode = React.useRef(); var rendererNode = React.useRef();
var state = useStoreState(function (s) { var state = useStoreState(function (s) {
@@ -9232,7 +9234,8 @@
return React__default.createElement("div", { return React__default.createElement("div", {
className: "react-flow__renderer", className: "react-flow__renderer",
ref: rendererNode ref: rendererNode
}, React__default.createElement(GridRenderer, { }, showGrid && React__default.createElement(GridRenderer, {
gap: gridGap,
strokeColor: gridColor strokeColor: gridColor
}), React__default.createElement(NodeRenderer, { }), React__default.createElement(NodeRenderer, {
nodeTypes: nodeTypes, nodeTypes: nodeTypes,
@@ -9929,7 +9932,9 @@
connectionLineStyle = _ref.connectionLineStyle, connectionLineStyle = _ref.connectionLineStyle,
deleteKeyCode = _ref.deleteKeyCode, deleteKeyCode = _ref.deleteKeyCode,
selectionKeyCode = _ref.selectionKeyCode, selectionKeyCode = _ref.selectionKeyCode,
gridColor = _ref.gridColor; gridColor = _ref.gridColor,
showGrid = _ref.showGrid,
gridGap = _ref.gridGap;
var nodeTypesParsed = React.useMemo(function () { var nodeTypesParsed = React.useMemo(function () {
return createNodeTypes(nodeTypes); return createNodeTypes(nodeTypes);
}, []); }, []);
@@ -9955,7 +9960,9 @@
deleteKeyCode: deleteKeyCode, deleteKeyCode: deleteKeyCode,
elements: elements, elements: elements,
onConnect: onConnect, onConnect: onConnect,
gridColor: gridColor gridColor: gridColor,
gridGap: gridGap,
showGrid: showGrid
}), children)); }), children));
}; };
@@ -9981,7 +9988,9 @@
connectionLineStyle: {}, connectionLineStyle: {},
deleteKeyCode: 8, deleteKeyCode: 8,
selectionKeyCode: 16, selectionKeyCode: 16,
gridColor: '#999' gridColor: '#999',
gridGap: 24,
showGrid: true
}; };
var baseStyle = { var baseStyle = {
@@ -146,6 +146,7 @@ class App extends PureComponent {
connectionLineStyle={{ stroke: '#ddd', strokeWidth: 2 }} connectionLineStyle={{ stroke: '#ddd', strokeWidth: 2 }}
connectionLineType="bezier" connectionLineType="bezier"
gridColor="#aaa" gridColor="#aaa"
gridGap={16}
> >
<MiniMap <MiniMap
style={{ position: 'absolute', right: 10, bottom: 10 }} style={{ position: 'absolute', right: 10, bottom: 10 }}
+1
View File
@@ -61,6 +61,7 @@ class App extends PureComponent {
onConnect={this.onConnect} onConnect={this.onConnect}
onNodeDragStop={onNodeDragStop} onNodeDragStop={onNodeDragStop}
style={{ width: '100%', height: '100%' }} style={{ width: '100%', height: '100%' }}
showGrid={false}
/> />
); );
} }
+2 -2
View File
@@ -17,7 +17,7 @@ const GraphView = memo(({
nodeTypes, edgeTypes, onMove, onLoad, nodeTypes, edgeTypes, onMove, onLoad,
onElementClick, onNodeDragStop, connectionLineType, connectionLineStyle, onElementClick, onNodeDragStop, connectionLineType, connectionLineStyle,
selectionKeyCode, onElementsRemove, deleteKeyCode, elements, selectionKeyCode, onElementsRemove, deleteKeyCode, elements,
onConnect, gridColor onConnect, gridColor, showGrid, gridGap
}) => { }) => {
const zoomPane = useRef(); const zoomPane = useRef();
const rendererNode = useRef(); const rendererNode = useRef();
@@ -68,7 +68,7 @@ const GraphView = memo(({
return ( return (
<div className="react-flow__renderer" ref={rendererNode}> <div className="react-flow__renderer" ref={rendererNode}>
<GridRenderer strokeColor={gridColor} /> {showGrid && <GridRenderer gap={gridGap} strokeColor={gridColor} />}
<NodeRenderer <NodeRenderer
nodeTypes={nodeTypes} nodeTypes={nodeTypes}
onElementClick={onElementClick} onElementClick={onElementClick}
+7 -2
View File
@@ -25,7 +25,8 @@ const ReactFlow = ({
style, onElementClick, elements, children, style, onElementClick, elements, children,
nodeTypes, edgeTypes, onLoad, onMove, nodeTypes, edgeTypes, onLoad, onMove,
onElementsRemove, onConnect, onNodeDragStop, connectionLineType, onElementsRemove, onConnect, onNodeDragStop, connectionLineType,
connectionLineStyle, deleteKeyCode, selectionKeyCode, gridColor connectionLineStyle, deleteKeyCode, selectionKeyCode, gridColor,
showGrid, gridGap
}) => { }) => {
const nodeTypesParsed = useMemo(() => createNodeTypes(nodeTypes), []); const nodeTypesParsed = useMemo(() => createNodeTypes(nodeTypes), []);
const edgeTypesParsed = useMemo(() => createEdgeTypes(edgeTypes), []); const edgeTypesParsed = useMemo(() => createEdgeTypes(edgeTypes), []);
@@ -48,6 +49,8 @@ const ReactFlow = ({
elements={elements} elements={elements}
onConnect={onConnect} onConnect={onConnect}
gridColor={gridColor} gridColor={gridColor}
gridGap={gridGap}
showGrid={showGrid}
/> />
{children} {children}
</StoreProvider> </StoreProvider>
@@ -78,7 +81,9 @@ ReactFlow.defaultProps = {
connectionLineStyle: {}, connectionLineStyle: {},
deleteKeyCode: 8, deleteKeyCode: 8,
selectionKeyCode: 16, selectionKeyCode: 16,
gridColor: '#999' gridColor: '#999',
gridGap: 24,
showGrid: true
}; };
export default ReactFlow; export default ReactFlow;