mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
get layer fix
This commit is contained in:
parent
7b83cdf8aa
commit
3c8c0831ab
10
src/Node.js
10
src/Node.js
@ -829,7 +829,11 @@
|
||||
* @memberof Kinetic.Node.prototype
|
||||
*/
|
||||
getLayer: function() {
|
||||
return this.getParent().getLayer();
|
||||
if (this.getParent()) {
|
||||
return this.getParent().getLayer();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* get stage ancestor
|
||||
@ -1005,8 +1009,8 @@
|
||||
x = config.x || 0,
|
||||
y = config.y || 0,
|
||||
canvas = new Kinetic.SceneCanvas({
|
||||
width: config.width || stage.getWidth(),
|
||||
height: config.height || stage.getHeight(),
|
||||
width: this.getWidth() || config.width || (stage ? stage.getWidth() : 0),
|
||||
height: this.getHeight() || config.height || (stage ? stage.getHeight() : 0),
|
||||
pixelRatio: 1
|
||||
}),
|
||||
context = canvas.getContext();
|
||||
|
@ -30,7 +30,24 @@ suite('Node', function() {
|
||||
|
||||
|
||||
});
|
||||
// ======================================================
|
||||
test('get layer', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Kinetic.Layer();
|
||||
var circle = new Kinetic.Circle({
|
||||
x: stage.getWidth() / 2,
|
||||
y: stage.getHeight() / 2,
|
||||
radius: 70,
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4
|
||||
});
|
||||
assert.equal(circle.getLayer(), null);
|
||||
|
||||
stage.add(layer.add(circle));
|
||||
assert.equal(circle.getLayer(), layer);
|
||||
|
||||
});
|
||||
// ======================================================
|
||||
test('setAttr', function() {
|
||||
var stage = addStage();
|
||||
@ -933,6 +950,39 @@ suite('Node', function() {
|
||||
showHit(layer);
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('node caching width minimal configuration', function(done) {
|
||||
var stage = addStage();
|
||||
var layer = new Kinetic.Layer();
|
||||
stage.add(layer);
|
||||
|
||||
var rect = new Kinetic.Rect({
|
||||
width : 50,
|
||||
height : 50,
|
||||
fill: 'green',
|
||||
stroke: 'blue',
|
||||
strokeWidth: 5,
|
||||
draggable: true
|
||||
});
|
||||
|
||||
rect.toImage({
|
||||
callback: function(imageObj) {
|
||||
assert.equal(Kinetic.Util._isElement(imageObj), true);
|
||||
var cachedShape = new Kinetic.Image({
|
||||
image: imageObj,
|
||||
draggable: true,
|
||||
stroke: 'red',
|
||||
strokeWidth: 5
|
||||
});
|
||||
|
||||
layer.add(cachedShape);
|
||||
layer.draw();
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
showHit(layer);
|
||||
});
|
||||
// ======================================================
|
||||
test('hide group', function() {
|
||||
var stage = addStage();
|
||||
|
Loading…
Reference in New Issue
Block a user