mirror of
https://github.com/konvajs/konva.git
synced 2025-04-29 23:37:24 +08:00
added _setPoints so that points setter methods could leverage the same logic that was in the setAttrs() method
This commit is contained in:
parent
7f8a174b51
commit
ec415c55de
72
dist/kinetic-core.js
vendored
72
dist/kinetic-core.js
vendored
@ -163,9 +163,9 @@ Kinetic.GlobalObject = {
|
||||
return obj === Object(obj);
|
||||
},
|
||||
/*
|
||||
* takes the arguments passed into a function and
|
||||
* takes the arguments passed into a function and
|
||||
* creates a point object from it. The arguments
|
||||
* can be an obect or an array
|
||||
* can be a point object or an array of two elements
|
||||
*/
|
||||
_getXY: function(arg) {
|
||||
if(arg.length === 1) {
|
||||
@ -178,6 +178,10 @@ Kinetic.GlobalObject = {
|
||||
}
|
||||
}
|
||||
},
|
||||
/*
|
||||
* val will be either a point object or an
|
||||
* array with two elements
|
||||
*/
|
||||
_setXY: function(obj, key, val) {
|
||||
if(obj[key] === undefined) {
|
||||
obj[key] = {};
|
||||
@ -199,6 +203,11 @@ Kinetic.GlobalObject = {
|
||||
}
|
||||
}
|
||||
},
|
||||
/*
|
||||
* val will be either an object with height and
|
||||
* width properties or an array with four elements
|
||||
* in which the last two elements are width and height
|
||||
*/
|
||||
_setSize: function(obj, key, val) {
|
||||
if(obj[key] === undefined) {
|
||||
obj[key] = {};
|
||||
@ -219,6 +228,33 @@ Kinetic.GlobalObject = {
|
||||
obj[key].height = val.height;
|
||||
}
|
||||
}
|
||||
},
|
||||
/*
|
||||
* val will be either an array of numbers or
|
||||
* an array of point objects
|
||||
*/
|
||||
_setPoints: function(obj, key, val) {
|
||||
/*
|
||||
* if points contains an array of objects, just set
|
||||
* the attr normally
|
||||
*/
|
||||
if(this._isObject(val[0])) {
|
||||
obj[key] = val;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* convert array of numbers into an array
|
||||
* of objects containing x, y
|
||||
*/
|
||||
var arr = [];
|
||||
for(var n = 0; n < val.length; n += 2) {
|
||||
arr.push({
|
||||
x: val[n],
|
||||
y: val[n + 1]
|
||||
});
|
||||
}
|
||||
obj[key] = arr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -418,27 +454,7 @@ Kinetic.Node.prototype = {
|
||||
go._setXY(this.attrs, key, val);
|
||||
break;
|
||||
case 'points':
|
||||
/*
|
||||
* if points contains an array of objects, just set
|
||||
* the attr normally
|
||||
*/
|
||||
if(Kinetic.GlobalObject._isObject(val[0])) {
|
||||
this.attrs[key] = config[key];
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* convert array of numbers into an array
|
||||
* of objects containing x, y
|
||||
*/
|
||||
var arr = [];
|
||||
for(var n = 0; n < val.length; n += 2) {
|
||||
arr.push({
|
||||
x: val[n],
|
||||
y: val[n + 1]
|
||||
});
|
||||
}
|
||||
this.attrs[key] = arr;
|
||||
}
|
||||
go._setPoints(this.attrs, key, val);
|
||||
break;
|
||||
case 'crop':
|
||||
go._setXY(this.attrs, key, val);
|
||||
@ -3253,10 +3269,11 @@ Kinetic.Polygon = function(config) {
|
||||
Kinetic.Polygon.prototype = {
|
||||
/**
|
||||
* set points array
|
||||
* @param {Array} points
|
||||
* @param {Array} can be an array of point objects or an array
|
||||
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] == [1,2,3,4]
|
||||
*/
|
||||
setPoints: function(points) {
|
||||
this.attrs.points = points;
|
||||
Kinetic.GlobalObject._setPoints(this.attrs, 'points', points);
|
||||
},
|
||||
/**
|
||||
* get points array
|
||||
@ -3752,10 +3769,11 @@ Kinetic.Line = function(config) {
|
||||
Kinetic.Line.prototype = {
|
||||
/**
|
||||
* set points array
|
||||
* @param {Array} points
|
||||
* @param {Array} can be an array of point objects or an array
|
||||
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] == [1,2,3,4]
|
||||
*/
|
||||
setPoints: function(points) {
|
||||
this.attrs.points = points;
|
||||
Kinetic.GlobalObject._setPoints(this.attrs, 'points', points);
|
||||
},
|
||||
/**
|
||||
* get points array
|
||||
|
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,9 +135,9 @@ Kinetic.GlobalObject = {
|
||||
return obj === Object(obj);
|
||||
},
|
||||
/*
|
||||
* takes the arguments passed into a function and
|
||||
* takes the arguments passed into a function and
|
||||
* creates a point object from it. The arguments
|
||||
* can be an obect or an array
|
||||
* can be a point object or an array of two elements
|
||||
*/
|
||||
_getXY: function(arg) {
|
||||
if(arg.length === 1) {
|
||||
@ -150,6 +150,10 @@ Kinetic.GlobalObject = {
|
||||
}
|
||||
}
|
||||
},
|
||||
/*
|
||||
* val will be either a point object or an
|
||||
* array with two elements
|
||||
*/
|
||||
_setXY: function(obj, key, val) {
|
||||
if(obj[key] === undefined) {
|
||||
obj[key] = {};
|
||||
@ -171,6 +175,11 @@ Kinetic.GlobalObject = {
|
||||
}
|
||||
}
|
||||
},
|
||||
/*
|
||||
* val will be either an object with height and
|
||||
* width properties or an array with four elements
|
||||
* in which the last two elements are width and height
|
||||
*/
|
||||
_setSize: function(obj, key, val) {
|
||||
if(obj[key] === undefined) {
|
||||
obj[key] = {};
|
||||
@ -191,6 +200,33 @@ Kinetic.GlobalObject = {
|
||||
obj[key].height = val.height;
|
||||
}
|
||||
}
|
||||
},
|
||||
/*
|
||||
* val will be either an array of numbers or
|
||||
* an array of point objects
|
||||
*/
|
||||
_setPoints: function(obj, key, val) {
|
||||
/*
|
||||
* if points contains an array of objects, just set
|
||||
* the attr normally
|
||||
*/
|
||||
if(this._isObject(val[0])) {
|
||||
obj[key] = val;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* convert array of numbers into an array
|
||||
* of objects containing x, y
|
||||
*/
|
||||
var arr = [];
|
||||
for(var n = 0; n < val.length; n += 2) {
|
||||
arr.push({
|
||||
x: val[n],
|
||||
y: val[n + 1]
|
||||
});
|
||||
}
|
||||
obj[key] = arr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
22
src/Node.js
22
src/Node.js
@ -187,27 +187,7 @@ Kinetic.Node.prototype = {
|
||||
go._setXY(this.attrs, key, val);
|
||||
break;
|
||||
case 'points':
|
||||
/*
|
||||
* if points contains an array of objects, just set
|
||||
* the attr normally
|
||||
*/
|
||||
if(Kinetic.GlobalObject._isObject(val[0])) {
|
||||
this.attrs[key] = config[key];
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* convert array of numbers into an array
|
||||
* of objects containing x, y
|
||||
*/
|
||||
var arr = [];
|
||||
for(var n = 0; n < val.length; n += 2) {
|
||||
arr.push({
|
||||
x: val[n],
|
||||
y: val[n + 1]
|
||||
});
|
||||
}
|
||||
this.attrs[key] = arr;
|
||||
}
|
||||
go._setPoints(this.attrs, key, val);
|
||||
break;
|
||||
case 'crop':
|
||||
go._setXY(this.attrs, key, val);
|
||||
|
@ -52,10 +52,11 @@ Kinetic.Line = function(config) {
|
||||
Kinetic.Line.prototype = {
|
||||
/**
|
||||
* set points array
|
||||
* @param {Array} points
|
||||
* @param {Array} can be an array of point objects or an array
|
||||
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] == [1,2,3,4]
|
||||
*/
|
||||
setPoints: function(points) {
|
||||
this.attrs.points = points;
|
||||
Kinetic.GlobalObject._setPoints(this.attrs, 'points', points);
|
||||
},
|
||||
/**
|
||||
* get points array
|
||||
|
@ -32,10 +32,11 @@ Kinetic.Polygon = function(config) {
|
||||
Kinetic.Polygon.prototype = {
|
||||
/**
|
||||
* set points array
|
||||
* @param {Array} points
|
||||
* @param {Array} can be an array of point objects or an array
|
||||
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] == [1,2,3,4]
|
||||
*/
|
||||
setPoints: function(points) {
|
||||
this.attrs.points = points;
|
||||
Kinetic.GlobalObject._setPoints(this.attrs, 'points', points);
|
||||
},
|
||||
/**
|
||||
* get points array
|
||||
|
@ -1271,6 +1271,12 @@ Test.prototype.tests = {
|
||||
line.on('dragend', function() {
|
||||
line.saveData();
|
||||
});
|
||||
|
||||
line.setPoints([1, 2, 3, 4]);
|
||||
test(line.getPoints()[0].x === 1, 'first point x should be 1');
|
||||
|
||||
line.setPoints([73, 160, 340, 23]);
|
||||
test(line.getPoints()[0].x === 73, 'first point x should be 73');
|
||||
},
|
||||
'SHAPES - add dashed line': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
|
Loading…
Reference in New Issue
Block a user