@@ -17,7 +17,10 @@ var Blocks = function(errorHandler = null, openParameterEditor = null)
17
17
this . editable = true ;
18
18
19
19
// View center & scale
20
- this . center = { } ;
20
+ this . center = {
21
+ x : 0 ,
22
+ y : 0
23
+ } ;
21
24
this . newBlockOffset = 0 ;
22
25
this . scale = 1.3 ;
23
26
this . redrawTimeout = null ;
@@ -102,7 +105,8 @@ Blocks.prototype.run = function(selector, editable = true)
102
105
this . editable = editable ;
103
106
104
107
if ( ! this . div ) {
105
- console . log ( 'blocks.js: Unable to find ' + selector ) ;
108
+ console . error ( 'blocks.js: Unable to find ' + selector ) ;
109
+ return ;
106
110
}
107
111
108
112
// Inject the initial editor
@@ -119,7 +123,6 @@ Blocks.prototype.run = function(selector, editable = true)
119
123
var rect = Utils . domBoundingBox ( this . div ) ;
120
124
this . center . x = rect . width / 2 ;
121
125
this . center . y = rect . height / 2 ;
122
- this . newBlockOffset = 0 ;
123
126
124
127
// Listen for mouse position
125
128
this . div . addEventListener ( 'mousemove' , event => {
@@ -222,19 +225,6 @@ Blocks.prototype.showParameters = function(block) {
222
225
}
223
226
} ;
224
227
225
- /**
226
- * Gets the mouse position
227
- */
228
- Blocks . prototype . getPosition = function ( )
229
- {
230
- var position = { } ;
231
- position . x = ( this . mouseX - this . center . x ) / this . scale ;
232
- position . y = ( this . mouseY - this . center . y ) / this . scale ;
233
-
234
- return position ;
235
- } ;
236
-
237
-
238
228
Blocks . prototype . hasUndo = function ( )
239
229
{
240
230
if ( this . history === null ) {
@@ -316,8 +306,9 @@ Blocks.prototype.addBlock = function(name, type, x, y, values = {})
316
306
throw "'" + name + "' not available." ;
317
307
}
318
308
var block = new Block ( this , name , type , this . moduleTypes [ type ] [ name ] , this . id ) ;
319
- block . x = x === null ? ( - block . getWidth ( ) / 2 + this . newBlockOffset ) : x ;
320
- block . y = y === null ? ( - block . getHeight ( ) / 2 + this . newBlockOffset ) : y ;
309
+ 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 ;
321
312
if ( this . newBlockOffset < 150 ) {
322
313
this . newBlockOffset += 10 ;
323
314
}
@@ -601,7 +592,7 @@ Blocks.prototype.doRedraw = function()
601
592
'stroke-width' : 3 * this . scale
602
593
} ) ;
603
594
} catch ( error ) {
604
- console . log ( error ) ;
595
+ console . error ( error ) ;
605
596
this . linking = null ;
606
597
}
607
598
}
@@ -723,7 +714,7 @@ Blocks.prototype.showError = function(message, title = null) {
723
714
this . errorHandler ( message , title ) ;
724
715
}
725
716
else {
726
- console . log ( title , message ) ;
717
+ console . error ( title , message ) ;
727
718
}
728
719
}
729
720
@@ -950,7 +941,6 @@ Blocks.prototype.perfectScale = function()
950
941
}
951
942
952
943
var rect = this . div . getBoundingClientRect ( ) ;
953
-
954
944
var scaleA = rect . width / ( xMax - xMin ) ;
955
945
var scaleB = rect . height / ( yMax - yMin ) ;
956
946
var scale = Math . min ( scaleA , scaleB ) ;
0 commit comments