Skip to content

Commit 5e5a65b

Browse files
committed
Finally solved the add block in the middle bug, final v0.4.0-beta.2
1 parent a053dcc commit 5e5a65b

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/components/blocks/block.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ Block.prototype.redraw = function(selected)
326326
if (this.lastScale != this.blocks.scale) {
327327
this.div.style.fontSize = Math.round(this.blocks.scale*this.defaultFont)+'px';
328328
this.div.style.width = Math.round(this.blocks.scale*this.getWidth())+'px';
329-
330-
this.lastScale = this.blocks.scale
329+
this.lastScale = this.blocks.scale;
331330
}
332331

333332
// Changing the circle rendering

src/components/blocks/blocks.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ Blocks.prototype.addBlock = function(name, type, x, y, values = {})
307307
}
308308
var block = new Block(this, name, type, this.moduleTypes[type][name], this.id);
309309
var rect = Utils.domBoundingBox(this.div);
310-
block.x = x === null ? (-this.center.x + rect.width/2 - block.getWidth()/2 + this.newBlockOffset) : x;
311-
block.y = y === null ? (-this.center.y + rect.height/2 - block.getHeight()/2 + this.newBlockOffset) : y;
310+
block.x = x === null ? ((-this.center.x + rect.width/2)/this.scale - block.getWidth()/2 + this.newBlockOffset) : x;
311+
block.y = y === null ? ((-this.center.y + rect.height/2)/this.scale - block.getHeight()/2 + this.newBlockOffset) : y;
312312
if (this.newBlockOffset < 150) {
313313
this.newBlockOffset += 10;
314314
}
@@ -943,11 +943,9 @@ Blocks.prototype.perfectScale = function()
943943
var rect = this.div.getBoundingClientRect();
944944
var scaleA = rect.width/(xMax-xMin);
945945
var scaleB = rect.height/(yMax-yMin);
946-
var scale = Math.min(scaleA, scaleB);
947-
948-
this.scale = scale;
949-
this.center.x = rect.width/2 - scale*(xMin+xMax)/2.0;
950-
this.center.y = rect.height/2 - scale*(yMin+yMax)/2.0;
946+
this.scale = Math.min(scaleA, scaleB);
947+
this.center.x = rect.width/2 - this.scale*(xMin+xMax)/2.0;
948+
this.center.y = rect.height/2 - this.scale*(yMin+yMax)/2.0;
951949
this.newBlockOffset = 0;
952950

953951
this.redraw();

0 commit comments

Comments
 (0)