From 45c861953bbcf5fa59a5842b9fd5d56e48a11b82 Mon Sep 17 00:00:00 2001 From: Ian Fitzpatrick Date: Mon, 29 Aug 2016 15:57:28 -0700 Subject: [PATCH] Make snap configurable property of graph editor --- the-graph-editor/the-graph-editor.html | 2 ++ the-graph/the-graph-app.js | 10 +++++++++- the-graph/the-graph-graph.js | 3 ++- the-graph/the-graph-node.js | 2 +- the-graph/the-graph.html | 7 ++++++- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/the-graph-editor/the-graph-editor.html b/the-graph-editor/the-graph-editor.html index 4a196d62..29af83fa 100644 --- a/the-graph-editor/the-graph-editor.html +++ b/the-graph-editor/the-graph-editor.html @@ -6,6 +6,8 @@ name="{{ graph.properties.name }}" graph="{{nofloGraph}}" menus="{{menus}}" + grid="{{grid}}" + snap="{{snap}}" width="{{width}}" height="{{height}}" pan="{{pan}}" scale="{{scale}}" autolayout="{{autolayout}}" diff --git a/the-graph/the-graph-app.js b/the-graph/the-graph-app.js index 5d0c991b..2e044bf8 100644 --- a/the-graph/the-graph-app.js +++ b/the-graph/the-graph-app.js @@ -88,6 +88,12 @@ offsetX: this.props.offsetX }; }, + getDefaultProps: function () { + return { + snap: TheGraph.config.nodeSize / 2, + grid: TheGraph.config.nodeSize + }; + }, zoomFactor: 0, zoomX: 0, zoomY: 0, @@ -477,7 +483,7 @@ // Background grid pattern var scale = this.state.scale; - var g = TheGraph.config.nodeSize * scale; + var g = this.props.grid * scale; var dx = this.state.x % g; var dy = this.state.y % g; @@ -566,6 +572,8 @@ var graphElementOptions = { graph: this.props.graph, scale: this.state.scale, + grid: this.props.grid, + snap: this.props.snap, app: this, library: this.props.library, onNodeSelection: this.props.onNodeSelection, diff --git a/the-graph/the-graph-graph.js b/the-graph/the-graph-graph.js index 7c5e314a..27cc913d 100644 --- a/the-graph/the-graph-graph.js +++ b/the-graph/the-graph-graph.js @@ -194,7 +194,7 @@ }); } else { // Snap to grid - var snap = TheGraph.config.nodeHeight / 2; + var snap = this.props.snap; graph.setNodeMetadata(node.id, { x: Math.round(node.metadata.x/snap) * snap, y: Math.round(node.metadata.y/snap) * snap @@ -465,6 +465,7 @@ y: node.metadata.y, label: node.metadata.label, sublabel: node.metadata.sublabel || node.component, + snap: self.props.snap, width: node.metadata.width, height: node.metadata.height, app: self.props.app, diff --git a/the-graph/the-graph-node.js b/the-graph/the-graph-node.js index 20e5dcec..e05771a5 100644 --- a/the-graph/the-graph-node.js +++ b/the-graph/the-graph-node.js @@ -183,7 +183,7 @@ // Snap to grid var snapToGrid = true; - var snap = TheGraph.config.node.snap / 2; + var snap = this.props.snap || TheGraph.config.node.snap / 2; if (snapToGrid) { var x, y; if (this.props.export) { diff --git a/the-graph/the-graph.html b/the-graph/the-graph.html index e646a74d..5d85a34f 100644 --- a/the-graph/the-graph.html +++ b/the-graph/the-graph.html @@ -1,4 +1,4 @@ - +