fix getClientRect for container. close #85

This commit is contained in:
lavrton
2015-06-19 23:17:02 +07:00
parent 74221f396b
commit e21ea5daa2
3 changed files with 29 additions and 7 deletions

View File

@@ -5,7 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Not released][Not released] ## [Not released][Not released]
### Fixed ### Fixed
- Correct calculation in `getClientRect` method of `Konva.Line. - Correct calculation in `getClientRect` method of `Konva.Line` and `Konva.Container`.
### Changed ### Changed
- Dragging now works much better. If your pointer is out of stage content dragging will still continue. - Dragging now works much better. If your pointer is out of stage content dragging will still continue.

View File

@@ -410,6 +410,12 @@
}, },
getClientRect: function(skipTransform) { getClientRect: function(skipTransform) {
var minX, minY, maxX, maxY; var minX, minY, maxX, maxY;
var selfRect = {
x: 0,
y: 0,
width: 0,
height: 0
};
this.children.each(function(child) { this.children.each(function(child) {
var rect = child.getClientRect(); var rect = child.getClientRect();
if (minX === undefined) { // initial value for first child if (minX === undefined) { // initial value for first child
@@ -426,12 +432,15 @@
}); });
var selfRect = { if (this.children.length !== 0) {
x: minX, selfRect = {
y: minY, x: minX,
width: maxX - minX, y: minY,
height: maxY - minY width: maxX - minX,
}; height: maxY - minY
};
}
if (!skipTransform) { if (!skipTransform) {
return this._transformedRect(selfRect); return this._transformedRect(selfRect);
} }

View File

@@ -1616,4 +1616,17 @@ suite('Container', function() {
layer.add(circle1, circle2, circle3); layer.add(circle1, circle2, circle3);
assert.equal(layer.getChildren().length, 3, 'layer has exactly three children'); assert.equal(layer.getChildren().length, 3, 'layer has exactly three children');
}); });
test('getClientRect - test empty case', function() {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
var group = new Konva.Group({
x : 10,
y : 10
});
group.add(new Konva.Group());
assert.deepEqual(group.getClientRect(), {x:10, y:10, width: 0, height:0});
});
}); });