Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make snap configurable property of graph editor #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions the-graph-editor/the-graph-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
Expand Down
10 changes: 9 additions & 1 deletion the-graph/the-graph-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion the-graph/the-graph-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion the-graph/the-graph-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion the-graph/the-graph.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<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">
<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">


<template>
Expand Down Expand Up @@ -98,6 +98,8 @@
this.appView = ReactDOM.render(
window.TheGraph.App({
graph: this.graph,
grid: this.grid,
snap: this.snap,
width: this.width,
minZoom: this.minZoom,
maxZoom: this.maxZoom,
Expand Down