Skip to content

Commit 8c1662b

Browse files
committed
interaction tweaks
1 parent 49ac4f2 commit 8c1662b

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

demo/mindmap/index.less

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ body {
1818
// mindmap stuff
1919

2020
.Mindmap {
21-
width: 800px;
21+
width: 1200px;
2222
height: 800px;
2323
margin: 30px auto;
2424
box-shadow: 0 0 10px black inset;
@@ -41,7 +41,7 @@ body {
4141
.MindmapMovable {
4242
overflow: hidden;
4343
height: 800px;
44-
width: 800px;
44+
width: 1200px;
4545
position: absolute;
4646
top: 0;
4747
left: 0;
@@ -91,7 +91,8 @@ body {
9191

9292
&_main {
9393
padding: 20px;
94-
width: 200px;
94+
width: 250px;
95+
box-sizing: border-box;
9596
}
9697

9798
&_children {

views/mindmap/index.js

+29-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var React = require('react/addons')
99

1010
var Mindmap = React.createClass({
1111
getDefaultProps: function () {
12-
return {width: 800, height: 800}
12+
return {width: 1200, height: 800}
1313
},
1414

1515
mixins: [
@@ -60,7 +60,7 @@ var Mindmap = React.createClass({
6060
this.props.store.actions.db.nodes,
6161
20,
6262
100,
63-
200,
63+
250,
6464
this.state.heights);
6565
return positions
6666
},
@@ -115,7 +115,7 @@ var Movable = React.createClass({
115115
if (!pos) return
116116
var nx = this.state.left + pos.x
117117
, ny = this.state.top + pos.y
118-
, margin = 100
118+
, margin = 30
119119
, dx = 0
120120
, dy = 0
121121
if (nx - margin < 0) {
@@ -139,6 +139,31 @@ var Movable = React.createClass({
139139
],
140140

141141
componentWillReceiveProps: function (nextProps) {
142+
var aid = this.state.activeNode
143+
, pos = nextProps.positions.boxes[aid]
144+
if (!pos) return
145+
var nx = this.state.left + pos.x
146+
, ny = this.state.top + pos.y
147+
, margin = 30
148+
, dx = 0
149+
, dy = 0
150+
if (nx - margin < 0) {
151+
dx -= nx - margin
152+
}
153+
if (ny - margin < 0) {
154+
dy -= ny - margin
155+
}
156+
if (nx + pos.width + margin > this.props.width) {
157+
dx -= nx + pos.width + margin - this.props.width
158+
}
159+
if (ny + pos.height + margin > this.props.height) {
160+
dy -= ny + pos.height + margin - this.props.height
161+
}
162+
this.setState( {
163+
left: this.state.left + dx,
164+
top: this.state.top + dy,
165+
})
166+
/*
142167
var aid = this.props.store.view.active
143168
, ppos = this.props.positions.boxes[aid]
144169
, npos = nextProps.positions.boxes[aid]
@@ -157,6 +182,7 @@ var Movable = React.createClass({
157182
left: this.state.left + dx,
158183
top: this.state.top + dy,
159184
})
185+
*/
160186
},
161187

162188
componentDidUpdate: function (prevProps, prevState) {

0 commit comments

Comments
 (0)