mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 09:50:05 +08:00
fixed bug with setScale method and _isNumber method. Added unit tests
This commit is contained in:
17
dist/kinetic-core.js
vendored
17
dist/kinetic-core.js
vendored
@@ -163,7 +163,7 @@ Kinetic.GlobalObject = {
|
|||||||
return obj === Object(obj);
|
return obj === Object(obj);
|
||||||
},
|
},
|
||||||
_isNumber: function(obj) {
|
_isNumber: function(obj) {
|
||||||
return toString.call(obj) == '[object Number]';
|
return Object.prototype.toString.call(obj) == '[object Number]';
|
||||||
},
|
},
|
||||||
_hasMethods: function(obj) {
|
_hasMethods: function(obj) {
|
||||||
var names = [];
|
var names = [];
|
||||||
@@ -3128,7 +3128,8 @@ Kinetic.Rect.prototype = {
|
|||||||
* set width and height
|
* set width and height
|
||||||
*/
|
*/
|
||||||
setSize: function() {
|
setSize: function() {
|
||||||
this.setAttrs(arguments);
|
var size = Kinetic.GlobalObject._getSize(arguments);
|
||||||
|
this.setAttrs(size);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* return rect size
|
* return rect size
|
||||||
@@ -3304,7 +3305,8 @@ Kinetic.Image.prototype = {
|
|||||||
* set width and height
|
* set width and height
|
||||||
*/
|
*/
|
||||||
setSize: function() {
|
setSize: function() {
|
||||||
this.setAttrs(arguments);
|
var size = Kinetic.GlobalObject._getSize(arguments);
|
||||||
|
this.setAttrs(size);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* return image size
|
* return image size
|
||||||
@@ -3965,7 +3967,7 @@ Kinetic.Line = function(config) {
|
|||||||
if(!!this.attrs.lineCap) {
|
if(!!this.attrs.lineCap) {
|
||||||
context.lineCap = this.attrs.lineCap;
|
context.lineCap = this.attrs.lineCap;
|
||||||
}
|
}
|
||||||
this.fill();
|
|
||||||
this.stroke();
|
this.stroke();
|
||||||
};
|
};
|
||||||
// call super constructor
|
// call super constructor
|
||||||
@@ -4093,8 +4095,6 @@ Kinetic.Path = function(config) {
|
|||||||
var context = this.getContext();
|
var context = this.getContext();
|
||||||
var ca = this.commandsArray;
|
var ca = this.commandsArray;
|
||||||
// context position
|
// context position
|
||||||
var cpx = 0;
|
|
||||||
var cpy = 0;
|
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
for(var n = 0; n < ca.length; n++) {
|
for(var n = 0; n < ca.length; n++) {
|
||||||
var c = ca[n].command;
|
var c = ca[n].command;
|
||||||
@@ -4134,8 +4134,9 @@ Kinetic.Path.prototype = {
|
|||||||
var cs = this.attrs.commands;
|
var cs = this.attrs.commands;
|
||||||
// command chars
|
// command chars
|
||||||
var cc = ['M', 'l', 'L', 'v', 'V', 'h', 'H', 'z'];
|
var cc = ['M', 'l', 'L', 'v', 'V', 'h', 'H', 'z'];
|
||||||
// remove white spaces
|
// convert white spaces to commas
|
||||||
cs = cs.replace(new RegExp(' ', 'g'), '');
|
cs = cs.replace(new RegExp(' ', 'g'), ',');
|
||||||
|
// create pipes so that we can split the commands
|
||||||
for(var n = 0; n < cc.length; n++) {
|
for(var n = 0; n < cc.length; n++) {
|
||||||
cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
|
cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
|
||||||
}
|
}
|
||||||
|
4
dist/kinetic-core.min.js
vendored
4
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -135,7 +135,7 @@ Kinetic.GlobalObject = {
|
|||||||
return obj === Object(obj);
|
return obj === Object(obj);
|
||||||
},
|
},
|
||||||
_isNumber: function(obj) {
|
_isNumber: function(obj) {
|
||||||
return toString.call(obj) == '[object Number]';
|
return Object.prototype.toString.call(obj) == '[object Number]';
|
||||||
},
|
},
|
||||||
_hasMethods: function(obj) {
|
_hasMethods: function(obj) {
|
||||||
var names = [];
|
var names = [];
|
||||||
|
@@ -95,7 +95,8 @@ Kinetic.Image.prototype = {
|
|||||||
* set width and height
|
* set width and height
|
||||||
*/
|
*/
|
||||||
setSize: function() {
|
setSize: function() {
|
||||||
this.setAttrs(arguments);
|
var size = Kinetic.GlobalObject._getSize(arguments);
|
||||||
|
this.setAttrs(size);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* return image size
|
* return image size
|
||||||
|
@@ -41,7 +41,7 @@ Kinetic.Line = function(config) {
|
|||||||
if(!!this.attrs.lineCap) {
|
if(!!this.attrs.lineCap) {
|
||||||
context.lineCap = this.attrs.lineCap;
|
context.lineCap = this.attrs.lineCap;
|
||||||
}
|
}
|
||||||
this.fill();
|
|
||||||
this.stroke();
|
this.stroke();
|
||||||
};
|
};
|
||||||
// call super constructor
|
// call super constructor
|
||||||
|
@@ -16,8 +16,6 @@ Kinetic.Path = function(config) {
|
|||||||
var context = this.getContext();
|
var context = this.getContext();
|
||||||
var ca = this.commandsArray;
|
var ca = this.commandsArray;
|
||||||
// context position
|
// context position
|
||||||
var cpx = 0;
|
|
||||||
var cpy = 0;
|
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
for(var n = 0; n < ca.length; n++) {
|
for(var n = 0; n < ca.length; n++) {
|
||||||
var c = ca[n].command;
|
var c = ca[n].command;
|
||||||
@@ -57,8 +55,9 @@ Kinetic.Path.prototype = {
|
|||||||
var cs = this.attrs.commands;
|
var cs = this.attrs.commands;
|
||||||
// command chars
|
// command chars
|
||||||
var cc = ['M', 'l', 'L', 'v', 'V', 'h', 'H', 'z'];
|
var cc = ['M', 'l', 'L', 'v', 'V', 'h', 'H', 'z'];
|
||||||
// remove white spaces
|
// convert white spaces to commas
|
||||||
cs = cs.replace(new RegExp(' ', 'g'), '');
|
cs = cs.replace(new RegExp(' ', 'g'), ',');
|
||||||
|
// create pipes so that we can split the commands
|
||||||
for(var n = 0; n < cc.length; n++) {
|
for(var n = 0; n < cc.length; n++) {
|
||||||
cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
|
cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
|
||||||
}
|
}
|
||||||
|
@@ -77,7 +77,8 @@ Kinetic.Rect.prototype = {
|
|||||||
* set width and height
|
* set width and height
|
||||||
*/
|
*/
|
||||||
setSize: function() {
|
setSize: function() {
|
||||||
this.setAttrs(arguments);
|
var size = Kinetic.GlobalObject._getSize(arguments);
|
||||||
|
this.setAttrs(size);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* return rect size
|
* return rect size
|
||||||
|
@@ -440,6 +440,9 @@ Test.prototype.tests = {
|
|||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
stage.setScale(0.5);
|
stage.setScale(0.5);
|
||||||
|
|
||||||
|
test(stage.getScale().x === 0.5, 'stage scale x should be 0.5');
|
||||||
|
test(stage.getScale().y === 0.5, 'stage scale y should be 0.5');
|
||||||
|
|
||||||
stage.draw();
|
stage.draw();
|
||||||
},
|
},
|
||||||
@@ -460,6 +463,10 @@ Test.prototype.tests = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
stage.setScale(0.5);
|
stage.setScale(0.5);
|
||||||
|
|
||||||
|
test(stage.getScale().x === 0.5, 'stage scale x should be 0.5');
|
||||||
|
test(stage.getScale().y === 0.5, 'stage scale y should be 0.5');
|
||||||
|
|
||||||
layer.add(circle);
|
layer.add(circle);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user