Skip to content

Commit 45c8619

Browse files
committed
Make snap configurable property of graph editor
1 parent 373b0d7 commit 45c8619

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

the-graph-editor/the-graph-editor.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
name="{{ graph.properties.name }}"
77
graph="{{nofloGraph}}"
88
menus="{{menus}}"
9+
grid="{{grid}}"
10+
snap="{{snap}}"
911
width="{{width}}" height="{{height}}"
1012
pan="{{pan}}" scale="{{scale}}"
1113
autolayout="{{autolayout}}"

the-graph/the-graph-app.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@
8888
offsetX: this.props.offsetX
8989
};
9090
},
91+
getDefaultProps: function () {
92+
return {
93+
snap: TheGraph.config.nodeSize / 2,
94+
grid: TheGraph.config.nodeSize
95+
};
96+
},
9197
zoomFactor: 0,
9298
zoomX: 0,
9399
zoomY: 0,
@@ -477,7 +483,7 @@
477483

478484
// Background grid pattern
479485
var scale = this.state.scale;
480-
var g = TheGraph.config.nodeSize * scale;
486+
var g = this.props.grid * scale;
481487

482488
var dx = this.state.x % g;
483489
var dy = this.state.y % g;
@@ -566,6 +572,8 @@
566572
var graphElementOptions = {
567573
graph: this.props.graph,
568574
scale: this.state.scale,
575+
grid: this.props.grid,
576+
snap: this.props.snap,
569577
app: this,
570578
library: this.props.library,
571579
onNodeSelection: this.props.onNodeSelection,

the-graph/the-graph-graph.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
});
195195
} else {
196196
// Snap to grid
197-
var snap = TheGraph.config.nodeHeight / 2;
197+
var snap = this.props.snap;
198198
graph.setNodeMetadata(node.id, {
199199
x: Math.round(node.metadata.x/snap) * snap,
200200
y: Math.round(node.metadata.y/snap) * snap
@@ -465,6 +465,7 @@
465465
y: node.metadata.y,
466466
label: node.metadata.label,
467467
sublabel: node.metadata.sublabel || node.component,
468+
snap: self.props.snap,
468469
width: node.metadata.width,
469470
height: node.metadata.height,
470471
app: self.props.app,

the-graph/the-graph-node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183

184184
// Snap to grid
185185
var snapToGrid = true;
186-
var snap = TheGraph.config.node.snap / 2;
186+
var snap = this.props.snap || TheGraph.config.node.snap / 2;
187187
if (snapToGrid) {
188188
var x, y;
189189
if (this.props.export) {

the-graph/the-graph.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<polymer-element name="the-graph" attributes="graph menus library width height autolayout theme selectedNodes errorNodes selectedEdges animatedEdges getMenuDef pan scale maxZoom minZoom displaySelectionGroup forceSelection offsetY offsetX" touch-action="none">
1+
<polymer-element name="the-graph" attributes="graph menus library snap width height autolayout theme selectedNodes errorNodes selectedEdges animatedEdges getMenuDef pan scale maxZoom minZoom displaySelectionGroup forceSelection offsetY offsetX" touch-action="none">
22

33

44
<template>
@@ -66,6 +66,9 @@
6666
ready: function () {
6767
this.themeChanged();
6868
},
69+
snapChanged: function () {
70+
this.appView
71+
},
6972
themeChanged: function () {
7073
this.$.svgcontainer.className = "the-graph-"+this.theme;
7174
},
@@ -98,6 +101,8 @@
98101
this.appView = ReactDOM.render(
99102
window.TheGraph.App({
100103
graph: this.graph,
104+
grid: this.grid,
105+
snap: this.snap,
101106
width: this.width,
102107
minZoom: this.minZoom,
103108
maxZoom: this.maxZoom,

0 commit comments

Comments
 (0)